Skip to content

Commit

Permalink
make pk and chainpk required inputs
Browse files Browse the repository at this point in the history
We can't use the Required: true API from "github.com/urfave/cli/v2"
since that will complain even if the flag is set in a config file.

urfave/cli#849

In future we may want to force these keys to be supplied at the command line (best practices would steer away from storing sensitive information in a config file).

This commit also enhances the output of the constructor.
  • Loading branch information
geoknee committed May 12, 2023
1 parent bf9f688 commit df9bd90
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,6 @@ func main() {
altsrc.NewStringFlag(&cli.StringFlag{
Name: PK,
Usage: "Specifies the private key for the client.",
Value: "2d999770f7b5d49b694080f987b82bbc9fc9ac2b4dcc10b0f8aba7d700f69c6d",
DefaultText: "Alice's private key",
Category: "Keys:",
Destination: &pkString,
}),
Expand All @@ -80,8 +78,6 @@ func main() {
altsrc.NewStringFlag(&cli.StringFlag{
Name: CHAIN_PK,
Usage: "Specifies the private key to use when interacting with the chain.",
Value: "ac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80",
DefaultText: "A hardhat / annvil default funded account",
Category: "Keys:",
Destination: &chainPk,
}),
Expand Down Expand Up @@ -121,21 +117,29 @@ func main() {
Flags: flags,
Before: altsrc.InitInputSourceWithContext(flags, altsrc.NewTomlSourceFromFlagFunc(CONFIG)),
Action: func(cCtx *cli.Context) error {
if pkString == "" {
panic("pk must be set")
}
if chainPk == "" {
panic("chainpk must be set")
}
pk := common.Hex2Bytes(pkString)
me := crypto.GetAddressFromSecretKeyBytes(pk)

logDestination := os.Stdout

var ourStore store.Store
fmt.Println("Initialising store...")

if useDurableStore {
fmt.Println("Initialising durable store...")
dataFolder := fmt.Sprintf("./data/nitro-service/%s", me.String())
ourStore = store.NewDurableStore(pk, dataFolder, buntdb.Config{})
} else {
fmt.Println("Initialising mem store...")
ourStore = store.NewMemStore(pk)
}

fmt.Println("Connecting to chain...")
fmt.Println("Connecting to chain " + chainUrl + " with chain id " + fmt.Sprint(chainId) + "...")
ethClient, txSubmitter, err := chainutils.ConnectToChain(context.Background(), chainUrl, chainId, common.Hex2Bytes(chainPk))
if err != nil {
panic(err)
Expand All @@ -151,7 +155,7 @@ func main() {
panic(err)
}

fmt.Println("Initializing message service...")
fmt.Println("Initializing message service on port " + fmt.Sprint(msgPort) + "...")
messageservice := p2pms.NewMessageService("127.0.0.1", msgPort, *ourStore.GetAddress(), pk, logDestination)
node := client.New(
messageservice,
Expand All @@ -164,8 +168,10 @@ func main() {
var transport transport.Responder

if useNats {
fmt.Println("Initializing NATS RPC transport...")
transport, err = nats.NewNatsTransportAsServer(rpcPort)
} else {
fmt.Println("Initializing websocketNATS RPC transport...")
transport, err = ws.NewWebSocketTransportAsServer(fmt.Sprint(rpcPort))
}
if err != nil {
Expand Down

0 comments on commit df9bd90

Please sign in to comment.