Actualmente estoy construyendo un dapp que usa ambas funciones:
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);
}
Puedo enumerar los argumentos de eventos múltiples en Orden, pero no puedo generar los datos, digamos para verificar si existe orden.
¿Es eso lo correcto para generar el hash? ¿Supongo que esta ( bytes32 hash = sha256(this)
) es la dirección del remitente?
var orderhash = web3.sha3(user, tokenGet, amountGet, tokenGive, amountGive, expires, nonce);
EDITAR: entendí que web3.sha3 no actúa como sha3 de solidity. Aún así, no puedo hacer que funcione de la manera correcta y no puedo instalar el módulo de nodo
El equivalente de web3.sha3
es solidez keccak256
. La función de solidez sha256
es un hash completamente diferente y no tiene un equivalente con web3.