|
19 | 19 | package hex |
20 | 20 |
|
21 | 21 | import ( |
| 22 | + "encoding/hex" |
22 | 23 | "log" |
23 | 24 |
|
24 | 25 | "github.com/onflow/flow-go-sdk" |
@@ -48,17 +49,49 @@ var Cmd = &cobra.Command{ |
48 | 49 | Run: func(cmd *cobra.Command, args []string) { |
49 | 50 | projectConf := cli.LoadConfig() |
50 | 51 |
|
| 52 | + if conf.Name == "" { |
| 53 | + cli.Exitf(1, "missing name") |
| 54 | + } |
| 55 | + |
51 | 56 | _, accountExists := projectConf.Accounts[conf.Name] |
52 | 57 | if accountExists && !conf.Overwrite { |
53 | 58 | cli.Exitf(1, "%s already exists in the config, and overwrite is false", conf.Name) |
54 | 59 | } |
55 | 60 |
|
| 61 | + // Parse address |
| 62 | + decodedAddress, err := hex.DecodeString(conf.Address) |
| 63 | + if err != nil { |
| 64 | + cli.Exitf(1, "invalid address: %s", err.Error()) |
| 65 | + } |
| 66 | + address := flow.BytesToAddress(decodedAddress) |
| 67 | + |
| 68 | + // Parse signature algorithm |
| 69 | + if conf.SigAlgo == "" { |
| 70 | + cli.Exitf(1, "missing signature algorithm") |
| 71 | + } |
| 72 | + |
| 73 | + algorithm := crypto.StringToSignatureAlgorithm(conf.SigAlgo) |
| 74 | + if algorithm == crypto.UnknownSignatureAlgorithm { |
| 75 | + cli.Exitf(1, "invalid signature algorithm") |
| 76 | + } |
| 77 | + |
| 78 | + // Parse hash algorithm |
| 79 | + |
| 80 | + if conf.HashAlgo == "" { |
| 81 | + cli.Exitf(1, "missing hash algorithm") |
| 82 | + } |
| 83 | + |
| 84 | + hashAlgorithm := crypto.StringToHashAlgorithm(conf.HashAlgo) |
| 85 | + if hashAlgorithm == crypto.UnknownHashAlgorithm { |
| 86 | + cli.Exitf(1, "invalid hash algorithm") |
| 87 | + } |
| 88 | + |
56 | 89 | // Populate account |
57 | 90 | account := &cli.Account{ |
58 | 91 | KeyType: cli.KeyTypeHex, |
59 | | - Address: flow.HexToAddress(conf.Address), |
60 | | - SigAlgo: crypto.StringToSignatureAlgorithm(conf.SigAlgo), |
61 | | - HashAlgo: crypto.StringToHashAlgorithm(conf.HashAlgo), |
| 92 | + Address: address, |
| 93 | + SigAlgo: algorithm, |
| 94 | + HashAlgo: hashAlgorithm, |
62 | 95 | KeyIndex: conf.KeyIndex, |
63 | 96 | KeyContext: map[string]string{"privateKey": conf.KeyHex}, |
64 | 97 | } |
|
0 commit comments