Skip to content

Commit 2c1734d

Browse files
authored
Account settings refactor and cleanup (#49)
1 parent d834680 commit 2c1734d

17 files changed

+108
-233
lines changed

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@bithomp/xrpl-api",
3-
"version": "2.2.17",
3+
"version": "2.2.18",
44
"description": "A Bithomp JavaScript/TypeScript library for interacting with the XRP Ledger",
55
"main": "lib/index.js",
66
"types": "lib/index.d.ts",

src/models/account_info.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { LedgerEntry } from "xrpl";
1+
import { LedgerEntry, AccountSetAsfFlags } from "xrpl";
22
import BigNumber from "bignumber.js";
33

44
import { BLACKHOLE_ACCOUNTS } from "../common";
@@ -36,6 +36,23 @@ export interface AccountRootFlagsKeysInterface {
3636
disallowIncomingTrustline?: boolean;
3737
}
3838

39+
export const AccountSetFlags = {
40+
requireDestinationTag: AccountSetAsfFlags.asfRequireDest,
41+
requireAuthorization: AccountSetAsfFlags.asfRequireAuth,
42+
depositAuth: AccountSetAsfFlags.asfDepositAuth,
43+
disallowIncomingXRP: AccountSetAsfFlags.asfDisallowXRP,
44+
disableMasterKey: AccountSetAsfFlags.asfDisableMaster,
45+
enableTransactionIDTracking: AccountSetAsfFlags.asfAccountTxnID,
46+
noFreeze: AccountSetAsfFlags.asfNoFreeze,
47+
globalFreeze: AccountSetAsfFlags.asfGlobalFreeze,
48+
defaultRipple: AccountSetAsfFlags.asfDefaultRipple,
49+
authorizedMinter: AccountSetAsfFlags.asfAuthorizedNFTokenMinter,
50+
disallowIncomingNFTokenOffer: AccountSetAsfFlags.asfDisallowIncomingNFTokenOffer,
51+
disallowIncomingCheck: AccountSetAsfFlags.asfDisallowIncomingCheck,
52+
disallowIncomingPayChan: AccountSetAsfFlags.asfDisallowIncomingPayChan,
53+
disallowIncomingTrustline: AccountSetAsfFlags.asfDisallowIncomingTrustline,
54+
};
55+
3956
export const SignerListFlagsKeys = {
4057
oneOwnerCount: LedgerEntry.SignerListFlags.lsfOneOwnerCount,
4158
};
@@ -51,6 +68,8 @@ export const AccountFields = {
5168
Domain: { name: "domain", encoding: "hex" },
5269
TransferRate: { name: "transferRate", defaults: 0, shift: 9 },
5370
TickSize: { name: "tickSize", defaults: 0 },
71+
RegularKey: { name: "regularKey" },
72+
NFTokenMinter: { name: "nftokenMinter" },
5473
};
5574

5675
/**

src/v1/common/constants.ts

Lines changed: 0 additions & 100 deletions
This file was deleted.

src/v1/common/index.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import * as constants from './constants'
21
import * as errors from './errors'
32
import {xAddressToClassicAddress, isValidXAddress} from 'ripple-address-codec'
43

@@ -22,7 +21,7 @@ export function ensureClassicAddress(account: string): string {
2221
}
2322
}
2423

25-
export {constants, errors}
24+
export {errors}
2625
export {
2726
dropsToXrp,
2827
xrpToDrops,
@@ -33,4 +32,3 @@ export {
3332
iso8601ToRippleTime,
3433
rippleTimeToISO8601
3534
} from './utils'
36-
export {txFlags} from './txflags'

src/v1/common/txflags.ts

Lines changed: 0 additions & 62 deletions
This file was deleted.

src/v1/ledger/parse/fields.ts

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import * as _ from 'lodash'
22
import BigNumber from 'bignumber.js'
3-
import {constants} from '../../common'
4-
const AccountFields = constants.AccountFields
3+
import {AccountFields} from "../../../models/account_info";
54

65
function parseField(info, value) {
76
if (info.encoding === 'hex' && !info.length) {
@@ -25,14 +24,6 @@ function parseFields(data: any): object {
2524
}
2625
}
2726

28-
if (data.RegularKey) {
29-
settings.regularKey = data.RegularKey
30-
}
31-
32-
if (data.NFTokenMinter) {
33-
settings.nftokenMinter = data.NFTokenMinter;
34-
}
35-
3627
// Since an account can own at most one SignerList,
3728
// this array must have exactly one member if it is present.
3829
if (data.signer_lists && data.signer_lists.length === 1) {

src/v1/ledger/parse/order.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
11
import * as assert from 'assert'
2+
import {OfferCreateFlags} from "xrpl";
23
import {parseTimestamp} from './utils'
34
import parseAmount from './amount'
45
import parseMemos from "./memos";
5-
import {removeUndefined, txFlags} from '../../common'
6+
import {removeUndefined} from '../../common'
67
import {
78
FormattedOrderSpecification,
89
OfferCreateTransaction
910
} from '../../common/types/objects/index'
1011

11-
const flags = txFlags.OfferCreate
12-
1312
function parseOrder(tx: OfferCreateTransaction): FormattedOrderSpecification {
1413
assert.ok(tx.TransactionType === 'OfferCreate')
1514

1615
// tslint:disable-next-line:no-bitwise
17-
const direction = (tx.Flags & flags.Sell) === 0 ? 'buy' : 'sell'
16+
const direction = (tx.Flags & OfferCreateFlags.tfSell) === 0 ? 'buy' : 'sell'
1817
const takerGetsAmount = parseAmount(tx.TakerGets)
1918
const takerPaysAmount = parseAmount(tx.TakerPays)
2019
const quantity = direction === 'buy' ? takerPaysAmount : takerGetsAmount
@@ -29,11 +28,11 @@ function parseOrder(tx: OfferCreateTransaction): FormattedOrderSpecification {
2928
// tslint:disable-next-line:object-literal-shorthand
3029
totalPrice: totalPrice,
3130
// tslint:disable-next-line:no-bitwise
32-
passive: (tx.Flags & flags.Passive) !== 0 || undefined,
31+
passive: (tx.Flags & OfferCreateFlags.tfPassive) !== 0 || undefined,
3332
// tslint:disable-next-line:no-bitwise
34-
immediateOrCancel: (tx.Flags & flags.ImmediateOrCancel) !== 0 || undefined,
33+
immediateOrCancel: (tx.Flags & OfferCreateFlags.tfImmediateOrCancel) !== 0 || undefined,
3534
// tslint:disable-next-line:no-bitwise
36-
fillOrKill: (tx.Flags & flags.FillOrKill) !== 0 || undefined,
35+
fillOrKill: (tx.Flags & OfferCreateFlags.tfFillOrKill) !== 0 || undefined,
3736
expirationTime: parseTimestamp(tx.Expiration)
3837
})
3938
}

src/v1/ledger/parse/payment-channel-claim.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import * as assert from 'assert'
2-
import {removeUndefined, txFlags} from '../../common'
2+
import {PaymentChannelClaimFlags} from "xrpl";
3+
import {removeUndefined} from '../../common'
34
import parseRippledAmount from './ripple-amount'
45
import parseMemos from "./memos";
5-
const claimFlags = txFlags.PaymentChannelClaim
66

77
function parsePaymentChannelClaim(tx: any): object {
88
assert.ok(tx.TransactionType === 'PaymentChannelClaim')
@@ -15,9 +15,9 @@ function parsePaymentChannelClaim(tx: any): object {
1515
signature: tx.Signature,
1616
publicKey: tx.PublicKey,
1717
// tslint:disable-next-line:no-bitwise
18-
renew: Boolean(tx.Flags & claimFlags.Renew) || undefined,
18+
renew: Boolean(tx.Flags & PaymentChannelClaimFlags.tfRenew) || undefined,
1919
// tslint:disable-next-line:no-bitwise
20-
close: Boolean(tx.Flags & claimFlags.Close) || undefined
20+
close: Boolean(tx.Flags & PaymentChannelClaimFlags.tfClose) || undefined
2121
})
2222
}
2323

src/v1/ledger/parse/payment.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
import * as _ from 'lodash'
22
import * as assert from 'assert'
3+
import {PaymentFlags} from "xrpl";
34
import {isPartialPayment} from './utils'
4-
import {txFlags, removeUndefined} from '../../common'
5+
import {removeUndefined} from '../../common'
56
import parseAmount from './amount'
67
import parseMemos from "./memos";
78

89
function isNoDirectRipple(tx) {
910
// tslint:disable-next-line:no-bitwise
10-
return (tx.Flags & txFlags.Payment.NoRippleDirect) !== 0
11+
return (tx.Flags & PaymentFlags.tfNoDirectRipple) !== 0
1112
}
1213

1314
function isQualityLimited(tx) {
1415
// tslint:disable-next-line:no-bitwise
15-
return (tx.Flags & txFlags.Payment.LimitQuality) !== 0
16+
return (tx.Flags & PaymentFlags.tfLimitQuality) !== 0
1617
}
1718

1819
function removeGenericCounterparty(amount, address) {

0 commit comments

Comments
 (0)