Skip to content

Commit

Permalink
Use SnarkyJS number types
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinMinkov committed Mar 9, 2023
1 parent 0cb36fe commit 8aec801
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 36 deletions.
4 changes: 2 additions & 2 deletions src/lib/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -594,10 +594,10 @@ async function fetchEvents(
});
return {
events,
blockHeight: event.blockInfo.height.toString(),
blockHeight: UInt32.from(event.blockInfo.height),
blockHash: event.blockInfo.stateHash,
parentBlockHash: event.blockInfo.parentHash,
globalSlot: event.blockInfo.globalSlotSinceGenesis.toString(),
globalSlot: UInt32.from(event.blockInfo.globalSlotSinceGenesis),
chainStatus: event.blockInfo.chainStatus,
transactionHash: event.transactionInfo.hash,
transactionStatus: event.transactionInfo.status,
Expand Down
4 changes: 2 additions & 2 deletions src/lib/mina.ts
Original file line number Diff line number Diff line change
Expand Up @@ -464,8 +464,8 @@ function LocalBlockchain({
}
events[addr][tokenId].push({
events: p.body.events,
blockHeight: networkState.blockchainLength.toString(),
globalSlot: networkState.globalSlotSinceGenesis.toString(),
blockHeight: networkState.blockchainLength,
globalSlot: networkState.globalSlotSinceGenesis,
// The following fields are fetched from the Mina network. For now, we mock these values out
// since networkState does not contain these fields.
blockHash: '',
Expand Down
45 changes: 13 additions & 32 deletions src/lib/zkapp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1055,10 +1055,10 @@ super.init();
{
type: string;
event: ProvablePure<any>;
blockHeight: string;
blockHeight: UInt32;
blockHash: string;
parentBlockHash: string;
globalSlot: string;
globalSlot: UInt32;
chainStatus: string;
transactionHash: string;
transactionStatus: string;
Expand All @@ -1083,15 +1083,8 @@ super.init();
.map((event) => {
return event.events.map((eventData) => {
return {
...event,
event: eventData,
blockHeight: event.blockHeight.toString(),
blockHash: event.blockHash,
parentBlockHash: event.parentBlockHash,
globalSlot: event.globalSlot.toString(),
chainStatus: event.chainStatus,
transactionHash: event.transactionHash,
transactionStatus: event.transactionStatus,
transactionMemo: event.transactionMemo,
};
});
})
Expand All @@ -1104,39 +1097,27 @@ super.init();
// if there is only one event type, the event structure has no index and can directly be matched to the event type
if (sortedEventTypes.length === 1) {
let type = sortedEventTypes[0];
let event = this.events[type].fromFields(
eventData.event.map((f: string) => Field(f))
);
return {
...eventData,
type,
event: this.events[type].fromFields(
eventData.event.map((f: string) => Field(f))
),
blockHeight: eventData.blockHeight,
blockHash: eventData.blockHash,
parentBlockHash: eventData.parentBlockHash,
globalSlot: eventData.globalSlot,
chainStatus: eventData.chainStatus,
transactionHash: eventData.transactionHash,
transactionStatus: eventData.transactionStatus,
transactionMemo: eventData.transactionMemo,
event,
};
} else {
// if there are multiple events we have to use the index event[0] to find the exact event type
let eventObjectIndex = Number(eventData.event[0]);
let type = sortedEventTypes[eventObjectIndex];
// all other elements of the array are values used to construct the original object, we can drop the first value since its just an index
let eventProps = eventData.event.slice(1);
let event = this.events[type].fromFields(
eventProps.map((f: string) => Field(f))
);
return {
...eventData,
type,
event: this.events[type].fromFields(
eventProps.map((f: string) => Field(f))
),
blockHeight: eventData.blockHeight,
blockHash: eventData.blockHash,
parentBlockHash: eventData.parentBlockHash,
globalSlot: eventData.globalSlot,
chainStatus: eventData.chainStatus,
transactionHash: eventData.transactionHash,
transactionStatus: eventData.transactionStatus,
transactionMemo: eventData.transactionMemo,
event,
};
}
});
Expand Down

0 comments on commit 8aec801

Please sign in to comment.