Skip to content

Commit

Permalink
Merge pull request #4 from base-org/michael/signer-error-later
Browse files Browse the repository at this point in the history
Allow command to still be run without ledger
  • Loading branch information
mdehoog committed Sep 13, 2023
2 parents 4efb3a3 + 742a78c commit 2ef9060
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@ import (
"encoding/hex"
"flag"
"fmt"
"golang.org/x/exp/slices"
"io"
"log"
"os"
"os/exec"
"strings"

"golang.org/x/exp/slices"

"github.com/decred/dcrd/hdkeychain/v3"
"github.com/ethereum/go-ethereum/accounts"
"github.com/ethereum/go-ethereum/accounts/usbwallet"
Expand Down Expand Up @@ -54,20 +55,23 @@ func main() {
log.Fatalf("One (and only one) of --private-key, --ledger, --mnemonic must be set")
}

s, err := createSigner(privateKey, mnemonic, hdPath)
if err != nil {
log.Fatalf("Error creating signer: %v", err)
// signer creation error is handled later, allowing the command that generates the signable
// data to run without a key / ledger, which is useful for simulation purposes
s, signerErr := createSigner(privateKey, mnemonic, hdPath)
if signerErr != nil {
log.Printf("Warning: signer creation failed: %v", signerErr)
}

var input []byte
var err error
if flag.NArg() == 0 {
input, err = io.ReadAll(os.Stdin)
if err != nil {
log.Fatalf("Error reading from stdin: %v", err)
}
} else {
args := flag.Args()
if !skipSender && args[0] == "forge" && args[1] == "script" && !slices.Contains(args, "--sender") {
if !skipSender && args[0] == "forge" && args[1] == "script" && !slices.Contains(args, "--sender") && s != nil {
args = append(args, "--sender", s.address().String())
}
fmt.Printf("Running '%s\n", strings.Join(args, " "))
Expand Down Expand Up @@ -96,6 +100,10 @@ func main() {
fmt.Printf("Domain hash: 0x%s\n", hex.EncodeToString(domainHash))
fmt.Printf("Message hash: 0x%s\n", hex.EncodeToString(messageHash))

if signerErr != nil {
log.Fatalf("Error creating signer: %v", signerErr)
}

if ledger {
fmt.Printf("Data sent to ledger, awaiting signature...")
}
Expand Down

0 comments on commit 2ef9060

Please sign in to comment.