git ssb

0+

wanderer🌟 / js-primea-hypervisor



Tree: 00d436ed0d3c6e425ef1955e0a39f2cf831fad69

Files: 00d436ed0d3c6e425ef1955e0a39f2cf831fad69 / environment.js

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

Built with git-ssb-web