Commit 69097f452f01a61429f16530219f9f1dc548b8d3
move things around
wanderer committed on 10/27/2016, 1:54:50 PMParent: 5626d2b938fbe2739a9576eb4bf4a2bdced83d13
Files changed
environment.js | changed |
index.js | changed |
interface.js | changed |
address.js | deleted |
block.js | deleted |
deps/address.js | added |
deps/block.js | added |
deps/transaction.js | added |
deps/u256.js | added |
deps/utils.js | added |
transaction.js | deleted |
u256.js | deleted |
utils.js | deleted |
environment.js | ||
---|---|---|
@@ -1,7 +1,7 @@ | ||
1 | -const U256 = require('./u256.js') | |
2 | -const Address = require('./address.js') | |
3 | -const Block = require('./block.js') | |
1 | +const U256 = require('./deps/u256.js') | |
2 | +const Address = require('./deps/address.js') | |
3 | +const Block = require('./deps/block.js') | |
4 | 4 | const fakeBlockChain = require('./fakeBlockChain.js') |
5 | 5 | |
6 | 6 | module.exports = class Environment { |
7 | 7 | constructor (data) { |
index.js | ||
---|---|---|
@@ -18,12 +18,12 @@ | ||
18 | 18 | // The Kernel Stores all of its state in the Environment. The Interface is used |
19 | 19 | // to by the VM to retrive infromation from the Environment. |
20 | 20 | const Environment = require('./environment.js') |
21 | 21 | const DebugInterface = require('./debugInterface.js') |
22 | -const Address = require('./address.js') | |
23 | -const U256 = require('./u256.js') | |
24 | -const Utils = require('./utils.js') | |
25 | -const Transaction = require('./transaction.js') | |
22 | +const Address = require('./deps/address.js') | |
23 | +const U256 = require('./deps/u256.js') | |
24 | +const Utils = require('./deps/utils.js') | |
25 | +const Transaction = require('./deps/transaction.js') | |
26 | 26 | const Precompile = require('./precompile.js') |
27 | 27 | |
28 | 28 | const identityContract = new Address('0x0000000000000000000000000000000000000004') |
29 | 29 | const meteringContract = new Address('0x000000000000000000000000000000000000000A') |
interface.js | ||
---|---|---|
@@ -1,10 +1,10 @@ | ||
1 | 1 | /** |
2 | 2 | * This is the Ethereum interface that is exposed to the WASM instance which |
3 | 3 | * enables to interact with the Ethereum Environment |
4 | 4 | */ |
5 | -const Address = require('./address.js') | |
6 | -const U256 = require('./u256.js') | |
5 | +const Address = require('./deps/address.js') | |
6 | +const U256 = require('./deps/u256.js') | |
7 | 7 | const fs = require('fs') |
8 | 8 | const path = require('path') |
9 | 9 | |
10 | 10 | const U128_SIZE_BYTES = 16 |
@@ -498,12 +498,15 @@ | ||
498 | 498 | * from Memory |
499 | 499 | * @param {interger} pathOffest the memory offset to load the the path from |
500 | 500 | * @param {interger} valueOffset the memory offset to load the value from |
501 | 501 | */ |
502 | - storageStore (pathOffset, valueOffset) { | |
502 | + storageStore (pathOffset, valueOffset, cbDest) { | |
503 | + console.log('sstore'); | |
503 | 504 | const path = new Buffer(this.getMemory(pathOffset, U256_SIZE_BYTES)).toString('hex') |
504 | 505 | // copy the value |
505 | 506 | const value = this.getMemory(valueOffset, U256_SIZE_BYTES).slice(0) |
507 | + console.log('value:' + value) | |
508 | + console.log('path:' + path) | |
506 | 509 | const oldValue = this.environment.state.get(path) |
507 | 510 | const valIsZero = value.every((i) => i === 0) |
508 | 511 | |
509 | 512 | this.takeGas(5000) |
@@ -519,21 +522,30 @@ | ||
519 | 522 | this.environment.state.delete(path) |
520 | 523 | } else { |
521 | 524 | this.environment.state.set(path, value) |
522 | 525 | } |
526 | + | |
527 | + setTimeout(() => { | |
528 | + this.module.exports['0']() | |
529 | + }, 0) | |
523 | 530 | } |
524 | 531 | |
525 | 532 | /** |
526 | 533 | * reterives a value at a given path in long term storage |
527 | 534 | * @param {interger} pathOffest the memory offset to load the the path from |
528 | 535 | * @param {interger} resultOffset the memory offset to load the value from |
529 | 536 | */ |
530 | - storageLoad (pathOffset, resultOffset) { | |
537 | + storageLoad (pathOffset, resultOffset, cbDest) { | |
538 | + console.log('sload'); | |
531 | 539 | this.takeGas(50) |
532 | 540 | |
533 | 541 | const path = new Buffer(this.getMemory(pathOffset, U256_SIZE_BYTES)).toString('hex') |
542 | + console.log(path); | |
534 | 543 | const result = this.environment.state.get(path) || new Uint8Array(32) |
535 | 544 | this.setMemory(resultOffset, U256_SIZE_BYTES, result) |
545 | + setTimeout(() => { | |
546 | + this.module.exports['0']() | |
547 | + }, 0) | |
536 | 548 | } |
537 | 549 | |
538 | 550 | /** |
539 | 551 | * Halt execution returning output data. |
address.js | ||
---|---|---|
@@ -1,42 +1,0 @@ | ||
1 | -const BN = require('bn.js') | |
2 | -const U256 = require('./u256.js') | |
3 | - | |
4 | -module.exports = class Address extends U256 { | |
5 | - constructor (value) { | |
6 | - super(value) | |
7 | - if (this._value.byteLength() > 20) { | |
8 | - throw new Error('Invalid address length: ' + this._value.byteLength() + ' for ' + value) | |
9 | - } | |
10 | - } | |
11 | - | |
12 | - // This assumes Uint8Array in LSB (WASM code) | |
13 | - static fromMemory (value) { | |
14 | - return new Address(new BN(value, 16, 'le')) | |
15 | - } | |
16 | - | |
17 | - // This assumes Uint8Array in LSB (WASM code) | |
18 | - toMemory () { | |
19 | - return this._value.toBuffer('le', 20) | |
20 | - } | |
21 | - | |
22 | - toBuffer () { | |
23 | - return super.toBuffer(20) | |
24 | - } | |
25 | - | |
26 | - // Needs to be displayed as a hex always | |
27 | - toString () { | |
28 | - return '0x' + this._value.toString('hex', 40) | |
29 | - } | |
30 | - | |
31 | - static zero () { | |
32 | - return new Address('0x0000000000000000000000000000000000000000') | |
33 | - } | |
34 | - | |
35 | - isZero () { | |
36 | - return this._value.isZero() | |
37 | - } | |
38 | - | |
39 | - equals (address) { | |
40 | - return this.toString() === address.toString() | |
41 | - } | |
42 | -} |
block.js | ||
---|---|---|
@@ -1,31 +1,0 @@ | ||
1 | -// | |
2 | -// This class parses a serialised Ethereum Block | |
3 | -// | |
4 | -// The input is a Buffer. | |
5 | -// | |
6 | -const Address = require('./address.js') | |
7 | -const ethUtil = require('ethereumjs-util') | |
8 | -const OldBlock = require('ethereumjs-block') | |
9 | -const U256 = require('./u256.js') | |
10 | - | |
11 | -module.exports = class Block extends OldBlock { | |
12 | - get number () { | |
13 | - return ethUtil.bufferToInt(this.header.number) | |
14 | - } | |
15 | - | |
16 | - get gasLimit () { | |
17 | - return ethUtil.bufferToInt(this.header.gasLimit) | |
18 | - } | |
19 | - | |
20 | - get difficulty () { | |
21 | - return new U256(this.header.difficulty) | |
22 | - } | |
23 | - | |
24 | - get timestamp () { | |
25 | - return ethUtil.bufferToInt(this.header.timestamp) | |
26 | - } | |
27 | - | |
28 | - get coinbase () { | |
29 | - return new Address(this.header.coinbase) | |
30 | - } | |
31 | -} |
deps/address.js | ||
---|---|---|
@@ -1,0 +1,42 @@ | ||
1 | +const BN = require('bn.js') | |
2 | +const U256 = require('./u256.js') | |
3 | + | |
4 | +module.exports = class Address extends U256 { | |
5 | + constructor (value) { | |
6 | + super(value) | |
7 | + if (this._value.byteLength() > 20) { | |
8 | + throw new Error('Invalid address length: ' + this._value.byteLength() + ' for ' + value) | |
9 | + } | |
10 | + } | |
11 | + | |
12 | + // This assumes Uint8Array in LSB (WASM code) | |
13 | + static fromMemory (value) { | |
14 | + return new Address(new BN(value, 16, 'le')) | |
15 | + } | |
16 | + | |
17 | + // This assumes Uint8Array in LSB (WASM code) | |
18 | + toMemory () { | |
19 | + return this._value.toBuffer('le', 20) | |
20 | + } | |
21 | + | |
22 | + toBuffer () { | |
23 | + return super.toBuffer(20) | |
24 | + } | |
25 | + | |
26 | + // Needs to be displayed as a hex always | |
27 | + toString () { | |
28 | + return '0x' + this._value.toString('hex', 40) | |
29 | + } | |
30 | + | |
31 | + static zero () { | |
32 | + return new Address('0x0000000000000000000000000000000000000000') | |
33 | + } | |
34 | + | |
35 | + isZero () { | |
36 | + return this._value.isZero() | |
37 | + } | |
38 | + | |
39 | + equals (address) { | |
40 | + return this.toString() === address.toString() | |
41 | + } | |
42 | +} |
deps/block.js | ||
---|---|---|
@@ -1,0 +1,31 @@ | ||
1 | +// | |
2 | +// This class parses a serialised Ethereum Block | |
3 | +// | |
4 | +// The input is a Buffer. | |
5 | +// | |
6 | +const Address = require('./address.js') | |
7 | +const ethUtil = require('ethereumjs-util') | |
8 | +const OldBlock = require('ethereumjs-block') | |
9 | +const U256 = require('./u256.js') | |
10 | + | |
11 | +module.exports = class Block extends OldBlock { | |
12 | + get number () { | |
13 | + return ethUtil.bufferToInt(this.header.number) | |
14 | + } | |
15 | + | |
16 | + get gasLimit () { | |
17 | + return ethUtil.bufferToInt(this.header.gasLimit) | |
18 | + } | |
19 | + | |
20 | + get difficulty () { | |
21 | + return new U256(this.header.difficulty) | |
22 | + } | |
23 | + | |
24 | + get timestamp () { | |
25 | + return ethUtil.bufferToInt(this.header.timestamp) | |
26 | + } | |
27 | + | |
28 | + get coinbase () { | |
29 | + return new Address(this.header.coinbase) | |
30 | + } | |
31 | +} |
deps/transaction.js | ||
---|---|---|
@@ -1,0 +1,49 @@ | ||
1 | +// | |
2 | +// This class parses a serialised Ethereum transaction | |
3 | +// | |
4 | +// The input is a Buffer. | |
5 | +// | |
6 | +const Address = require('./address.js') | |
7 | +const U256 = require('./u256.js') | |
8 | +const OldTx = require('ethereumjs-tx') | |
9 | + | |
10 | +module.exports = class Transaction { | |
11 | + constructor (tx) { | |
12 | + this._tx = new OldTx(tx) | |
13 | + } | |
14 | + | |
15 | + get valid () { | |
16 | + return this._tx.verifySignature() | |
17 | + } | |
18 | + | |
19 | + get nonce () { | |
20 | + return new U256(this._tx.nonce) | |
21 | + } | |
22 | + | |
23 | + get gasPrice () { | |
24 | + return new U256(this._tx.gasPrice) | |
25 | + } | |
26 | + | |
27 | + get gasLimit () { | |
28 | + return new U256(this._tx.gasLimit) | |
29 | + } | |
30 | + | |
31 | + get value () { | |
32 | + return new U256(this._tx.value) | |
33 | + } | |
34 | + | |
35 | + get data () { | |
36 | + return Uint8Array.from(this._tx.data) | |
37 | + } | |
38 | + | |
39 | + get from () { | |
40 | + return new Address(this._tx.getSenderAddress()) | |
41 | + } | |
42 | + | |
43 | + get to () { | |
44 | + if (this._tx.to.length === 0) { | |
45 | + return new Address('0x0000000000000000000000000000000000000000') | |
46 | + } | |
47 | + return new Address(this._tx.to) | |
48 | + } | |
49 | +} |
deps/u256.js | ||
---|---|---|
@@ -1,0 +1,65 @@ | ||
1 | +const BN = require('bn.js') | |
2 | +const ethUtil = require('ethereumjs-util') | |
3 | + | |
4 | +module.exports = class U256 { | |
5 | + constructor (value) { | |
6 | + // bn.js still doesn't support hex prefixes... | |
7 | + if ((typeof value === 'string') && ethUtil.isHexPrefixed(value)) { | |
8 | + this._value = new BN(ethUtil.stripHexPrefix(value), 16) | |
9 | + } else { | |
10 | + this._value = new BN(value, 10) | |
11 | + } | |
12 | + } | |
13 | + | |
14 | + // This assumes Uint8Array in LSB (WASM code) | |
15 | + static fromMemory (value) { | |
16 | + return new U256(new BN(value, 16, 'le')) | |
17 | + } | |
18 | + | |
19 | + // This assumes Uint8Array in LSB (WASM code) | |
20 | + toMemory (width) { | |
21 | + return this._value.toBuffer('le', width || 32) | |
22 | + } | |
23 | + | |
24 | + toString (radix = 10) { | |
25 | + if (radix === 16) { | |
26 | + return '0x' + this._value.toString(16) | |
27 | + } | |
28 | + return this._value.toString(radix) | |
29 | + } | |
30 | + | |
31 | + toBuffer (width) { | |
32 | + if (width <= 0 || width > 32) { | |
33 | + throw new Error('Invalid U256 width') | |
34 | + } | |
35 | + return this._value.toBuffer('be', width || 32) | |
36 | + } | |
37 | + | |
38 | + isZero () { | |
39 | + return this._value.isZero() | |
40 | + } | |
41 | + | |
42 | + sub (u256) { | |
43 | + return new U256(this._value.sub(u256._value)) | |
44 | + } | |
45 | + | |
46 | + add (u256) { | |
47 | + return new U256(this._value.add(u256._value)) | |
48 | + } | |
49 | + | |
50 | + mul (u256) { | |
51 | + return new U256(this._value.mul(u256._value)) | |
52 | + } | |
53 | + | |
54 | + div (u256) { | |
55 | + return new U256(this._value.div(u256._value)) | |
56 | + } | |
57 | + | |
58 | + lt (u256) { | |
59 | + return this._value.lt(u256._value) | |
60 | + } | |
61 | + | |
62 | + gt (u256) { | |
63 | + return this._value.gt(u256._value) | |
64 | + } | |
65 | +} |
deps/utils.js | ||
---|---|---|
@@ -1,0 +1,14 @@ | ||
1 | +const ethUtil = require('ethereumjs-util') | |
2 | +const Address = require('./address.js') | |
3 | + | |
4 | +var Utils = {} | |
5 | + | |
6 | +Utils.isWASMCode = function (code) { | |
7 | + return code.slice(0, 4).toString() === new Uint8Array([0, 0x61, 0x73, 0x6d]).toString() | |
8 | +} | |
9 | + | |
10 | +Utils.newAccountAddress = function (sender, data) { | |
11 | + return new Address('0x' + ethUtil.sha3(Buffer.concat([ sender.toBuffer(), Buffer.from(data) ])).slice(0, 20).toString('hex')) | |
12 | +} | |
13 | + | |
14 | +module.exports = Utils |
transaction.js | ||
---|---|---|
@@ -1,49 +1,0 @@ | ||
1 | -// | |
2 | -// This class parses a serialised Ethereum transaction | |
3 | -// | |
4 | -// The input is a Buffer. | |
5 | -// | |
6 | -const Address = require('./address.js') | |
7 | -const U256 = require('./u256.js') | |
8 | -const OldTx = require('ethereumjs-tx') | |
9 | - | |
10 | -module.exports = class Transaction { | |
11 | - constructor (tx) { | |
12 | - this._tx = new OldTx(tx) | |
13 | - } | |
14 | - | |
15 | - get valid () { | |
16 | - return this._tx.verifySignature() | |
17 | - } | |
18 | - | |
19 | - get nonce () { | |
20 | - return new U256(this._tx.nonce) | |
21 | - } | |
22 | - | |
23 | - get gasPrice () { | |
24 | - return new U256(this._tx.gasPrice) | |
25 | - } | |
26 | - | |
27 | - get gasLimit () { | |
28 | - return new U256(this._tx.gasLimit) | |
29 | - } | |
30 | - | |
31 | - get value () { | |
32 | - return new U256(this._tx.value) | |
33 | - } | |
34 | - | |
35 | - get data () { | |
36 | - return Uint8Array.from(this._tx.data) | |
37 | - } | |
38 | - | |
39 | - get from () { | |
40 | - return new Address(this._tx.getSenderAddress()) | |
41 | - } | |
42 | - | |
43 | - get to () { | |
44 | - if (this._tx.to.length === 0) { | |
45 | - return new Address('0x0000000000000000000000000000000000000000') | |
46 | - } | |
47 | - return new Address(this._tx.to) | |
48 | - } | |
49 | -} |
u256.js | ||
---|---|---|
@@ -1,65 +1,0 @@ | ||
1 | -const BN = require('bn.js') | |
2 | -const ethUtil = require('ethereumjs-util') | |
3 | - | |
4 | -module.exports = class U256 { | |
5 | - constructor (value) { | |
6 | - // bn.js still doesn't support hex prefixes... | |
7 | - if ((typeof value === 'string') && ethUtil.isHexPrefixed(value)) { | |
8 | - this._value = new BN(ethUtil.stripHexPrefix(value), 16) | |
9 | - } else { | |
10 | - this._value = new BN(value, 10) | |
11 | - } | |
12 | - } | |
13 | - | |
14 | - // This assumes Uint8Array in LSB (WASM code) | |
15 | - static fromMemory (value) { | |
16 | - return new U256(new BN(value, 16, 'le')) | |
17 | - } | |
18 | - | |
19 | - // This assumes Uint8Array in LSB (WASM code) | |
20 | - toMemory (width) { | |
21 | - return this._value.toBuffer('le', width || 32) | |
22 | - } | |
23 | - | |
24 | - toString (radix = 10) { | |
25 | - if (radix === 16) { | |
26 | - return '0x' + this._value.toString(16) | |
27 | - } | |
28 | - return this._value.toString(radix) | |
29 | - } | |
30 | - | |
31 | - toBuffer (width) { | |
32 | - if (width <= 0 || width > 32) { | |
33 | - throw new Error('Invalid U256 width') | |
34 | - } | |
35 | - return this._value.toBuffer('be', width || 32) | |
36 | - } | |
37 | - | |
38 | - isZero () { | |
39 | - return this._value.isZero() | |
40 | - } | |
41 | - | |
42 | - sub (u256) { | |
43 | - return new U256(this._value.sub(u256._value)) | |
44 | - } | |
45 | - | |
46 | - add (u256) { | |
47 | - return new U256(this._value.add(u256._value)) | |
48 | - } | |
49 | - | |
50 | - mul (u256) { | |
51 | - return new U256(this._value.mul(u256._value)) | |
52 | - } | |
53 | - | |
54 | - div (u256) { | |
55 | - return new U256(this._value.div(u256._value)) | |
56 | - } | |
57 | - | |
58 | - lt (u256) { | |
59 | - return this._value.lt(u256._value) | |
60 | - } | |
61 | - | |
62 | - gt (u256) { | |
63 | - return this._value.gt(u256._value) | |
64 | - } | |
65 | -} |
utils.js | ||
---|---|---|
@@ -1,14 +1,0 @@ | ||
1 | -const ethUtil = require('ethereumjs-util') | |
2 | -const Address = require('./address.js') | |
3 | - | |
4 | -var Utils = {} | |
5 | - | |
6 | -Utils.isWASMCode = function (code) { | |
7 | - return code.slice(0, 4).toString() === new Uint8Array([0, 0x61, 0x73, 0x6d]).toString() | |
8 | -} | |
9 | - | |
10 | -Utils.newAccountAddress = function (sender, data) { | |
11 | - return new Address('0x' + ethUtil.sha3(Buffer.concat([ sender.toBuffer(), Buffer.from(data) ])).slice(0, 20).toString('hex')) | |
12 | -} | |
13 | - | |
14 | -module.exports = Utils |
Built with git-ssb-web