Skip to content

Commit a28365d

Browse files
committed
Add block timestamp to response
1 parent 07aa49b commit a28365d

File tree

4 files changed

+48
-13
lines changed

4 files changed

+48
-13
lines changed

BridgeTx.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
module.exports = class BridgeTx {
2-
constructor(txHash, method, events, sender, blockNumber) {
2+
constructor(txHash, method, events, sender, blockNumber, blockTimestamp) {
33
this.txHash = txHash;
44
this.method = method;
55
this.events = events;
66
this.sender = sender;
77
this.blockNumber = blockNumber;
8+
this.blockTimestamp = blockTimestamp;
89
}
910
}

index.d.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import Web3 from "web3";
2-
import {TransactionReceipt, Transaction as Web3Transaction} from "web3-core";
2+
import { TransactionReceipt, Transaction as Web3Transaction } from "web3-core";
33

44
interface Transaction {
55
txHash: string,
66
method: BridgeMethod,
77
events: BridgeEvent[],
88
sender: string,
9-
blockNumber: number
9+
blockNumber: number,
10+
blockTimestamp: number
1011
}
1112

1213
interface BridgeMethod {
@@ -58,6 +59,5 @@ export class BridgeTransactionParser {
5859
* @returns Object - A transaction object
5960
*/
6061
decodeBridgeTransaction(web3Tx: Web3Transaction, bridgeTxReceipt: TransactionReceipt): Promise<Transaction>;
61-
6262
}
6363

index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ class BridgeTransactionParser {
101101
const txData = tx.input;
102102
const method = bridge._jsonInterface.find(i => i.signature === txData.substr(0, 10));
103103
const events = this.decodeLogs(txReceipt, bridge);
104+
const block = await this.web3Client.eth.getBlock(txReceipt.blockNumber);
104105

105106
let bridgeMethod = '';
106107
if (method) {
@@ -112,7 +113,8 @@ class BridgeTransactionParser {
112113
bridgeMethod,
113114
events,
114115
txReceipt.from,
115-
txReceipt.blockNumber
116+
txReceipt.blockNumber,
117+
block.timestamp
116118
);
117119
};
118120

test/index.test.js

Lines changed: 40 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
const chai = require('chai')
2-
const assert = chai.assert;
32
const chaiAsPromised = require('chai-as-promised');
4-
chai.use(chaiAsPromised);
5-
const {expect} = chai;
6-
73
const sinon = require('sinon');
84
const rewire = require('rewire');
95

6+
const assert = chai.assert;
7+
chai.use(chaiAsPromised);
8+
const {expect} = chai;
9+
1010
const bridgeTransactionParserModule = rewire('../index');
1111
const BridgeTransactionParser = bridgeTransactionParserModule.__get__('BridgeTransactionParser');
1212

@@ -217,21 +217,50 @@ const blocksStub = [
217217
'0x6547e88a30d1b43c6fbea07fa7443dfeb697d076495c3e4fc56ebf40228e0431', // Not bridge transaction
218218
'0x7f6c029fba670f1ee14729e5531c672e813ac1ef4c86dec313b090119c14fa78', // Not bridge transaction
219219
'0x73a4d1592c5e922c2c6820985982d2715538717e4b4b52502685bc4c924300b7' // Bridge transaction
220-
]
220+
],
221+
timestamp: 1683234772
221222
},
222223
{
223224
number: 1002,
224225
hash: '0xcdc8e7d4d5417ae5a36c6c246fa34df2ec0ebc9056055eeea401dc95e85e98f1',
225226
transactions: [
226227
'0x719715d6dc0617b6495d74aa4aa21b0755057ef6ad7cdcb71bdffcc2b3af4b24' // Not bridge transaction
227-
]
228+
],
229+
timestamp: 1688764372
228230
},
229231
{
230232
number: 1003,
231233
hash: '0x5f4da1a8bc0f04fd1bca304cbfca19bbf618307a8855bfd71841428a83474f20',
232234
transactions: [
233235
'0x7a3c39f59e1f2c624602c9b54c28155a251963ec878049c0f78a7d281b2e3b87' // Bridge transaction
234-
]
236+
],
237+
timestamp: 1694023972
238+
},
239+
{
240+
number: 1004,
241+
hash: '0x3c57396af7db18317efa29a3e4de1c4b66fe3f0e49b6236f62d30927d107d030',
242+
transactions: [
243+
'0x112439355294e02096078c3b77cb12546fe79d284f46d478b3584873c2bacb8b' // Bridge transaction
244+
],
245+
timestamp: 1697289052
246+
},
247+
{
248+
number: 1005,
249+
hash: '0xa2ee5fddb10d16e9b1bf0e9e8afdf5cb4efd9e84d4d308ef4949da6068cd9d16',
250+
transactions: [
251+
'0x73a4d1592c5e922c2c6820985982d2715538717e4b4b52502685bc4c924300b7', // Bridge transaction
252+
'0x6de85c65973ade9993a6f5c02603e979ac3c09dc18a3206421c2931d559b64ed' // Not bridge transaction
253+
],
254+
timestamp: 1710421852
255+
},
256+
{
257+
number: 1006,
258+
hash: '0x3411a34eaf3c239595642db1225c34c137833672460d45afc4140e4d4aeaa390',
259+
transactions: [
260+
'0x7a3c39f59e1f2c624602c9b54c28155a251963ec878049c0f78a7d281b2e3b87', // Bridge transaction
261+
'0xfd9012ec6b585186fabb8b48e75dca559be5e197ea776139cbf35816914a2dfa' // Not bridge transaction
262+
],
263+
timestamp: 1754170133
235264
}
236265
]
237266

@@ -361,13 +390,16 @@ describe('Get Bridge transaction by tx hash', () => {
361390

362391
it('Should verify and return Bridge transaction from tx hash', async () => {
363392
const txReceipt = txReceiptsStub[4];
393+
const block = web3ClientStub.eth.getBlock(txReceipt.blockNumber);
364394
const result = await bridgeTransactionParser.getBridgeTransactionByTxHash(
365395
txReceipt.transactionHash
366396
);
367397

368398
assert.equal(result.txHash, txReceipt.transactionHash);
369399
assert.equal(result.sender, txReceipt.from);
370400
assert.equal(result.blockNumber, txReceipt.blockNumber);
401+
assert.equal(result.blockNumber, block.number);
402+
assert.equal(result.blockTimestamp, block.timestamp);
371403

372404
assert.equal(result.method.name, "updateCollections");
373405
assert.equal(result.method.signature, "0x0c5a9990");
@@ -468,7 +500,7 @@ describe('Get Bridge transactions from multiple blocks', () => {
468500
.to.be.rejectedWith('blocksToSearch must be greater than 0 or less than 100');
469501
});
470502

471-
it('Should Verify And Return Bridge Transactions From Blocks', async () => {
503+
it('Should verify and return Bridge transactions from blocks', async () => {
472504
const startingBlockNumber = 1001;
473505
const blocksToSearch = 3;
474506
const result = await bridgeTransactionParser.getBridgeTransactionsSinceThisBlock(startingBlockNumber, blocksToSearch);

0 commit comments

Comments
 (0)