@@ -17,10 +17,10 @@ import { CosmosKeyPair as KeyPair } from './keyPair';
1717import { CosmosTransaction } from './transaction' ;
1818import { CosmosUtils } from './utils' ;
1919
20- export abstract class CosmosTransactionBuilder extends BaseTransactionBuilder {
21- protected _transaction : CosmosTransaction ;
20+ export abstract class CosmosTransactionBuilder < CustomMessage = never > extends BaseTransactionBuilder {
21+ protected _transaction : CosmosTransaction < CustomMessage > ;
2222 protected _sequence : number ;
23- protected _messages : MessageData [ ] ;
23+ protected _messages : MessageData < CustomMessage > [ ] ;
2424 protected _gasBudget : FeeData ;
2525 protected _accountNumber ?: number ;
2626 protected _signature : Buffer ;
@@ -29,9 +29,9 @@ export abstract class CosmosTransactionBuilder extends BaseTransactionBuilder {
2929 protected _signer : KeyPair ;
3030 protected _memo ?: string ;
3131
32- protected _utils : CosmosUtils ;
32+ protected _utils : CosmosUtils < CustomMessage > ;
3333
34- constructor ( _coinConfig : Readonly < CoinConfig > , _utils : CosmosUtils ) {
34+ constructor ( _coinConfig : Readonly < CoinConfig > , _utils : CosmosUtils < CustomMessage > ) {
3535 super ( _coinConfig ) ;
3636 this . _transaction = new CosmosTransaction ( _coinConfig , _utils ) ;
3737 }
@@ -42,12 +42,12 @@ export abstract class CosmosTransactionBuilder extends BaseTransactionBuilder {
4242 protected abstract get transactionType ( ) : TransactionType ;
4343
4444 /** @inheritdoc */
45- protected get transaction ( ) : CosmosTransaction {
45+ protected get transaction ( ) : CosmosTransaction < CustomMessage > {
4646 return this . _transaction ;
4747 }
4848
4949 /** @inheritdoc */
50- protected set transaction ( transaction : CosmosTransaction ) {
50+ protected set transaction ( transaction : CosmosTransaction < CustomMessage > ) {
5151 this . _transaction = transaction ;
5252 }
5353
@@ -78,7 +78,7 @@ export abstract class CosmosTransactionBuilder extends BaseTransactionBuilder {
7878 * @param {CosmosTransactionMessage[] } messages
7979 * @returns {TransactionBuilder } This transaction builder
8080 */
81- abstract messages ( messages : CosmosTransactionMessage [ ] ) : this;
81+ abstract messages ( messages : CosmosTransactionMessage < CustomMessage > [ ] ) : this;
8282
8383 publicKey ( publicKey : string | undefined ) : this {
8484 this . _publicKey = publicKey ;
@@ -101,7 +101,7 @@ export abstract class CosmosTransactionBuilder extends BaseTransactionBuilder {
101101 }
102102
103103 /** @inheritdoc */
104- protected signImplementation ( key : BaseKey ) : CosmosTransaction {
104+ protected signImplementation ( key : BaseKey ) : CosmosTransaction < CustomMessage > {
105105 this . validateKey ( key ) ;
106106 if ( this . _accountNumber === undefined ) {
107107 throw new SigningError ( 'accountNumber is required before signing' ) ;
@@ -147,7 +147,7 @@ export abstract class CosmosTransactionBuilder extends BaseTransactionBuilder {
147147 * Initialize the transaction builder fields using the decoded transaction data
148148 * @param {CosmosTransaction } tx the transaction data
149149 */
150- initBuilder ( tx : CosmosTransaction ) : void {
150+ initBuilder ( tx : CosmosTransaction < CustomMessage > ) : void {
151151 this . _transaction = tx ;
152152 const txData = tx . toJson ( ) ;
153153 this . gasBudget ( txData . gasBudget ) ;
@@ -166,16 +166,23 @@ export abstract class CosmosTransactionBuilder extends BaseTransactionBuilder {
166166 }
167167 }
168168
169+ /**
170+ * Creates a new CosmosTransaction instance
171+ */
172+ protected newTransaction ( ) : CosmosTransaction < CustomMessage > {
173+ return new CosmosTransaction < CustomMessage > ( this . _coinConfig , this . _utils ) ;
174+ }
175+
169176 /** @inheritdoc */
170- protected fromImplementation ( rawTransaction : string ) : CosmosTransaction {
171- const tx = new CosmosTransaction ( this . _coinConfig , this . _utils ) ;
177+ protected fromImplementation ( rawTransaction : string ) : CosmosTransaction < CustomMessage > {
178+ const tx = this . newTransaction ( ) ;
172179 tx . enrichTransactionDetailsFromRawTransaction ( rawTransaction ) ;
173180 this . initBuilder ( tx ) ;
174181 return this . transaction ;
175182 }
176183
177184 /** @inheritdoc */
178- protected async buildImplementation ( ) : Promise < CosmosTransaction > {
185+ protected async buildImplementation ( ) : Promise < CosmosTransaction < CustomMessage > > {
179186 this . transaction . transactionType = this . transactionType ;
180187 if ( this . _accountNumber ) {
181188 this . transaction . accountNumber = this . _accountNumber ;
@@ -240,7 +247,7 @@ export abstract class CosmosTransactionBuilder extends BaseTransactionBuilder {
240247 }
241248
242249 /** @inheritdoc */
243- validateTransaction ( transaction : CosmosTransaction ) : void {
250+ validateTransaction ( transaction : CosmosTransaction < CustomMessage > ) : void {
244251 this . _utils . validateTransaction ( {
245252 sequence : this . _sequence ,
246253 sendMessages : this . _messages ,
0 commit comments