@bithomp/xrpl-api 2.6.6 → 2.7.0

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.
@@ -1,4 +1,4 @@
1
- import { AccountObjectType, AccountObjectsResponse, AccountNFTObjectsResponse, AccountURITokensObjectsResponse } from "../models/account_object";
1
+ import { AccountObjectType, AccountObjects, AccountNFTObjectsResponse, AccountURITokensObjectsResponse } from "../models/account_object";
2
2
  import { AccountLinesResponse } from "../models/account_lines";
3
3
  import { ErrorResponse } from "../models/base_model";
4
4
  import { LedgerIndex } from "../models/ledger";
@@ -9,11 +9,11 @@ export interface GetAccountObjectsOptions {
9
9
  limit?: number;
10
10
  marker?: string;
11
11
  }
12
- export declare function getAccountObjects(account: string, options?: GetAccountObjectsOptions): Promise<AccountObjectsResponse | ErrorResponse>;
12
+ export declare function getAccountObjects(account: string, options?: GetAccountObjectsOptions): Promise<AccountObjects | ErrorResponse>;
13
13
  export interface GetAccountAllObjectsOptions extends GetAccountObjectsOptions {
14
14
  timeout?: number;
15
15
  }
16
- export declare function getAccountAllObjects(account: string, options?: GetAccountAllObjectsOptions): Promise<AccountObjectsResponse | ErrorResponse>;
16
+ export declare function getAccountAllObjects(account: string, options?: GetAccountAllObjectsOptions): Promise<AccountObjects | ErrorResponse>;
17
17
  export interface GetAccountLinesObjectsOptions {
18
18
  ledgerHash?: string;
19
19
  ledgerIndex?: LedgerIndex;
@@ -1,8 +1,13 @@
1
1
  import { LedgerIndex } from "../models/ledger";
2
2
  import { ErrorResponse } from "../models/base_model";
3
+ import { FormattedAccountOrders } from "../parse/ledger/account-order";
4
+ import { AccountOffers } from "../v1/common/types/commands/account_offers";
3
5
  export interface GetAccountOffers {
4
6
  ledgerIndex?: LedgerIndex;
5
7
  limit?: number;
6
8
  marker?: any;
9
+ legacy?: boolean;
10
+ formatted?: boolean;
7
11
  }
8
- export declare function getAccountOffers(account: string, options?: GetAccountOffers): Promise<object | ErrorResponse>;
12
+ export declare function getAccountOffers(account: string, options?: GetAccountOffers): Promise<AccountOffers | FormattedAccountOrders | ErrorResponse>;
13
+ export declare function getAccountAllOffers(account: string, options?: GetAccountOffers): Promise<AccountOffers | FormattedAccountOrders | ErrorResponse>;
@@ -22,11 +22,18 @@ var __importStar = (this && this.__importStar) || function (mod) {
22
22
  __setModuleDefault(result, mod);
23
23
  return result;
24
24
  };
25
+ var __importDefault = (this && this.__importDefault) || function (mod) {
26
+ return (mod && mod.__esModule) ? mod : { "default": mod };
27
+ };
25
28
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.getAccountOffers = void 0;
29
+ exports.getAccountAllOffers = exports.getAccountOffers = void 0;
30
+ const lodash_1 = __importDefault(require("lodash"));
27
31
  const Client = __importStar(require("../client"));
28
32
  const utils_1 = require("../common/utils");
33
+ const account_order_1 = require("../parse/ledger/account-order");
34
+ const OFFERS_LIMIT_MAX = 400;
29
35
  async function getAccountOffers(account, options = {}) {
36
+ const formatted = options.legacy === true || options.formatted === true;
30
37
  const { hash, marker } = (0, utils_1.parseMarker)(options.marker);
31
38
  options.marker = marker;
32
39
  const connection = Client.findConnection(undefined, undefined, undefined, hash);
@@ -62,6 +69,61 @@ async function getAccountOffers(account, options = {}) {
62
69
  if (newMarker) {
63
70
  result.marker = newMarker;
64
71
  }
72
+ if (formatted === true) {
73
+ result.offers = formatResponse(account, result.offers);
74
+ }
65
75
  return result;
66
76
  }
67
77
  exports.getAccountOffers = getAccountOffers;
78
+ async function getAccountAllOffers(account, options = {}) {
79
+ const limit = options.limit;
80
+ let response;
81
+ const accountOffers = [];
82
+ while (true) {
83
+ if (options.limit && limit) {
84
+ const left = limit - accountOffers.length;
85
+ const parts = Math.floor(left / OFFERS_LIMIT_MAX);
86
+ if (parts === 0) {
87
+ options.limit = left;
88
+ }
89
+ else {
90
+ options.limit = left;
91
+ }
92
+ }
93
+ response = await getAccountOffers(account, options);
94
+ if (response.error) {
95
+ return response;
96
+ }
97
+ accountOffers.push(...response.offers);
98
+ if (limit && accountOffers.length >= limit) {
99
+ response.limit = accountOffers.length;
100
+ break;
101
+ }
102
+ if (response.marker) {
103
+ options.marker = response.marker;
104
+ }
105
+ else {
106
+ break;
107
+ }
108
+ }
109
+ if (response.error) {
110
+ const { error, error_code, error_message, status, validated } = response;
111
+ return {
112
+ account,
113
+ error,
114
+ error_code,
115
+ error_message,
116
+ status,
117
+ validated,
118
+ };
119
+ }
120
+ response.offers = accountOffers;
121
+ return response;
122
+ }
123
+ exports.getAccountAllOffers = getAccountAllOffers;
124
+ function formatResponse(address, offers) {
125
+ const orders = offers.map((offer) => {
126
+ return (0, account_order_1.parseAccountOrder)(address, offer);
127
+ });
128
+ return lodash_1.default.sortBy(orders, (order) => order.properties.sequence);
129
+ }
@@ -26,7 +26,7 @@ interface LegacyPaymentInterface {
26
26
  destinationValue: string;
27
27
  destinationCurrency: string;
28
28
  networkID?: number;
29
- memos: FormattedMemo[];
29
+ memos?: FormattedMemo[];
30
30
  secret: string;
31
31
  fee?: string;
32
32
  }
@@ -3,7 +3,7 @@ import { Trustline } from "./account_lines";
3
3
  import { Amount } from "../v1/common/types/objects";
4
4
  export type AccountObject = LedgerEntry.Check | LedgerEntry.DepositPreauth | LedgerEntry.Escrow | LedgerEntry.Offer | LedgerEntry.PayChannel | LedgerEntry.SignerList | LedgerEntry.Ticket | LedgerEntry.RippleState;
5
5
  export type AccountObjectType = "check" | "escrow" | "offer" | "payment_channel" | "signer_list" | "state" | "ticket" | "nft_offer";
6
- export interface AccountObjectsResponse {
6
+ export interface AccountObjects {
7
7
  account: string;
8
8
  account_objects: AccountObject[];
9
9
  ledger_hash?: string;
@@ -1,4 +1,12 @@
1
1
  import { FormattedOfferCreateSpecification } from "../../v1/common/types/objects";
2
+ export type FormattedAccountOrders = {
3
+ account: string;
4
+ offers?: FormattedAccountOrder[];
5
+ ledger_current_index?: number;
6
+ ledger_index?: number;
7
+ ledger_hash?: string;
8
+ marker?: unknown;
9
+ };
2
10
  export type FormattedAccountOrder = {
3
11
  specification: FormattedOfferCreateSpecification;
4
12
  properties: {
@@ -0,0 +1,13 @@
1
+ import { FormattedSourceAddress, FormattedDestinationAddress } from "../../v1/common/types/objects/account";
2
+ declare function parseEscrowChanges(tx: any): {
3
+ status: string | undefined;
4
+ escrowIndex: any;
5
+ escrowSequence: any;
6
+ amount: any;
7
+ condition: any;
8
+ source: FormattedSourceAddress;
9
+ destination: FormattedDestinationAddress;
10
+ allowCancelAfter: string | undefined;
11
+ allowExecuteAfter: string | undefined;
12
+ } | undefined;
13
+ export { parseEscrowChanges };
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parseEscrowChanges = void 0;
4
+ const common_1 = require("../../common");
5
+ const utils_1 = require("../../v1/common/utils");
6
+ const utils_2 = require("../utils");
7
+ function parseEscrowStatus(tx, node) {
8
+ if (node.diffType === "CreatedNode") {
9
+ return "created";
10
+ }
11
+ if (node.diffType === "DeletedNode") {
12
+ if (tx.TransactionType === "EscrowCancel") {
13
+ return "cancelled";
14
+ }
15
+ if (tx.TransactionType === "EscrowFinish") {
16
+ return "executed";
17
+ }
18
+ return "deleted";
19
+ }
20
+ return undefined;
21
+ }
22
+ function parseEscrowSequence(tx) {
23
+ if (tx.TransactionType === "EscrowCreate") {
24
+ return tx.Sequence || tx.TicketSequence;
25
+ }
26
+ if (tx.TransactionType === "EscrowCancel" || tx.TransactionType === "EscrowFinish") {
27
+ return tx.OfferSequence;
28
+ }
29
+ return undefined;
30
+ }
31
+ function summarizeEscrow(tx, node) {
32
+ const final = node.diffType === "CreatedNode" ? node.newFields : node.finalFields;
33
+ const source = {
34
+ address: final.Account,
35
+ tag: final.SourceTag,
36
+ };
37
+ const destination = {
38
+ address: final.Destination,
39
+ tag: final.DestinationTag,
40
+ };
41
+ const summary = (0, common_1.removeUndefined)({
42
+ status: parseEscrowStatus(tx, node),
43
+ escrowIndex: node.ledgerIndex,
44
+ escrowSequence: parseEscrowSequence(tx),
45
+ amount: final.Amount,
46
+ condition: final.Condition,
47
+ source: (0, common_1.removeUndefined)(source),
48
+ destination: (0, common_1.removeUndefined)(destination),
49
+ allowCancelAfter: (0, utils_2.parseTimestamp)(final.CancelAfter),
50
+ allowExecuteAfter: (0, utils_2.parseTimestamp)(final.FinishAfter),
51
+ });
52
+ return summary;
53
+ }
54
+ function parseEscrowChanges(tx) {
55
+ const escrows = (0, utils_1.normalizeNodes)(tx.meta).filter((n) => {
56
+ return n.entryType === "Escrow";
57
+ });
58
+ return escrows.length === 1 ? summarizeEscrow(tx, escrows[0]) : undefined;
59
+ }
60
+ exports.parseEscrowChanges = parseEscrowChanges;
@@ -9,3 +9,4 @@ export { parseChannelChanges } from "./channel_changes";
9
9
  export { parseOrderbookChanges } from "./orderbook_changes";
10
10
  export { parseHooksExecutions } from "./hooks_executions";
11
11
  export { parseEmittedTxns } from "./emitted_txns";
12
+ export { parseEscrowChanges } from "./escrow_changes";
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.parseEmittedTxns = exports.parseHooksExecutions = exports.parseOrderbookChanges = exports.parseChannelChanges = exports.parseLockedBalanceChanges = exports.parseBalanceChanges = exports.parseURITokenSellOfferChanges = exports.parseURITokenChanges = exports.parseNFTokenOfferChanges = exports.parseNFTokenChanges = exports.parseAffectedObjects = void 0;
3
+ exports.parseEscrowChanges = exports.parseEmittedTxns = exports.parseHooksExecutions = exports.parseOrderbookChanges = exports.parseChannelChanges = exports.parseLockedBalanceChanges = exports.parseBalanceChanges = exports.parseURITokenSellOfferChanges = exports.parseURITokenChanges = exports.parseNFTokenOfferChanges = exports.parseNFTokenChanges = exports.parseAffectedObjects = void 0;
4
4
  var affected_objects_1 = require("./affected_objects");
5
5
  Object.defineProperty(exports, "parseAffectedObjects", { enumerable: true, get: function () { return affected_objects_1.parseAffectedObjects; } });
6
6
  var nftoken_changes_1 = require("./nftoken_changes");
@@ -23,3 +23,5 @@ var hooks_executions_1 = require("./hooks_executions");
23
23
  Object.defineProperty(exports, "parseHooksExecutions", { enumerable: true, get: function () { return hooks_executions_1.parseHooksExecutions; } });
24
24
  var emitted_txns_1 = require("./emitted_txns");
25
25
  Object.defineProperty(exports, "parseEmittedTxns", { enumerable: true, get: function () { return emitted_txns_1.parseEmittedTxns; } });
26
+ var escrow_changes_1 = require("./escrow_changes");
27
+ Object.defineProperty(exports, "parseEscrowChanges", { enumerable: true, get: function () { return escrow_changes_1.parseEscrowChanges; } });
@@ -69,6 +69,7 @@ function parseOutcome(tx, nativeCurrency, definitions) {
69
69
  const lockedBalanceChanges = (0, index_1.parseLockedBalanceChanges)(metadata);
70
70
  const orderbookChanges = (0, index_1.parseOrderbookChanges)(metadata);
71
71
  const channelChanges = (0, index_1.parseChannelChanges)(metadata);
72
+ const escrowChanges = (0, index_1.parseEscrowChanges)(tx);
72
73
  const nftokenChanges = (0, index_1.parseNFTokenChanges)(tx);
73
74
  const nftokenOfferChanges = (0, index_1.parseNFTokenOfferChanges)(tx);
74
75
  const uritokenChanges = (0, index_1.parseURITokenChanges)(tx);
@@ -84,11 +85,12 @@ function parseOutcome(tx, nativeCurrency, definitions) {
84
85
  timestamp: (0, utils_1.parseTimestamp)(tx.date),
85
86
  fee: (0, common_1.dropsToXrp)(tx.Fee),
86
87
  balanceChanges,
87
- lockedBalanceChanges,
88
- orderbookChanges,
88
+ lockedBalanceChanges: Object.keys(lockedBalanceChanges).length > 0 ? lockedBalanceChanges : undefined,
89
+ orderbookChanges: Object.keys(orderbookChanges).length > 0 ? orderbookChanges : undefined,
89
90
  channelChanges,
90
- nftokenChanges,
91
- nftokenOfferChanges,
91
+ escrowChanges,
92
+ nftokenChanges: Object.keys(nftokenChanges).length > 0 ? nftokenChanges : undefined,
93
+ nftokenOfferChanges: Object.keys(nftokenOfferChanges).length > 0 ? nftokenOfferChanges : undefined,
92
94
  uritokenChanges: Object.keys(uritokenChanges).length > 0 ? uritokenChanges : undefined,
93
95
  uritokenSellOfferChanges: Object.keys(uritokenSellOfferChanges).length > 0 ? uritokenSellOfferChanges : undefined,
94
96
  affectedObjects: affectedObjects ? (0, common_1.removeUndefined)(affectedObjects) : undefined,
@@ -31,10 +31,15 @@ const common_1 = require("../../common");
31
31
  const memos_1 = __importDefault(require("../ledger/memos"));
32
32
  function parseEscrowCancel(tx) {
33
33
  assert.ok(tx.TransactionType === "EscrowCancel");
34
+ const source = {
35
+ address: tx.Account,
36
+ tag: tx.SourceTag,
37
+ };
34
38
  return (0, common_1.removeUndefined)({
35
- memos: (0, memos_1.default)(tx),
39
+ source: (0, common_1.removeUndefined)(source),
36
40
  owner: tx.Owner,
37
41
  escrowSequence: tx.OfferSequence,
42
+ memos: (0, memos_1.default)(tx),
38
43
  });
39
44
  }
40
45
  exports.default = parseEscrowCancel;
@@ -28,20 +28,26 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
28
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
29
  const assert = __importStar(require("assert"));
30
30
  const common_1 = require("../../common");
31
- const ripple_amount_1 = __importDefault(require("../ledger/ripple-amount"));
32
31
  const utils_1 = require("../utils");
33
32
  const memos_1 = __importDefault(require("../ledger/memos"));
34
33
  function parseEscrowCreation(tx) {
35
34
  assert.ok(tx.TransactionType === "EscrowCreate");
35
+ const source = {
36
+ address: tx.Account,
37
+ tag: tx.SourceTag,
38
+ };
39
+ const destination = {
40
+ address: tx.Destination,
41
+ tag: tx.DestinationTag,
42
+ };
36
43
  return (0, common_1.removeUndefined)({
37
- amount: (0, ripple_amount_1.default)(tx.Amount),
38
- destination: tx.Destination,
39
- memos: (0, memos_1.default)(tx),
44
+ amount: tx.Amount,
45
+ source: (0, common_1.removeUndefined)(source),
46
+ destination: (0, common_1.removeUndefined)(destination),
40
47
  condition: tx.Condition,
41
48
  allowCancelAfter: (0, utils_1.parseTimestamp)(tx.CancelAfter),
42
49
  allowExecuteAfter: (0, utils_1.parseTimestamp)(tx.FinishAfter),
43
- sourceTag: tx.SourceTag,
44
- destinationTag: tx.DestinationTag,
50
+ memos: (0, memos_1.default)(tx),
45
51
  });
46
52
  }
47
53
  exports.default = parseEscrowCreation;
@@ -31,12 +31,17 @@ const common_1 = require("../../common");
31
31
  const memos_1 = __importDefault(require("../ledger/memos"));
32
32
  function parseEscrowFinish(tx) {
33
33
  assert.ok(tx.TransactionType === "EscrowFinish");
34
+ const source = {
35
+ address: tx.Account,
36
+ tag: tx.SourceTag,
37
+ };
34
38
  return (0, common_1.removeUndefined)({
35
- memos: (0, memos_1.default)(tx),
39
+ source: (0, common_1.removeUndefined)(source),
36
40
  owner: tx.Owner,
37
41
  escrowSequence: tx.OfferSequence,
38
42
  condition: tx.Condition,
39
43
  fulfillment: tx.Fulfillment,
44
+ memos: (0, memos_1.default)(tx),
40
45
  });
41
46
  }
42
47
  exports.default = parseEscrowFinish;
@@ -14,7 +14,7 @@ export interface AccountObjectsRequest {
14
14
  limit?: number;
15
15
  marker?: string;
16
16
  }
17
- export interface AccountObjectsResponse {
17
+ export interface AccountObjects {
18
18
  account: string;
19
19
  account_objects: Array<CheckLedgerEntry | RippleStateLedgerEntry | OfferLedgerEntry | SignerListLedgerEntry | EscrowLedgerEntry | PayChannelLedgerEntry | DepositPreauthLedgerEntry>;
20
20
  ledger_hash?: string;
@@ -1,4 +1,4 @@
1
- import { Amount } from "../objects";
1
+ import { AccountOffer } from "xrpl";
2
2
  export interface AccountOffersRequest {
3
3
  account: string;
4
4
  ledger_hash?: string;
@@ -6,19 +6,11 @@ export interface AccountOffersRequest {
6
6
  limit?: number;
7
7
  marker?: any;
8
8
  }
9
- export interface AccountOffersResponse {
9
+ export interface AccountOffers {
10
10
  account: string;
11
- ledger_hash?: string;
11
+ offers?: AccountOffer[];
12
12
  ledger_current_index?: number;
13
13
  ledger_index?: number;
14
- marker?: any;
15
- offers?: AccountOffer[];
16
- }
17
- export interface AccountOffer {
18
- seq: number;
19
- flags: number;
20
- taker_gets: Amount;
21
- taker_pays: Amount;
22
- quality: string;
23
- expiration?: number;
14
+ ledger_hash?: string;
15
+ marker?: unknown;
24
16
  }
@@ -1,19 +1,21 @@
1
1
  import { FormattedBaseSpecification } from "./specification";
2
- import { FormattedAmount } from "../../../../types";
2
+ import { Amount } from "../../../../types";
3
+ import { FormattedSourceAddress, FormattedDestinationAddress } from "./account";
3
4
  export type FormattedEscrowCancelSpecification = {
5
+ source: FormattedSourceAddress;
4
6
  owner: string;
5
7
  escrowSequence: number;
6
8
  } & FormattedBaseSpecification;
7
9
  export type FormattedEscrowCreateSpecification = {
8
- amount?: FormattedAmount;
9
- destination: string;
10
+ amount?: Amount;
11
+ source: FormattedSourceAddress;
12
+ destination: FormattedDestinationAddress;
10
13
  condition: string;
11
14
  allowCancelAfter?: string;
12
15
  allowExecuteAfter?: string;
13
- sourceTag?: number;
14
- destinationTag?: number;
15
16
  } & FormattedBaseSpecification;
16
17
  export type FormattedEscrowFinishSpecification = {
18
+ source: FormattedSourceAddress;
17
19
  owner: string;
18
20
  escrowSequence: number;
19
21
  condition?: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bithomp/xrpl-api",
3
- "version": "2.6.6",
3
+ "version": "2.7.0",
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",
@@ -47,7 +47,7 @@
47
47
  "lib/**/*"
48
48
  ],
49
49
  "dependencies": {
50
- "axios": "^1.6.1",
50
+ "axios": "^1.6.2",
51
51
  "base-x": "^4.0.0",
52
52
  "bignumber.js": "^9.1.2",
53
53
  "elliptic": "^6.5.4",
@@ -63,8 +63,8 @@
63
63
  "@types/mocha": "^10.0.4",
64
64
  "@types/nconf": "^0.10.6",
65
65
  "@types/node": "^20.9.0",
66
- "@typescript-eslint/eslint-plugin": "^6.10.0",
67
- "@typescript-eslint/parser": "^6.10.0",
66
+ "@typescript-eslint/eslint-plugin": "^6.11.0",
67
+ "@typescript-eslint/parser": "^6.11.0",
68
68
  "chai": "^4.3.10",
69
69
  "chai-as-promised": "^7.1.1",
70
70
  "mocha": "^10.2.0",