mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-11-28 16:15:49 +00:00
refactor: define TicketCreate transaction model (#1547)
- Defines a TypeScript type for TicketCreate - Provides an optional function to users for verifying a TicketCreate instance at runtime: verifyTicketCreate() - Adds tests for verifyTicketCreate()
This commit is contained in:
committed by
Mayukha Vadari
parent
18cce5a50a
commit
250ebc5a99
@@ -5,6 +5,7 @@ export * from './checkCancel'
|
||||
export * from './checkCash'
|
||||
export * from './checkCreate'
|
||||
export * from './signerListSet'
|
||||
export * from './ticketCreate'
|
||||
export * from './depositPreauth'
|
||||
export * from './escrowCancel'
|
||||
export * from './escrowFinish'
|
||||
|
||||
30
src/models/transactions/ticketCreate.ts
Normal file
30
src/models/transactions/ticketCreate.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
import { ValidationError } from '../../common/errors'
|
||||
import { BaseTransaction, verifyBaseTransaction } from './common'
|
||||
|
||||
export interface TicketCreate extends BaseTransaction {
|
||||
TransactionType: 'TicketCreate'
|
||||
TicketCount: number
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {TicketCreate} tx A TicketCreate Transaction.
|
||||
* @returns {void}
|
||||
* @throws {ValidationError} When the TicketCreate is malformed.
|
||||
*/
|
||||
export function verifyTicketCreate(tx: TicketCreate): void {
|
||||
verifyBaseTransaction(tx)
|
||||
const { TicketCount } = tx
|
||||
|
||||
if (TicketCount === undefined) {
|
||||
throw new ValidationError('TicketCreate: missing field TicketCount')
|
||||
}
|
||||
|
||||
if (typeof TicketCount !== 'number') {
|
||||
throw new ValidationError('TicketCreate: TicketCount must be a number')
|
||||
}
|
||||
|
||||
if (!Number.isInteger(TicketCount) || TicketCount < 1 || TicketCount > 250) {
|
||||
throw new ValidationError('TicketCreate: TicketCount must be an integer from 1 to 250')
|
||||
}
|
||||
}
|
||||
@@ -11,6 +11,7 @@ import { OfferCancel } from "./offerCancel"
|
||||
import { OfferCreate } from "./offerCreate"
|
||||
import { PaymentTransaction } from "./paymentTransaction"
|
||||
import { SignerListSet } from "./signerListSet"
|
||||
import { TicketCreate } from "./ticketCreate"
|
||||
import { TrustSet } from "./trustSet"
|
||||
|
||||
export type Transaction =
|
||||
@@ -31,7 +32,7 @@ export type Transaction =
|
||||
// | PaymentChannelFund
|
||||
// | SetRegularKey
|
||||
| SignerListSet
|
||||
// | TicketCreate
|
||||
| TicketCreate
|
||||
| TrustSet
|
||||
|
||||
export interface TransactionAndMetadata {
|
||||
|
||||
Reference in New Issue
Block a user