创建 "Transaction Handler" 智能合约

Create a "Transaction Handler" smart contract

刚接触 solidity 和 geth 作为我的实习生,我开始使用 solidity online IDE 和 geth 开发模式部署合约。我的问题是我尝试了几种不同的方法,但似乎没有任何效果。

代码:

contract Transaction {
  address public owner;
  mapping (address => uint) public balances;

  function Transaction () {
      owner = msg.sender;
  }

  function validateTransaction (address receiver, uint amount) constant returns (bool) {
    if  (balances[owner] < amount || owner == receiver || amount == 0)
        return (false);
    balances[owner] -= msg.value;
    return (true);
  }

  function transact (address receiver, uint amount) {
    if (!validateTransaction(receiver, amount))
        return ;
    balances[receiver] += msg.value;
  }

  function remove () {
      if (msg.sender == owner)
        selfdestruct(owner);
  }
}

我也试过这个 contract of a solidity tutorial 但它也没有像我预期的那样工作:

contract Coin {
    // The keyword "public" makes those variables
    // readable from outside.
    address public minter;
    mapping (address => uint) public balances;

    // Events allow light clients to react on
    // changes efficiently.
    event Sent(address from, address to, uint amount);

    // This is the constructor whose code is
    // run only when the contract is created.
    function Coin() {
        minter = msg.sender;
    }

    function mint(address receiver, uint amount) {
        if (msg.sender != minter) return;
        balances[receiver] += amount;
    }

    function send(address receiver, uint amount) {
        if (balances[msg.sender] < amount) return;
        balances[msg.sender] -= amount;
        balances[receiver] += amount;
        Sent(msg.sender, receiver, amount);
    }
}

我只是想制作一个智能合约,可以在发送方和接收方之间进行交易,但账户余额不会移动。这些函数是否只是抽象的以了解 solidity 是如何工作的,或者这真的可以改变平衡吗?感谢您的回答:)

在对 solidity 进行搜索和深入研究后,我发现这个合约确实将抽象交易转化为 HIS 数据。所以以太并没有真正发送,余额变量是这个合约的本地变量。