Skip to content

Commit 5d60455

Browse files
authored
Merge pull request #839 from symbol/fix/missing-tx-meta
task: fix missing tx meta
2 parents 0b6e5d4 + 54e4cad commit 5d60455

File tree

11 files changed

+149
-22
lines changed

11 files changed

+149
-22
lines changed

src/infrastructure/transaction/CreateTransactionFromDTO.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,25 @@ const extractTransactionMeta = (meta: any, id: string): TransactionInfo | Aggreg
118118
return undefined;
119119
}
120120
if (meta.aggregateHash || meta.aggregateId) {
121-
return new AggregateTransactionInfo(UInt64.fromNumericString(meta.height), meta.index, id, meta.aggregateHash, meta.aggregateId);
121+
return new AggregateTransactionInfo(
122+
UInt64.fromNumericString(meta.height),
123+
meta.index,
124+
id,
125+
UInt64.fromNumericString(meta.timestamp),
126+
meta.feeMultiplier,
127+
meta.aggregateHash,
128+
meta.aggregateId,
129+
);
122130
}
123-
return new TransactionInfo(UInt64.fromNumericString(meta.height), meta.index, id, meta.hash, meta.merkleComponentHash);
131+
return new TransactionInfo(
132+
UInt64.fromNumericString(meta.height),
133+
meta.index,
134+
id,
135+
UInt64.fromNumericString(meta.timestamp),
136+
meta.feeMultiplier,
137+
meta.hash,
138+
meta.merkleComponentHash,
139+
);
124140
};
125141
/**
126142
* @internal

src/model/transaction/AggregateTransactionInfo.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,15 @@ export class AggregateTransactionInfo extends TransactionInfo {
2727
* @param id
2828
* @param aggregateHash
2929
* @param aggregateId
30+
* @param timestamp
31+
* @param feeMultiplier
3032
*/
3133
constructor(
3234
height: UInt64,
3335
index: number,
3436
id: string,
37+
timestamp: UInt64,
38+
feeMultiplier: number,
3539
/**
3640
* The hash of the aggregate transaction.
3741
*/
@@ -41,6 +45,6 @@ export class AggregateTransactionInfo extends TransactionInfo {
4145
*/
4246
public readonly aggregateId: string,
4347
) {
44-
super(height, index, id);
48+
super(height, index, id, timestamp, feeMultiplier);
4549
}
4650
}

src/model/transaction/TransactionInfo.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ export class TransactionInfo {
2424
* @param height
2525
* @param index
2626
* @param id
27+
* @param timestamp
28+
* @param feeMultiplier
2729
* @param hash
2830
* @param merkleComponentHash
2931
*/
@@ -40,6 +42,14 @@ export class TransactionInfo {
4042
* The transaction db id.
4143
*/
4244
public readonly id: string,
45+
/**
46+
* The transaction timestamp.
47+
*/
48+
public readonly timestamp?: UInt64,
49+
/**
50+
* The transaction fee multiplier.
51+
*/
52+
public readonly feeMultiplier?: number,
4353
/**
4454
* The transaction hash.
4555
*/

test/infrastructure/Listener.spec.ts

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ describe('Listener', () => {
285285
);
286286
const transferTransactionDTO = transferTransaction.toJSON();
287287
const hash = 'abc';
288-
transferTransactionDTO.meta = { height: '1', hash: hash };
288+
transferTransactionDTO.meta = { height: '1', hash: hash, timestamp: '0', feeMultiplier: 0 };
289289

290290
const listener = new Listener('http://localhost:3000', namespaceRepo, WebSocketMultisigMock, multisigRepo);
291291
listener.open();
@@ -315,7 +315,7 @@ describe('Listener', () => {
315315
);
316316
const transferTransactionDTO = transferTransaction.toJSON();
317317
const hash = 'abc';
318-
transferTransactionDTO.meta = { height: '1', hash: hash };
318+
transferTransactionDTO.meta = { height: '1', hash: hash, timestamp: '0', feeMultiplier: 0 };
319319

320320
const reportedTransactions: Transaction[] = [];
321321
const listener = new Listener('http://localhost:3000', namespaceRepo, WebSocketMockAlias);
@@ -334,7 +334,10 @@ describe('Listener', () => {
334334
listener.handleMessage(
335335
{
336336
topic: name.toString(),
337-
data: { meta: { height: '2', hash: 'new hash' }, transaction: transferTransactionDTO.transaction },
337+
data: {
338+
meta: { height: '2', hash: 'new hash', timestamp: '2', feeMultiplier: 1 },
339+
transaction: transferTransactionDTO.transaction,
340+
},
338341
},
339342
null,
340343
);
@@ -360,7 +363,7 @@ describe('Listener', () => {
360363
const transferTransactionDTO = transferTransaction.toJSON();
361364
const hash = 'abc';
362365
const hash2 = 'abc2';
363-
transferTransactionDTO.meta = { height: '1', hash: hash };
366+
transferTransactionDTO.meta = { height: '1', hash: hash, timestamp: '0', feeMultiplier: 0 };
364367

365368
const reportedTransactions: Transaction[] = [];
366369
const listener = new Listener('http://localhost:3000', namespaceRepo, WebSocketMock);
@@ -379,7 +382,10 @@ describe('Listener', () => {
379382
listener.handleMessage(
380383
{
381384
topic: name.toString(),
382-
data: { meta: { height: '1', hash: 'new hash' }, transaction: transferTransactionDTO.transaction },
385+
data: {
386+
meta: { height: '1', hash: 'new hash', timestamp: '1', feeMultiplier: 1 },
387+
transaction: transferTransactionDTO.transaction,
388+
},
383389
},
384390
null,
385391
);
@@ -399,7 +405,7 @@ describe('Listener', () => {
399405
);
400406
const transferTransactionDTO = transferTransaction.toJSON();
401407
const hash = 'abc';
402-
transferTransactionDTO.meta = { height: '1', hash: hash };
408+
transferTransactionDTO.meta = { height: '1', hash: hash, timestamp: '0', feeMultiplier: 0 };
403409

404410
const reportedTransactions: Transaction[] = [];
405411
const listener = new Listener('http://localhost:3000', namespaceRepo, WebSocketMockAlias);
@@ -418,7 +424,10 @@ describe('Listener', () => {
418424
listener.handleMessage(
419425
{
420426
topic: name.toString(),
421-
data: { meta: { height: '1', hash: 'new hash' }, transaction: transferTransactionDTO.transaction },
427+
data: {
428+
meta: { height: '1', hash: 'new hash', timestamp: '1', feeMultiplier: 1 },
429+
transaction: transferTransactionDTO.transaction,
430+
},
422431
},
423432
null,
424433
);
@@ -438,7 +447,7 @@ describe('Listener', () => {
438447
);
439448
const transferTransactionDTO = transferTransaction.toJSON();
440449
const hash = 'abc';
441-
transferTransactionDTO.meta = { height: '1', hash: hash };
450+
transferTransactionDTO.meta = { height: '1', hash: hash, timestamp: '0', feeMultiplier: 0 };
442451

443452
const reportedTransactions: Transaction[] = [];
444453

@@ -458,7 +467,10 @@ describe('Listener', () => {
458467
listener.handleMessage(
459468
{
460469
topic: name.toString(),
461-
data: { meta: { height: '1', hash: 'new hash' }, transaction: transferTransactionDTO.transaction },
470+
data: {
471+
meta: { height: '1', hash: 'new hash', timestamp: '1', feeMultiplier: 1 },
472+
transaction: transferTransactionDTO.transaction,
473+
},
462474
},
463475
null,
464476
);
@@ -487,7 +499,7 @@ describe('Listener', () => {
487499
);
488500
const transferTransactionDTO = transferTransaction.toJSON();
489501
const hash = 'abc';
490-
transferTransactionDTO.meta = { height: '1', hash: hash };
502+
transferTransactionDTO.meta = { height: '1', hash: hash, timestamp: '0', feeMultiplier: 0 };
491503

492504
const reportedTransactions: Transaction[] = [];
493505

@@ -507,7 +519,10 @@ describe('Listener', () => {
507519
listener.handleMessage(
508520
{
509521
topic: name.toString(),
510-
data: { meta: { height: '1', hash: 'new hash' }, transaction: transferTransactionDTO.transaction },
522+
data: {
523+
meta: { height: '1', hash: 'new hash', timestamp: '1', feeMultiplier: 1 },
524+
transaction: transferTransactionDTO.transaction,
525+
},
511526
},
512527
null,
513528
);

test/infrastructure/TransactionHttp.spec.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@ describe('TransactionHttp', () => {
101101
metaDto.hash = 'hash';
102102
metaDto.height = '1';
103103
metaDto.index = 0;
104+
metaDto.timestamp = '0';
105+
metaDto.feeMultiplier = 0;
104106
metaDto.merkleComponentHash = 'merkleHash';
105107

106108
const transactionDto = {} as TransferTransactionDTO;
@@ -186,6 +188,8 @@ describe('TransactionHttp', () => {
186188
expect(((transactions.data[0] as TransferTransaction).recipientAddress as Address).plain()).to.be.equal(TestAddress.plain());
187189
expect(transactions.data[0].transactionInfo?.id).to.be.equal('id');
188190
expect(transactions.data[0].transactionInfo?.hash).to.be.equal('hash');
191+
expect(transactions.data[0].transactionInfo?.timestamp?.toString()).to.be.equal('0');
192+
expect(transactions.data[0].transactionInfo?.feeMultiplier).to.be.equal(0);
189193

190194
expect(transactions.pageNumber).to.be.equal(1);
191195
expect(transactions.pageSize).to.be.equal(1);
@@ -219,6 +223,8 @@ describe('TransactionHttp', () => {
219223
metaDto.hash = 'hash';
220224
metaDto.height = '1';
221225
metaDto.index = 0;
226+
metaDto.timestamp = '0';
227+
metaDto.feeMultiplier = 0;
222228
metaDto.merkleComponentHash = 'merkleHash';
223229

224230
const transactionDto = {} as TransferTransactionDTO;
@@ -245,14 +251,15 @@ describe('TransactionHttp', () => {
245251
expect(((transaction as TransferTransaction).recipientAddress as Address).plain()).to.be.equal(TestAddress.plain());
246252
expect(transaction.transactionInfo?.id).to.be.equal('id');
247253
expect(transaction.transactionInfo?.hash).to.be.equal('hash');
254+
expect(transaction.transactionInfo?.timestamp?.toString()).to.be.equal('0');
255+
expect(transaction.transactionInfo?.feeMultiplier).to.be.equal(0);
248256

249257
transaction = await firstValueFrom(transactionHttp.getTransaction(generationHash, TransactionGroup.Partial));
250258

251259
expect(transaction.type.valueOf()).to.be.equal(TransactionType.TRANSFER.valueOf());
252260
expect(((transaction as TransferTransaction).recipientAddress as Address).plain()).to.be.equal(TestAddress.plain());
253261
expect(transaction.transactionInfo?.id).to.be.equal('id');
254262
expect(transaction.transactionInfo?.hash).to.be.equal('hash');
255-
256263
transaction = await firstValueFrom(transactionHttp.getTransaction(generationHash, TransactionGroup.Unconfirmed));
257264

258265
expect(transaction.type.valueOf()).to.be.equal(TransactionType.TRANSFER.valueOf());
@@ -267,6 +274,8 @@ describe('TransactionHttp', () => {
267274
metaDto.hash = 'hash';
268275
metaDto.height = '1';
269276
metaDto.index = 0;
277+
metaDto.timestamp = '0';
278+
metaDto.feeMultiplier = 0;
270279
metaDto.merkleComponentHash = 'merkleHash';
271280

272281
const transactionDto = {} as TransferTransactionDTO;
@@ -309,6 +318,8 @@ describe('TransactionHttp', () => {
309318
expect(((transactionConfirmed[0] as TransferTransaction).recipientAddress as Address).plain()).to.be.equal(TestAddress.plain());
310319
expect(transactionConfirmed[0].transactionInfo?.id).to.be.equal('id');
311320
expect(transactionConfirmed[0].transactionInfo?.hash).to.be.equal('hash');
321+
expect(transactionConfirmed[0].transactionInfo?.timestamp?.toString()).to.be.equal('0');
322+
expect(transactionConfirmed[0].transactionInfo?.feeMultiplier).to.be.equal(0);
312323

313324
expect(transactionUnconfirmed.length).to.be.equal(1);
314325
expect(transactionUnconfirmed[0].type.valueOf()).to.be.equal(TransactionType.TRANSFER.valueOf());
@@ -330,6 +341,8 @@ describe('TransactionHttp', () => {
330341
metaDto.height = '1';
331342
metaDto.index = 0;
332343
metaDto.merkleComponentHash = 'merkleHash';
344+
metaDto.timestamp = '0';
345+
metaDto.feeMultiplier = 0;
333346

334347
const transactionDto = {} as TransferTransactionDTO;
335348
transactionDto.deadline = '1';

0 commit comments

Comments
 (0)