저는 AccountManager 스마트 계약서와 그 두 인스턴스 (PARTYA 및 PARTYB)를 생성했습니다. TransferAgent.transfer (AccountManager.address, AccountManager.address)를 호출 할 때 예상대로 [msg.sender]. balanceance 계정을 볼 수 있습니다. 그러나 인스턴스 (PARTYA 및 PARTYB)를 호출 할 때 (예 : TransferAgent.transfer (PARTYA.address, PARTYB.address)) 잔액에 변경 사항이 반영되지 않습니다.고결 - 외부 계약에서 스마트 계약 인스턴스를 호출하는 방법?
주소를 사용하여 TransferAgent (외부 계약)에서 AccountManager (인스턴스)를 호출하는 방법을 연구했지만 시간이 많이 걸렸습니다. 저는 변화를 반영하기 위해 균형을 잡을 수 없습니다. 어떤 제안?
환경 - 에테 리움 - 착수 프레임 워크 - 견고
{
"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 }
}