From 6de4a5d8a9d114c4c33c58f8a304b60e7370eeff Mon Sep 17 00:00:00 2001 From: Richard Moore Date: Sat, 27 Jul 2019 18:51:39 -0300 Subject: [PATCH] Added TypeScript tool support for functions with multiple outputs. --- packages/cli/src.ts/typescript.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/packages/cli/src.ts/typescript.ts b/packages/cli/src.ts/typescript.ts index 4fc16f847..c2615aca9 100644 --- a/packages/cli/src.ts/typescript.ts +++ b/packages/cli/src.ts/typescript.ts @@ -9,6 +9,8 @@ function getType(param: ethers.utils.ParamType, flexible?: boolean): string { if (param.type === "address" || param.type === "string") { return "string"; } + if (param.type === "bool") { return "boolean" } + if (param.type.substring(0, 5) === "bytes") { if (flexible) { return "string | ethers.utils.BytesLike"; @@ -76,7 +78,15 @@ export function generate(contract: ContractCode, bytecode?: string): string { if (fragment.outputs.length === 1) { output = "Promise<" + getType(fragment.outputs[0]) + ">"; } else { - throw new Error('not implemented yet'); + // If all output parameters are names, we can specify the struct + if (fragment.outputs.filter((o) => (!!o.name)).length === fragment.outputs.length) { + output = "Promise<{ " + fragment.outputs.map((o, i) => + ((o.name || ("arg" + String(i)))+ ": " + getType(o)) + ).join(", ") + " }>"; + } else { + // Otherwise, all we know is that it will be an Array + output = "Promise<{ Array }>" + } } }