ripple-binary-codec 1.0.2 → 1.0.3-mpt-beta
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -3
- package/dist/binary.d.ts +34 -20
- package/dist/binary.js +51 -34
- package/dist/binary.js.map +1 -1
- package/dist/coretypes.d.ts +9 -9
- package/dist/coretypes.js +33 -9
- package/dist/coretypes.js.map +1 -1
- package/dist/enums/bytes.d.ts +25 -0
- package/dist/enums/bytes.js +63 -0
- package/dist/enums/bytes.js.map +1 -0
- package/dist/enums/constants.d.ts +4 -0
- package/dist/enums/constants.js +8 -0
- package/dist/enums/constants.js.map +1 -0
- package/dist/enums/definitions.json +3066 -1760
- package/dist/enums/field.d.ts +28 -0
- package/dist/enums/field.js +58 -0
- package/dist/enums/field.js.map +1 -0
- package/dist/enums/index.d.ts +12 -46
- package/dist/enums/index.js +22 -110
- package/dist/enums/index.js.map +1 -1
- package/dist/enums/src/enums/definitions.json +3073 -0
- package/dist/enums/utils-renumber.js +20 -20
- package/dist/enums/utils-renumber.js.map +1 -1
- package/dist/enums/xrpl-definitions-base.d.ts +44 -0
- package/dist/enums/xrpl-definitions-base.js +59 -0
- package/dist/enums/xrpl-definitions-base.js.map +1 -0
- package/dist/enums/xrpl-definitions.d.ts +21 -0
- package/dist/enums/xrpl-definitions.js +29 -0
- package/dist/enums/xrpl-definitions.js.map +1 -0
- package/dist/hash-prefixes.d.ts +1 -2
- package/dist/hash-prefixes.js +7 -6
- package/dist/hash-prefixes.js.map +1 -1
- package/dist/hashes.d.ts +7 -8
- package/dist/hashes.js +23 -44
- package/dist/hashes.js.map +1 -1
- package/dist/index.d.ts +16 -17
- package/dist/index.js +65 -40
- package/dist/index.js.map +1 -1
- package/dist/ledger-hashes.d.ts +6 -3
- package/dist/ledger-hashes.js +40 -33
- package/dist/ledger-hashes.js.map +1 -1
- package/dist/quality.d.ts +3 -4
- package/dist/quality.js +20 -19
- package/dist/quality.js.map +1 -1
- package/dist/serdes/binary-parser.d.ts +8 -6
- package/dist/serdes/binary-parser.js +74 -64
- package/dist/serdes/binary-parser.js.map +1 -1
- package/dist/serdes/binary-serializer.d.ts +10 -11
- package/dist/serdes/binary-serializer.js +50 -48
- package/dist/serdes/binary-serializer.js.map +1 -1
- package/dist/shamap.d.ts +6 -7
- package/dist/shamap.js +74 -97
- package/dist/shamap.js.map +1 -1
- package/dist/src/binary.d.ts +90 -0
- package/dist/src/binary.js +128 -0
- package/dist/src/binary.js.map +1 -0
- package/dist/src/coretypes.d.ts +9 -0
- package/dist/src/coretypes.js +48 -0
- package/dist/src/coretypes.js.map +1 -0
- package/dist/src/enums/bytes.d.ts +25 -0
- package/dist/src/enums/bytes.js +63 -0
- package/dist/src/enums/bytes.js.map +1 -0
- package/dist/src/enums/constants.d.ts +4 -0
- package/dist/src/enums/constants.js +8 -0
- package/dist/src/enums/constants.js.map +1 -0
- package/dist/src/enums/definitions.json +3068 -0
- package/dist/src/enums/field.d.ts +28 -0
- package/dist/src/enums/field.js +58 -0
- package/dist/src/enums/field.js.map +1 -0
- package/dist/src/enums/index.d.ts +12 -0
- package/dist/src/enums/index.js +31 -0
- package/dist/src/enums/index.js.map +1 -0
- package/dist/src/enums/utils-renumber.d.ts +101 -0
- package/dist/src/enums/utils-renumber.js +127 -0
- package/dist/src/enums/utils-renumber.js.map +1 -0
- package/dist/src/enums/xrpl-definitions-base.d.ts +44 -0
- package/dist/src/enums/xrpl-definitions-base.js +59 -0
- package/dist/src/enums/xrpl-definitions-base.js.map +1 -0
- package/dist/src/enums/xrpl-definitions.d.ts +21 -0
- package/dist/src/enums/xrpl-definitions.js +29 -0
- package/dist/src/enums/xrpl-definitions.js.map +1 -0
- package/dist/src/hash-prefixes.d.ts +5 -0
- package/dist/src/hash-prefixes.js +41 -0
- package/dist/src/hash-prefixes.js.map +1 -0
- package/dist/src/hashes.d.ts +50 -0
- package/dist/src/hashes.js +76 -0
- package/dist/src/hashes.js.map +1 -0
- package/dist/src/index.d.ts +64 -0
- package/dist/src/index.js +123 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/ledger-hashes.d.ts +48 -0
- package/dist/src/ledger-hashes.js +141 -0
- package/dist/src/ledger-hashes.js.map +1 -0
- package/dist/src/quality.d.ts +21 -0
- package/dist/src/quality.js +42 -0
- package/dist/src/quality.js.map +1 -0
- package/dist/src/serdes/binary-parser.d.ts +100 -0
- package/dist/src/serdes/binary-parser.js +194 -0
- package/dist/src/serdes/binary-parser.js.map +1 -0
- package/dist/src/serdes/binary-serializer.d.ts +81 -0
- package/dist/src/serdes/binary-serializer.js +149 -0
- package/dist/src/serdes/binary-serializer.js.map +1 -0
- package/dist/src/shamap.d.ts +102 -0
- package/dist/src/shamap.js +172 -0
- package/dist/src/shamap.js.map +1 -0
- package/dist/src/types/account-id.d.ts +35 -0
- package/dist/src/types/account-id.js +69 -0
- package/dist/src/types/account-id.js.map +1 -0
- package/dist/src/types/amount.d.ts +91 -0
- package/dist/src/types/amount.js +289 -0
- package/dist/src/types/amount.js.map +1 -0
- package/dist/src/types/blob.d.ts +24 -0
- package/dist/src/types/blob.js +43 -0
- package/dist/src/types/blob.js.map +1 -0
- package/dist/src/types/currency.d.ts +28 -0
- package/dist/src/types/currency.js +127 -0
- package/dist/src/types/currency.js.map +1 -0
- package/dist/src/types/hash-128.d.ts +16 -0
- package/dist/src/types/hash-128.js +32 -0
- package/dist/src/types/hash-128.js.map +1 -0
- package/dist/src/types/hash-160.d.ts +10 -0
- package/dist/src/types/hash-160.js +19 -0
- package/dist/src/types/hash-160.js.map +1 -0
- package/dist/src/types/hash-192.d.ts +10 -0
- package/dist/src/types/hash-192.js +19 -0
- package/dist/src/types/hash-192.js.map +1 -0
- package/dist/src/types/hash-256.d.ts +10 -0
- package/dist/src/types/hash-256.js +16 -0
- package/dist/src/types/hash-256.js.map +1 -0
- package/dist/src/types/hash.d.ts +40 -0
- package/dist/src/types/hash.js +73 -0
- package/dist/src/types/hash.js.map +1 -0
- package/dist/src/types/index.d.ts +19 -0
- package/dist/src/types/index.js +64 -0
- package/dist/src/types/index.js.map +1 -0
- package/dist/src/types/issue.d.ts +38 -0
- package/dist/src/types/issue.js +81 -0
- package/dist/src/types/issue.js.map +1 -0
- package/dist/src/types/path-set.d.ts +36 -0
- package/dist/src/types/path-set.js +233 -0
- package/dist/src/types/path-set.js.map +1 -0
- package/dist/src/types/serialized-type.d.ts +70 -0
- package/dist/src/types/serialized-type.js +105 -0
- package/dist/src/types/serialized-type.js.map +1 -0
- package/dist/src/types/st-array.d.ts +31 -0
- package/dist/src/types/st-array.js +86 -0
- package/dist/src/types/st-array.js.map +1 -0
- package/dist/src/types/st-object.d.ts +32 -0
- package/dist/src/types/st-object.js +155 -0
- package/dist/src/types/st-object.js.map +1 -0
- package/dist/src/types/uint-16.d.ts +24 -0
- package/dist/src/types/uint-16.js +45 -0
- package/dist/src/types/uint-16.js.map +1 -0
- package/dist/src/types/uint-32.d.ts +24 -0
- package/dist/src/types/uint-32.js +50 -0
- package/dist/src/types/uint-32.js.map +1 -0
- package/dist/src/types/uint-64.d.ts +37 -0
- package/dist/src/types/uint-64.js +86 -0
- package/dist/src/types/uint-64.js.map +1 -0
- package/dist/src/types/uint-8.d.ts +24 -0
- package/dist/src/types/uint-8.js +46 -0
- package/dist/src/types/uint-8.js.map +1 -0
- package/dist/src/types/uint.d.ts +29 -0
- package/dist/src/types/uint.js +47 -0
- package/dist/src/types/uint.js.map +1 -0
- package/dist/src/types/vector-256.d.ts +30 -0
- package/dist/src/types/vector-256.js +73 -0
- package/dist/src/types/vector-256.js.map +1 -0
- package/dist/src/types/xchain-bridge.d.ts +44 -0
- package/dist/src/types/xchain-bridge.js +102 -0
- package/dist/src/types/xchain-bridge.js.map +1 -0
- package/dist/src/utils.d.ts +47 -0
- package/dist/src/utils.js +137 -0
- package/dist/src/utils.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/dist/types/account-id.d.ts +2 -3
- package/dist/types/account-id.js +29 -37
- package/dist/types/account-id.js.map +1 -1
- package/dist/types/amount.d.ts +33 -10
- package/dist/types/amount.js +181 -101
- package/dist/types/amount.js.map +1 -1
- package/dist/types/blob.d.ts +3 -4
- package/dist/types/blob.js +16 -27
- package/dist/types/blob.js.map +1 -1
- package/dist/types/currency.d.ts +5 -13
- package/dist/types/currency.js +53 -66
- package/dist/types/currency.js.map +1 -1
- package/dist/types/hash-128.d.ts +8 -3
- package/dist/types/hash-128.js +23 -22
- package/dist/types/hash-128.js.map +1 -1
- package/dist/types/hash-160.d.ts +2 -3
- package/dist/types/hash-160.js +7 -24
- package/dist/types/hash-160.js.map +1 -1
- package/dist/types/hash-192.d.ts +10 -0
- package/dist/types/hash-192.js +19 -0
- package/dist/types/hash-192.js.map +1 -0
- package/dist/types/hash-256.d.ts +2 -3
- package/dist/types/hash-256.js +7 -22
- package/dist/types/hash-256.js.map +1 -1
- package/dist/types/hash.d.ts +4 -5
- package/dist/types/hash.js +25 -39
- package/dist/types/hash.js.map +1 -1
- package/dist/types/index.d.ts +19 -33
- package/dist/types/index.js +44 -24
- package/dist/types/index.js.map +1 -1
- package/dist/types/issue.d.ts +38 -0
- package/dist/types/issue.js +81 -0
- package/dist/types/issue.js.map +1 -0
- package/dist/types/path-set.d.ts +2 -2
- package/dist/types/path-set.js +73 -94
- package/dist/types/path-set.js.map +1 -1
- package/dist/types/serialized-type.d.ts +26 -18
- package/dist/types/serialized-type.js +50 -60
- package/dist/types/serialized-type.js.map +1 -1
- package/dist/types/st-array.d.ts +7 -4
- package/dist/types/st-array.js +36 -47
- package/dist/types/st-array.js.map +1 -1
- package/dist/types/st-object.d.ts +8 -5
- package/dist/types/st-object.js +73 -74
- package/dist/types/st-object.js.map +1 -1
- package/dist/types/uint-16.d.ts +3 -4
- package/dist/types/uint-16.js +20 -33
- package/dist/types/uint-16.js.map +1 -1
- package/dist/types/uint-32.d.ts +3 -4
- package/dist/types/uint-32.js +23 -36
- package/dist/types/uint-32.js.map +1 -1
- package/dist/types/uint-64.d.ts +5 -6
- package/dist/types/uint-64.js +44 -48
- package/dist/types/uint-64.js.map +1 -1
- package/dist/types/uint-8.d.ts +3 -4
- package/dist/types/uint-8.js +21 -33
- package/dist/types/uint-8.js.map +1 -1
- package/dist/types/uint.d.ts +5 -5
- package/dist/types/uint.js +17 -27
- package/dist/types/uint.js.map +1 -1
- package/dist/types/vector-256.d.ts +3 -4
- package/dist/types/vector-256.js +28 -45
- package/dist/types/vector-256.js.map +1 -1
- package/dist/types/xchain-bridge.d.ts +44 -0
- package/dist/types/xchain-bridge.js +102 -0
- package/dist/types/xchain-bridge.js.map +1 -0
- package/dist/utils.d.ts +47 -0
- package/dist/utils.js +137 -0
- package/dist/utils.js.map +1 -0
- package/package.json +23 -33
- package/src/README.md +5 -0
- package/src/binary.ts +194 -0
- package/src/coretypes.ts +31 -0
- package/src/enums/README.md +144 -0
- package/src/enums/bytes.ts +74 -0
- package/src/enums/constants.ts +4 -0
- package/src/enums/definitions.json +3073 -0
- package/src/enums/field.ts +84 -0
- package/src/enums/index.ts +34 -0
- package/src/enums/utils-renumber.ts +134 -0
- package/src/enums/xrpl-definitions-base.ts +111 -0
- package/src/enums/xrpl-definitions.ts +32 -0
- package/src/hash-prefixes.ts +40 -0
- package/src/hashes.ts +75 -0
- package/src/index.ts +153 -0
- package/src/ledger-hashes.ts +191 -0
- package/src/quality.ts +38 -0
- package/src/serdes/binary-parser.ts +228 -0
- package/src/serdes/binary-serializer.ts +166 -0
- package/src/shamap.ts +186 -0
- package/src/types/account-id.ts +86 -0
- package/src/types/amount.ts +362 -0
- package/src/types/blob.ts +46 -0
- package/src/types/currency.ts +140 -0
- package/src/types/hash-128.ts +33 -0
- package/src/types/hash-160.ts +19 -0
- package/src/types/hash-192.ts +19 -0
- package/src/types/hash-256.ts +15 -0
- package/src/types/hash.ts +83 -0
- package/src/types/index.ts +66 -0
- package/src/types/issue.ts +96 -0
- package/src/types/path-set.ts +290 -0
- package/src/types/serialized-type.ts +122 -0
- package/src/types/st-array.ts +113 -0
- package/src/types/st-object.ts +192 -0
- package/src/types/uint-16.ts +53 -0
- package/src/types/uint-32.ts +59 -0
- package/src/types/uint-64.ts +104 -0
- package/src/types/uint-8.ts +52 -0
- package/src/types/uint.ts +60 -0
- package/src/types/vector-256.ts +79 -0
- package/src/types/xchain-bridge.ts +128 -0
- package/src/utils.ts +152 -0
- package/HISTORY.md +0 -74
- package/test/amount.test.js +0 -43
- package/test/binary-json.test.js +0 -47
- package/test/binary-parser.test.js +0 -397
- package/test/binary-serializer.test.js +0 -248
- package/test/fixtures/account-tx-transactions.db +0 -0
- package/test/fixtures/codec-fixtures.json +0 -4466
- package/test/fixtures/data-driven-tests.json +0 -3721
- package/test/fixtures/delivermin-tx-binary.json +0 -1
- package/test/fixtures/delivermin-tx.json +0 -98
- package/test/fixtures/deposit-preauth-tx-binary.json +0 -1
- package/test/fixtures/deposit-preauth-tx-meta-binary.json +0 -1
- package/test/fixtures/deposit-preauth-tx.json +0 -58
- package/test/fixtures/escrow-cancel-binary.json +0 -1
- package/test/fixtures/escrow-cancel-tx.json +0 -6
- package/test/fixtures/escrow-create-binary.json +0 -1
- package/test/fixtures/escrow-create-tx.json +0 -10
- package/test/fixtures/escrow-finish-binary.json +0 -1
- package/test/fixtures/escrow-finish-meta-binary.json +0 -1
- package/test/fixtures/escrow-finish-tx.json +0 -95
- package/test/fixtures/ledger-full-38129.json +0 -1
- package/test/fixtures/ledger-full-40000.json +0 -1
- package/test/fixtures/negative-unl.json +0 -12
- package/test/fixtures/payment-channel-claim-binary.json +0 -1
- package/test/fixtures/payment-channel-claim-tx.json +0 -8
- package/test/fixtures/payment-channel-create-binary.json +0 -1
- package/test/fixtures/payment-channel-create-tx.json +0 -11
- package/test/fixtures/payment-channel-fund-binary.json +0 -1
- package/test/fixtures/payment-channel-fund-tx.json +0 -7
- package/test/fixtures/signerlistset-tx-binary.json +0 -1
- package/test/fixtures/signerlistset-tx-meta-binary.json +0 -1
- package/test/fixtures/signerlistset-tx.json +0 -94
- package/test/fixtures/x-codec-fixtures.json +0 -188
- package/test/hash.test.js +0 -82
- package/test/ledger.test.js +0 -29
- package/test/lower-case-hex.test.js +0 -45
- package/test/pseudo-transaction.test.js +0 -38
- package/test/quality.test.js +0 -15
- package/test/shamap.test.js +0 -88
- package/test/signing-data-encoding.test.js +0 -129
- package/test/tx-encode-decode.test.js +0 -80
- package/test/types.test.js +0 -34
- package/test/uint.test.js +0 -40
- package/test/utils.js +0 -29
- package/test/x-address.test.js +0 -147
|
@@ -0,0 +1,290 @@
|
|
|
1
|
+
import { AccountID } from './account-id'
|
|
2
|
+
import { Currency } from './currency'
|
|
3
|
+
import { BinaryParser } from '../serdes/binary-parser'
|
|
4
|
+
import { SerializedType, JsonObject } from './serialized-type'
|
|
5
|
+
import { bytesToHex, concat } from '@xrplf/isomorphic/utils'
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Constants for separating Paths in a PathSet
|
|
9
|
+
*/
|
|
10
|
+
const PATHSET_END_BYTE = 0x00
|
|
11
|
+
const PATH_SEPARATOR_BYTE = 0xff
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Constant for masking types of a Hop
|
|
15
|
+
*/
|
|
16
|
+
const TYPE_ACCOUNT = 0x01
|
|
17
|
+
const TYPE_CURRENCY = 0x10
|
|
18
|
+
const TYPE_ISSUER = 0x20
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* The object representation of a Hop, an issuer AccountID, an account AccountID, and a Currency
|
|
22
|
+
*/
|
|
23
|
+
interface HopObject extends JsonObject {
|
|
24
|
+
issuer?: string
|
|
25
|
+
account?: string
|
|
26
|
+
currency?: string
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* TypeGuard for HopObject
|
|
31
|
+
*/
|
|
32
|
+
function isHopObject(arg): arg is HopObject {
|
|
33
|
+
return (
|
|
34
|
+
arg.issuer !== undefined ||
|
|
35
|
+
arg.account !== undefined ||
|
|
36
|
+
arg.currency !== undefined
|
|
37
|
+
)
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* TypeGuard for PathSet
|
|
42
|
+
*/
|
|
43
|
+
function isPathSet(arg): arg is Array<Array<HopObject>> {
|
|
44
|
+
return (
|
|
45
|
+
(Array.isArray(arg) && arg.length === 0) ||
|
|
46
|
+
(Array.isArray(arg) && Array.isArray(arg[0]) && arg[0].length === 0) ||
|
|
47
|
+
(Array.isArray(arg) && Array.isArray(arg[0]) && isHopObject(arg[0][0]))
|
|
48
|
+
)
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Serialize and Deserialize a Hop
|
|
53
|
+
*/
|
|
54
|
+
class Hop extends SerializedType {
|
|
55
|
+
/**
|
|
56
|
+
* Create a Hop from a HopObject
|
|
57
|
+
*
|
|
58
|
+
* @param value Either a hop or HopObject to create a hop with
|
|
59
|
+
* @returns a Hop
|
|
60
|
+
*/
|
|
61
|
+
static from(value: Hop | HopObject): Hop {
|
|
62
|
+
if (value instanceof Hop) {
|
|
63
|
+
return value
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const bytes: Array<Uint8Array> = [Uint8Array.from([0])]
|
|
67
|
+
|
|
68
|
+
if (value.account) {
|
|
69
|
+
bytes.push(AccountID.from(value.account).toBytes())
|
|
70
|
+
bytes[0][0] |= TYPE_ACCOUNT
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
if (value.currency) {
|
|
74
|
+
bytes.push(Currency.from(value.currency).toBytes())
|
|
75
|
+
bytes[0][0] |= TYPE_CURRENCY
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
if (value.issuer) {
|
|
79
|
+
bytes.push(AccountID.from(value.issuer).toBytes())
|
|
80
|
+
bytes[0][0] |= TYPE_ISSUER
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
return new Hop(concat(bytes))
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Construct a Hop from a BinaryParser
|
|
88
|
+
*
|
|
89
|
+
* @param parser BinaryParser to read the Hop from
|
|
90
|
+
* @returns a Hop
|
|
91
|
+
*/
|
|
92
|
+
static fromParser(parser: BinaryParser): Hop {
|
|
93
|
+
const type = parser.readUInt8()
|
|
94
|
+
const bytes: Array<Uint8Array> = [Uint8Array.from([type])]
|
|
95
|
+
|
|
96
|
+
if (type & TYPE_ACCOUNT) {
|
|
97
|
+
bytes.push(parser.read(AccountID.width))
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
if (type & TYPE_CURRENCY) {
|
|
101
|
+
bytes.push(parser.read(Currency.width))
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
if (type & TYPE_ISSUER) {
|
|
105
|
+
bytes.push(parser.read(AccountID.width))
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
return new Hop(concat(bytes))
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Get the JSON interpretation of this hop
|
|
113
|
+
*
|
|
114
|
+
* @returns a HopObject, an JS object with optional account, issuer, and currency
|
|
115
|
+
*/
|
|
116
|
+
toJSON(): HopObject {
|
|
117
|
+
const hopParser = new BinaryParser(bytesToHex(this.bytes))
|
|
118
|
+
const type = hopParser.readUInt8()
|
|
119
|
+
|
|
120
|
+
let account, currency, issuer
|
|
121
|
+
if (type & TYPE_ACCOUNT) {
|
|
122
|
+
account = (AccountID.fromParser(hopParser) as AccountID).toJSON()
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
if (type & TYPE_CURRENCY) {
|
|
126
|
+
currency = (Currency.fromParser(hopParser) as Currency).toJSON()
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
if (type & TYPE_ISSUER) {
|
|
130
|
+
issuer = (AccountID.fromParser(hopParser) as AccountID).toJSON()
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
const result: HopObject = {}
|
|
134
|
+
if (account) {
|
|
135
|
+
result.account = account
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
if (issuer) {
|
|
139
|
+
result.issuer = issuer
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
if (currency) {
|
|
143
|
+
result.currency = currency
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
return result
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* get a number representing the type of this hop
|
|
151
|
+
*
|
|
152
|
+
* @returns a number to be bitwise and-ed with TYPE_ constants to describe the types in the hop
|
|
153
|
+
*/
|
|
154
|
+
type(): number {
|
|
155
|
+
return this.bytes[0]
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Class for serializing/deserializing Paths
|
|
161
|
+
*/
|
|
162
|
+
class Path extends SerializedType {
|
|
163
|
+
/**
|
|
164
|
+
* construct a Path from an array of Hops
|
|
165
|
+
*
|
|
166
|
+
* @param value Path or array of HopObjects to construct a Path
|
|
167
|
+
* @returns the Path
|
|
168
|
+
*/
|
|
169
|
+
static from(value: Path | Array<HopObject>): Path {
|
|
170
|
+
if (value instanceof Path) {
|
|
171
|
+
return value
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
const bytes: Array<Uint8Array> = []
|
|
175
|
+
value.forEach((hop: HopObject) => {
|
|
176
|
+
bytes.push(Hop.from(hop).toBytes())
|
|
177
|
+
})
|
|
178
|
+
|
|
179
|
+
return new Path(concat(bytes))
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* Read a Path from a BinaryParser
|
|
184
|
+
*
|
|
185
|
+
* @param parser BinaryParser to read Path from
|
|
186
|
+
* @returns the Path represented by the bytes read from the BinaryParser
|
|
187
|
+
*/
|
|
188
|
+
static fromParser(parser: BinaryParser): Path {
|
|
189
|
+
const bytes: Array<Uint8Array> = []
|
|
190
|
+
while (!parser.end()) {
|
|
191
|
+
bytes.push(Hop.fromParser(parser).toBytes())
|
|
192
|
+
|
|
193
|
+
if (
|
|
194
|
+
parser.peek() === PATHSET_END_BYTE ||
|
|
195
|
+
parser.peek() === PATH_SEPARATOR_BYTE
|
|
196
|
+
) {
|
|
197
|
+
break
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
return new Path(concat(bytes))
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* Get the JSON representation of this Path
|
|
205
|
+
*
|
|
206
|
+
* @returns an Array of HopObject constructed from this.bytes
|
|
207
|
+
*/
|
|
208
|
+
toJSON(): Array<HopObject> {
|
|
209
|
+
const json: Array<HopObject> = []
|
|
210
|
+
const pathParser = new BinaryParser(this.toString())
|
|
211
|
+
|
|
212
|
+
while (!pathParser.end()) {
|
|
213
|
+
json.push(Hop.fromParser(pathParser).toJSON())
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
return json
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/**
|
|
221
|
+
* Deserialize and Serialize the PathSet type
|
|
222
|
+
*/
|
|
223
|
+
class PathSet extends SerializedType {
|
|
224
|
+
/**
|
|
225
|
+
* Construct a PathSet from an Array of Arrays representing paths
|
|
226
|
+
*
|
|
227
|
+
* @param value A PathSet or Array of Array of HopObjects
|
|
228
|
+
* @returns the PathSet constructed from value
|
|
229
|
+
*/
|
|
230
|
+
static from<T extends PathSet | Array<Array<HopObject>>>(value: T): PathSet {
|
|
231
|
+
if (value instanceof PathSet) {
|
|
232
|
+
return value
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
if (isPathSet(value)) {
|
|
236
|
+
const bytes: Array<Uint8Array> = []
|
|
237
|
+
|
|
238
|
+
value.forEach((path: Array<HopObject>) => {
|
|
239
|
+
bytes.push(Path.from(path).toBytes())
|
|
240
|
+
bytes.push(Uint8Array.from([PATH_SEPARATOR_BYTE]))
|
|
241
|
+
})
|
|
242
|
+
|
|
243
|
+
bytes[bytes.length - 1] = Uint8Array.from([PATHSET_END_BYTE])
|
|
244
|
+
|
|
245
|
+
return new PathSet(concat(bytes))
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
throw new Error('Cannot construct PathSet from given value')
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
/**
|
|
252
|
+
* Construct a PathSet from a BinaryParser
|
|
253
|
+
*
|
|
254
|
+
* @param parser A BinaryParser to read PathSet from
|
|
255
|
+
* @returns the PathSet read from parser
|
|
256
|
+
*/
|
|
257
|
+
static fromParser(parser: BinaryParser): PathSet {
|
|
258
|
+
const bytes: Array<Uint8Array> = []
|
|
259
|
+
|
|
260
|
+
while (!parser.end()) {
|
|
261
|
+
bytes.push(Path.fromParser(parser).toBytes())
|
|
262
|
+
bytes.push(parser.read(1))
|
|
263
|
+
|
|
264
|
+
if (bytes[bytes.length - 1][0] == PATHSET_END_BYTE) {
|
|
265
|
+
break
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
return new PathSet(concat(bytes))
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
/**
|
|
273
|
+
* Get the JSON representation of this PathSet
|
|
274
|
+
*
|
|
275
|
+
* @returns an Array of Array of HopObjects, representing this PathSet
|
|
276
|
+
*/
|
|
277
|
+
toJSON(): Array<Array<HopObject>> {
|
|
278
|
+
const json: Array<Array<HopObject>> = []
|
|
279
|
+
const pathParser = new BinaryParser(this.toString())
|
|
280
|
+
|
|
281
|
+
while (!pathParser.end()) {
|
|
282
|
+
json.push(Path.fromParser(pathParser).toJSON())
|
|
283
|
+
pathParser.skip(1)
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
return json
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
export { PathSet }
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { BytesList } from '../serdes/binary-serializer'
|
|
2
|
+
import { BinaryParser } from '../serdes/binary-parser'
|
|
3
|
+
import { XrplDefinitionsBase } from '../enums'
|
|
4
|
+
import { bytesToHex } from '@xrplf/isomorphic/utils'
|
|
5
|
+
|
|
6
|
+
type JSON = string | number | boolean | null | undefined | JSON[] | JsonObject
|
|
7
|
+
|
|
8
|
+
type JsonObject = { [key: string]: JSON }
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* The base class for all binary-codec types
|
|
12
|
+
*/
|
|
13
|
+
class SerializedType {
|
|
14
|
+
protected readonly bytes: Uint8Array = new Uint8Array(0)
|
|
15
|
+
|
|
16
|
+
constructor(bytes?: Uint8Array) {
|
|
17
|
+
this.bytes = bytes ?? new Uint8Array(0)
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
static fromParser(parser: BinaryParser, hint?: number): SerializedType {
|
|
21
|
+
throw new Error('fromParser not implemented')
|
|
22
|
+
return this.fromParser(parser, hint)
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
static from(value: SerializedType | JSON | bigint): SerializedType {
|
|
26
|
+
throw new Error('from not implemented')
|
|
27
|
+
return this.from(value)
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Write the bytes representation of a SerializedType to a BytesList
|
|
32
|
+
*
|
|
33
|
+
* @param list The BytesList to write SerializedType bytes to
|
|
34
|
+
*/
|
|
35
|
+
toBytesSink(list: BytesList): void {
|
|
36
|
+
list.put(this.bytes)
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Get the hex representation of a SerializedType's bytes
|
|
41
|
+
*
|
|
42
|
+
* @returns hex String of this.bytes
|
|
43
|
+
*/
|
|
44
|
+
toHex(): string {
|
|
45
|
+
return bytesToHex(this.toBytes())
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Get the bytes representation of a SerializedType
|
|
50
|
+
*
|
|
51
|
+
* @returns A Uint8Array of the bytes
|
|
52
|
+
*/
|
|
53
|
+
toBytes(): Uint8Array {
|
|
54
|
+
if (this.bytes) {
|
|
55
|
+
return this.bytes
|
|
56
|
+
}
|
|
57
|
+
const bytes = new BytesList()
|
|
58
|
+
this.toBytesSink(bytes)
|
|
59
|
+
return bytes.toBytes()
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Return the JSON representation of a SerializedType
|
|
64
|
+
*
|
|
65
|
+
* @param _definitions rippled definitions used to parse the values of transaction types and such.
|
|
66
|
+
* Unused in default, but used in STObject, STArray
|
|
67
|
+
* Can be customized for sidechains and amendments.
|
|
68
|
+
* @returns any type, if not overloaded returns hexString representation of bytes
|
|
69
|
+
*/
|
|
70
|
+
toJSON(_definitions?: XrplDefinitionsBase): JSON {
|
|
71
|
+
return this.toHex()
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* @returns hexString representation of this.bytes
|
|
76
|
+
*/
|
|
77
|
+
toString(): string {
|
|
78
|
+
return this.toHex()
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Base class for SerializedTypes that are comparable.
|
|
84
|
+
*
|
|
85
|
+
* @template T - What types you want to allow comparisons between. You must specify all types. Primarily used to allow
|
|
86
|
+
* comparisons between built-in types (like `string`) and SerializedType subclasses (like `Hash`).
|
|
87
|
+
*
|
|
88
|
+
* Ex. `class Hash extends Comparable<Hash | string>`
|
|
89
|
+
*/
|
|
90
|
+
class Comparable<T extends Object> extends SerializedType {
|
|
91
|
+
lt(other: T): boolean {
|
|
92
|
+
return this.compareTo(other) < 0
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
eq(other: T): boolean {
|
|
96
|
+
return this.compareTo(other) === 0
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
gt(other: T): boolean {
|
|
100
|
+
return this.compareTo(other) > 0
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
gte(other: T): boolean {
|
|
104
|
+
return this.compareTo(other) > -1
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
lte(other: T): boolean {
|
|
108
|
+
return this.compareTo(other) < 1
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Overload this method to define how two Comparable SerializedTypes are compared
|
|
113
|
+
*
|
|
114
|
+
* @param other The comparable object to compare this to
|
|
115
|
+
* @returns A number denoting the relationship of this and other
|
|
116
|
+
*/
|
|
117
|
+
compareTo(other: T): number {
|
|
118
|
+
throw new Error(`cannot compare ${this.toString()} and ${other.toString()}`)
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
export { SerializedType, Comparable, JSON, JsonObject }
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { DEFAULT_DEFINITIONS, XrplDefinitionsBase } from '../enums'
|
|
2
|
+
import { SerializedType, JsonObject } from './serialized-type'
|
|
3
|
+
import { STObject } from './st-object'
|
|
4
|
+
import { BinaryParser } from '../serdes/binary-parser'
|
|
5
|
+
import { concat } from '@xrplf/isomorphic/utils'
|
|
6
|
+
|
|
7
|
+
const ARRAY_END_MARKER = Uint8Array.from([0xf1])
|
|
8
|
+
const ARRAY_END_MARKER_NAME = 'ArrayEndMarker'
|
|
9
|
+
|
|
10
|
+
const OBJECT_END_MARKER = Uint8Array.from([0xe1])
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* TypeGuard for Array<JsonObject>
|
|
14
|
+
*/
|
|
15
|
+
function isObjects(args): args is Array<JsonObject> {
|
|
16
|
+
return (
|
|
17
|
+
Array.isArray(args) &&
|
|
18
|
+
args.every(
|
|
19
|
+
(arg) =>
|
|
20
|
+
typeof arg === 'object' &&
|
|
21
|
+
Object.keys(arg).length === 1 &&
|
|
22
|
+
typeof Object.values(arg)[0] === 'object',
|
|
23
|
+
)
|
|
24
|
+
)
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Class for serializing and deserializing Arrays of Objects
|
|
29
|
+
*/
|
|
30
|
+
class STArray extends SerializedType {
|
|
31
|
+
/**
|
|
32
|
+
* Construct an STArray from a BinaryParser
|
|
33
|
+
*
|
|
34
|
+
* @param parser BinaryParser to parse an STArray from
|
|
35
|
+
* @returns An STArray Object
|
|
36
|
+
*/
|
|
37
|
+
static fromParser(parser: BinaryParser): STArray {
|
|
38
|
+
const bytes: Array<Uint8Array> = []
|
|
39
|
+
|
|
40
|
+
while (!parser.end()) {
|
|
41
|
+
const field = parser.readField()
|
|
42
|
+
if (field.name === ARRAY_END_MARKER_NAME) {
|
|
43
|
+
break
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
bytes.push(
|
|
47
|
+
field.header,
|
|
48
|
+
parser.readFieldValue(field).toBytes(),
|
|
49
|
+
OBJECT_END_MARKER,
|
|
50
|
+
)
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
bytes.push(ARRAY_END_MARKER)
|
|
54
|
+
return new STArray(concat(bytes))
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Construct an STArray from an Array of JSON Objects
|
|
59
|
+
*
|
|
60
|
+
* @param value STArray or Array of Objects to parse into an STArray
|
|
61
|
+
* @param definitions optional, types and values to use to encode/decode a transaction
|
|
62
|
+
* @returns An STArray object
|
|
63
|
+
*/
|
|
64
|
+
static from<T extends STArray | Array<JsonObject>>(
|
|
65
|
+
value: T,
|
|
66
|
+
definitions: XrplDefinitionsBase = DEFAULT_DEFINITIONS,
|
|
67
|
+
): STArray {
|
|
68
|
+
if (value instanceof STArray) {
|
|
69
|
+
return value
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
if (isObjects(value)) {
|
|
73
|
+
const bytes: Array<Uint8Array> = []
|
|
74
|
+
value.forEach((obj) => {
|
|
75
|
+
bytes.push(STObject.from(obj, undefined, definitions).toBytes())
|
|
76
|
+
})
|
|
77
|
+
|
|
78
|
+
bytes.push(ARRAY_END_MARKER)
|
|
79
|
+
return new STArray(concat(bytes))
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
throw new Error('Cannot construct STArray from value given')
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Return the JSON representation of this.bytes
|
|
87
|
+
*
|
|
88
|
+
* @param definitions optional, types and values to use to encode/decode a transaction
|
|
89
|
+
* @returns An Array of JSON objects
|
|
90
|
+
*/
|
|
91
|
+
toJSON(
|
|
92
|
+
definitions: XrplDefinitionsBase = DEFAULT_DEFINITIONS,
|
|
93
|
+
): Array<JsonObject> {
|
|
94
|
+
const result: Array<JsonObject> = []
|
|
95
|
+
|
|
96
|
+
const arrayParser = new BinaryParser(this.toString(), definitions)
|
|
97
|
+
|
|
98
|
+
while (!arrayParser.end()) {
|
|
99
|
+
const field = arrayParser.readField()
|
|
100
|
+
if (field.name === ARRAY_END_MARKER_NAME) {
|
|
101
|
+
break
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
const outer = {}
|
|
105
|
+
outer[field.name] = STObject.fromParser(arrayParser).toJSON(definitions)
|
|
106
|
+
result.push(outer)
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
return result
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export { STArray }
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
import {
|
|
2
|
+
DEFAULT_DEFINITIONS,
|
|
3
|
+
FieldInstance,
|
|
4
|
+
Bytes,
|
|
5
|
+
XrplDefinitionsBase,
|
|
6
|
+
} from '../enums'
|
|
7
|
+
import { SerializedType, JsonObject } from './serialized-type'
|
|
8
|
+
import { xAddressToClassicAddress, isValidXAddress } from 'ripple-address-codec'
|
|
9
|
+
import { BinaryParser } from '../serdes/binary-parser'
|
|
10
|
+
import { BinarySerializer, BytesList } from '../serdes/binary-serializer'
|
|
11
|
+
|
|
12
|
+
import { STArray } from './st-array'
|
|
13
|
+
|
|
14
|
+
const OBJECT_END_MARKER_BYTE = Uint8Array.from([0xe1])
|
|
15
|
+
const OBJECT_END_MARKER = 'ObjectEndMarker'
|
|
16
|
+
const ST_OBJECT = 'STObject'
|
|
17
|
+
const DESTINATION = 'Destination'
|
|
18
|
+
const ACCOUNT = 'Account'
|
|
19
|
+
const SOURCE_TAG = 'SourceTag'
|
|
20
|
+
const DEST_TAG = 'DestinationTag'
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Break down an X-Address into an account and a tag
|
|
24
|
+
*
|
|
25
|
+
* @param field Name of field
|
|
26
|
+
* @param xAddress X-Address corresponding to the field
|
|
27
|
+
*/
|
|
28
|
+
function handleXAddress(field: string, xAddress: string): JsonObject {
|
|
29
|
+
const decoded = xAddressToClassicAddress(xAddress)
|
|
30
|
+
|
|
31
|
+
let tagName
|
|
32
|
+
if (field === DESTINATION) tagName = DEST_TAG
|
|
33
|
+
else if (field === ACCOUNT) tagName = SOURCE_TAG
|
|
34
|
+
else if (decoded.tag !== false)
|
|
35
|
+
throw new Error(`${field} cannot have an associated tag`)
|
|
36
|
+
|
|
37
|
+
return decoded.tag !== false
|
|
38
|
+
? { [field]: decoded.classicAddress, [tagName]: decoded.tag }
|
|
39
|
+
: { [field]: decoded.classicAddress }
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Validate that two objects don't both have the same tag fields
|
|
44
|
+
*
|
|
45
|
+
* @param obj1 First object to check for tags
|
|
46
|
+
* @param obj2 Second object to check for tags
|
|
47
|
+
* @throws When both objects have SourceTag or DestinationTag
|
|
48
|
+
*/
|
|
49
|
+
function checkForDuplicateTags(obj1: JsonObject, obj2: JsonObject): void {
|
|
50
|
+
if (!(obj1[SOURCE_TAG] === undefined || obj2[SOURCE_TAG] === undefined))
|
|
51
|
+
throw new Error('Cannot have Account X-Address and SourceTag')
|
|
52
|
+
if (!(obj1[DEST_TAG] === undefined || obj2[DEST_TAG] === undefined))
|
|
53
|
+
throw new Error('Cannot have Destination X-Address and DestinationTag')
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Class for Serializing/Deserializing objects
|
|
58
|
+
*/
|
|
59
|
+
class STObject extends SerializedType {
|
|
60
|
+
/**
|
|
61
|
+
* Construct a STObject from a BinaryParser
|
|
62
|
+
*
|
|
63
|
+
* @param parser BinaryParser to read STObject from
|
|
64
|
+
* @returns A STObject object
|
|
65
|
+
*/
|
|
66
|
+
static fromParser(parser: BinaryParser): STObject {
|
|
67
|
+
const list: BytesList = new BytesList()
|
|
68
|
+
const bytes: BinarySerializer = new BinarySerializer(list)
|
|
69
|
+
|
|
70
|
+
while (!parser.end()) {
|
|
71
|
+
const field = parser.readField()
|
|
72
|
+
if (field.name === OBJECT_END_MARKER) {
|
|
73
|
+
break
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const associatedValue = parser.readFieldValue(field)
|
|
77
|
+
|
|
78
|
+
bytes.writeFieldAndValue(field, associatedValue)
|
|
79
|
+
if (field.type.name === ST_OBJECT) {
|
|
80
|
+
bytes.put(OBJECT_END_MARKER_BYTE)
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
return new STObject(list.toBytes())
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Construct a STObject from a JSON object
|
|
89
|
+
*
|
|
90
|
+
* @param value An object to include
|
|
91
|
+
* @param filter optional, denote which field to include in serialized object
|
|
92
|
+
* @param definitions optional, types and values to use to encode/decode a transaction
|
|
93
|
+
* @returns a STObject object
|
|
94
|
+
*/
|
|
95
|
+
static from<T extends STObject | JsonObject>(
|
|
96
|
+
value: T,
|
|
97
|
+
filter?: (...any) => boolean,
|
|
98
|
+
definitions: XrplDefinitionsBase = DEFAULT_DEFINITIONS,
|
|
99
|
+
): STObject {
|
|
100
|
+
if (value instanceof STObject) {
|
|
101
|
+
return value
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
const list: BytesList = new BytesList()
|
|
105
|
+
const bytes: BinarySerializer = new BinarySerializer(list)
|
|
106
|
+
|
|
107
|
+
let isUnlModify = false
|
|
108
|
+
|
|
109
|
+
const xAddressDecoded = Object.entries(value).reduce((acc, [key, val]) => {
|
|
110
|
+
let handled: JsonObject | undefined = undefined
|
|
111
|
+
if (val && isValidXAddress(val.toString())) {
|
|
112
|
+
handled = handleXAddress(key, val.toString())
|
|
113
|
+
checkForDuplicateTags(handled, value)
|
|
114
|
+
}
|
|
115
|
+
return Object.assign(acc, handled ?? { [key]: val })
|
|
116
|
+
}, {})
|
|
117
|
+
|
|
118
|
+
let sorted = Object.keys(xAddressDecoded)
|
|
119
|
+
.map((f: string): FieldInstance => definitions.field[f] as FieldInstance)
|
|
120
|
+
.filter(
|
|
121
|
+
(f: FieldInstance): boolean =>
|
|
122
|
+
f !== undefined &&
|
|
123
|
+
xAddressDecoded[f.name] !== undefined &&
|
|
124
|
+
f.isSerialized,
|
|
125
|
+
)
|
|
126
|
+
.sort((a, b) => {
|
|
127
|
+
return a.ordinal - b.ordinal
|
|
128
|
+
})
|
|
129
|
+
|
|
130
|
+
if (filter !== undefined) {
|
|
131
|
+
sorted = sorted.filter(filter)
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
sorted.forEach((field) => {
|
|
135
|
+
const associatedValue =
|
|
136
|
+
field.type.name === ST_OBJECT
|
|
137
|
+
? this.from(xAddressDecoded[field.name], undefined, definitions)
|
|
138
|
+
: field.type.name === 'STArray'
|
|
139
|
+
? STArray.from(xAddressDecoded[field.name], definitions)
|
|
140
|
+
: field.associatedType.from(xAddressDecoded[field.name])
|
|
141
|
+
|
|
142
|
+
if (associatedValue == undefined) {
|
|
143
|
+
throw new TypeError(
|
|
144
|
+
`Unable to interpret "${field.name}: ${
|
|
145
|
+
xAddressDecoded[field.name]
|
|
146
|
+
}".`,
|
|
147
|
+
)
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
if ((associatedValue as unknown as Bytes).name === 'UNLModify') {
|
|
151
|
+
// triggered when the TransactionType field has a value of 'UNLModify'
|
|
152
|
+
isUnlModify = true
|
|
153
|
+
}
|
|
154
|
+
// true when in the UNLModify pseudotransaction (after the transaction type has been processed) and working with the
|
|
155
|
+
// Account field
|
|
156
|
+
// The Account field must not be a part of the UNLModify pseudotransaction encoding, due to a bug in rippled
|
|
157
|
+
const isUnlModifyWorkaround = field.name == 'Account' && isUnlModify
|
|
158
|
+
bytes.writeFieldAndValue(field, associatedValue, isUnlModifyWorkaround)
|
|
159
|
+
if (field.type.name === ST_OBJECT) {
|
|
160
|
+
bytes.put(OBJECT_END_MARKER_BYTE)
|
|
161
|
+
}
|
|
162
|
+
})
|
|
163
|
+
|
|
164
|
+
return new STObject(list.toBytes())
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* Get the JSON interpretation of this.bytes
|
|
169
|
+
* @param definitions rippled definitions used to parse the values of transaction types and such.
|
|
170
|
+
* Can be customized for sidechains and amendments.
|
|
171
|
+
* @returns a JSON object
|
|
172
|
+
*/
|
|
173
|
+
toJSON(definitions?: XrplDefinitionsBase): JsonObject {
|
|
174
|
+
const objectParser = new BinaryParser(this.toString(), definitions)
|
|
175
|
+
const accumulator = {}
|
|
176
|
+
|
|
177
|
+
while (!objectParser.end()) {
|
|
178
|
+
const field = objectParser.readField()
|
|
179
|
+
if (field.name === OBJECT_END_MARKER) {
|
|
180
|
+
break
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
accumulator[field.name] = objectParser
|
|
184
|
+
.readFieldValue(field)
|
|
185
|
+
.toJSON(definitions)
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
return accumulator
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
export { STObject }
|