@@ -27,8 +27,11 @@ import { Transaction } from './transaction';
2727import { BaseTransactionSchema , SignedTransactionSchema , SigningPayloadTransactionSchema } from './txnSchema' ;
2828import utils from './utils' ;
2929
30- export abstract class TransactionBuilder extends BaseTransactionBuilder {
31- protected _transaction : Transaction ;
30+ export abstract class TransactionBuilder <
31+ TMethod = TxMethod ,
32+ TTransaction extends Transaction = Transaction
33+ > extends BaseTransactionBuilder {
34+ protected _transaction : TTransaction ;
3235 protected _keyPair : KeyPair ;
3336 protected _signature ?: string ;
3437 protected _sender : string ;
@@ -39,7 +42,7 @@ export abstract class TransactionBuilder extends BaseTransactionBuilder {
3942 protected _tip ?: number ;
4043 protected _eraPeriod ?: number ;
4144 protected _registry : TypeRegistry ;
42- protected _method ?: TxMethod ;
45+ protected _method ?: TMethod ;
4346 protected _material : Material ;
4447 // signatures that will be used to sign a transaction when building
4548 // not the same as the _signatures in transaction which is the signature in
@@ -48,7 +51,7 @@ export abstract class TransactionBuilder extends BaseTransactionBuilder {
4851
4952 constructor ( _coinConfig : Readonly < CoinConfig > ) {
5053 super ( _coinConfig ) ;
51- this . _transaction = new Transaction ( _coinConfig ) ;
54+ this . _transaction = new Transaction ( _coinConfig ) as TTransaction ;
5255 }
5356
5457 /**
@@ -134,7 +137,7 @@ export abstract class TransactionBuilder extends BaseTransactionBuilder {
134137 return this ;
135138 }
136139
137- private method ( method : TxMethod ) : this {
140+ private method ( method : TMethod ) : this {
138141 this . _method = method ;
139142 return this ;
140143 }
@@ -154,17 +157,17 @@ export abstract class TransactionBuilder extends BaseTransactionBuilder {
154157 }
155158
156159 /** @inheritdoc */
157- protected get transaction ( ) : Transaction {
160+ protected get transaction ( ) : TTransaction {
158161 return this . _transaction ;
159162 }
160163
161164 /** @inheritdoc */
162- protected set transaction ( transaction : Transaction ) {
165+ protected set transaction ( transaction : TTransaction ) {
163166 this . _transaction = transaction ;
164167 }
165168
166169 /** @inheritdoc */
167- protected fromImplementation ( rawTransaction : string ) : Transaction {
170+ protected fromImplementation ( rawTransaction : string ) : TTransaction {
168171 const decodedTxn = decode ( rawTransaction , {
169172 metadataRpc : this . _material . metadata ,
170173 registry : this . _registry ,
@@ -186,7 +189,7 @@ export abstract class TransactionBuilder extends BaseTransactionBuilder {
186189 if ( decodedTxn . tip ) {
187190 this . fee ( { amount : `${ decodedTxn . tip } ` , type : 'tip' } ) ;
188191 }
189- this . method ( decodedTxn . method as unknown as TxMethod ) ;
192+ this . method ( decodedTxn . method as unknown as TMethod ) ;
190193 return this . _transaction ;
191194 }
192195
@@ -197,7 +200,7 @@ export abstract class TransactionBuilder extends BaseTransactionBuilder {
197200 }
198201
199202 /** @inheritdoc */
200- protected async buildImplementation ( ) : Promise < Transaction > {
203+ protected async buildImplementation ( ) : Promise < TTransaction > {
201204 this . transaction . setTransaction ( this . buildTransaction ( ) ) ;
202205 this . transaction . transactionType ( this . transactionType ) ;
203206 this . transaction . registry ( this . _registry ) ;
@@ -320,7 +323,7 @@ export abstract class TransactionBuilder extends BaseTransactionBuilder {
320323 }
321324
322325 /** @inheritdoc */
323- validateTransaction ( _ : Transaction ) : void {
326+ validateTransaction ( _ : TTransaction ) : void {
324327 this . validateBaseFields (
325328 this . _sender ,
326329 this . _blockNumber ,
@@ -382,7 +385,7 @@ export abstract class TransactionBuilder extends BaseTransactionBuilder {
382385 }
383386
384387 /** @inheritdoc */
385- protected signImplementation ( { key } : BaseKey ) : Transaction {
388+ protected signImplementation ( { key } : BaseKey ) : TTransaction {
386389 this . _keyPair = new KeyPair ( { prv : key } ) ;
387390 return this . _transaction ;
388391 }
0 commit comments