Skip to content

Commit e8c7849

Browse files
committed
compatible for contract tx
1 parent db013f3 commit e8c7849

4 files changed

Lines changed: 279 additions & 1 deletion

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "chainsql-binary-codec",
3-
"version": "0.1.35",
3+
"version": "0.1.35 ",
44
"description": "chainsql binary codec",
55
"files": [
66
"distrib/npm/*",

src/enums/definitions.json

Lines changed: 211 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"Hash128": 4,
66
"Blob": 7,
77
"AccountID": 8,
8+
"STEntry": 9,
89
"Amount": 6,
910
"Hash256": 5,
1011
"UInt8": 16,
@@ -241,6 +242,26 @@
241242
"type": "UInt32"
242243
}
243244
],
245+
[
246+
"TxnLgrSeq",
247+
{
248+
"nth": 50,
249+
"isVLEncoded": false,
250+
"isSerialized": true,
251+
"isSigningField": true,
252+
"type": "UInt32"
253+
}
254+
],
255+
[
256+
"CreateLgrSeq",
257+
{
258+
"nth": 51,
259+
"isVLEncoded": false,
260+
"isSerialized": true,
261+
"isSigningField": true,
262+
"type": "UInt32"
263+
}
264+
],
244265
[
245266
"NeedVerify",
246267
{
@@ -251,6 +272,16 @@
251272
"type": "UInt32"
252273
}
253274
],
275+
[
276+
"Gas",
277+
{
278+
"nth": 55,
279+
"isVLEncoded": false,
280+
"isSerialized": true,
281+
"isSigningField": true,
282+
"type": "UInt32"
283+
}
284+
],
254285
[
255286
"HighQualityIn",
256287
{
@@ -721,6 +752,86 @@
721752
"type": "Hash256"
722753
}
723754
],
755+
[
756+
"PrevTxnLedgerHash",
757+
{
758+
"nth": 50,
759+
"isVLEncoded": false,
760+
"isSerialized": false,
761+
"isSigningField": false,
762+
"type": "Hash256"
763+
}
764+
],
765+
[
766+
"TxnLedgerHash",
767+
{
768+
"nth": 51,
769+
"isVLEncoded": false,
770+
"isSerialized": false,
771+
"isSigningField": false,
772+
"type": "Hash256"
773+
}
774+
],
775+
[
776+
"TxCheckHash",
777+
{
778+
"nth": 52,
779+
"isVLEncoded": false,
780+
"isSerialized": false,
781+
"isSigningField": false,
782+
"type": "Hash256"
783+
}
784+
],
785+
[
786+
"CreatedLedgerHash",
787+
{
788+
"nth": 53,
789+
"isVLEncoded": false,
790+
"isSerialized": false,
791+
"isSigningField": false,
792+
"type": "Hash256"
793+
}
794+
],
795+
[
796+
"CreatedTxnHash",
797+
{
798+
"nth": 54,
799+
"isVLEncoded": false,
800+
"isSerialized": false,
801+
"isSigningField": false,
802+
"type": "Hash256"
803+
}
804+
],
805+
[
806+
"CurTxHash",
807+
{
808+
"nth": 55,
809+
"isVLEncoded": false,
810+
"isSerialized": false,
811+
"isSigningField": false,
812+
"type": "Hash256"
813+
}
814+
],
815+
[
816+
"FutureTxHash",
817+
{
818+
"nth": 56,
819+
"isVLEncoded": false,
820+
"isSerialized": false,
821+
"isSigningField": false,
822+
"type": "Hash256"
823+
}
824+
],
825+
[
826+
"ChainId",
827+
{
828+
"nth": 57,
829+
"isVLEncoded": false,
830+
"isSerialized": false,
831+
"isSigningField": false,
832+
"type": "Hash256"
833+
}
834+
],
724835
[
725836
"hash",
726837
{
@@ -1141,6 +1252,56 @@
11411252
"type": "Blob"
11421253
}
11431254
],
1255+
[
1256+
"InsertRule",
1257+
{
1258+
"nth": 57,
1259+
"isVLEncoded": true,
1260+
"isSerialized": true,
1261+
"isSigningField": true,
1262+
"type": "Blob"
1263+
}
1264+
],
1265+
[
1266+
"UpdateRule",
1267+
{
1268+
"nth": 58,
1269+
"isVLEncoded": true,
1270+
"isSerialized": true,
1271+
"isSigningField": true,
1272+
"type": "Blob"
1273+
}
1274+
],
1275+
[
1276+
"DeleteRule",
1277+
{
1278+
"nth": 59,
1279+
"isVLEncoded": true,
1280+
"isSerialized": true,
1281+
"isSigningField": true,
1282+
"type": "Blob"
1283+
}
1284+
],
1285+
[
1286+
"GetRule",
1287+
{
1288+
"nth": 60,
1289+
"isVLEncoded": true,
1290+
"isSerialized": true,
1291+
"isSigningField": true,
1292+
"type": "Blob"
1293+
}
1294+
],
1295+
[
1296+
"InsertCountMap",
1297+
{
1298+
"nth": 61,
1299+
"isVLEncoded": true,
1300+
"isSerialized": true,
1301+
"isSigningField": true,
1302+
"type": "Blob"
1303+
}
1304+
],
11441305
[
11451306
"TransferFeeMin",
11461307
{
@@ -1181,6 +1342,16 @@
11811342
"type": "Blob"
11821343
}
11831344
],
1345+
[
1346+
"ContractTxs",
1347+
{
1348+
"nth": 66,
1349+
"isVLEncoded": true,
1350+
"isSerialized": true,
1351+
"isSigningField": true,
1352+
"type": "Blob"
1353+
}
1354+
],
11841355
[
11851356
"Fulfillment",
11861357
{
@@ -1411,6 +1582,16 @@
14111582
"type": "STObject"
14121583
}
14131584
],
1585+
[
1586+
"Rule",
1587+
{
1588+
"nth": 51,
1589+
"isVLEncoded": false,
1590+
"isSerialized": true,
1591+
"isSigningField": true,
1592+
"type": "STObject"
1593+
}
1594+
],
14141595
[
14151596
"Signer",
14161597
{
@@ -1431,6 +1612,16 @@
14311612
"type": "STObject"
14321613
}
14331614
],
1615+
[
1616+
"Entry",
1617+
{
1618+
"nth": 1,
1619+
"isVLEncoded": false,
1620+
"isSerialized": true,
1621+
"isSigningField": true,
1622+
"type": "STEntry"
1623+
}
1624+
],
14341625
[
14351626
"ArrayEndMarker",
14361627
{
@@ -1511,6 +1702,16 @@
15111702
"type": "STArray"
15121703
}
15131704
],
1705+
[
1706+
"TableEntries",
1707+
{
1708+
"nth": 50,
1709+
"isVLEncoded": false,
1710+
"isSerialized": true,
1711+
"isSigningField": true,
1712+
"type": "STArray"
1713+
}
1714+
],
15141715
[
15151716
"Tables",
15161717
{
@@ -1521,6 +1722,16 @@
15211722
"type": "STArray"
15221723
}
15231724
],
1725+
[
1726+
"Users",
1727+
{
1728+
"nth": 52,
1729+
"isVLEncoded": false,
1730+
"isSerialized": true,
1731+
"isSigningField": true,
1732+
"type": "STArray"
1733+
}
1734+
],
15241735
[
15251736
"Majorities",
15261737
{

src/types/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ const {Hash256} = require('./hash-256');
1010
const {PathSet} = require('./path-set');
1111
const {STArray} = require('./st-array');
1212
const {STObject} = require('./st-object');
13+
const {STEntry} = require('./st_entry');
1314
const {UInt16} = require('./uint-16');
1415
const {UInt32} = require('./uint-32');
1516
const {UInt64} = require('./uint-64');
@@ -27,6 +28,7 @@ const coreTypes = {
2728
PathSet,
2829
STArray,
2930
STObject,
31+
STEntry,
3032
UInt8,
3133
UInt16,
3234
UInt32,

src/types/st-entry.js

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
'use strict';var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) {return typeof obj;} : function (obj) {return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;};var _ = require('lodash');
2+
var makeClass = require('../utils/make-class');var _require =
3+
require('../enums'),Field = _require.Field;var _require2 =
4+
require('../serdes/binary-serializer'),BinarySerializer = _require2.BinarySerializer;var
5+
ObjectEndMarker = Field.ObjectEndMarker;var _require3 =
6+
require('./serialized-type'),SerializedType = _require3.SerializedType;
7+
8+
var STEntry = makeClass({
9+
mixins: SerializedType,
10+
statics: {
11+
fromParser: function fromParser(parser, hint) {
12+
var end = typeof hint === 'number' ? parser.pos() + hint : null;
13+
var so = new this();
14+
while (!parser.end(end)) {
15+
var field = parser.readField();
16+
if (field === ObjectEndMarker) {
17+
break;
18+
}
19+
so[field] = parser.readFieldValue(field);
20+
}
21+
return so;
22+
},
23+
from: function from(value) {
24+
if (value instanceof this) {
25+
return value;
26+
}
27+
if ((typeof value === 'undefined' ? 'undefined' : _typeof(value)) === 'object') {
28+
return _.transform(value, function (so, val, key) {
29+
var field = Field[key];
30+
if (field) {
31+
so[field] = field.associatedType.from(val);
32+
} else {
33+
so[key] = val;
34+
}
35+
}, new this());
36+
}
37+
throw new Error(value + ' is unsupported');
38+
} },
39+
40+
fieldKeys: function fieldKeys() {
41+
return Object.keys(this).map(function (k) {return Field[k];}).filter(Boolean);
42+
},
43+
toJSON: function toJSON() {
44+
// Otherwise seemingly result will have same prototype as `this`
45+
var accumulator = {}; // of only `own` properties
46+
return _.transform(this, function (result, value, key) {
47+
result[key] = value && value.toJSON ? value.toJSON() : value;
48+
}, accumulator);
49+
},
50+
toBytesSink: function toBytesSink(sink) {var _this = this;var filter = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : function () {return true;};
51+
var serializer = new BinarySerializer(sink);
52+
var fields = this.fieldKeys();
53+
var sorted = _.sortBy(fields, 'ordinal');
54+
sorted.filter(filter).forEach(function (field) {
55+
var value = _this[field];
56+
if (!field.isSerialized) {
57+
return;
58+
}
59+
serializer.writeFieldAndValue(field, value);
60+
});
61+
} });
62+
63+
64+
module.exports = {
65+
STEntry: STEntry };

0 commit comments

Comments
 (0)