Skip to content

Commit 7cdeb90

Browse files
authored
Fixed PendingUpdate type (#292)
* Fixed `PendingUpdate` type
1 parent 81a6312 commit 7cdeb90

File tree

5 files changed

+31
-6
lines changed

5 files changed

+31
-6
lines changed

packages/sdk/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ Several types have been replaced with a module containing the type itself togeth
7474
- Removed `JsonRpcClient` and types and functionality associated solely with this class.
7575
- Renamed `AccountSequenceNumber` module to `SequenceNumber`.
7676
- Fix type for `TranferredEvent` from `ContractTraceEvent` to only be from contract addresses to account addresses.
77+
- Added `effectiveTime` field to `PendingUpdate`.
7778

7879
### Added
7980

packages/sdk/src/grpc/translation.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1586,6 +1586,15 @@ function trMintDistributionCpv1Update(
15861586
export function pendingUpdate(
15871587
pendingUpdate: v2.PendingUpdate
15881588
): v1.PendingUpdate {
1589+
return {
1590+
effectiveTime: Timestamp.fromProto(unwrap(pendingUpdate.effectiveTime)),
1591+
effect: trPendingUpdateEffect(pendingUpdate),
1592+
};
1593+
}
1594+
1595+
export function trPendingUpdateEffect(
1596+
pendingUpdate: v2.PendingUpdate
1597+
): v1.PendingUpdateEffect {
15891598
const effect = pendingUpdate.effect;
15901599
switch (effect.oneofKind) {
15911600
case 'protocol':

packages/sdk/src/types/chainUpdate.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import type {
1919
import type * as Energy from './Energy.js';
2020
import type * as Duration from './Duration.js';
2121
import type * as CcdAmount from './CcdAmount.js';
22+
import { Timestamp } from '../Timestamp.js';
2223

2324
type ChainUpdate<UpdateType, T> = {
2425
/** The type of the update */
@@ -184,8 +185,16 @@ export type CommonUpdate =
184185
/** A union of chain updates */
185186
export type UpdateInstructionPayload = CommonUpdate | RootUpdate | Level1Update;
186187

187-
/** A union of possible pending updates */
188-
export type PendingUpdate =
188+
/** A pending update */
189+
export type PendingUpdate = {
190+
/** The effective time of the update */
191+
effectiveTime: Timestamp.Type;
192+
/** The effect of the update */
193+
effect: PendingUpdateEffect;
194+
};
195+
196+
/** A union of possible effects */
197+
export type PendingUpdateEffect =
189198
| CommonUpdate
190199
| PendingHigherLevelKeyUpdate
191200
| PendingAuthorizationKeysUpdate;

packages/sdk/test/client/clientV2.test.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -758,7 +758,11 @@ test.each([clientV2, clientWeb])('getBlockPendingUpdates', async (client) => {
758758
client.getBlockPendingUpdates(pendingUpdateBlock);
759759
const pendingUpdateList = await streamToList(pendingUpdateStream);
760760

761-
expect(pendingUpdateList).toEqual(expected.pendingUpdateList);
761+
expect(pendingUpdateList.length).toEqual(1);
762+
expect(pendingUpdateList[0].effectiveTime.value).toEqual(
763+
expected.pendingUpdate.effectiveTime.value
764+
);
765+
expect(pendingUpdateList[0].effect).toEqual(expected.pendingUpdate.effect);
762766
});
763767

764768
test.each([clientV2, clientWeb])(

packages/sdk/test/client/resources/expectedJsons.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ import {
6262
ReturnValue,
6363
SequenceNumber,
6464
StakePendingChangeType,
65+
Timestamp,
6566
TransactionEventTag,
6667
TransactionHash,
6768
TransactionKindString,
@@ -626,8 +627,9 @@ export const specialEventList: BlockSpecialEvent[] = [
626627
},
627628
];
628629

629-
export const pendingUpdateList: PendingUpdate[] = [
630-
{
630+
export const pendingUpdate: PendingUpdate = {
631+
effectiveTime: Timestamp.fromMillis(1669115100n),
632+
effect: {
631633
updateType: UpdateType.Protocol,
632634
update: {
633635
message: 'Enable protocol version 5',
@@ -638,7 +640,7 @@ export const pendingUpdateList: PendingUpdate[] = [
638640
specificationAuxiliaryData: '',
639641
},
640642
},
641-
];
643+
};
642644

643645
export const blockFinalizationSummary: BlockFinalizationSummary = {
644646
tag: 'record',

0 commit comments

Comments
 (0)