Skip to content

Commit

Permalink
Rename MPTokenHolder to Holder (#2)
Browse files Browse the repository at this point in the history
* rename

* update definition.json
  • Loading branch information
shawnxie999 authored Oct 28, 2024
1 parent 9bfb200 commit 92efe13
Show file tree
Hide file tree
Showing 11 changed files with 1,213 additions and 1,242 deletions.
2,399 changes: 1,187 additions & 1,212 deletions packages/ripple-binary-codec/src/enums/definitions.json

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions packages/xrpl/src/models/ledger/MPToken.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ import { BaseLedgerEntry, HasPreviousTxnID } from './BaseLedgerEntry'
export interface MPToken extends BaseLedgerEntry, HasPreviousTxnID {
LedgerEntryType: 'MPToken'
MPTokenIssuanceID: string
MPTAmount: MPTAmount
LockedAmount?: MPTAmount
MPTAmount?: MPTAmount
Flags: number
OwnerNode?: string
}
1 change: 0 additions & 1 deletion packages/xrpl/src/models/ledger/MPTokenIssuance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ export interface MPTokenIssuance extends BaseLedgerEntry, HasPreviousTxnID {
AssetScale?: number
MaximumAmount?: string
OutstandingAmount: string
LockedAmount?: string
TransferFee?: number
MPTokenMetadata?: string
OwnerNode?: string
Expand Down
4 changes: 2 additions & 2 deletions packages/xrpl/src/models/transactions/MPTokenAuthorize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export interface MPTokenAuthorize extends BaseTransaction {
* An optional XRPL Address of an individual token holder balance to lock/unlock.
* If omitted, this transaction will apply to all any accounts holding MPTs.
*/
MPTokenHolder?: Account
Holder?: Account
Flags?: number | MPTokenAuthorizeFlagsInterface
}

Expand All @@ -63,5 +63,5 @@ export interface MPTokenAuthorize extends BaseTransaction {
export function validateMPTokenAuthorize(tx: Record<string, unknown>): void {
validateBaseTransaction(tx)
validateRequiredField(tx, 'MPTokenIssuanceID', isString)
validateOptionalField(tx, 'MPTokenHolder', isAccount)
validateOptionalField(tx, 'Holder', isAccount)
}
4 changes: 2 additions & 2 deletions packages/xrpl/src/models/transactions/MPTokenIssuanceSet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export interface MPTokenIssuanceSet extends BaseTransaction {
* An optional XRPL Address of an individual token holder balance to lock/unlock.
* If omitted, this transaction will apply to all any accounts holding MPTs.
*/
MPTokenHolder?: Account
Holder?: Account
Flags?: number | MPTokenIssuanceSetFlagsInterface
}

Expand All @@ -65,7 +65,7 @@ export interface MPTokenIssuanceSet extends BaseTransaction {
export function validateMPTokenIssuanceSet(tx: Record<string, unknown>): void {
validateBaseTransaction(tx)
validateRequiredField(tx, 'MPTokenIssuanceID', isString)
validateOptionalField(tx, 'MPTokenHolder', isAccount)
validateOptionalField(tx, 'Holder', isAccount)

/* eslint-disable no-bitwise -- We need bitwise operations for flag checks here */
if (typeof tx.Flags === 'number') {
Expand Down
16 changes: 7 additions & 9 deletions packages/xrpl/src/models/transactions/clawback.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export interface Clawback extends BaseTransaction {
* Indicates the AccountID that the issuer wants to clawback. This field is only valid for clawing back
* MPTs.
*/
MPTokenHolder?: string
Holder?: string
}

/**
Expand All @@ -42,7 +42,7 @@ export interface Clawback extends BaseTransaction {
*/
export function validateClawback(tx: Record<string, unknown>): void {
validateBaseTransaction(tx)
validateOptionalField(tx, 'MPTokenHolder', isAccount)
validateOptionalField(tx, 'Holder', isAccount)

if (tx.Amount == null) {
throw new ValidationError('Clawback: missing field Amount')
Expand All @@ -56,17 +56,15 @@ export function validateClawback(tx: Record<string, unknown>): void {
throw new ValidationError('Clawback: invalid holder Account')
}

if (isMPTAmount(tx.Amount) && tx.Account === tx.MPTokenHolder) {
if (isMPTAmount(tx.Amount) && tx.Account === tx.Holder) {
throw new ValidationError('Clawback: invalid holder Account')
}

if (isIssuedCurrency(tx.Amount) && tx.MPTokenHolder) {
throw new ValidationError(
'Clawback: cannot have MPTokenHolder for currency',
)
if (isIssuedCurrency(tx.Amount) && tx.Holder) {
throw new ValidationError('Clawback: cannot have Holder for currency')
}

if (isMPTAmount(tx.Amount) && !tx.MPTokenHolder) {
throw new ValidationError('Clawback: missing MPTokenHolder')
if (isMPTAmount(tx.Amount) && !tx.Holder) {
throw new ValidationError('Clawback: missing Holder')
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ describe('Clawback', function () {
mpt_issuance_id: mptID!,
value: '500',
},
MPTokenHolder: wallet2.classicAddress,
Holder: wallet2.classicAddress,
}
await testTransaction(testContext.client, clawTx, testContext.wallet)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ describe('MPTokenIssuanceDestroy', function () {
TransactionType: 'MPTokenAuthorize',
Account: testContext.wallet.classicAddress,
MPTokenIssuanceID: mptID!,
MPTokenHolder: wallet2.classicAddress,
Holder: wallet2.classicAddress,
}

await testTransaction(testContext.client, authTx, testContext.wallet)
Expand Down
4 changes: 2 additions & 2 deletions packages/xrpl/test/models/MPTokenAuthorize.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ describe('MPTokenAuthorize', function () {
validMPTokenAuthorize = {
TransactionType: 'MPTokenAuthorize',
Account: 'rWYkbWkCeg8dP6rXALnjgZSjjLyih5NXm',
MPTokenHolder: 'rajgkBmMxmz161r8bWYH7CQAFZP5bA9oSG',
Holder: 'rajgkBmMxmz161r8bWYH7CQAFZP5bA9oSG',
MPTokenIssuanceID: TOKEN_ID,
} as any

Expand Down Expand Up @@ -50,7 +50,7 @@ describe('MPTokenAuthorize', function () {
TransactionType: 'MPTokenAuthorize',
Account: 'rWYkbWkCeg8dP6rXALnjgZSjjLyih5NXm',
MPTokenIssuanceID: TOKEN_ID,
MPTokenHolder: 'rajgkBmMxmz161r8bWYH7CQAFZP5bA9oSG',
Holder: 'rajgkBmMxmz161r8bWYH7CQAFZP5bA9oSG',
Flags: MPTokenAuthorizeFlags.tfMPTUnauthorize,
} as any

Expand Down
4 changes: 2 additions & 2 deletions packages/xrpl/test/models/MPTokenIssuanceSet.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ describe('MPTokenIssuanceSet', function () {
TransactionType: 'MPTokenIssuanceSet',
Account: 'rWYkbWkCeg8dP6rXALnjgZSjjLyih5NXm',
MPTokenIssuanceID: TOKEN_ID,
MPTokenHolder: 'rajgkBmMxmz161r8bWYH7CQAFZP5bA9oSG',
Holder: 'rajgkBmMxmz161r8bWYH7CQAFZP5bA9oSG',
Flags: MPTokenIssuanceSetFlags.tfMPTLock,
} as any

Expand All @@ -34,7 +34,7 @@ describe('MPTokenIssuanceSet', function () {
TransactionType: 'MPTokenIssuanceSet',
Account: 'rWYkbWkCeg8dP6rXALnjgZSjjLyih5NXm',
MPTokenIssuanceID: TOKEN_ID,
MPTokenHolder: 'rajgkBmMxmz161r8bWYH7CQAFZP5bA9oSG',
Holder: 'rajgkBmMxmz161r8bWYH7CQAFZP5bA9oSG',
} as any

assert.doesNotThrow(() => validate(validMPTokenIssuanceSet))
Expand Down
16 changes: 8 additions & 8 deletions packages/xrpl/test/models/clawback.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,21 +87,21 @@ describe('Clawback', function () {
value: '10',
},
Account: 'rWYkbWkCeg8dP6rXALnjgZSjjLyih5NXm',
MPTokenHolder: 'rfkE1aSy9G8Upk4JssnwBxhEv5p4mn2KTy',
Holder: 'rfkE1aSy9G8Upk4JssnwBxhEv5p4mn2KTy',
} as any

assert.doesNotThrow(() => validate(validClawback))
})

it(`throws w/ invalid MPTokenHolder Account`, function () {
it(`throws w/ invalid Holder Account`, function () {
const invalidAccount = {
TransactionType: 'Clawback',
Amount: {
mpt_issuance_id: '000004C463C52827307480341125DA0577DEFC38405B0E3E',
value: '10',
},
Account: 'rWYkbWkCeg8dP6rXALnjgZSjjLyih5NXm',
MPTokenHolder: 'rWYkbWkCeg8dP6rXALnjgZSjjLyih5NXm',
Holder: 'rWYkbWkCeg8dP6rXALnjgZSjjLyih5NXm',
} as any

assert.throws(
Expand All @@ -111,7 +111,7 @@ describe('Clawback', function () {
)
})

it(`throws w/ invalid MPTokenHolder`, function () {
it(`throws w/ invalid Holder`, function () {
const invalidAccount = {
TransactionType: 'Clawback',
Amount: {
Expand All @@ -124,11 +124,11 @@ describe('Clawback', function () {
assert.throws(
() => validate(invalidAccount),
ValidationError,
'Clawback: missing MPTokenHolder',
'Clawback: missing Holder',
)
})

it(`throws w/ invalid currency MPTokenHolder`, function () {
it(`throws w/ invalid currency Holder`, function () {
const invalidAccount = {
TransactionType: 'Clawback',
Amount: {
Expand All @@ -137,13 +137,13 @@ describe('Clawback', function () {
value: '43.11584856965009',
},
Account: 'rWYkbWkCeg8dP6rXALnjgZSjjLyih5NXm',
MPTokenHolder: 'rfkE1aSy9G8Upk4JssnwBxhEv5p4mn2KTy',
Holder: 'rfkE1aSy9G8Upk4JssnwBxhEv5p4mn2KTy',
} as any

assert.throws(
() => validate(invalidAccount),
ValidationError,
'Clawback: cannot have MPTokenHolder for currency',
'Clawback: cannot have Holder for currency',
)
})
})

0 comments on commit 92efe13

Please sign in to comment.