Skip to content

Commit d92a6bc

Browse files
committed
support ref time and block proposer in tx/rx headers.
1 parent ff4d4ce commit d92a6bc

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

src/codec/OpGetBlock.ts

+8
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ export interface TransactionsBlockHeader {
4040
prevBlockHash: Uint8Array;
4141
timestamp: Date;
4242
numTransactions: number;
43+
referenceTime: number;
44+
blockProposerAddress: Uint8Array;
4345
}
4446

4547
export interface ResultsBlockHeader {
@@ -50,6 +52,8 @@ export interface ResultsBlockHeader {
5052
timestamp: Date;
5153
transactionsBlockHash: Uint8Array;
5254
numTransactionReceipts: number;
55+
referenceTime: number;
56+
blockProposerAddress: Uint8Array;
5357
}
5458

5559
export interface BlockTransaction {
@@ -182,6 +186,8 @@ export function decodeGetBlockResponse(buf: Uint8Array): GetBlockResponse {
182186
prevBlockHash: transactionsBlockHeaderMsg.getBytes(3),
183187
timestamp: Protocol.unixNanoToDate(transactionsBlockHeaderMsg.getUint64(4)),
184188
numTransactions: transactionsBlockHeaderMsg.getUint32(7),
189+
referenceTime: transactionsBlockHeaderMsg.getUint32(9),
190+
blockProposerAddress: transactionsBlockHeaderMsg.getBytes(8)
185191
},
186192
resultsBlockHash: Hash.calcSha256(resultsBlockHeaderMsg.rawBuffer()),
187193
resultsBlockHeader: {
@@ -192,6 +198,8 @@ export function decodeGetBlockResponse(buf: Uint8Array): GetBlockResponse {
192198
timestamp: Protocol.unixNanoToDate(resultsBlockHeaderMsg.getUint64(4)),
193199
transactionsBlockHash: resultsBlockHeaderMsg.getBytes(7),
194200
numTransactionReceipts: resultsBlockHeaderMsg.getUint32(9),
201+
blockProposerAddress: resultsBlockHeaderMsg.getBytes(11),
202+
referenceTime: resultsBlockHeaderMsg.getUint32(12)
195203
},
196204
transactions: transactions,
197205
};

src/codec/contract.test.ts

+4
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,8 @@ describe("Codec contract", () => {
207207
Timestamp: decoded.transactionsBlockHeader.timestamp.toISOString(),
208208
NumTransactions: decoded.transactionsBlockHeader.numTransactions.toString(),
209209
PrevBlockHash: jsonMarshalBase64Bytes(decoded.transactionsBlockHeader.prevBlockHash),
210+
ReferenceTime: decoded.transactionsBlockHeader.referenceTime,
211+
BlockProposerAddress: jsonMarshalBase64Bytes(decoded.transactionsBlockHeader.blockProposerAddress)
210212
},
211213
ResultsBlockHash: jsonMarshalBase64Bytes(decoded.resultsBlockHash),
212214
ResultsBlockHeader: {
@@ -217,6 +219,8 @@ describe("Codec contract", () => {
217219
NumTransactionReceipts: decoded.resultsBlockHeader.numTransactionReceipts.toString(),
218220
PrevBlockHash: jsonMarshalBase64Bytes(decoded.resultsBlockHeader.prevBlockHash),
219221
TransactionsBlockHash: jsonMarshalBase64Bytes(decoded.resultsBlockHeader.transactionsBlockHash),
222+
ReferenceTime: decoded.resultsBlockHeader.referenceTime,
223+
BlockProposerAddress: jsonMarshalBase64Bytes(decoded.resultsBlockHeader.blockProposerAddress)
220224
},
221225
Transactions: jsonMarshalBlockTransactions(decoded.transactions),
222226
};

src/protocol/Protocol.ts

+15-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { BaseBuilder } from "./Base";
1010
import { FieldTypes } from "membuffers";
1111

1212
// nanoNonce = nanoseconds in range 0 - 499,999 (that will still round down to 0 in milliseconds)
13-
// used to give different timestamps to transactions created in the same millisecond
13+
// used to give different timestamps to transactions created in the same millisecond
1414
export function dateToUnixNano(date: Date, nanoNonce: number): bigint {
1515
if (nanoNonce < 0 || nanoNonce > 499999) throw new Error(`nanoNonce is ${nanoNonce} and must be 0 - 499,999`);
1616
return (BigInt(date.getTime()) * BigInt(1000000)) + BigInt(nanoNonce);
@@ -269,7 +269,18 @@ export class SignedQueryBuilder extends BaseBuilder {
269269

270270
export const QueryResult_Scheme = [FieldTypes.TypeUint16, FieldTypes.TypeBytes, FieldTypes.TypeBytes];
271271

272-
export const TransactionsBlockHeader_Scheme = [FieldTypes.TypeUint32, FieldTypes.TypeUint32, FieldTypes.TypeUint64, FieldTypes.TypeBytes, FieldTypes.TypeUint64, FieldTypes.TypeBytes, FieldTypes.TypeBytes, FieldTypes.TypeUint32];
272+
export const TransactionsBlockHeader_Scheme = [
273+
FieldTypes.TypeUint32,
274+
FieldTypes.TypeUint32,
275+
FieldTypes.TypeUint64,
276+
FieldTypes.TypeBytes,
277+
FieldTypes.TypeUint64,
278+
FieldTypes.TypeBytes,
279+
FieldTypes.TypeBytes,
280+
FieldTypes.TypeUint32,
281+
FieldTypes.TypeBytes,
282+
FieldTypes.TypeUint32
283+
];
273284

274285
export const ResultsBlockHeader_Scheme = [
275286
FieldTypes.TypeUint32,
@@ -283,4 +294,6 @@ export const ResultsBlockHeader_Scheme = [
283294
FieldTypes.TypeBytes,
284295
FieldTypes.TypeUint32,
285296
FieldTypes.TypeUint32,
297+
FieldTypes.TypeBytes,
298+
FieldTypes.TypeUint32
286299
];

0 commit comments

Comments
 (0)