2017-03-26 12 views
4

私はAccountManagerスマートコントラクトとその2つのインスタンス(PARTYAとPARTYB)を作成しました。 TransferAgent.transfer(AccountManager.address、AccountManager.address)を呼び出すと、アカウント[msg.sender] .balanceの更新が予想どおりに表示されます。 インスタンス(PARTYAとPARTYB)を呼び出すときしかし、例えば、バランスに反映変化はTransferAgent.transfer(PARTYA.address、PARTYB.address)は存在しません。固執 - スマート契約インスタンスを外部契約から呼び出す方法?

私はアドレスを使用してTransferAgent(外部契約)からのA​​ccountManager(インスタンス)を呼び出す方法を研究していくつかの時間を費やしているが、これに特定の何かを見つけることができませんでした。私は変化を反映するためのバランスを取ることができません。助言がありますか?

環境 - イーサリアム - 乗り出すフレームワーク を - ソリディティ

マイセットアップが

以下contracts.json

{ 
     "default": { 
     "gas": "auto", 
     "contracts": { 
      "SimpleStorage": { 
      "args": [ 
       100 
      ] 
      }, 
      "Agent" : { 
      "args": [ 
      ] 
      }, 
      "AccountManager" : { 
      "args": [ 
      ] 
      }, 
      "PARTYA" : { 
      "instanceOf" : "AccountManager", 
      "args" : [ 
      ]  
      }, 
      "PARTYB" : { 
      "instanceOf" : "AccountManager", 
      "args" : [ 
      ]  
      }, 
      "TransferAgent" : { 
      "args": [ 
      ] 
      } 
     } 
     } 
    } 

あるAgent.sol

pragma solidity ^0.4.0; 

contract Agent { 
/* Define variable owner of the type address*/ 
address owner; 

/* this function is executed at initialization and sets the owner of the contract */ 
function Agent() { owner = msg.sender; } 

/* Function to recover the funds on the contract */ 
function kill() { if (msg.sender == owner) selfdestruct(owner); } 
} 

contract AccountManager is Agent { 
enum ACTIVE { Y, N } 
enum STATUS { CREDIT, DEBIT } 
mapping (address => Account) public accounts; 

struct Account { 
    bytes32 ssn; 
    int balance; 
    ACTIVE active; 
    STATUS status; 
} 

modifier withdrawValidation(int withdrawAmt) { 
    if(withdrawAmt <= accounts[msg.sender].balance) { 
     throw; 
    } 
    _; 
} 

// Check for current account matching 
modifier transferValidation(address _from, address _to, bytes32 _ssn) { 
    if(AccountManager(_from).getSSN() != _ssn || 
      AccountManager(_to).getSSN() != _ssn || 
       AccountManager(_from).getStatus() == STATUS.CREDIT) { 
     throw; 
    } 
    _; 
} 

function register(bytes32 _ssn) public returns (bool success) { 
    Account memory newRegistree; 
    newRegistree.ssn = _ssn; 
    newRegistree.balance = 0; 
    newRegistree.active = ACTIVE.Y; 
    newRegistree.status = STATUS.DEBIT; 
    accounts[msg.sender] = newRegistree; 
    return true; 
} 

function update(bytes32 _ssn) public returns (bool success) { 
    accounts[msg.sender].ssn = _ssn; 
    return true; 
} 

function deposit(int _depositAmt) public returns(bool success) { 
    accounts[msg.sender].balance += _depositAmt; 
    return true; 
} 

function withdraw(int _withdrawAmt) public returns(bool success) { 
    accounts[msg.sender].balance = (accounts[msg.sender].balance - _withdrawAmt); 
    return true; 
} 

function getBalance() public constant returns(int balance) { 
    return accounts[msg.sender].balance; 
} 

function setBalance(int _balance) external returns(bool success) { 
    accounts[msg.sender].balance = _balance; 
    return true; 
} 

function setStatus() internal { 
    if(accounts[msg.sender].balance >= 0) 
     accounts[msg.sender].status = STATUS.DEBIT; 
    else 
     accounts[msg.sender].status = STATUS.CREDIT; 
} 

function getStatus() external constant returns (STATUS status) { 
    return accounts[msg.sender].status; 
} 

function getSSN() external constant returns(bytes32 ssn) { 
    return accounts[msg.sender].ssn; 
} 

function getAccount() public constant returns (bytes32 ssn, int balance, ACTIVE active, STATUS status) { 
    return (accounts[msg.sender].ssn, accounts[msg.sender].balance, accounts[msg.sender].active, accounts[msg.sender].status); 
} 
} 

contract TransferAgent is Agent { 
function transfer(address _from, address _to) public returns (bool success) { 
    AccountManager(_from).setBalance(100); // not working for instances PARTYA,PARTYB 
    AccountManager(_to).setBalance(200); // not working for instances PARTYA,PARTYB } 
} 

答えて

3

はここです非常にミニ他の契約にトランザクションを送信することに集中している。

「ハブ」は、2つの「スポーク」展開すると、あなたは、スポークの一つにメッセージを送信するためにfunction local()を使用することができます。イベントは両側に記録されているので、何が起こっているのかを見ることができます。

contract Hub { 

    Spoke public A; 
    Spoke public B; 

    event LogTXNSent(address spoke); 

    function Hub() { 
    A = new Spoke(); 
    B = new Spoke(); 
    } 

    function local(address spokeAddress) 
    public 
    returns(bool success) 
    { 
    if(spokeAddress != address(A) && spokeAddress != address(B)) throw; 
    if(!Spoke(spokeAddress).logEvent()) throw; 
    LogTXNSent(spokeAddress); 
    return true; 
    } 

} 

contract Spoke { 

    event LogTXNFrom(address sender); 

    function logEvent() 
    public 
    returns(bool success) 
    { 
    LogTXNFrom(msg.sender); 
    return true; 
    } 
} 

希望します。

関連する問題