refactor: Define PaymentChannelCreate transaction (#1533)

refactor: Define PaymentChannelCreate transaction model (#1533)
This commit is contained in:
Nathan Nichols
2021-08-19 11:03:14 -05:00
committed by Mayukha Vadari
parent 250ebc5a99
commit 3997227b3c
4 changed files with 196 additions and 1 deletions

View File

@@ -12,6 +12,7 @@ export * from './escrowFinish'
export * from './offerCancel'
export * from './offerCreate'
export * from './paymentTransaction'
export * from './paymentChannelCreate'
export * from './signerListSet'
export * from './trustSet'

View File

@@ -0,0 +1,53 @@
import { ValidationError } from "../../common/errors"
import { BaseTransaction, verifyBaseTransaction } from "./common"
export interface PaymentChannelCreate extends BaseTransaction {
TransactionType: "PaymentChannelCreate"
Amount: string
Destination: string
SettleDelay: number
PublicKey: string
CancelAfter?: number
DestinationTag?: number
}
/**
* Verify the form and type of an PaymentChannelCreate at runtime.
*
* @param tx - An PaymentChannelCreate Transaction
* @returns - Void.
* @throws - When the PaymentChannelCreate is Malformed.
*/
export function verifyPaymentChannelCreate(tx: PaymentChannelCreate): void {
verifyBaseTransaction(tx)
if (tx.Amount === undefined)
throw new ValidationError("PaymentChannelCreate: missing Amount")
if (typeof tx.Amount !== 'string')
throw new ValidationError("PaymentChannelCreate: Amount must be a string")
if (tx.Destination === undefined)
throw new ValidationError("PaymentChannelCreate: missing Destination")
if (typeof tx.Destination !== 'string')
throw new ValidationError("PaymentChannelCreate: Destination must be a string")
if (tx.SettleDelay === undefined)
throw new ValidationError("PaymentChannelCreate: missing SettleDelay")
if (typeof tx.SettleDelay !== 'number')
throw new ValidationError("PaymentChannelCreate: SettleDelay must be a number")
if (tx.PublicKey === undefined)
throw new ValidationError("PaymentChannelCreate: missing PublicKey")
if (typeof tx.PublicKey !== 'string')
throw new ValidationError("PaymentChannelCreate: PublicKey must be a string")
if (tx.CancelAfter !== undefined && typeof tx.CancelAfter !== 'number')
throw new ValidationError("PaymentChannelCreate: CancelAfter must be a number")
if (tx.DestinationTag !== undefined && typeof tx.DestinationTag !== 'number')
throw new ValidationError("PaymentChannelCreate: DestinationTag must be a number")
}

View File

@@ -10,6 +10,7 @@ import { EscrowFinish } from "./escrowFinish"
import { OfferCancel } from "./offerCancel"
import { OfferCreate } from "./offerCreate"
import { PaymentTransaction } from "./paymentTransaction"
import { PaymentChannelCreate } from "./paymentChannelCreate"
import { SignerListSet } from "./signerListSet"
import { TicketCreate } from "./ticketCreate"
import { TrustSet } from "./trustSet"
@@ -28,7 +29,7 @@ export type Transaction =
| OfferCreate
| PaymentTransaction
// | PaymentChannelClaim
// | PaymentChannelCreate
| PaymentChannelCreate
// | PaymentChannelFund
// | SetRegularKey
| SignerListSet