Skip to content
This repository was archived by the owner on Aug 2, 2022. It is now read-only.

Commit 42eb121

Browse files
committed
Add deserialize struct type
1 parent b10b79d commit 42eb121

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/eosjs-serialize.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1143,3 +1143,17 @@ export function deserializeAction(contract: Contract, account: string, name: str
11431143
data: deserializeActionData(contract, account, name, data, textEncoder, textDecoder),
11441144
};
11451145
}
1146+
1147+
/** Deserialize struct type. If `data` is a `string`, then it's assumed to be in hex. */
1148+
export function deserializeTypeData(contract: Contract, account: string, structName: string, data: string | Uint8Array, textEncoder: TextEncoder, textDecoder: TextDecoder): any {
1149+
const type = contract.types.get(structName);
1150+
if (typeof data === "string") {
1151+
data = hexToUint8Array(data);
1152+
}
1153+
if(!type) {
1154+
throw new Error(`Unknown type ${structName} in contract ${account}`);
1155+
}
1156+
const buffer = new SerialBuffer({textDecoder, textEncoder});
1157+
buffer.pushArray(data);
1158+
return type.deserialize(buffer);
1159+
}

0 commit comments

Comments
 (0)