[Ethereum] Converting oraclize result from string to address

oraclessolidity

I am trying to set up a contract that gets an ethereum address from a json file using oraclize, and in turn i'd like to send ether to that address.

function __callback(bytes32 myid, address result) {
  if (msg.sender != oraclize_cbAddress()) throw;
  _address = result;
  if (!_address.send(_withdrawAmount)) throw;
  Withdraw(now, _withdrawAmount, this, _owner);
 }

function withdraw(uint value) {
  _withdrawAmount = value;
  oraclize_query("URL", url);
}

And here is the json

{
  "address" : "0xf519f8bf364fb6bf0185f0bacf19fb8e5c3f134a"
}

I havent been able to send ether in the __callback function and i am not sure how to resolve it.

I am guessing it is because it returns a string, so in the __callback function the type of 'result' would be a string. But how would i convert a string to an address i'd be able to send ether to?

EDIT: In addition to Xavier's answer, I found that I can't send transactions from within the callback function. So i added an executeWithdrawal function that the user would have to call to execute the transaction once the callback has been made from oraclize.

Best Answer

You need to look at other answers where parsing JSON strings is discussed. For instance here Parse JSON in Solidity

Then, when you have your string, you can use Oraclize's own helper method:

contract usingOraclize {
    function parseAddr(string _a) internal returns (address);
    ...
}

There https://github.com/oraclize/ethereum-api/blob/master/oraclizeAPI_pre0.4.sol#L149

Related Topic