Commit 553fa6781ed17dced2be7e810acef66344511e72
Kernel: map out callHandler layout
Alex Beregszaszi committed on 8/23/2016, 12:27:46 AMParent: b980b56bceafa5b9e36547c7963484662f2e36c3
Files changed
index.js | changed |
index.js | ||
---|---|---|
@@ -29,8 +29,10 @@ | ||
29 | 29 | this.environment = environment |
30 | 30 | } |
31 | 31 | |
32 | 32 | // handles running code. |
33 | + // NOTE: it assumes that wasm will raise an exception if something went wrong, | |
34 | + // otherwise execution succeeded | |
33 | 35 | static codeHandler (code, ethInterface = new Interface(new Environment())) { |
34 | 36 | const debugInterface = new DebugInterface(ethInterface.environment) |
35 | 37 | |
36 | 38 | const instance = Wasm.instantiateModule(code, { |
@@ -76,9 +78,28 @@ | ||
76 | 78 | |
77 | 79 | // run tx; the tx message handler |
78 | 80 | runTx (tx, environment = new Environment()) { |
79 | 81 | // verify tx then send to call Handler |
80 | - this.callHandler(tx, environment) | |
82 | + // - from account has enough balance | |
83 | + // - check nonce | |
84 | + // - ecrecover | |
85 | + // new ethTx(tx).validate(tx) | |
86 | + // - reduce balance | |
87 | + | |
88 | + // Contract deployment | |
89 | + const isDeployment = tx.data && !tx.to; | |
90 | + if (isDeployment) { | |
91 | + this.environment.accounts.set(new Uint8Array()) | |
92 | + } | |
93 | + | |
94 | + var toAccount = this.environment.accounts.get(new Uint8Array(tx.to).toString()) | |
95 | + var fromAccount = this.environment.accounts.get(new Uint8Array(tx.form).toString()) | |
96 | + | |
97 | + if (!toAccount) { | |
98 | + throw new Error('Account not found') | |
99 | + } | |
100 | + | |
101 | + this.callHandler(account.codeHash, environment) | |
81 | 102 | } |
82 | 103 | |
83 | 104 | // run block; the block message handler |
84 | 105 | runBlock (block, environment = new Environment()) { |
Built with git-ssb-web