@bithomp/xrpl-api 3.3.1 → 3.3.8
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/lib/ledger/currency.js
CHANGED
|
@@ -39,7 +39,9 @@ const utils_1 = require("../parse/utils");
|
|
|
39
39
|
const transaction_1 = require("../parse/transaction");
|
|
40
40
|
const client_1 = require("../client");
|
|
41
41
|
const common_1 = require("../common");
|
|
42
|
-
const
|
|
42
|
+
const amm_info_1 = require("../models/amm_info");
|
|
43
|
+
const maxLength = 20;
|
|
44
|
+
const DECODED_HEX_CURRENCY_REGEX = /[^-\w\(\)\[\]\u0020-\u007E\u00A0-\uFFFF]*/g;
|
|
43
45
|
async function parseCurrencyInformation(currency) {
|
|
44
46
|
if (!currency || typeof currency !== "string") {
|
|
45
47
|
return null;
|
|
@@ -67,6 +69,9 @@ async function decodeCurrencyHex(currencyCode) {
|
|
|
67
69
|
if (prefix === "02" && isXlf15d(currencyCode)) {
|
|
68
70
|
return await decodeXlf15d(currencyCode);
|
|
69
71
|
}
|
|
72
|
+
else if (prefix === "03" && amm_info_1.AMM_LP_TOKEN_REGEX.test(currencyCode)) {
|
|
73
|
+
return decodeLPTokenHex(currencyCode);
|
|
74
|
+
}
|
|
70
75
|
else {
|
|
71
76
|
return decodeHex(currencyCode);
|
|
72
77
|
}
|
|
@@ -129,16 +134,39 @@ async function decodeXlf15d(currencyCode) {
|
|
|
129
134
|
};
|
|
130
135
|
}
|
|
131
136
|
function decodeHex(currencyHex) {
|
|
132
|
-
|
|
133
|
-
|
|
137
|
+
let hex = currencyHex;
|
|
138
|
+
const prefix = currencyHex.substring(0, 2);
|
|
139
|
+
if (prefix === "02") {
|
|
140
|
+
hex = currencyHex.substring(16, currencyHex.length);
|
|
141
|
+
}
|
|
142
|
+
const decoded = (0, utils_1.hexToString)(hex)
|
|
143
|
+
?.slice(0, maxLength)
|
|
144
|
+
?.replace(/^\u0000+/, "")
|
|
145
|
+
?.replace(/\u0000+$/, "")
|
|
146
|
+
?.trim();
|
|
147
|
+
const trimmed = decoded
|
|
148
|
+
.replace(DECODED_HEX_CURRENCY_REGEX, "")
|
|
149
|
+
.replace(/[�]*/g, "")
|
|
150
|
+
.replace(/\s+/g, " ")
|
|
151
|
+
.trim();
|
|
152
|
+
if (trimmed.length > 1 &&
|
|
153
|
+
trimmed.length >= decoded.length / 2 &&
|
|
154
|
+
trimmed.toUpperCase() !== (0, client_1.getNativeCurrency)()) {
|
|
134
155
|
return {
|
|
135
156
|
type: "hex",
|
|
136
157
|
currencyCode: currencyHex,
|
|
137
|
-
currency:
|
|
158
|
+
currency: trimmed,
|
|
138
159
|
};
|
|
139
160
|
}
|
|
140
161
|
return null;
|
|
141
162
|
}
|
|
163
|
+
function decodeLPTokenHex(currencyHex) {
|
|
164
|
+
return {
|
|
165
|
+
type: "lp_token",
|
|
166
|
+
currencyCode: currencyHex,
|
|
167
|
+
currency: "LP Token",
|
|
168
|
+
};
|
|
169
|
+
}
|
|
142
170
|
async function getLedger(ledgerIndex) {
|
|
143
171
|
let ledgerInfo = null;
|
|
144
172
|
try {
|
|
@@ -58,7 +58,10 @@ const RippleStateToTrustLine = (ledgerEntry, account) => {
|
|
|
58
58
|
const balance = ledgerEntry.HighLimit.issuer === account && ledgerEntry.Balance.value.startsWith("-")
|
|
59
59
|
? ledgerEntry.Balance.value.slice(1)
|
|
60
60
|
: ledgerEntry.Balance.value;
|
|
61
|
-
|
|
61
|
+
let lockedBalance = ledgerEntry.LockedBalance?.value;
|
|
62
|
+
if (lockedBalance && lockedBalance.startsWith("-")) {
|
|
63
|
+
lockedBalance = lockedBalance.slice(1);
|
|
64
|
+
}
|
|
62
65
|
let lockCount = undefined;
|
|
63
66
|
if (lockedBalance) {
|
|
64
67
|
lockCount = ledgerEntry.LockCount;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const AMM_LP_TOKEN_REGEX: RegExp;
|
package/lib/models/index.d.ts
CHANGED
package/lib/models/index.js
CHANGED
|
@@ -21,6 +21,7 @@ exports.parseOfferFlags = exports.parseTrustlineFlags = exports.parseURITokenFla
|
|
|
21
21
|
__exportStar(require("./account_info"), exports);
|
|
22
22
|
__exportStar(require("./account_nfts"), exports);
|
|
23
23
|
__exportStar(require("./account_object"), exports);
|
|
24
|
+
__exportStar(require("./amm_info"), exports);
|
|
24
25
|
__exportStar(require("./ledger"), exports);
|
|
25
26
|
__exportStar(require("./manifest"), exports);
|
|
26
27
|
__exportStar(require("./transaction"), exports);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bithomp/xrpl-api",
|
|
3
|
-
"version": "3.3.
|
|
3
|
+
"version": "3.3.8",
|
|
4
4
|
"description": "A Bithomp JavaScript/TypeScript library for interacting with the XRP Ledger",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -52,15 +52,15 @@
|
|
|
52
52
|
"lib/**/*"
|
|
53
53
|
],
|
|
54
54
|
"dependencies": {
|
|
55
|
-
"axios": "^1.
|
|
55
|
+
"axios": "^1.10.0",
|
|
56
56
|
"base-x": "^5.0.1",
|
|
57
57
|
"bignumber.js": "^9.3.0",
|
|
58
58
|
"elliptic": "^6.6.1",
|
|
59
59
|
"lodash": "^4.17.21",
|
|
60
60
|
"ripple-address-codec": "5.0.0",
|
|
61
|
-
"ripple-binary-codec": "2.
|
|
61
|
+
"ripple-binary-codec": "2.4.1",
|
|
62
62
|
"ripple-keypairs": "2.0.0",
|
|
63
|
-
"xrpl": "4.
|
|
63
|
+
"xrpl": "4.3.0"
|
|
64
64
|
},
|
|
65
65
|
"devDependencies": {
|
|
66
66
|
"@eslint/eslintrc": "^3.3.1",
|