ripple-binary-codec 1.0.4-beta.1 → 1.0.4-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 -36
- 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 -1780
- 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 -111
- 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 -7
- 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 +7 -5
- package/dist/ledger-hashes.js +40 -34
- package/dist/ledger-hashes.js.map +1 -1
- package/dist/quality.d.ts +3 -4
- package/dist/quality.js +20 -21
- package/dist/quality.js.map +1 -1
- package/dist/serdes/binary-parser.d.ts +8 -6
- package/dist/serdes/binary-parser.js +74 -65
- 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 -49
- package/dist/serdes/binary-serializer.js.map +1 -1
- package/dist/shamap.d.ts +6 -7
- package/dist/shamap.js +74 -98
- 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 -40
- package/dist/types/account-id.js.map +1 -1
- package/dist/types/amount.d.ts +33 -10
- package/dist/types/amount.js +181 -114
- package/dist/types/amount.js.map +1 -1
- package/dist/types/blob.d.ts +3 -4
- package/dist/types/blob.js +16 -28
- package/dist/types/blob.js.map +1 -1
- package/dist/types/currency.d.ts +5 -13
- package/dist/types/currency.js +53 -67
- package/dist/types/currency.js.map +1 -1
- package/dist/types/hash-128.d.ts +8 -3
- package/dist/types/hash-128.js +23 -23
- 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 -25
- 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 -23
- package/dist/types/hash-256.js.map +1 -1
- package/dist/types/hash.d.ts +4 -5
- package/dist/types/hash.js +25 -40
- 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 -95
- package/dist/types/path-set.js.map +1 -1
- package/dist/types/serialized-type.d.ts +27 -20
- package/dist/types/serialized-type.js +50 -61
- 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 -48
- 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 -75
- 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 -34
- 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 -37
- package/dist/types/uint-32.js.map +1 -1
- package/dist/types/uint-64.d.ts +6 -8
- package/dist/types/uint-64.js +43 -58
- 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 -34
- package/dist/types/uint-8.js.map +1 -1
- package/dist/types/uint.d.ts +6 -7
- package/dist/types/uint.js +16 -26
- 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 -36
- 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/dist/index.js.LICENSE.txt +0 -17
- package/test/amount.test.js +0 -43
- package/test/binary-json.test.js +0 -47
- package/test/binary-parser.test.js +0 -398
- package/test/binary-serializer.test.js +0 -264
- 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/ticket-create-binary.json +0 -1
- package/test/fixtures/ticket-create-tx.json +0 -7
- package/test/fixtures/x-codec-fixtures.json +0 -188
- package/test/hash.test.js +0 -83
- 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 -89
- package/test/signing-data-encoding.test.js +0 -129
- package/test/tx-encode-decode.test.js +0 -97
- package/test/types.test.js +0 -34
- package/test/uint.test.js +0 -40
- package/test/utils.js +0 -30
- package/test/x-address.test.js +0 -147
package/dist/types/account-id.js
CHANGED
|
@@ -1,30 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __extends = (this && this.__extends) || (function () {
|
|
3
|
-
var extendStatics = function (d, b) {
|
|
4
|
-
extendStatics = Object.setPrototypeOf ||
|
|
5
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
-
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
|
|
7
|
-
return extendStatics(d, b);
|
|
8
|
-
};
|
|
9
|
-
return function (d, b) {
|
|
10
|
-
extendStatics(d, b);
|
|
11
|
-
function __() { this.constructor = d; }
|
|
12
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
13
|
-
};
|
|
14
|
-
})();
|
|
15
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
3
|
exports.AccountID = void 0;
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
4
|
+
const ripple_address_codec_1 = require("ripple-address-codec");
|
|
5
|
+
const hash_160_1 = require("./hash-160");
|
|
6
|
+
const utils_1 = require("@xrplf/isomorphic/utils");
|
|
7
|
+
const HEX_REGEX = /^[A-F0-9]{40}$/;
|
|
21
8
|
/**
|
|
22
9
|
* Class defining how to encode and decode an AccountID
|
|
23
10
|
*/
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
return _super.call(this, bytes !== null && bytes !== void 0 ? bytes : AccountID.defaultAccountID.bytes) || this;
|
|
11
|
+
class AccountID extends hash_160_1.Hash160 {
|
|
12
|
+
constructor(bytes) {
|
|
13
|
+
super(bytes !== null && bytes !== void 0 ? bytes : AccountID.defaultAccountID.bytes);
|
|
28
14
|
}
|
|
29
15
|
/**
|
|
30
16
|
* Defines how to construct an AccountID
|
|
@@ -32,49 +18,52 @@ var AccountID = /** @class */ (function (_super) {
|
|
|
32
18
|
* @param value either an existing AccountID, a hex-string, or a base58 r-Address
|
|
33
19
|
* @returns an AccountID object
|
|
34
20
|
*/
|
|
35
|
-
|
|
21
|
+
static from(value) {
|
|
36
22
|
if (value instanceof AccountID) {
|
|
37
23
|
return value;
|
|
38
24
|
}
|
|
39
|
-
if (typeof value ===
|
|
40
|
-
if (value ===
|
|
25
|
+
if (typeof value === 'string') {
|
|
26
|
+
if (value === '') {
|
|
41
27
|
return new AccountID();
|
|
42
28
|
}
|
|
43
29
|
return HEX_REGEX.test(value)
|
|
44
|
-
? new AccountID(
|
|
30
|
+
? new AccountID((0, utils_1.hexToBytes)(value))
|
|
45
31
|
: this.fromBase58(value);
|
|
46
32
|
}
|
|
47
|
-
throw new Error(
|
|
48
|
-
}
|
|
33
|
+
throw new Error('Cannot construct AccountID from value given');
|
|
34
|
+
}
|
|
49
35
|
/**
|
|
50
36
|
* Defines how to build an AccountID from a base58 r-Address
|
|
51
37
|
*
|
|
52
38
|
* @param value a base58 r-Address
|
|
53
39
|
* @returns an AccountID object
|
|
54
40
|
*/
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
41
|
+
static fromBase58(value) {
|
|
42
|
+
if ((0, ripple_address_codec_1.isValidXAddress)(value)) {
|
|
43
|
+
const classic = (0, ripple_address_codec_1.xAddressToClassicAddress)(value);
|
|
44
|
+
if (classic.tag !== false)
|
|
45
|
+
throw new Error('Only allowed to have tag on Account or Destination');
|
|
46
|
+
value = classic.classicAddress;
|
|
47
|
+
}
|
|
48
|
+
return new AccountID(Uint8Array.from((0, ripple_address_codec_1.decodeAccountID)(value)));
|
|
49
|
+
}
|
|
58
50
|
/**
|
|
59
51
|
* Overload of toJSON
|
|
60
52
|
*
|
|
61
53
|
* @returns the base58 string for this AccountID
|
|
62
54
|
*/
|
|
63
|
-
|
|
55
|
+
toJSON() {
|
|
64
56
|
return this.toBase58();
|
|
65
|
-
}
|
|
57
|
+
}
|
|
66
58
|
/**
|
|
67
59
|
* Defines how to encode AccountID into a base58 address
|
|
68
60
|
*
|
|
69
61
|
* @returns the base58 string defined by this.bytes
|
|
70
62
|
*/
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
};
|
|
76
|
-
AccountID.defaultAccountID = new AccountID(buffer_1.Buffer.alloc(20));
|
|
77
|
-
return AccountID;
|
|
78
|
-
}(hash_160_1.Hash160));
|
|
63
|
+
toBase58() {
|
|
64
|
+
return (0, ripple_address_codec_1.encodeAccountID)(this.bytes);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
79
67
|
exports.AccountID = AccountID;
|
|
68
|
+
AccountID.defaultAccountID = new AccountID(new Uint8Array(20));
|
|
80
69
|
//# sourceMappingURL=account-id.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"account-id.js","sourceRoot":"","sources":["../../src/types/account-id.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"account-id.js","sourceRoot":"","sources":["../../src/types/account-id.ts"],"names":[],"mappings":";;;AAAA,+DAK6B;AAC7B,yCAAoC;AACpC,mDAAoD;AAEpD,MAAM,SAAS,GAAG,gBAAgB,CAAA;AAElC;;GAEG;AACH,MAAM,SAAU,SAAQ,kBAAO;IAK7B,YAAY,KAAkB;QAC5B,KAAK,CAAC,KAAK,aAAL,KAAK,cAAL,KAAK,GAAI,SAAS,CAAC,gBAAgB,CAAC,KAAK,CAAC,CAAA;IAClD,CAAC;IAED;;;;;OAKG;IACH,MAAM,CAAC,IAAI,CAA6B,KAAQ;QAC9C,IAAI,KAAK,YAAY,SAAS,EAAE;YAC9B,OAAO,KAAK,CAAA;SACb;QAED,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE;YAC7B,IAAI,KAAK,KAAK,EAAE,EAAE;gBAChB,OAAO,IAAI,SAAS,EAAE,CAAA;aACvB;YAED,OAAO,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC;gBAC1B,CAAC,CAAC,IAAI,SAAS,CAAC,IAAA,kBAAU,EAAC,KAAK,CAAC,CAAC;gBAClC,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,CAAA;SAC3B;QAED,MAAM,IAAI,KAAK,CAAC,6CAA6C,CAAC,CAAA;IAChE,CAAC;IAED;;;;;OAKG;IACH,MAAM,CAAC,UAAU,CAAC,KAAa;QAC7B,IAAI,IAAA,sCAAe,EAAC,KAAK,CAAC,EAAE;YAC1B,MAAM,OAAO,GAAG,IAAA,+CAAwB,EAAC,KAAK,CAAC,CAAA;YAE/C,IAAI,OAAO,CAAC,GAAG,KAAK,KAAK;gBACvB,MAAM,IAAI,KAAK,CAAC,oDAAoD,CAAC,CAAA;YAEvE,KAAK,GAAG,OAAO,CAAC,cAAc,CAAA;SAC/B;QAED,OAAO,IAAI,SAAS,CAAC,UAAU,CAAC,IAAI,CAAC,IAAA,sCAAe,EAAC,KAAK,CAAC,CAAC,CAAC,CAAA;IAC/D,CAAC;IAED;;;;OAIG;IACH,MAAM;QACJ,OAAO,IAAI,CAAC,QAAQ,EAAE,CAAA;IACxB,CAAC;IAED;;;;OAIG;IACH,QAAQ;QACN,OAAO,IAAA,sCAAe,EAAC,IAAI,CAAC,KAAK,CAAC,CAAA;IACpC,CAAC;;AAGM,8BAAS;AAtEA,0BAAgB,GAAc,IAAI,SAAS,CACzD,IAAI,UAAU,CAAC,EAAE,CAAC,CACnB,CAAA"}
|
package/dist/types/amount.d.ts
CHANGED
|
@@ -1,22 +1,26 @@
|
|
|
1
|
-
import { BinaryParser } from
|
|
2
|
-
import { JsonObject, SerializedType } from
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Interface for JSON objects that represent amounts
|
|
6
|
-
*/
|
|
7
|
-
interface AmountObject extends JsonObject {
|
|
1
|
+
import { BinaryParser } from '../serdes/binary-parser';
|
|
2
|
+
import { JsonObject, SerializedType } from './serialized-type';
|
|
3
|
+
interface AmountObjectIOU extends JsonObject {
|
|
8
4
|
value: string;
|
|
9
5
|
currency: string;
|
|
10
6
|
issuer: string;
|
|
11
7
|
}
|
|
8
|
+
interface AmountObjectMPT extends JsonObject {
|
|
9
|
+
value: string;
|
|
10
|
+
mpt_issuance_id: string;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Interface for JSON objects that represent amounts
|
|
14
|
+
*/
|
|
15
|
+
type AmountObject = AmountObjectIOU | AmountObjectMPT;
|
|
12
16
|
/**
|
|
13
17
|
* Class for serializing/Deserializing Amounts
|
|
14
18
|
*/
|
|
15
19
|
declare class Amount extends SerializedType {
|
|
16
20
|
static defaultAmount: Amount;
|
|
17
|
-
constructor(bytes:
|
|
21
|
+
constructor(bytes: Uint8Array);
|
|
18
22
|
/**
|
|
19
|
-
* Construct an amount from an IOU or string amount
|
|
23
|
+
* Construct an amount from an IOU, MPT or string amount
|
|
20
24
|
*
|
|
21
25
|
* @param value An Amount, object representing an IOU, or a string
|
|
22
26
|
* representing an integer amount
|
|
@@ -46,10 +50,17 @@ declare class Amount extends SerializedType {
|
|
|
46
50
|
/**
|
|
47
51
|
* Validate IOU.value amount
|
|
48
52
|
*
|
|
49
|
-
* @param decimal
|
|
53
|
+
* @param decimal BigNumber object representing IOU.value
|
|
50
54
|
* @returns void, but will throw if invalid amount
|
|
51
55
|
*/
|
|
52
56
|
private static assertIouIsValid;
|
|
57
|
+
/**
|
|
58
|
+
* Validate MPT.value amount
|
|
59
|
+
*
|
|
60
|
+
* @param decimal BigNumber object representing MPT.value
|
|
61
|
+
* @returns void, but will throw if invalid amount
|
|
62
|
+
*/
|
|
63
|
+
private static assertMptIsValid;
|
|
53
64
|
/**
|
|
54
65
|
* Ensure that the value after being multiplied by the exponent does not
|
|
55
66
|
* contain a decimal.
|
|
@@ -64,5 +75,17 @@ declare class Amount extends SerializedType {
|
|
|
64
75
|
* @returns true if Native (XRP)
|
|
65
76
|
*/
|
|
66
77
|
private isNative;
|
|
78
|
+
/**
|
|
79
|
+
* Test if this amount is in units of MPT
|
|
80
|
+
*
|
|
81
|
+
* @returns true if MPT
|
|
82
|
+
*/
|
|
83
|
+
private isMPT;
|
|
84
|
+
/**
|
|
85
|
+
* Test if this amount is in units of IOU
|
|
86
|
+
*
|
|
87
|
+
* @returns true if IOU
|
|
88
|
+
*/
|
|
89
|
+
private isIOU;
|
|
67
90
|
}
|
|
68
91
|
export { Amount, AmountObject };
|
package/dist/types/amount.js
CHANGED
|
@@ -1,153 +1,169 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
-
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
|
|
7
|
-
return extendStatics(d, b);
|
|
8
|
-
};
|
|
9
|
-
return function (d, b) {
|
|
10
|
-
extendStatics(d, b);
|
|
11
|
-
function __() { this.constructor = d; }
|
|
12
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
13
|
-
};
|
|
14
|
-
})();
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
15
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
6
|
exports.Amount = void 0;
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
7
|
+
const binary_parser_1 = require("../serdes/binary-parser");
|
|
8
|
+
const account_id_1 = require("./account-id");
|
|
9
|
+
const currency_1 = require("./currency");
|
|
10
|
+
const serialized_type_1 = require("./serialized-type");
|
|
11
|
+
const bignumber_js_1 = __importDefault(require("bignumber.js"));
|
|
12
|
+
const utils_1 = require("@xrplf/isomorphic/utils");
|
|
13
|
+
const utils_2 = require("../utils");
|
|
14
|
+
const hash_192_1 = require("./hash-192");
|
|
24
15
|
/**
|
|
25
16
|
* Constants for validating amounts
|
|
26
17
|
*/
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
18
|
+
const MIN_IOU_EXPONENT = -96;
|
|
19
|
+
const MAX_IOU_EXPONENT = 80;
|
|
20
|
+
const MAX_IOU_PRECISION = 16;
|
|
21
|
+
const MAX_DROPS = new bignumber_js_1.default('1e17');
|
|
22
|
+
const MIN_XRP = new bignumber_js_1.default('1e-6');
|
|
23
|
+
const mask = BigInt(0x00000000ffffffff);
|
|
24
|
+
const mptMask = BigInt(0x8000000000000000);
|
|
33
25
|
/**
|
|
34
|
-
*
|
|
26
|
+
* BigNumber configuration for Amount IOUs
|
|
35
27
|
*/
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
28
|
+
bignumber_js_1.default.config({
|
|
29
|
+
EXPONENTIAL_AT: [
|
|
30
|
+
MIN_IOU_EXPONENT - MAX_IOU_PRECISION,
|
|
31
|
+
MAX_IOU_EXPONENT + MAX_IOU_PRECISION,
|
|
32
|
+
],
|
|
39
33
|
});
|
|
40
34
|
/**
|
|
41
|
-
* Type guard for
|
|
35
|
+
* Type guard for AmountObjectIOU
|
|
42
36
|
*/
|
|
43
|
-
function
|
|
44
|
-
|
|
37
|
+
function isAmountObjectIOU(arg) {
|
|
38
|
+
const keys = Object.keys(arg).sort();
|
|
45
39
|
return (keys.length === 3 &&
|
|
46
|
-
keys[0] ===
|
|
47
|
-
keys[1] ===
|
|
48
|
-
keys[2] ===
|
|
40
|
+
keys[0] === 'currency' &&
|
|
41
|
+
keys[1] === 'issuer' &&
|
|
42
|
+
keys[2] === 'value');
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Type guard for AmountObjectMPT
|
|
46
|
+
*/
|
|
47
|
+
function isAmountObjectMPT(arg) {
|
|
48
|
+
const keys = Object.keys(arg).sort();
|
|
49
|
+
return (keys.length === 2 && keys[0] === 'mpt_issuance_id' && keys[1] === 'value');
|
|
49
50
|
}
|
|
50
51
|
/**
|
|
51
52
|
* Class for serializing/Deserializing Amounts
|
|
52
53
|
*/
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
return _super.call(this, bytes !== null && bytes !== void 0 ? bytes : Amount.defaultAmount.bytes) || this;
|
|
54
|
+
class Amount extends serialized_type_1.SerializedType {
|
|
55
|
+
constructor(bytes) {
|
|
56
|
+
super(bytes !== null && bytes !== void 0 ? bytes : Amount.defaultAmount.bytes);
|
|
57
57
|
}
|
|
58
58
|
/**
|
|
59
|
-
* Construct an amount from an IOU or string amount
|
|
59
|
+
* Construct an amount from an IOU, MPT or string amount
|
|
60
60
|
*
|
|
61
61
|
* @param value An Amount, object representing an IOU, or a string
|
|
62
62
|
* representing an integer amount
|
|
63
63
|
* @returns An Amount object
|
|
64
64
|
*/
|
|
65
|
-
|
|
65
|
+
static from(value) {
|
|
66
66
|
if (value instanceof Amount) {
|
|
67
67
|
return value;
|
|
68
68
|
}
|
|
69
|
-
|
|
70
|
-
if (typeof value ===
|
|
69
|
+
let amount = new Uint8Array(8);
|
|
70
|
+
if (typeof value === 'string') {
|
|
71
71
|
Amount.assertXrpIsValid(value);
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
intBuf[0]
|
|
75
|
-
intBuf[1]
|
|
76
|
-
amount =
|
|
72
|
+
const number = BigInt(value);
|
|
73
|
+
const intBuf = [new Uint8Array(4), new Uint8Array(4)];
|
|
74
|
+
(0, utils_2.writeUInt32BE)(intBuf[0], Number(number >> BigInt(32)), 0);
|
|
75
|
+
(0, utils_2.writeUInt32BE)(intBuf[1], Number(number & BigInt(mask)), 0);
|
|
76
|
+
amount = (0, utils_1.concat)(intBuf);
|
|
77
77
|
amount[0] |= 0x40;
|
|
78
78
|
return new Amount(amount);
|
|
79
79
|
}
|
|
80
|
-
if (
|
|
81
|
-
|
|
80
|
+
if (isAmountObjectIOU(value)) {
|
|
81
|
+
const number = new bignumber_js_1.default(value.value);
|
|
82
82
|
Amount.assertIouIsValid(number);
|
|
83
83
|
if (number.isZero()) {
|
|
84
84
|
amount[0] |= 0x80;
|
|
85
85
|
}
|
|
86
86
|
else {
|
|
87
|
-
|
|
88
|
-
.times(
|
|
87
|
+
const integerNumberString = number
|
|
88
|
+
.times(`1e${-((number.e || 0) - 15)}`)
|
|
89
89
|
.abs()
|
|
90
90
|
.toString();
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
intBuf[0]
|
|
94
|
-
intBuf[1]
|
|
95
|
-
amount =
|
|
91
|
+
const num = BigInt(integerNumberString);
|
|
92
|
+
const intBuf = [new Uint8Array(4), new Uint8Array(4)];
|
|
93
|
+
(0, utils_2.writeUInt32BE)(intBuf[0], Number(num >> BigInt(32)), 0);
|
|
94
|
+
(0, utils_2.writeUInt32BE)(intBuf[1], Number(num & BigInt(mask)), 0);
|
|
95
|
+
amount = (0, utils_1.concat)(intBuf);
|
|
96
96
|
amount[0] |= 0x80;
|
|
97
|
-
if (number.gt(new
|
|
97
|
+
if (number.gt(new bignumber_js_1.default(0))) {
|
|
98
98
|
amount[0] |= 0x40;
|
|
99
99
|
}
|
|
100
|
-
|
|
101
|
-
|
|
100
|
+
const exponent = (number.e || 0) - 15;
|
|
101
|
+
const exponentByte = 97 + exponent;
|
|
102
102
|
amount[0] |= exponentByte >>> 2;
|
|
103
103
|
amount[1] |= (exponentByte & 0x03) << 6;
|
|
104
104
|
}
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
return new Amount(
|
|
105
|
+
const currency = currency_1.Currency.from(value.currency).toBytes();
|
|
106
|
+
const issuer = account_id_1.AccountID.from(value.issuer).toBytes();
|
|
107
|
+
return new Amount((0, utils_1.concat)([amount, currency, issuer]));
|
|
108
108
|
}
|
|
109
|
-
|
|
110
|
-
|
|
109
|
+
if (isAmountObjectMPT(value)) {
|
|
110
|
+
Amount.assertMptIsValid(value.value);
|
|
111
|
+
let leadingByte = new Uint8Array(1);
|
|
112
|
+
leadingByte[0] |= 0x60;
|
|
113
|
+
const num = BigInt(value.value);
|
|
114
|
+
const intBuf = [new Uint8Array(4), new Uint8Array(4)];
|
|
115
|
+
(0, utils_2.writeUInt32BE)(intBuf[0], Number(num >> BigInt(32)), 0);
|
|
116
|
+
(0, utils_2.writeUInt32BE)(intBuf[1], Number(num & BigInt(mask)), 0);
|
|
117
|
+
amount = (0, utils_1.concat)(intBuf);
|
|
118
|
+
const mptIssuanceID = hash_192_1.Hash192.from(value.mpt_issuance_id).toBytes();
|
|
119
|
+
return new Amount((0, utils_1.concat)([leadingByte, amount, mptIssuanceID]));
|
|
120
|
+
}
|
|
121
|
+
throw new Error('Invalid type to construct an Amount');
|
|
122
|
+
}
|
|
111
123
|
/**
|
|
112
124
|
* Read an amount from a BinaryParser
|
|
113
125
|
*
|
|
114
126
|
* @param parser BinaryParser to read the Amount from
|
|
115
127
|
* @returns An Amount object
|
|
116
128
|
*/
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
129
|
+
static fromParser(parser) {
|
|
130
|
+
const isIOU = parser.peek() & 0x80;
|
|
131
|
+
if (isIOU)
|
|
132
|
+
return new Amount(parser.read(48));
|
|
133
|
+
// the amount can be either MPT or XRP at this point
|
|
134
|
+
const isMPT = parser.peek() & 0x20;
|
|
135
|
+
const numBytes = isMPT ? 33 : 8;
|
|
120
136
|
return new Amount(parser.read(numBytes));
|
|
121
|
-
}
|
|
137
|
+
}
|
|
122
138
|
/**
|
|
123
139
|
* Get the JSON representation of this Amount
|
|
124
140
|
*
|
|
125
141
|
* @returns the JSON interpretation of this.bytes
|
|
126
142
|
*/
|
|
127
|
-
|
|
143
|
+
toJSON() {
|
|
128
144
|
if (this.isNative()) {
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
145
|
+
const bytes = this.bytes;
|
|
146
|
+
const isPositive = bytes[0] & 0x40;
|
|
147
|
+
const sign = isPositive ? '' : '-';
|
|
132
148
|
bytes[0] &= 0x3f;
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
return
|
|
149
|
+
const msb = BigInt((0, utils_2.readUInt32BE)(bytes.slice(0, 4), 0));
|
|
150
|
+
const lsb = BigInt((0, utils_2.readUInt32BE)(bytes.slice(4), 0));
|
|
151
|
+
const num = (msb << BigInt(32)) | lsb;
|
|
152
|
+
return `${sign}${num.toString()}`;
|
|
137
153
|
}
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
154
|
+
if (this.isIOU()) {
|
|
155
|
+
const parser = new binary_parser_1.BinaryParser(this.toString());
|
|
156
|
+
const mantissa = parser.read(8);
|
|
157
|
+
const currency = currency_1.Currency.fromParser(parser);
|
|
158
|
+
const issuer = account_id_1.AccountID.fromParser(parser);
|
|
159
|
+
const b1 = mantissa[0];
|
|
160
|
+
const b2 = mantissa[1];
|
|
161
|
+
const isPositive = b1 & 0x40;
|
|
162
|
+
const sign = isPositive ? '' : '-';
|
|
163
|
+
const exponent = ((b1 & 0x3f) << 2) + ((b2 & 0xff) >> 6) - 97;
|
|
148
164
|
mantissa[0] = 0;
|
|
149
165
|
mantissa[1] &= 0x3f;
|
|
150
|
-
|
|
166
|
+
const value = new bignumber_js_1.default(`${sign}0x${(0, utils_1.bytesToHex)(mantissa)}`).times(`1e${exponent}`);
|
|
151
167
|
Amount.assertIouIsValid(value);
|
|
152
168
|
return {
|
|
153
169
|
value: value.toString(),
|
|
@@ -155,42 +171,78 @@ var Amount = /** @class */ (function (_super) {
|
|
|
155
171
|
issuer: issuer.toJSON(),
|
|
156
172
|
};
|
|
157
173
|
}
|
|
158
|
-
|
|
174
|
+
if (this.isMPT()) {
|
|
175
|
+
const parser = new binary_parser_1.BinaryParser(this.toString());
|
|
176
|
+
const leadingByte = parser.read(1);
|
|
177
|
+
const amount = parser.read(8);
|
|
178
|
+
const mptID = hash_192_1.Hash192.fromParser(parser);
|
|
179
|
+
const isPositive = leadingByte[0] & 0x40;
|
|
180
|
+
const sign = isPositive ? '' : '-';
|
|
181
|
+
const msb = BigInt((0, utils_2.readUInt32BE)(amount.slice(0, 4), 0));
|
|
182
|
+
const lsb = BigInt((0, utils_2.readUInt32BE)(amount.slice(4), 0));
|
|
183
|
+
const num = (msb << BigInt(32)) | lsb;
|
|
184
|
+
return {
|
|
185
|
+
value: `${sign}${num.toString()}`,
|
|
186
|
+
mpt_issuance_id: mptID.toString(),
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
throw new Error('Invalid amount to construct JSON');
|
|
190
|
+
}
|
|
159
191
|
/**
|
|
160
192
|
* Validate XRP amount
|
|
161
193
|
*
|
|
162
194
|
* @param amount String representing XRP amount
|
|
163
195
|
* @returns void, but will throw if invalid amount
|
|
164
196
|
*/
|
|
165
|
-
|
|
166
|
-
if (amount.indexOf(
|
|
167
|
-
throw new Error(amount.toString()
|
|
197
|
+
static assertXrpIsValid(amount) {
|
|
198
|
+
if (amount.indexOf('.') !== -1) {
|
|
199
|
+
throw new Error(`${amount.toString()} is an illegal amount`);
|
|
168
200
|
}
|
|
169
|
-
|
|
201
|
+
const decimal = new bignumber_js_1.default(amount);
|
|
170
202
|
if (!decimal.isZero()) {
|
|
171
203
|
if (decimal.lt(MIN_XRP) || decimal.gt(MAX_DROPS)) {
|
|
172
|
-
throw new Error(amount.toString()
|
|
204
|
+
throw new Error(`${amount.toString()} is an illegal amount`);
|
|
173
205
|
}
|
|
174
206
|
}
|
|
175
|
-
}
|
|
207
|
+
}
|
|
176
208
|
/**
|
|
177
209
|
* Validate IOU.value amount
|
|
178
210
|
*
|
|
179
|
-
* @param decimal
|
|
211
|
+
* @param decimal BigNumber object representing IOU.value
|
|
180
212
|
* @returns void, but will throw if invalid amount
|
|
181
213
|
*/
|
|
182
|
-
|
|
214
|
+
static assertIouIsValid(decimal) {
|
|
183
215
|
if (!decimal.isZero()) {
|
|
184
|
-
|
|
185
|
-
|
|
216
|
+
const p = decimal.precision();
|
|
217
|
+
const e = (decimal.e || 0) - 15;
|
|
186
218
|
if (p > MAX_IOU_PRECISION ||
|
|
187
219
|
e > MAX_IOU_EXPONENT ||
|
|
188
220
|
e < MIN_IOU_EXPONENT) {
|
|
189
|
-
throw new Error(
|
|
221
|
+
throw new Error('Decimal precision out of range');
|
|
190
222
|
}
|
|
191
223
|
this.verifyNoDecimal(decimal);
|
|
192
224
|
}
|
|
193
|
-
}
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* Validate MPT.value amount
|
|
228
|
+
*
|
|
229
|
+
* @param decimal BigNumber object representing MPT.value
|
|
230
|
+
* @returns void, but will throw if invalid amount
|
|
231
|
+
*/
|
|
232
|
+
static assertMptIsValid(amount) {
|
|
233
|
+
if (amount.indexOf('.') !== -1) {
|
|
234
|
+
throw new Error(`${amount.toString()} is an illegal amount`);
|
|
235
|
+
}
|
|
236
|
+
const decimal = new bignumber_js_1.default(amount);
|
|
237
|
+
if (!decimal.isZero()) {
|
|
238
|
+
if (decimal < (0, bignumber_js_1.default)(0)) {
|
|
239
|
+
throw new Error(`${amount.toString()} is an illegal amount`);
|
|
240
|
+
}
|
|
241
|
+
if (Number(BigInt(amount) & BigInt(mptMask)) != 0) {
|
|
242
|
+
throw new Error(`${amount.toString()} is an illegal amount`);
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
}
|
|
194
246
|
/**
|
|
195
247
|
* Ensure that the value after being multiplied by the exponent does not
|
|
196
248
|
* contain a decimal.
|
|
@@ -198,25 +250,40 @@ var Amount = /** @class */ (function (_super) {
|
|
|
198
250
|
* @param decimal a Decimal object
|
|
199
251
|
* @returns a string of the object without a decimal
|
|
200
252
|
*/
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
.times(
|
|
253
|
+
static verifyNoDecimal(decimal) {
|
|
254
|
+
const integerNumberString = decimal
|
|
255
|
+
.times(`1e${-((decimal.e || 0) - 15)}`)
|
|
204
256
|
.abs()
|
|
205
257
|
.toString();
|
|
206
|
-
if (integerNumberString.indexOf(
|
|
207
|
-
throw new Error(
|
|
258
|
+
if (integerNumberString.indexOf('.') !== -1) {
|
|
259
|
+
throw new Error('Decimal place found in integerNumberString');
|
|
208
260
|
}
|
|
209
|
-
}
|
|
261
|
+
}
|
|
210
262
|
/**
|
|
211
263
|
* Test if this amount is in units of Native Currency(XRP)
|
|
212
264
|
*
|
|
213
265
|
* @returns true if Native (XRP)
|
|
214
266
|
*/
|
|
215
|
-
|
|
216
|
-
return (this.bytes[0] & 0x80) === 0;
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
267
|
+
isNative() {
|
|
268
|
+
return (this.bytes[0] & 0x80) === 0 && (this.bytes[0] & 0x20) === 0;
|
|
269
|
+
}
|
|
270
|
+
/**
|
|
271
|
+
* Test if this amount is in units of MPT
|
|
272
|
+
*
|
|
273
|
+
* @returns true if MPT
|
|
274
|
+
*/
|
|
275
|
+
isMPT() {
|
|
276
|
+
return (this.bytes[0] & 0x80) === 0 && (this.bytes[0] & 0x20) !== 0;
|
|
277
|
+
}
|
|
278
|
+
/**
|
|
279
|
+
* Test if this amount is in units of IOU
|
|
280
|
+
*
|
|
281
|
+
* @returns true if IOU
|
|
282
|
+
*/
|
|
283
|
+
isIOU() {
|
|
284
|
+
return (this.bytes[0] & 0x80) !== 0;
|
|
285
|
+
}
|
|
286
|
+
}
|
|
221
287
|
exports.Amount = Amount;
|
|
288
|
+
Amount.defaultAmount = new Amount((0, utils_1.hexToBytes)('4000000000000000'));
|
|
222
289
|
//# sourceMappingURL=amount.js.map
|