Files: 92b25513d4a47b5f802137f167db1b71bb72a64b / message.js
836 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 | sync: 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._vistedAgents = [] |
18 | } |
19 | |
20 | finished () { |
21 | if (this.sync) { |
22 | this._vistedAgents.pop() |
23 | } |
24 | } |
25 | |
26 | addVistedKernel (kernel) { |
27 | const parentMessage = kernel._messageQueue.currentMessage |
28 | this.hops++ |
29 | if (this.sync && parentMessage) { |
30 | this._vistedAgents = parentMessage._vistedAgents |
31 | this._vistedAgents.push(kernel) |
32 | } |
33 | } |
34 | |
35 | isCyclic (kernel) { |
36 | return this.sync && this._vistedAgents.some(process => process === kernel) |
37 | } |
38 | } |
39 |
Built with git-ssb-web