Skip to content

Commit

Permalink
add/update models
Browse files Browse the repository at this point in the history
  • Loading branch information
mvadari committed Jul 31, 2022
1 parent 597be56 commit 691fb44
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 2 deletions.
21 changes: 19 additions & 2 deletions packages/xrpl/src/models/transactions/XChainAddAttestation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,25 @@ export interface XChainAddAttestation extends BaseTransaction {
}
}>

// TODO: update this once it's been implemented in rippled
XChainCreateAccountAttestationBatch: Array<Record<string, never>>
XChainCreateAccountAttestationBatch: Array<{
XChainClaimAttestationBatchElement: {
Account: string

Amount: Amount

AttestationRewardAccount: string

Destination: string

PublicKey: string

Signature: string

WasLockingChainSend: 0 | 1

XChainAccountCreateCount: string
}
}>
}

/**
Expand Down
1 change: 1 addition & 0 deletions packages/xrpl/src/models/transactions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,4 @@ export { XChainClaim } from './XChainClaim'
export { XChainCommit } from './XChainCommit'
export { XChainCreateBridge } from './XChainCreateBridge'
export { XChainCreateClaimID } from './XChainCreateClaimID'
export { SidechainXChainAccountCreate } from './sidechainXChainAccountCreate'
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { ValidationError } from '../../errors'
import { Amount, XChainBridge } from '../common'

import { BaseTransaction, validateBaseTransaction } from './common'

/**
*
* @category Transaction Models
*/
export interface SidechainXChainAccountCreate extends BaseTransaction {
TransactionType: 'SidechainXChainAccountCreate'

XChainBridge: XChainBridge

SignatureReward: number | string

Destination: string

Amount: Amount
}

/**
* Verify the form and type of a SidechainXChainAccountCreate at runtime.
*
* @param tx - A SidechainXChainAccountCreate Transaction.
* @throws When the SidechainXChainAccountCreate is malformed.
*/
export function validateSidechainXChainAccountCreate(
tx: Record<string, unknown>,
): void {
validateBaseTransaction(tx)

if (tx.XChainBridge == null) {
throw new ValidationError(
'SidechainXChainAccountCreate: missing field XChainBridge',
)
}

if (tx.SignatureReward == null) {
throw new ValidationError(
'SidechainXChainAccountCreate: missing field SignatureReward',
)
}

if (tx.Destination == null) {
throw new ValidationError(
'SidechainXChainAccountCreate: missing field Destination',
)
}

if (tx.Amount == null) {
throw new ValidationError(
'SidechainXChainAccountCreate: missing field Amount',
)
}
}
8 changes: 8 additions & 0 deletions packages/xrpl/src/models/transactions/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ import {
validatePaymentChannelFund,
} from './paymentChannelFund'
import { SetRegularKey, validateSetRegularKey } from './setRegularKey'
import {
SidechainXChainAccountCreate,
validateSidechainXChainAccountCreate,
} from './sidechainXChainAccountCreate'
import { SignerListSet, validateSignerListSet } from './signerListSet'
import { TicketCreate, validateTicketCreate } from './ticketCreate'
import { TrustSet, validateTrustSet } from './trustSet'
Expand Down Expand Up @@ -98,6 +102,7 @@ export type Transaction =
| XChainCommit
| XChainCreateBridge
| XChainCreateClaimID
| SidechainXChainAccountCreate

/**
* @category Transaction Models
Expand Down Expand Up @@ -242,6 +247,9 @@ export function validate(transaction: Record<string, unknown>): void {
validateXChainCreateClaimID(tx)
break

case 'SidechainXChainAccountCreate':
validateSidechainXChainAccountCreate(tx)

default:
throw new ValidationError(
`Invalid field TransactionType: ${tx.TransactionType}`,
Expand Down

0 comments on commit 691fb44

Please sign in to comment.