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 42eb121
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/eosjs-serialize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1143,3 +1143,17 @@ 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 42eb121

Please sign in to comment.