Skip to content

Commit e22ae77

Browse files
committed
Check that the entire block item is deserialized
1 parent d44a141 commit e22ae77

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

packages/sdk/src/transactions/Transaction/finalized.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,25 +126,32 @@ export function deserializeBlockItem(buffer: ArrayBuffer): Upward<BlockItem> {
126126
const cursor = Cursor.fromBuffer(buffer);
127127

128128
const blockItemKind = deserializeUint8(cursor);
129+
let blockItem: BlockItem;
129130
switch (blockItemKind) {
130131
case BlockItemKind.AccountTransactionKind:
131-
return {
132+
blockItem = {
132133
kind: BlockItemKind.AccountTransactionKind,
133134
transaction: AccountTransactionV0.deserialize(cursor),
134135
};
136+
break;
135137
case BlockItemKind.CredentialDeploymentKind:
136-
return {
138+
blockItem = {
137139
kind: BlockItemKind.CredentialDeploymentKind,
138140
transaction: deserializeCredentialDeployment(cursor),
139141
};
142+
break;
140143
case BlockItemKind.UpdateInstructionKind:
141144
throw new Error('deserialization of UpdateInstructions is not supported');
142145
case BlockItemKind.AccountTransactionV1Kind:
143-
return {
146+
blockItem = {
144147
kind: BlockItemKind.AccountTransactionV1Kind,
145148
transaction: AccountTransactionV1.deserialize(cursor),
146149
};
150+
break;
147151
default:
148152
return null;
149153
}
154+
155+
if (cursor.remainingBytes.length !== 0) throw new Error('Deserializing the transaction did not exhaust the buffer');
156+
return blockItem;
150157
}

0 commit comments

Comments
 (0)