Files: a3b9c88c4884b2b2f42a88e75023168e5f85a08a / environment.js
1558 bytesRaw
1 | const U256 = require('./u256.js') |
2 | const Address = require('./address.js') |
3 | const Block = require('./block.js') |
4 | const blockChain = require('./fakeBlockChain.js') |
5 | |
6 | module.exports = class Environment { |
7 | constructor (data) { |
8 | const block = new Block() |
9 | |
10 | const defaults = { |
11 | block: block, |
12 | // gas tank |
13 | gasPrice: 0, |
14 | gasLeft: 1000000, |
15 | gasRefund: 0, |
16 | // call infromation |
17 | address: new Address('0x0000000000000000000000000000000000000000'), |
18 | origin: new Address('0x0000000000000000000000000000000000000000'), |
19 | caller: new Address('0x0000000000000000000000000000000000000000'), |
20 | callValue: new U256(0), |
21 | callData: new Uint8Array(), |
22 | // the ROM |
23 | code: new Uint8Array(), // the current running code |
24 | // output calls |
25 | logs: [], |
26 | selfDestructAddress: new Address('0x0000000000000000000000000000000000000000'), |
27 | // more output calls |
28 | returnValue: new Uint8Array() |
29 | } |
30 | |
31 | this.state = new Map() |
32 | |
33 | Object.assign(this, defaults, data || {}) |
34 | } |
35 | |
36 | getBalance (address) { |
37 | return this.state.get(address.toString()).balance |
38 | } |
39 | |
40 | getCode (address) { |
41 | return this.state.get(address.toString()).code |
42 | } |
43 | |
44 | getBlockHash (height) { |
45 | return blockChain.getBlock(height).hash() |
46 | } |
47 | |
48 | // kernal |
49 | create (code, value) { |
50 | // STUB |
51 | } |
52 | |
53 | call (gas, address, value, data) { |
54 | // STUB |
55 | return // result |
56 | } |
57 | |
58 | callCode (gas, address, value, data) { |
59 | // STUB |
60 | return // result |
61 | } |
62 | |
63 | delegateCall (gas, address, data) { |
64 | // STUB |
65 | return // result |
66 | } |
67 | } |
68 |
Built with git-ssb-web