Files: 05c4e2d027ee79f709d87c92e48f83e9cb3489ad / message.js
1042 bytesRaw
1 | const U256 = require('./deps/u256.js') |
2 | const Address = require('./deps/address.js') |
3 | |
4 | module.exports = class Message { |
5 | constructor (opts = {}) { |
6 | const defaults = { |
7 | // call infromation |
8 | to: [], |
9 | origin: new Address('0x0000000000000000000000000000000000000000'), |
10 | from: [], |
11 | data: new Uint8Array(), |
12 | sync: true, |
13 | // resource info |
14 | gas: new U256(0), |
15 | gasPrices: new U256(0) |
16 | } |
17 | Object.assign(this, defaults, opts) |
18 | this._index = 0 |
19 | this._parentProcesses = [] |
20 | } |
21 | |
22 | nextPort () { |
23 | // this.from.push(message.toPort) |
24 | this.toPort = this.to[this._index] |
25 | this._index++ |
26 | return this.toPort |
27 | } |
28 | |
29 | finished () { |
30 | if (this.sync) { |
31 | this._parentProcesses.pop() |
32 | } |
33 | } |
34 | |
35 | sending (kernel, parentMessage) { |
36 | if (this.sync && parentMessage) { |
37 | this._parentProcesses = parentMessage._parentProcesses |
38 | this._parentProcesses.push(kernel) |
39 | } |
40 | } |
41 | |
42 | isCyclic (kernel) { |
43 | return this.sync && this._parentProcesses.some(process => process === kernel) |
44 | } |
45 | } |
46 |
Built with git-ssb-web