add XChainClaim tx

This commit is contained in:
Mayukha Vadari
2022-07-12 11:00:50 -04:00
parent 0286b81745
commit 9d58400373
4 changed files with 60 additions and 0 deletions

View File

@@ -124,3 +124,10 @@ export interface NFTOffer {
destination?: string
expiration?: number
}
export interface Bridge {
src_chain_door: string
src_chain_issue: 'XRP' | IssuedCurrency
dst_chain_door: string
dst_chain_issue: 'XRP' | IssuedCurrency
}

View File

@@ -0,0 +1,46 @@
import { ValidationError } from '../../errors'
import { Amount, Bridge } from '../common'
import { BaseTransaction, validateBaseTransaction } from './common'
/**
*
* @category Transaction Models
*/
export interface XChainClaim extends BaseTransaction {
TransactionType: 'XChainClaim'
Bridge: Bridge
XChainClaimID: number | string
Destination: string
Amount: Amount
}
/**
* Verify the form and type of a XChainClaim at runtime.
*
* @param tx - A XChainClaim Transaction.
* @throws When the XChainClaim is malformed.
*/
export function validateXChainClaim(tx: Record<string, unknown>): void {
validateBaseTransaction(tx)
if (tx.Bridge == null) {
throw new ValidationError('XChainClaim: missing field Bridge')
}
if (tx.XChainClaimID == null) {
throw new ValidationError('XChainClaim: missing field XChainClaimID')
}
if (tx.Destination == null) {
throw new ValidationError('XChainClaim: missing field Destination')
}
if (tx.Amount == null) {
throw new ValidationError('XChainClaim: missing field Amount')
}
}

View File

@@ -45,3 +45,4 @@ export { SetRegularKey } from './setRegularKey'
export { SignerListSet } from './signerListSet'
export { TicketCreate } from './ticketCreate'
export { TrustSetFlagsInterface, TrustSetFlags, TrustSet } from './trustSet'
export { XChainClaim } from './XChainClaim'

View File

@@ -50,6 +50,7 @@ import { SetRegularKey, validateSetRegularKey } from './setRegularKey'
import { SignerListSet, validateSignerListSet } from './signerListSet'
import { TicketCreate, validateTicketCreate } from './ticketCreate'
import { TrustSet, validateTrustSet } from './trustSet'
import { XChainClaim, validateXChainClaim } from './XChainClaim'
/**
* @category Transaction Models
@@ -79,6 +80,7 @@ export type Transaction =
| SignerListSet
| TicketCreate
| TrustSet
| XChainClaim
/**
* @category Transaction Models
@@ -203,6 +205,10 @@ export function validate(transaction: Record<string, unknown>): void {
validateTrustSet(tx)
break
case 'XChainClaim':
validateXChainClaim(tx)
break
default:
throw new ValidationError(
`Invalid field TransactionType: ${tx.TransactionType}`,