Skip to content

Commit ba63378

Browse files
committed
refactor(sdk-core): change BaseTransaction.id return type to string | undefined
Update BaseTransaction.id getter return type from string to string | undefined to accurately reflect that transaction IDs may not be available before signing/serialization. Propagate the type change to all downstream coin modules: - sdk-coin-ada: update explainTransaction return type and test assertions - sdk-coin-apt: update TxData.id type - sdk-coin-dot: update test assertions - sdk-coin-flrp: update test assertions - sdk-coin-near: update test assertions - sdk-coin-sui: update Transaction<T>.id getter return type - sdk-coin-ton: update TxData.id and local ITransactionExplanation.id types - sdk-coin-vet: update VetTransactionData.id type and test assertions TICKET: BTC-3027 BREAKING CHANGE: return type of get id is being updated to reflect _id which is string | undefined
1 parent 0d8ede6 commit ba63378

50 files changed

Lines changed: 118 additions & 116 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

modules/abstract-cosmos/src/lib/transaction.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,13 @@ export class CosmosTransaction<CustomMessage = never> extends BaseTransaction {
6161
}
6262

6363
/** @inheritDoc **/
64-
get id(): string {
64+
get id(): string | undefined {
6565
if (this._id) {
6666
return this._id;
6767
} else if (this._cosmosLikeTransaction?.hash !== undefined) {
6868
return this._cosmosLikeTransaction.hash;
6969
}
70-
return UNAVAILABLE_TEXT;
70+
return undefined;
7171
}
7272

7373
/** @inheritdoc */

modules/sdk-coin-ada/src/lib/transaction.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ export interface PledgeDetails {
7777
* The transaction data returned from the toJson() function of a transaction
7878
*/
7979
export interface TxData {
80-
id: string;
80+
id: string | undefined;
8181
type: TransactionType;
8282
inputs: TransactionInput[];
8383
outputs: TransactionOutput[];
@@ -387,7 +387,7 @@ export class Transaction extends BaseTransaction {
387387
outputAmount: string;
388388
fee: { fee: string };
389389
displayOrder: string[];
390-
id: string;
390+
id: string | undefined;
391391
changeAmount: string;
392392
type: string;
393393
withdrawals: Withdrawal[];

modules/sdk-coin-ada/test/unit/StakingActivateBuilder.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ describe('ADA Staking Activate Transaction Builder', async () => {
169169
txBuilder2.addSignature({ pub: keyPairPayment.getKeys().pub }, Buffer.from(signaturePayment));
170170
txBuilder2.addSignature({ pub: keyPairStake.getKeys().pub }, Buffer.from(signatureStake));
171171
const signedTransaction2 = await txBuilder2.build();
172-
signedTransaction.id.should.equal(tx.id);
172+
signedTransaction.id!.should.equal(tx.id);
173173
const serializedTransaction2 = signedTransaction2.toBroadcastFormat();
174174
serializedTransaction2.should.equal(serializedTransaction);
175175
});
@@ -213,7 +213,7 @@ describe('ADA Staking Activate Transaction Builder', async () => {
213213
const signaturePayment = keyPairPayment.signMessage(signableHex2);
214214
txBuilder2.addSignature({ pub: keyPairPayment.getKeys().pub }, Buffer.from(signaturePayment));
215215
const signedTransaction2 = await txBuilder2.build();
216-
signedTransaction.id.should.equal(tx.id);
216+
signedTransaction.id!.should.equal(tx.id);
217217
const serializedTransaction2 = signedTransaction2.toBroadcastFormat();
218218
serializedTransaction2.should.equal(serializedTransaction);
219219
});

modules/sdk-coin-ada/test/unit/StakingDeactivateBuilder.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ describe('ADA Staking Deactivate Transaction Builder', async () => {
131131
txBuilder2.addSignature({ pub: keyPairPayment.getKeys().pub }, Buffer.from(signaturePayment));
132132
txBuilder2.addSignature({ pub: keyPairStake.getKeys().pub }, Buffer.from(signatureStake));
133133
const signedTransaction2 = await txBuilder2.build();
134-
signedTransaction.id.should.equal(tx.id);
134+
signedTransaction.id!.should.equal(tx.id);
135135
const serializedTransaction2 = signedTransaction2.toBroadcastFormat();
136136
serializedTransaction2.should.equal(serializedTransaction);
137137
});

modules/sdk-coin-ada/test/unit/stakingWithdrawBuilder.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ describe('ADA Staking Withdraw Transaction Builder', async () => {
140140
txBuilder2.addSignature({ pub: keyPairPayment.getKeys().pub }, Buffer.from(signaturePayment));
141141
txBuilder2.addSignature({ pub: keyPairStake.getKeys().pub }, Buffer.from(signatureStake));
142142
const signedTransaction2 = await txBuilder2.build();
143-
signedTransaction.id.should.equal(tx.id);
143+
signedTransaction.id!.should.equal(tx.id);
144144
const serializedTransaction2 = signedTransaction2.toBroadcastFormat();
145145
serializedTransaction2.should.equal(serializedTransaction);
146146
});

modules/sdk-coin-ada/test/unit/transaction.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ describe('ADA Transaction', () => {
4747
it('a signed transfer transaction', async () => {
4848
tx.fromRawTransaction(resources.rawTx.signedTx);
4949
const explain = tx.explainTransaction();
50-
explain.id.should.equal('1d0ac4a6496847341ddfd5087db6a687157cc6cc8ec9f999e72fbbc581a34523');
50+
explain.id!.should.equal('1d0ac4a6496847341ddfd5087db6a687157cc6cc8ec9f999e72fbbc581a34523');
5151
explain.outputAmount.should.equal('253329150');
5252
explain.outputs[0].amount.should.equal(resources.rawTx.outputAddress1.value);
5353
explain.outputs[0].address.should.equal(resources.rawTx.outputAddress1.address);
@@ -58,7 +58,7 @@ describe('ADA Transaction', () => {
5858
it('an unsigned transfer transaction', async () => {
5959
tx.fromRawTransaction(resources.rawTx.unsignedTx);
6060
const explain = tx.explainTransaction();
61-
explain.id.should.equal('c091e2a0ac5a8bc4f522e69b2986d3a9b2b5615e6fcb7b265d0b8d449c03e591');
61+
explain.id!.should.equal('c091e2a0ac5a8bc4f522e69b2986d3a9b2b5615e6fcb7b265d0b8d449c03e591');
6262
explain.outputAmount.should.equal('253329150');
6363
explain.outputs[0].amount.should.equal(resources.rawTx.outputAddress1.value);
6464
explain.outputs[0].address.should.equal(resources.rawTx.outputAddress1.address);

modules/sdk-coin-ada/test/unit/transactionBuilder.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ describe('ADA Transaction Builder', async () => {
3535
const fee = tx.getFee;
3636
txData.outputs[1].amount.should.equal((totalInput - outputAmount - Number(fee)).toString());
3737
fee.should.equal('167437');
38-
txData.id.should.equal(testData.rawTxByron.txHash2);
38+
txData.id!.should.equal(testData.rawTxByron.txHash2);
3939
const txBroadcast = tx.toBroadcastFormat();
4040
should.equal(txBroadcast, testData.rawTxByron.unsignedTx2);
4141
});
@@ -66,7 +66,7 @@ describe('ADA Transaction Builder', async () => {
6666
const fee = tx.getFee;
6767
txData.outputs[1].amount.should.equal((totalInput - outputAmount - Number(fee)).toString());
6868
fee.should.equal('167173');
69-
txData.id.should.equal(testData.rawTx.txHash2);
69+
txData.id!.should.equal(testData.rawTx.txHash2);
7070
const txBroadcast = tx.toBroadcastFormat();
7171
should.equal(txBroadcast, testData.rawTx.unsignedTx2);
7272
});
@@ -93,7 +93,7 @@ describe('ADA Transaction Builder', async () => {
9393
const fee = tx.getFee;
9494
txData.outputs[0].amount.should.equal((totalInput - outputAmount - Number(fee)).toString());
9595
fee.should.equal('165545');
96-
txData.id.should.equal(testData.rawTx.txHash5);
96+
txData.id!.should.equal(testData.rawTx.txHash5);
9797
const txBroadcast = tx.toBroadcastFormat();
9898
should.equal(txBroadcast, testData.rawTx.unsignedTx5);
9999
});
@@ -116,7 +116,7 @@ describe('ADA Transaction Builder', async () => {
116116
.get_asset(expectedPolicyId, expectedAssetName)
117117
.to_str()
118118
.should.equal(quantity);
119-
txData.id.should.equal(testData.rawTx.txHash3);
119+
txData.id!.should.equal(testData.rawTx.txHash3);
120120
const txBroadcast = tx.toBroadcastFormat();
121121
should.equal(txBroadcast, testData.rawTx.unsignedTx3);
122122
});
@@ -166,7 +166,7 @@ describe('ADA Transaction Builder', async () => {
166166
(totalInput - minAmountForSingleAsset - outputAmount - Number(fee)).toString()
167167
);
168168
fee.should.equal('170253');
169-
txData.id.should.equal(testData.rawTx.txHash3);
169+
txData.id!.should.equal(testData.rawTx.txHash3);
170170
const txBroadcast = tx.toBroadcastFormat();
171171
should.equal(txBroadcast, testData.rawTx.unsignedTx3);
172172
});
@@ -235,7 +235,7 @@ describe('ADA Transaction Builder', async () => {
235235
(totalInput - minAmountForSingleAsset * 2 - outputAmount - Number(fee)).toString()
236236
);
237237
fee.should.equal('175137');
238-
txData.id.should.equal(testData.rawTx.txHash4);
238+
txData.id!.should.equal(testData.rawTx.txHash4);
239239
const txBroadcast = tx.toBroadcastFormat();
240240
should.equal(txBroadcast, testData.rawTx.unsignedTx4);
241241
});
@@ -293,7 +293,7 @@ describe('ADA Transaction Builder', async () => {
293293
const fee = tx.getFee;
294294
txData.outputs[1].amount.should.equal((totalInput - outputAmount - Number(fee)).toString());
295295
fee.should.equal('167173');
296-
txData.id.should.equal(testData.rawTx.txHash2);
296+
txData.id!.should.equal(testData.rawTx.txHash2);
297297
const txBroadcast = tx.toBroadcastFormat();
298298
should.equal(txBroadcast, testData.rawTx.signedTx2);
299299
});

modules/sdk-coin-apt/src/lib/iface.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export interface AptTransactionExplanation extends BaseTransactionExplanation {
1414
* The transaction data returned from the toJson() function of a transaction
1515
*/
1616
export interface TxData {
17-
id: string;
17+
id: string | undefined;
1818
sender: string;
1919
/** @deprecated - use `recipients`. */
2020
recipient?: TransactionRecipient;

modules/sdk-coin-apt/src/lib/transaction/transaction.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ import {
3434
TransactionAuthenticatorFeePayer,
3535
TransactionPayload,
3636
} from '@aptos-labs/ts-sdk';
37-
import { DEFAULT_GAS_UNIT_PRICE, UNAVAILABLE_TEXT } from '../constants';
37+
import { DEFAULT_GAS_UNIT_PRICE } from '../constants';
3838
import utils from '../utils';
3939
import BigNumber from 'bignumber.js';
4040
import { AptTransactionExplanation, TxData } from '../iface';
@@ -94,9 +94,9 @@ export abstract class Transaction extends BaseTransaction {
9494
}
9595

9696
/** @inheritDoc **/
97-
public override get id(): string {
97+
public override get id(): string | undefined {
9898
this.generateTxnId();
99-
return this._id ?? UNAVAILABLE_TEXT;
99+
return this._id;
100100
}
101101

102102
get sender(): string {

modules/sdk-coin-avaxp/test/unit/lib/permissionlessValidatorTxBuilder.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ describe('AvaxP permissionlessValidatorTxBuilder', () => {
4646
});
4747

4848
it('Should get a txid', async () => {
49-
tx.id.should.equal(testData.ADD_VALIDATOR_ID_SAMPLE.txid);
49+
tx.id!.should.equal(testData.ADD_VALIDATOR_ID_SAMPLE.txid);
5050
});
5151
});
5252

0 commit comments

Comments
 (0)