systemObjects.jsView |
---|
1 | | -const cbor = require('cbor') |
| 1 | +const cbor = require('borc') |
2 | 2 | |
3 | 3 | const TAGS = { |
4 | 4 | id: 41, |
5 | 5 | link: 42, |
27 | 27 | class Serializable { |
28 | 28 | serialize () { |
29 | 29 | const encoder = new cbor.Encoder() |
30 | 30 | this.encodeCBOR(encoder) |
31 | | - return encoder.read().toString('hex') |
| 31 | + return encoder.finalize() |
32 | 32 | } |
33 | 33 | |
34 | 34 | static deserialize (serialized) { |
35 | | - decoder.push(Buffer.from(serialized, 'hex')) |
36 | | - return decoder.read() |
| 35 | + return decoder.decodeFirst(serialized) |
37 | 36 | } |
38 | 37 | } |
39 | 38 | |
40 | 39 | class FunctionRef extends Serializable { |
41 | 40 | constructor (privateFunc, identifier, params, id, gas=0) { |
42 | 41 | super() |
43 | 42 | this.private = privateFunc |
44 | 43 | this.identifier = identifier |
| 44 | + if (!(id instanceof ID)) |
| 45 | + id = new ID(id) |
45 | 46 | this.destId = id |
46 | 47 | this.params = params |
47 | 48 | this.gas = gas |
48 | 49 | } |
51 | 52 | return gen.write(new cbor.Tagged(TAGS.func, [ |
52 | 53 | this.private, |
53 | 54 | this.identifier, |
54 | 55 | this.params, |
55 | | - this.destId, |
56 | | - this.gas |
| 56 | + this.destId |
57 | 57 | ])) |
58 | 58 | } |
59 | 59 | |
60 | 60 | set container (container) { |