Files: 8ced6c46cc8f744d128a65d00c117a79e68918b8 / message.js
951 bytesRaw
1 | const U256 = require('./deps/u256.js') |
2 | |
3 | module.exports = class Message { |
4 | constructor (opts = {}) { |
5 | const defaults = { |
6 | // call infromation |
7 | to: [], |
8 | from: [], |
9 | data: new Uint8Array(), |
10 | atomic: true, |
11 | // resource info |
12 | gas: new U256(0), |
13 | gasPrices: new U256(0) |
14 | } |
15 | Object.assign(this, defaults, opts) |
16 | this.hops = 0 |
17 | this._vistedKernels = [] |
18 | this._resultPromise = new Promise((resolve, reject) => { |
19 | this._resolve = resolve |
20 | }) |
21 | } |
22 | |
23 | _finish () { |
24 | if (this.atomic) { |
25 | this._vistedKernels.pop() |
26 | } |
27 | } |
28 | |
29 | _respond (result) { |
30 | this._resolve(result) |
31 | } |
32 | |
33 | result () { |
34 | return this._resultPromise |
35 | } |
36 | |
37 | nextPort () { |
38 | return this.to[this.hops++] |
39 | } |
40 | |
41 | addVistedKernel (kernel) { |
42 | if (this.atomic) { |
43 | this._vistedKernels.push(kernel) |
44 | } |
45 | } |
46 | |
47 | isCyclic (kernel) { |
48 | return this.atomic && this._vistedKernels.some(process => process === kernel) |
49 | } |
50 | } |
51 |
Built with git-ssb-web