// Contracts can get non-constant return values from functions in other contracts. (Whereas you can't from web3/geth.) // These two contracts are meant to test this. Like so: // 1. Deploy Pong with a pongval. // 2. Deploy Ping, giving it the address of Pong. // 3. Call Ping.getPongvalRemote() using a sendTransaction... // 4. ... which retreives the value of pongval from Pong. // 5. If successful Ping.getPongval() should return the value from step 1. pragma solidity ^0.4.11; contract PongvalRetriever { int pongval_tx_retrieval_attempted = 0; function getPongvalTransactional() public returns (int){ // tells Ping how to interact with Pong. pongval_tx_retrieval_attempted = -1; return pongval_tx_retrieval_attempted; } } contract Ping is PongvalRetriever { int pongval; PongvalRetriever pvr; address creator; /********* Step 2: Deploy Ping, giving it the address of Pong. *********/ function Ping(PongvalRetriever _pongAddress) { creator = msg.sender; pongval = -1; pvr = _pongAddress; } /********* Step 3: Transactionally retrieve pongval from Pong. *********/ function getPongvalRemote() constant returns (int) { pongval = pvr.getPongvalTransactional(); return pongval; } /********* Step 5: Get pongval (which was previously retrieved from Pong via transaction) *********/ function getPongvalConstant() constant returns (int) { return pongval; } // ----------------------------------------------------------------------------------------------------------------- /********* Functions to get and set pongAddress just in case *********/ function setPongAddress(PongvalRetriever _pongAddress) { pvr = _pongAddress; } function getPongAddress() constant returns (address) { return pvr; } /**** For double-checking this contract's address ****/ function getAddress() returns (address) { return this; } /********* Standard kill() function to recover funds *********/ function kill() { if (msg.sender == creator) suicide(creator); // kills this contract and sends remaining funds back to creator } } // See Pong for deployment/use.