pragma solidity ^0.4.0; import "./Oraclize.sol"; //IMPORTANT: this is just a pseudocode example, you can find the original contract code // at https://github.com/markusait/ethereumSwap/blob/master/contracts/EthereumSwap.sol#L421 contract EthereumSwap is usingOraclize { //1. This function creates an Offer struct storing the necessary information in the //deposit Map function depositEther(string _bitcoinAddress, string _bitcoinWithdrawAmount) payable { require(!deposit[_bitcoinAddress].exists, " Offer for this address already exists"); Offer memory paymentStruct = Offer({ exists: true, ethDepositInWei: msg.value, bitcoinWithdrawAmount: _bitcoinWithdrawAmount, potentialPayoutAddress: uint80(0) }); deposit[_bitcoinAddress] = paymentStruct; } //2. Here the actual API query is sent to the Oracle function getTransaction(string _txHash, string _bitcoinAddress) payable { require(deposit[_cryptoAddress].exists, "No Offer for this address available"); string memory query = strConcat("https://blockchain.info/q/txresult/", _txHash, "/", _bitcoinAddress); oraclizeID = oraclize_query("URL", query, oraclizePrice); deposit[_bitcoinAddress].potentialPayoutAddress = msg.sender; oraclizeLookup[oraclizeID] = _bitcoinAddress; } //3. Oraclize calls this function which issues the deposited ether of the Offer if the // transferred amount of the Bitcoin Tx which was looked up is correct function __callback(bytes32 _oraclizeID, string _result) public { require(msg.sender == oraclize_cbAddress(), "Only Oraclize can call this function"); string memory cryptoAddress = oraclizeLookup[_oraclizeID]; address recipientAddress = deposit[cryptoAddress].potentialPayoutAddress; uint ethAmount = deposit[cryptoAddress].ethDepositInWei; if(stringToUint(_result) >= stringToUint(deposit[cryptoAddress].cryptoWithdrawAmount)){ recipientAddress.transfer(ethAmount); deposit[_cryptoAddress].exists = false; } } }
0.4.18