-
Notifications
You must be signed in to change notification settings - Fork 4
/
transaction.js
46 lines (40 loc) · 1.02 KB
/
transaction.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
const _ = require('@keyring/util');
const msgpack = require('@msgpack/msgpack');
const DefaultOptions = {
transaction: {}
};
class TransactionFacet {
constructor(root, options={}) {
this.root = root;
this.options = Object.assign({}, DefaultOptions, options);
}
init(klass) {}
construct(tx) {
const plugin = this;
tx.msgpack = (data) => {
if(_.r.isNil(data)) {
let results = [];
tx.data().forEach((datum) => {
if(
datum
&& datum[0].toString() === '19HxigV4QyBv3tHpQVcUEQyq1pzZVdoAut'
&& datum[2].toString() == 'application/msgpack'
) {
try {
results.push(msgpack.decode(datum[1]));
} catch (err) {}
}
});
return results;
} else {
return tx.data(
'19HxigV4QyBv3tHpQVcUEQyq1pzZVdoAut',
Buffer.from(msgpack.encode(data)),
'application/msgpack',
'binary'
);
}
};
}
}
module.exports = TransactionFacet;