1

I'm currently building a dapp that use both of theses functions :

function order(address tokenGet, uint amountGet, address tokenGive, uint amountGive, uint expires, uint nonce) {
    bytes32 hash = sha256(this, tokenGet, amountGet, tokenGive, amountGive, expires, nonce);
    orders[msg.sender][hash] = true;
    Order(tokenGet, amountGet, tokenGive, amountGive, expires, nonce, msg.sender);
  }

  function trade(address tokenGet, uint amountGet, address tokenGive, uint amountGive, uint expires, uint nonce, address user, uint8 v, bytes32 r, bytes32 s, uint amount) {
    //amount is in amountGet terms
    bytes32 hash = sha256(this, tokenGet, amountGet, tokenGive, amountGive, expires, nonce);
    if (!(
      (orders[user][hash] || ecrecover(sha3("\x19Ethereum Signed Message:\n32", hash),v,r,s) == user) &&
      block.number <= expires &&
      safeAdd(orderFills[user][hash], amount) <= amountGet
    )) throw;
    tradeBalances(tokenGet, amountGet, tokenGive, amountGive, user, amount);
    orderFills[user][hash] = safeAdd(orderFills[user][hash], amount);
    Trade(tokenGet, amount, tokenGive, amountGive * amount / amountGet, user, msg.sender);
  }

I'm able to list the multiple events arguments in Order, but I'm not able to generate the data let's say for checking if order exist.

Is that the correct what to generate the hash? I suppose this (bytes32 hash = sha256(this)) is the sender address?

var orderhash = web3.sha3(user, tokenGet, amountGet, tokenGive, amountGive, expires, nonce);

EDIT: I understood that web3.sha3 don't act as the sha3 from solidity. Still, I'm not able to get it work the correct way and I can't install node module

0

The equivalent of web3.sha3 is solidity keccak256. The solidity function sha256 is a completely different hash, and it doesn't have an equivalent with web3.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.