From 3d0bec7e89527fb5c437e7b0858d29dc281e1bf4 Mon Sep 17 00:00:00 2001 From: Jackson Mills Date: Tue, 21 Feb 2023 10:22:47 -0800 Subject: [PATCH] Add support for disallowIncoming flags (#2221) * Add support for disallowIncoming flags * Fix broken tests * Update packages/xrpl/src/models/ledger/AccountRoot.ts * Update packages/xrpl/src/models/ledger/AccountRoot.ts * Update HISTORY.md --- packages/xrpl/HISTORY.md | 1 + .../xrpl/src/models/ledger/AccountRoot.ts | 32 +++++++++++++++++++ .../src/models/transactions/accountSet.ts | 9 ++++++ packages/xrpl/test/models/accountSet.test.ts | 4 +-- packages/xrpl/test/models/utils.test.ts | 17 ++++++++-- 5 files changed, 59 insertions(+), 4 deletions(-) diff --git a/packages/xrpl/HISTORY.md b/packages/xrpl/HISTORY.md index e22ddc3d..a33e2d5a 100644 --- a/packages/xrpl/HISTORY.md +++ b/packages/xrpl/HISTORY.md @@ -26,6 +26,7 @@ Wallet.fromMmnemonic() ### Added * Optional custom amount field to `fundWallet`. +* Support for `disallowIncoming` account set flags (e.g. `asfDisallowIncomingTrustline`) ### Changed * Add support for Transaction objects in `verifyTransaction` diff --git a/packages/xrpl/src/models/ledger/AccountRoot.ts b/packages/xrpl/src/models/ledger/AccountRoot.ts index cb26bcdb..b98ead82 100644 --- a/packages/xrpl/src/models/ledger/AccountRoot.ts +++ b/packages/xrpl/src/models/ledger/AccountRoot.ts @@ -116,6 +116,22 @@ export interface AccountRootFlagsInterface { * (It has DepositAuth enabled.) */ lsfDepositAuth?: boolean + /** + * Disallow incoming NFTOffers from other accounts. + */ + lsfDisallowIncomingNFTOffer?: boolean + /** + * Disallow incoming Checks from other accounts. + */ + lsfDisallowIncomingCheck?: boolean + /** + * Disallow incoming PayChannels from other accounts. + */ + lsfDisallowIncomingPayChan?: boolean + /** + * Disallow incoming Trustlines from other accounts. + */ + lsfDisallowIncomingTrustline?: boolean } export enum AccountRootFlags { @@ -156,4 +172,20 @@ export enum AccountRootFlags { * (It has DepositAuth enabled.) */ lsfDepositAuth = 0x01000000, + /** + * Disallow incoming NFTOffers from other accounts. + */ + lsfDisallowIncomingNFTOffer = 0x04000000, + /** + * Disallow incoming Checks from other accounts. + */ + lsfDisallowIncomingCheck = 0x08000000, + /** + * Disallow incoming PayChannels from other accounts. + */ + lsfDisallowIncomingPayChan = 0x10000000, + /** + * Disallow incoming Trustlines from other accounts. + */ + lsfDisallowIncomingTrustline = 0x20000000, } diff --git a/packages/xrpl/src/models/transactions/accountSet.ts b/packages/xrpl/src/models/transactions/accountSet.ts index 8a57c575..9b57b1c6 100644 --- a/packages/xrpl/src/models/transactions/accountSet.ts +++ b/packages/xrpl/src/models/transactions/accountSet.ts @@ -44,6 +44,15 @@ export enum AccountSetAsfFlags { * Allow another account to mint and burn tokens on behalf of this account. */ asfAuthorizedNFTokenMinter = 10, + /** asf 11 is reserved for Hooks amendment */ + /** Disallow other accounts from creating incoming NFTOffers */ + asfDisallowIncomingNFTOffer = 12, + /** Disallow other accounts from creating incoming Checks */ + asfDisallowIncomingCheck = 13, + /** Disallow other accounts from creating incoming PayChannels */ + asfDisallowIncomingPayChan = 14, + /** Disallow other accounts from creating incoming Trustlines */ + asfDisallowIncomingTrustline = 15, } /** diff --git a/packages/xrpl/test/models/accountSet.test.ts b/packages/xrpl/test/models/accountSet.test.ts index 8b497250..3d9ba484 100644 --- a/packages/xrpl/test/models/accountSet.test.ts +++ b/packages/xrpl/test/models/accountSet.test.ts @@ -30,7 +30,7 @@ describe('AccountSet', function () { }) it(`throws w/ invalid SetFlag (out of range)`, function () { - account.SetFlag = 12 + account.SetFlag = 20 assert.throws( () => validateAccountSet(account), @@ -60,7 +60,7 @@ describe('AccountSet', function () { }) it(`throws w/ invalid ClearFlag`, function () { - account.ClearFlag = 12 + account.ClearFlag = 20 assert.throws( () => validateAccountSet(account), diff --git a/packages/xrpl/test/models/utils.test.ts b/packages/xrpl/test/models/utils.test.ts index 876256a6..b2eb9343 100644 --- a/packages/xrpl/test/models/utils.test.ts +++ b/packages/xrpl/test/models/utils.test.ts @@ -151,6 +151,7 @@ describe('Models Utils', function () { assert.strictEqual(tx.Flags, 0) }) + // eslint-disable-next-line complexity -- Simpler to list them all out at once. it('parseAccountRootFlags all enabled', function () { const accountRootFlags = AccountRootFlags.lsfDefaultRipple | @@ -161,7 +162,11 @@ describe('Models Utils', function () { AccountRootFlags.lsfNoFreeze | AccountRootFlags.lsfPasswordSpent | AccountRootFlags.lsfRequireAuth | - AccountRootFlags.lsfRequireDestTag + AccountRootFlags.lsfRequireDestTag | + AccountRootFlags.lsfDisallowIncomingNFTOffer | + AccountRootFlags.lsfDisallowIncomingCheck | + AccountRootFlags.lsfDisallowIncomingPayChan | + AccountRootFlags.lsfDisallowIncomingTrustline const parsed = parseAccountRootFlags(accountRootFlags) @@ -174,7 +179,11 @@ describe('Models Utils', function () { parsed.lsfNoFreeze && parsed.lsfPasswordSpent && parsed.lsfRequireAuth && - parsed.lsfRequireDestTag, + parsed.lsfRequireDestTag && + parsed.lsfDisallowIncomingNFTOffer && + parsed.lsfDisallowIncomingCheck && + parsed.lsfDisallowIncomingPayChan && + parsed.lsfDisallowIncomingTrustline, ) }) @@ -190,6 +199,10 @@ describe('Models Utils', function () { assert.isUndefined(parsed.lsfPasswordSpent) assert.isUndefined(parsed.lsfRequireAuth) assert.isUndefined(parsed.lsfRequireDestTag) + assert.isUndefined(parsed.lsfDisallowIncomingNFTOffer) + assert.isUndefined(parsed.lsfDisallowIncomingCheck) + assert.isUndefined(parsed.lsfDisallowIncomingPayChan) + assert.isUndefined(parsed.lsfDisallowIncomingTrustline) }) }) })