Ich baue derzeit eine Dapp, die diese beiden Funktionen verwendet:
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);
}
Ich kann die Argumente für mehrere Ereignisse in der Reihenfolge auflisten, aber ich kann die Daten nicht generieren, um beispielsweise zu überprüfen, ob die Reihenfolge vorhanden ist.
Ist das richtig, um den Hash zu generieren? Ich nehme an, das ( bytes32 hash = sha256(this)
) ist die Absenderadresse?
var orderhash = web3.sha3(user, tokenGet, amountGet, tokenGive, amountGive, expires, nonce);
BEARBEITEN: Ich habe verstanden, dass web3.sha3 nicht als sha3 aus Solidität fungiert. Trotzdem kann ich es nicht richtig zum Laufen bringen und ich kann das Knotenmodul nicht installieren
Das Äquivalent von web3.sha3
ist Solidität keccak256
. Die solidity-Funktion sha256
ist ein völlig anderer Hash und hat kein Äquivalent zu web3.