@@ -7,8 +7,10 @@ import {
77 GlobalFlags ,
88 GlobalFlagsInterface ,
99 isArray ,
10+ isNull ,
1011 isRecord ,
1112 isString ,
13+ isValue ,
1214 validateBaseTransaction ,
1315 validateOptionalField ,
1416 validateRequiredField ,
@@ -40,18 +42,6 @@ export interface BatchFlagsInterface extends GlobalFlagsInterface {
4042 tfIndependent ?: boolean
4143}
4244
43- export type BatchInnerTransaction = SubmittableTransaction & {
44- Fee ?: '0'
45-
46- SigningPubKey ?: ''
47-
48- TxnSignature ?: never
49-
50- Signers ?: never
51-
52- LastLedgerSequence ?: never
53- }
54-
5545export interface BatchSigner {
5646 BatchSigner : {
5747 Account : string
@@ -73,10 +63,48 @@ export interface Batch extends BaseTransaction {
7363 BatchSigners ?: BatchSigner [ ]
7464
7565 RawTransactions : Array < {
76- RawTransaction : BatchInnerTransaction
66+ RawTransaction : SubmittableTransaction
7767 } >
7868}
7969
70+ function validateBatchInnerTransaction (
71+ tx : Record < string , unknown > ,
72+ index : number ,
73+ ) : void {
74+ if ( tx . TransactionType === 'Batch' ) {
75+ throw new ValidationError (
76+ `Batch: RawTransactions[${ index } ] is a Batch transaction. Cannot nest Batch transactions.` ,
77+ )
78+ }
79+
80+ // Check for the `tfInnerBatchTxn` flag in the inner transactions
81+ if ( ! hasFlag ( tx , GlobalFlags . tfInnerBatchTxn , 'tfInnerBatchTxn' ) ) {
82+ throw new ValidationError (
83+ `Batch: RawTransactions[${ index } ] must contain the \`tfInnerBatchTxn\` flag.` ,
84+ )
85+ }
86+ validateOptionalField ( tx , 'Fee' , isValue ( '0' ) , {
87+ paramName : `RawTransactions[${ index } ].RawTransaction.Fee` ,
88+ txType : 'Batch' ,
89+ } )
90+ validateOptionalField ( tx , 'SigningPubKey' , isValue ( '' ) , {
91+ paramName : `RawTransactions[${ index } ].RawTransaction.SigningPubKey` ,
92+ txType : 'Batch' ,
93+ } )
94+ validateOptionalField ( tx , 'TxnSignature' , isNull , {
95+ paramName : `RawTransactions[${ index } ].RawTransaction.TxnSignature` ,
96+ txType : 'Batch' ,
97+ } )
98+ validateOptionalField ( tx , 'Signers' , isNull , {
99+ paramName : `RawTransactions[${ index } ].RawTransaction.Signers` ,
100+ txType : 'Batch' ,
101+ } )
102+ validateOptionalField ( tx , 'LastLedgerSequence' , isNull , {
103+ paramName : `RawTransactions[${ index } ].RawTransaction.LastLedgerSequence` ,
104+ txType : 'Batch' ,
105+ } )
106+ }
107+
80108/**
81109 * Verify the form and type of a Batch at runtime.
82110 *
@@ -101,18 +129,7 @@ export function validateBatch(tx: Record<string, unknown>): void {
101129 } )
102130
103131 const rawTx = rawTxObj . RawTransaction
104- if ( rawTx . TransactionType === 'Batch' ) {
105- throw new ValidationError (
106- `Batch: RawTransactions[${ index } ] is a Batch transaction. Cannot nest Batch transactions.` ,
107- )
108- }
109-
110- // Check for the `tfInnerBatchTxn` flag in the inner transactions
111- if ( ! hasFlag ( rawTx , GlobalFlags . tfInnerBatchTxn , 'tfInnerBatchTxn' ) ) {
112- throw new ValidationError (
113- `Batch: RawTransactions[${ index } ] must contain the \`tfInnerBatchTxn\` flag.` ,
114- )
115- }
132+ validateBatchInnerTransaction ( rawTx , index )
116133
117134 // Full validation of each `RawTransaction` object is done in `validate` to avoid dependency cycles
118135 } )
@@ -132,19 +149,19 @@ export function validateBatch(tx: Record<string, unknown>): void {
132149
133150 const signer = signerRecord . BatchSigner
134151 validateRequiredField ( signer , 'Account' , isString , {
135- paramName : `BatchSigners[${ index } ].Account` ,
152+ paramName : `BatchSigners[${ index } ].BatchSigner. Account` ,
136153 txType : 'Batch' ,
137154 } )
138155 validateOptionalField ( signer , 'SigningPubKey' , isString , {
139- paramName : `BatchSigners[${ index } ].SigningPubKey` ,
156+ paramName : `BatchSigners[${ index } ].BatchSigner. SigningPubKey` ,
140157 txType : 'Batch' ,
141158 } )
142159 validateOptionalField ( signer , 'TxnSignature' , isString , {
143- paramName : `BatchSigners[${ index } ].TxnSignature` ,
160+ paramName : `BatchSigners[${ index } ].BatchSigner. TxnSignature` ,
144161 txType : 'Batch' ,
145162 } )
146163 validateOptionalField ( signer , 'Signers' , isArray , {
147- paramName : `BatchSigners[${ index } ].Signers` ,
164+ paramName : `BatchSigners[${ index } ].BatchSigner. Signers` ,
148165 txType : 'Batch' ,
149166 } )
150167 } )
0 commit comments