git ssb

0+

wanderer🌟 / js-primea-hypervisor



Commit 51739ba9fc171bb7d0f5e1bfee7b9021587cdede

fix lint

wanderer committed on 11/22/2016, 2:20:55 AM
Parent: 59cc2a5d79adce2a9ce41c522b086bee196c3cc7

Files changed

EVMinterface.jschanged
package.jsonchanged
precompiles/create.jschanged
runBlock.jschanged
runTx.jschanged
EVMinterface.jsView
@@ -429,11 +429,11 @@
429429 create (valueOffset, dataOffset, length, resultOffset, cbIndex) {
430430 this.takeGas(32000)
431431
432432 const value = U256.fromMemory(this.getMemory(valueOffset, U128_SIZE_BYTES))
433- if (length) {
434- const code = this.getMemory(dataOffset, length).slice(0)
435- }
433+ // if (length) {
434+ // const code = this.getMemory(dataOffset, length).slice(0)
435+ // }
436436
437437 let opPromise
438438
439439 if (value.gt(this.kernel.environment.value)) {
package.jsonView
@@ -24,9 +24,9 @@
2424 "author": "mjbecze <mjbecze@gmail.com>",
2525 "contributors": "Alex Beregszaszi <alex@rtfs.hu>",
2626 "license": "MPL-2.0",
2727 "devDependencies": {
28- "standard": "^8.5.0",
28+ "standard": "*",
2929 "tape": "^4.5.1"
3030 },
3131 "standard": {
3232 "ignore": [
precompiles/create.jsView
@@ -1,55 +1,55 @@
1- createHandler (create) {
2- let code = create.data
1+ // createHandler (create) {
2+ // let code = create.data
33
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
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
1414
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- }
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+ // }
2121
22- let account = this.environment.state.get(create.from.toString())
23- if (!account) {
24- throw new Error('Account not found: ' + create.from.toString())
25- }
22+ // let account = this.environment.state.get(create.from.toString())
23+ // if (!account) {
24+ // throw new Error('Account not found: ' + create.from.toString())
25+ // }
2626
27- let address = Utils.newAccountAddress(create.from, account.get('nonce'))
27+ // let address = Utils.newAccountAddress(create.from, account.get('nonce'))
2828
29- this.environment.addAccount(address.toString(), {
30- balance: create.value,
31- code: code
32- })
29+ // this.environment.addAccount(address.toString(), {
30+ // balance: create.value,
31+ // code: code
32+ // })
3333
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
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
4343
44- // FIXME: special handling for selfdestruct
44+ // // FIXME: special handling for selfdestruct
4545
46- this.environment.state.get(address.toString()).set('code', code)
46+ // this.environment.state.get(address.toString()).set('code', code)
4747
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- }
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+ // }
runBlock.jsView
@@ -1,10 +1,11 @@
1- // run block; the block message handler
2- runBlock(block, environment = new Environment()) {
1+// run block; the block message handler:w
2+const Environment = require('./environment')
3+
4+module.exports = class runBlock {
5+ constuctor (block, environment = new Environment()) {
36 // verify block then run each tx
47 block.tx.forEach((tx) => {
58 this.runTx(tx, environment)
69 })
710 }
8-
9- // run blockchain
10- // runBlockchain () {}
11+}
runTx.jsView
@@ -1,77 +1,77 @@
11
22 // run tx; the tx message handler
3- runTx (tx, environment = new Environment()) {
4- this.environment = environment
3+ // runTx (tx, environment = new Environment()) {
4+ // this.environment = environment
55
6- if (Buffer.isBuffer(tx) || typeof tx === 'string') {
7- tx = new Transaction(tx)
8- if (!tx.valid) {
9- throw new Error('Invalid transaction signature')
10- }
11- }
6+ // if (Buffer.isBuffer(tx) || typeof tx === 'string') {
7+ // tx = new Transaction(tx)
8+ // if (!tx.valid) {
9+ // throw new Error('Invalid transaction signature')
10+ // }
11+ // }
1212
13- // look up sender
14- let fromAccount = this.environment.state.get(tx.from.toString())
15- if (!fromAccount) {
16- throw new Error('Sender account not found: ' + tx.from.toString())
17- }
13+ // // look up sender
14+ // let fromAccount = this.environment.state.get(tx.from.toString())
15+ // if (!fromAccount) {
16+ // throw new Error('Sender account not found: ' + tx.from.toString())
17+ // }
1818
19- if (fromAccount.get('nonce').gt(tx.nonce)) {
20- throw new Error(`Invalid nonce: ${fromAccount.get('nonce')} > ${tx.nonce}`)
21- }
19+ // if (fromAccount.get('nonce').gt(tx.nonce)) {
20+ // throw new Error(`Invalid nonce: ${fromAccount.get('nonce')} > ${tx.nonce}`)
21+ // }
2222
23- fromAccount.set('nonce', fromAccount.get('nonce').add(new U256(1)))
23+ // fromAccount.set('nonce', fromAccount.get('nonce').add(new U256(1)))
2424
25- let isCreation = false
25+ // let isCreation = false
2626
27- // Special case: contract deployment
28- if (tx.to.isZero() && (tx.data.length !== 0)) {
29- console.log('This is a contract deployment transaction')
30- isCreation = true
31- }
27+ // // Special case: contract deployment
28+ // if (tx.to.isZero() && (tx.data.length !== 0)) {
29+ // console.log('This is a contract deployment transaction')
30+ // isCreation = true
31+ // }
3232
33- // This cost will not be refunded
34- let txCost = 21000 + (isCreation ? 32000 : 0)
35- tx.data.forEach((item) => {
36- if (item === 0) {
37- txCost += 4
38- } else {
39- txCost += 68
40- }
41- })
33+ // // This cost will not be refunded
34+ // let txCost = 21000 + (isCreation ? 32000 : 0)
35+ // tx.data.forEach((item) => {
36+ // if (item === 0) {
37+ // txCost += 4
38+ // } else {
39+ // txCost += 68
40+ // }
41+ // })
4242
43- if (tx.gasLimit.lt(new U256(txCost))) {
44- throw new Error(`Minimum transaction gas limit not met: ${txCost}`)
45- }
43+ // if (tx.gasLimit.lt(new U256(txCost))) {
44+ // throw new Error(`Minimum transaction gas limit not met: ${txCost}`)
45+ // }
4646
47- if (fromAccount.get('balance').lt(tx.gasLimit.mul(tx.gasPrice))) {
48- throw new Error(`Insufficient account balance: ${fromAccount.get('balance').toString()} < ${tx.gasLimit.mul(tx.gasPrice).toString()}`)
49- }
47+ // if (fromAccount.get('balance').lt(tx.gasLimit.mul(tx.gasPrice))) {
48+ // throw new Error(`Insufficient account balance: ${fromAccount.get('balance').toString()} < ${tx.gasLimit.mul(tx.gasPrice).toString()}`)
49+ // }
5050
51- // deduct gasLimit * gasPrice from sender
52- fromAccount.set('balance', fromAccount.get('balance').sub(tx.gasLimit.mul(tx.gasPrice)))
51+ // // deduct gasLimit * gasPrice from sender
52+ // fromAccount.set('balance', fromAccount.get('balance').sub(tx.gasLimit.mul(tx.gasPrice)))
5353
54- const handler = isCreation ? this.createHandler.bind(this) : this.callHandler.bind(this)
55- let ret = handler({
56- to: tx.to,
57- from: tx.from,
58- gasLimit: tx.gasLimit - txCost,
59- value: tx.value,
60- data: tx.data
61- })
54+ // const handler = isCreation ? this.createHandler.bind(this) : this.callHandler.bind(this)
55+ // let ret = handler({
56+ // to: tx.to,
57+ // from: tx.from,
58+ // gasLimit: tx.gasLimit - txCost,
59+ // value: tx.value,
60+ // data: tx.data
61+ // })
6262
63- // refund unused gas
64- if (ret.executionOutcome === 1) {
65- fromAccount.set('balance', fromAccount.get('balance').add(tx.gasPrice.mul(ret.gasLeft.add(ret.gasRefund))))
66- }
63+ // // refund unused gas
64+ // if (ret.executionOutcome === 1) {
65+ // fromAccount.set('balance', fromAccount.get('balance').add(tx.gasPrice.mul(ret.gasLeft.add(ret.gasRefund))))
66+ // }
6767
68- // save new state?
68+ // // save new state?
6969
70- return {
71- executionOutcome: ret.executionOutcome,
72- accountCreated: isCreation ? ret.accountCreated : undefined,
73- returnValue: isCreation ? undefined : ret.returnValue,
74- gasLeft: ret.gasLeft,
75- logs: ret.logs
76- }
77- }
70+ // return {
71+ // executionOutcome: ret.executionOutcome,
72+ // accountCreated: isCreation ? ret.accountCreated : undefined,
73+ // returnValue: isCreation ? undefined : ret.returnValue,
74+ // gasLeft: ret.gasLeft,
75+ // logs: ret.logs
76+ // }
77+ // }

Built with git-ssb-web