git ssb

0+

wanderer🌟 / js-primea-hypervisor



Tree: 4deaaf0620b832ca0e463a1327d1d7d0ee6c8d6e

Files: 4deaaf0620b832ca0e463a1327d1d7d0ee6c8d6e / precompiles / create.js

1584 bytesRaw
1 createHandler (create) {
2 let code = create.data
3
4 // Inject metering
5 if (Utils.isWASMCode(code)) {
6 // FIXME: decide if these are the right values here: from: 0, gasLimit: 0, value: 0
7 code = this.callHandler({
8 from: Address.zero(),
9 to: meteringContract,
10 gasLimit: 0,
11 value: new U256(0),
12 data: code
13 }).returnValue
14
15 if (code[0] === 0) {
16 code = code.slice(1)
17 } else {
18 throw new Error('Metering injection failed: ' + Buffer.from(code).slice(1).toString())
19 }
20 }
21
22 let account = this.environment.state.get(create.from.toString())
23 if (!account) {
24 throw new Error('Account not found: ' + create.from.toString())
25 }
26
27 let address = Utils.newAccountAddress(create.from, account.get('nonce'))
28
29 this.environment.addAccount(address.toString(), {
30 balance: create.value,
31 code: code
32 })
33
34 // Run code and take return value as contract code
35 // FIXME: decide if these are the right values here: value: 0, data: ''
36 code = this.messageHandler({
37 from: create.from,
38 to: address,
39 gasLimit: create.gasLimit,
40 value: new U256(0),
41 data: new Uint8Array()
42 }).returnValue
43
44 // FIXME: special handling for selfdestruct
45
46 this.environment.state.get(address.toString()).set('code', code)
47
48 return {
49 executionOutcome: 1, // success
50 gasLeft: new U256(this.environment.gasLeft),
51 gasRefund: new U256(this.environment.gasRefund),
52 accountCreated: address,
53 logs: this.environment.logs
54 }
55 }
56

Built with git-ssb-web