git ssb

0+

wanderer🌟 / js-primea-hypervisor



Tree: 04af14cd7056250c22a08f3950f10cfa2dcbb8c8

Files: 04af14cd7056250c22a08f3950f10cfa2dcbb8c8 / environment.js

1894 bytesRaw
1const U256 = require('./u256.js')
2const Address = require('./address.js')
3const Block = require('./block.js')
4const blockChain = require('./fakeBlockChain.js')
5
6module.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 addAccount (address, trie) {
37 let account = new Map()
38 account.set('nonce', trie.nonce || new U256(0))
39 account.set('balance', trie.balance || new U256(0))
40 account.set('code', trie.code || new Uint8Array())
41 account.set('storage', trie.storage || new Map())
42
43 this.state.set(address.toString(), account)
44 }
45
46 getBalance (address) {
47 return this.state.get(address.toString())['balance']
48 }
49
50 getCode (address) {
51 return this.state.get(address.toString())['code']
52 }
53
54 getBlockHash (height) {
55 return blockChain.getBlock(height).hash()
56 }
57
58 // kernal
59 create (code, value) {
60 // STUB
61 }
62
63 call (gas, address, value, data) {
64 // STUB
65 return // result
66 }
67
68 callCode (gas, address, value, data) {
69 // STUB
70 return // result
71 }
72
73 delegateCall (gas, address, data) {
74 // STUB
75 return // result
76 }
77}
78

Built with git-ssb-web