-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathenvironment.js
105 lines (94 loc) · 2.64 KB
/
environment.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
const Vertex = require('merkle-trie')
const Store = require('merkle-trie/store')
const U256 = require('./deps/u256.js')
const Address = require('./deps/address.js')
const Block = require('./deps/block.js')
// TODO remove fakeblockchain
const fakeBlockChain = require('./fakeBlockChain.js')
module.exports = class Environment {
constructor (data = {}) {
const defaults = {
block: new Block(),
blockchain: fakeBlockChain,
coinbase: new Address('0x0000000000000000000000000000000000000000'),
// gas tank
gasPrice: 0,
gasLeft: 1000000,
gasRefund: 0,
// call infromation
address: new Address('0x0000000000000000000000000000000000000000'),
origin: new Address('0x0000000000000000000000000000000000000000'),
caller: new Address('0x0000000000000000000000000000000000000000'),
callValue: new U256(0),
callData: new Uint8Array(),
// the ROM
code: new Uint8Array(), // the current running code
// output calls
logs: [],
selfDestruct: false,
selfDestructAddress: new Address('0x0000000000000000000000000000000000000000'),
// more output calls
returnValue: new Uint8Array(),
state: new Vertex({store: new Store()})
}
Object.assign(this, defaults, data)
}
isAccountPresent (address) {
// const account = this.state.get(address.toString())
// if (account) {
// return true
// } else {
// return false
// }
}
getBalance (address) {
// const account = this.state.get(address.toString())
// if (account) {
// return account.get('balance')
// } else {
// return new U256()
// }
}
getCode (address) {
// const account = this.state.get(address.toString())
// if (account) {
// return account.get('code')
// } else {
// return Uint8Array.from(new Buffer([]))
// }
}
async getBlockHash (height) {
const block = await this.blockchain.getBlock(height)
return block.hash()
}
set createHandler (value) {
this.createhandler = value
}
set callHandler (value) {
this.callhandler = value
}
// kernal
create (code, value) {
// STUB
return [ 1, Address.zero() ]
}
call (gas, address, value, data) {
// FIXME: create a child environment here
const ret = this.root.messagehandler({
from: this.address,
to: address,
gasLimit: gas,
value: value,
data: data
})
return [ !!ret.executionOutcome, ret.returnValue ]
}
callCode (gas, address, value, data) {
// STUB
return [ 1, new Uint8Array() ]
}
delegateCall (gas, address, data) {
// STUB
return [ 1, new Uint8Array() ]
}
}