Skip to content

Commit cba0722

Browse files
committed
🐛 Fix parsing
1 parent 7661604 commit cba0722

2 files changed

Lines changed: 41 additions & 16 deletions

File tree

src/explorer/utils/blobDecoder.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { deserializeSmtTokenAction } from "@/model/smt_token";
88
import { deserializeFaucetAction } from "@/model/faucet";
99
import { deserializeOrderbookAction } from "@/model/orderbook";
1010
import { deserializeBoardGameAction, deserializeCrashGameAction } from "@/model/orange_trail";
11-
import { deserializeUtxoStateAction, deserializeUtxoBlob } from "@/model/utxo-state";
11+
import { deserializeUtxoStateAction, deserializeUtxoBlob, deserializeSmtInclusionProof } from "@/model/utxo-state";
1212

1313
export const parseHexToVec = (hex: string): number[] | null => {
1414
const tokens = hex.match(/[0-9a-f]{2}/gi);
@@ -113,6 +113,9 @@ export const decodeBlobData = (hex: string, contractName: string): string => {
113113
case "hyli_utxo":
114114
const utxoBlob = deserializeUtxoBlob(data);
115115
return formatObject(utxoBlob);
116+
case "hyli_smt_incl_proof":
117+
const smtInclProofBlob = deserializeSmtInclusionProof(data);
118+
return formatObject(smtInclProofBlob);
116119
default:
117120
if (contractName.startsWith("wallet")) {
118121
const walletAction = deserializeWalletAction(data);

src/model/utxo-state.ts

Lines changed: 37 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,56 @@
11
import { BorshSchema, borshDeserialize } from "borsher";
22

3-
export interface CommitmentSnapshot {
4-
notes_root: number[];
5-
nullified_notes_root: number[];
3+
export interface HyliUtxoStateBlob {
4+
output_note_commit0: number[];
5+
output_note_commit1: number[];
6+
nullifier0: number[];
7+
nullifier1: number[];
68
}
79

8-
export interface UtxoBlob {
9-
commit0: number[];
10-
commit1: number[];
10+
export interface HyliUtxoBlob {
11+
input_note_commit0: number[];
12+
input_note_commit1: number[];
1113
nullifier0: number[];
1214
nullifier1: number[];
1315
}
1416

15-
const commitmentSnapshotSchema = BorshSchema.Struct({
16-
notes_root: BorshSchema.Array(BorshSchema.u8, 32),
17-
nullified_notes_root: BorshSchema.Array(BorshSchema.u8, 32),
18-
});
17+
export interface HyliSmtInclusionProofBlob {
18+
input_note_commit0: number[];
19+
input_note_commit1: number[];
20+
notes_root: number[];
21+
}
1922

20-
export const deserializeUtxoStateAction = (data: number[]): CommitmentSnapshot => {
21-
return borshDeserialize(commitmentSnapshotSchema, new Uint8Array(data));
23+
export const deserializeUtxoStateAction = (data: number[]): HyliUtxoStateBlob => {
24+
if (data.length !== 128) {
25+
throw new Error(`Expected 128 bytes for utxo blob, got ${data.length}`);
26+
}
27+
return {
28+
output_note_commit0: data.slice(0, 32),
29+
output_note_commit1: data.slice(32, 64),
30+
nullifier0: data.slice(64, 96),
31+
nullifier1: data.slice(96, 128),
32+
};
2233
};
2334

24-
export const deserializeUtxoBlob = (data: number[]): UtxoBlob => {
35+
export const deserializeUtxoBlob = (data: number[]): HyliUtxoBlob => {
2536
if (data.length !== 128) {
2637
throw new Error(`Expected 128 bytes for utxo blob, got ${data.length}`);
2738
}
2839
return {
29-
commit0: data.slice(0, 32),
30-
commit1: data.slice(32, 64),
40+
input_note_commit0: data.slice(0, 32),
41+
input_note_commit1: data.slice(32, 64),
3142
nullifier0: data.slice(64, 96),
3243
nullifier1: data.slice(96, 128),
3344
};
3445
};
46+
47+
export const deserializeSmtInclusionProof = (data: number[]): HyliSmtInclusionProofBlob => {
48+
if (data.length < 96) {
49+
throw new Error(`Expected at least 96 bytes for SMT inclusion proof, got ${data.length}`);
50+
}
51+
return {
52+
input_note_commit0: data.slice(0, 32),
53+
input_note_commit1: data.slice(32, 64),
54+
notes_root: data.slice(64, 96),
55+
};
56+
};

0 commit comments

Comments
 (0)