Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for disallowIncoming flags #2221

Merged
merged 5 commits into from
Feb 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/xrpl/HISTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
32 changes: 32 additions & 0 deletions packages/xrpl/src/models/ledger/AccountRoot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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,
}
9 changes: 9 additions & 0 deletions packages/xrpl/src/models/transactions/accountSet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}

/**
Expand Down
4 changes: 2 additions & 2 deletions packages/xrpl/test/models/accountSet.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -60,7 +60,7 @@ describe('AccountSet', function () {
})

it(`throws w/ invalid ClearFlag`, function () {
account.ClearFlag = 12
account.ClearFlag = 20

assert.throws(
() => validateAccountSet(account),
Expand Down
17 changes: 15 additions & 2 deletions packages/xrpl/test/models/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand All @@ -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)

Expand All @@ -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,
)
})

Expand All @@ -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)
})
})
})