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

Commit

Permalink
Add deserialize struct type
Browse files Browse the repository at this point in the history
  • Loading branch information
emperorhan committed Apr 13, 2020
1 parent b10b79d commit faae17f
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/eosjs-serialize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1143,3 +1143,23 @@ export function deserializeAction(contract: Contract, account: string, name: str
data: deserializeActionData(contract, account, name, data, textEncoder, textDecoder),
};
}

/** Deserialize struct type. If `data` is a `string`, then it's assumed to be in hex. */
export function deserializeTypeData(
contract: Contract,
account: string,
structName: string,
data: string | Uint8Array,
textEncoder: TextEncoder,
textDecoder: TextDecoder): any {
const type = contract.types.get(structName);
if (typeof data === 'string') {
data = hexToUint8Array(data);
}
if (!type) {
throw new Error(`Unknown type ${structName} in contract ${account}`);
}
const buffer = new SerialBuffer({textDecoder, textEncoder});
buffer.pushArray(data);
return type.deserialize(buffer);
}

0 comments on commit faae17f

Please sign in to comment.