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

Commit faae17f

Browse files
committed
Add deserialize struct type
1 parent b10b79d commit faae17f

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

src/eosjs-serialize.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1143,3 +1143,23 @@ 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(
1149+
contract: Contract,
1150+
account: string,
1151+
structName: string,
1152+
data: string | Uint8Array,
1153+
textEncoder: TextEncoder,
1154+
textDecoder: TextDecoder): any {
1155+
const type = contract.types.get(structName);
1156+
if (typeof data === 'string') {
1157+
data = hexToUint8Array(data);
1158+
}
1159+
if (!type) {
1160+
throw new Error(`Unknown type ${structName} in contract ${account}`);
1161+
}
1162+
const buffer = new SerialBuffer({textDecoder, textEncoder});
1163+
buffer.pushArray(data);
1164+
return type.deserialize(buffer);
1165+
}

0 commit comments

Comments
 (0)