git ssb

0+

wanderer🌟 / js-primea-hypervisor



Tree: cfba6fdcb78b4019f623639fbd7dfecaacb4ab1c

Files: cfba6fdcb78b4019f623639fbd7dfecaacb4ab1c / runTx.js

2562 bytesRaw
1class runtx extends Kernel {
2 run (tx) {
3
4
5 }
6}
7
8
9 // run tx; the tx message handler
10 // runTx (tx, environment = new Environment()) {
11 // this.environment = environment
12
13 // if (Buffer.isBuffer(tx) || typeof tx === 'string') {
14 // tx = new Transaction(tx)
15 // if (!tx.valid) {
16 // throw new Error('Invalid transaction signature')
17 // }
18 // }
19
20 // // look up sender
21 // let fromAccount = this.environment.state.get(tx.from.toString())
22 // if (!fromAccount) {
23 // throw new Error('Sender account not found: ' + tx.from.toString())
24 // }
25
26 // if (fromAccount.get('nonce').gt(tx.nonce)) {
27 // throw new Error(`Invalid nonce: ${fromAccount.get('nonce')} > ${tx.nonce}`)
28 // }
29
30 // fromAccount.set('nonce', fromAccount.get('nonce').add(new U256(1)))
31
32 // let isCreation = false
33
34 // // Special case: contract deployment
35 // if (tx.to.isZero() && (tx.data.length !== 0)) {
36 // console.log('This is a contract deployment transaction')
37 // isCreation = true
38 // }
39
40 // // This cost will not be refunded
41 // let txCost = 21000 + (isCreation ? 32000 : 0)
42 // tx.data.forEach((item) => {
43 // if (item === 0) {
44 // txCost += 4
45 // } else {
46 // txCost += 68
47 // }
48 // })
49
50 // if (tx.gasLimit.lt(new U256(txCost))) {
51 // throw new Error(`Minimum transaction gas limit not met: ${txCost}`)
52 // }
53
54 // if (fromAccount.get('balance').lt(tx.gasLimit.mul(tx.gasPrice))) {
55 // throw new Error(`Insufficient account balance: ${fromAccount.get('balance').toString()} < ${tx.gasLimit.mul(tx.gasPrice).toString()}`)
56 // }
57
58 // // deduct gasLimit * gasPrice from sender
59 // fromAccount.set('balance', fromAccount.get('balance').sub(tx.gasLimit.mul(tx.gasPrice)))
60
61 // const handler = isCreation ? this.createHandler.bind(this) : this.callHandler.bind(this)
62 // let ret = handler({
63 // to: tx.to,
64 // from: tx.from,
65 // gasLimit: tx.gasLimit - txCost,
66 // value: tx.value,
67 // data: tx.data
68 // })
69
70 // // refund unused gas
71 // if (ret.executionOutcome === 1) {
72 // fromAccount.set('balance', fromAccount.get('balance').add(tx.gasPrice.mul(ret.gasLeft.add(ret.gasRefund))))
73 // }
74
75 // // save new state?
76
77 // return {
78 // executionOutcome: ret.executionOutcome,
79 // accountCreated: isCreation ? ret.accountCreated : undefined,
80 // returnValue: isCreation ? undefined : ret.returnValue,
81 // gasLeft: ret.gasLeft,
82 // logs: ret.logs
83 // }
84 // }
85

Built with git-ssb-web