mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-11-30 09:05:50 +00:00
refactor: define TrustSet transaction model (#1549)
- Defines a TypeScript type for TrustSet - Provides an optional function to users for verifying a TrustSet instance at runtime: verifyTrustSet() - Adds tests for verifyTrustSet()
This commit is contained in:
committed by
Mayukha Vadari
parent
f7b93c54ff
commit
9e16327676
@@ -7,5 +7,6 @@ export * from './checkCash'
|
||||
export * from './checkCancel'
|
||||
export * from './accountDelete'
|
||||
export * from './signerListSet'
|
||||
export * from './trustSet'
|
||||
export * from './depositPreauth'
|
||||
export * from './paymentTransaction'
|
||||
|
||||
@@ -9,6 +9,7 @@ import { OfferCancel } from "./offerCancel"
|
||||
import { OfferCreate } from "./offerCreate"
|
||||
import { PaymentTransaction } from "./paymentTransaction"
|
||||
import { SignerListSet } from "./signerListSet"
|
||||
import { TrustSet } from "./trustSet"
|
||||
|
||||
export type Transaction =
|
||||
AccountDelete
|
||||
@@ -30,7 +31,7 @@ export type Transaction =
|
||||
// | SetRegularKey
|
||||
| SignerListSet
|
||||
// | TicketCreate
|
||||
// | TrustSet
|
||||
| TrustSet
|
||||
|
||||
export interface TransactionAndMetadata {
|
||||
transaction: Transaction
|
||||
|
||||
54
src/models/transactions/trustSet.ts
Normal file
54
src/models/transactions/trustSet.ts
Normal file
@@ -0,0 +1,54 @@
|
||||
import { ValidationError } from '../../common/errors'
|
||||
import { Amount } from '../common'
|
||||
import { BaseTransaction, GlobalFlags, isAmount, verifyBaseTransaction } from './common'
|
||||
|
||||
export enum TrustSetFlagsEnum {
|
||||
tfSetfAuth = 0x00010000,
|
||||
tfSetNoRipple = 0x00020000,
|
||||
tfClearNoRipple = 0x00040000,
|
||||
tfSetFreeze = 0x00100000,
|
||||
tfClearFreeze = 0x00200000,
|
||||
}
|
||||
|
||||
export interface TrustSetFlags extends GlobalFlags {
|
||||
tfSetfAuth?: boolean
|
||||
tfSetNoRipple?: boolean
|
||||
tfClearNoRipple?: boolean
|
||||
tfSetFreeze?: boolean
|
||||
tfClearFreeze?: boolean
|
||||
}
|
||||
|
||||
export interface TrustSet extends BaseTransaction {
|
||||
TransactionType: 'TrustSet'
|
||||
LimitAmount: Amount
|
||||
QualityIn?: number
|
||||
QualityOut?: number
|
||||
Flags?: number | TrustSetFlags
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param tx A TrustSet Transaction.
|
||||
* @returns {void}
|
||||
* @throws {ValidationError} When the TrustSet is malformed.
|
||||
*/
|
||||
export function verifyTrustSet(tx: TrustSet): void {
|
||||
verifyBaseTransaction(tx)
|
||||
const { LimitAmount, QualityIn, QualityOut } = tx
|
||||
|
||||
if (LimitAmount === undefined) {
|
||||
throw new ValidationError('TrustSet: missing field LimitAmount')
|
||||
}
|
||||
|
||||
if (!isAmount(LimitAmount)) {
|
||||
throw new ValidationError('TrustSet: invalid LimitAmount')
|
||||
}
|
||||
|
||||
if (QualityIn !== undefined && typeof QualityIn !== 'number') {
|
||||
throw new ValidationError('TrustSet: QualityIn must be a number')
|
||||
}
|
||||
|
||||
if (QualityOut !== undefined && typeof QualityOut !== 'number') {
|
||||
throw new ValidationError('TrustSet: QualityOut must be a number')
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user