From 65c9506f7638b36ba4d262bf22ae59559f1cceba Mon Sep 17 00:00:00 2001 From: Xavier Romero Date: Thu, 12 Dec 2024 09:25:03 +0100 Subject: [PATCH] Fix wrap-contract when reading content from file --- cmd/wrapcontract/wrapcontract.go | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/cmd/wrapcontract/wrapcontract.go b/cmd/wrapcontract/wrapcontract.go index 23cce01f..7065b783 100644 --- a/cmd/wrapcontract/wrapcontract.go +++ b/cmd/wrapcontract/wrapcontract.go @@ -52,21 +52,24 @@ func init() { func getInputData(args []string) (string, error) { var deployedBytecode string + var deployedBytecodeOrFile string + if len(args) == 0 { - deployedBytecodeBytes, err := io.ReadAll(os.Stdin) + deployedBytecodeOrFileBytes, err := io.ReadAll(os.Stdin) if err != nil { return "", err } - deployedBytecode = string(deployedBytecodeBytes) + deployedBytecodeOrFile = string(deployedBytecodeOrFileBytes) } else { - deployedBytecodeOrFile := args[0] - // Try to open the param as a file, otherwise treat it as bytecode - deployedBytecodeBytes, err := os.ReadFile(deployedBytecodeOrFile) - if err != nil { - deployedBytecode = deployedBytecodeOrFile - } else { - deployedBytecode = string(deployedBytecodeBytes) - } + deployedBytecodeOrFile = args[0] + } + // Try to open the param as a file, otherwise treat it as bytecode + deployedBytecodeOrFile = strings.TrimSpace(deployedBytecodeOrFile) + deployedBytecodeBytes, err := os.ReadFile(deployedBytecodeOrFile) + if err != nil { + deployedBytecode = deployedBytecodeOrFile + } else { + deployedBytecode = string(deployedBytecodeBytes) } return strings.TrimSpace(deployedBytecode), nil