Add wallet program which can create a new Account for user

pull/61/head
Rongjian Lan 6 years ago
parent 6d4a4130e7
commit 4dff24ff05
  1. 68
      client/wallet/main.go
  2. 1
      utils/distribution_config.go

@ -0,0 +1,68 @@
package main
import (
"crypto/rand"
"flag"
"fmt"
"github.com/simple-rules/harmony-benchmark/crypto"
"github.com/simple-rules/harmony-benchmark/crypto/pki"
"io"
"os"
)
func main() {
// Account subcommands
//accountNewCommand := flag.NewFlagSet("new", flag.ExitOnError)
//accountListCommand := flag.NewFlagSet("list", flag.ExitOnError)
//
//// Transaction subcommands
//transactionNewCommand := flag.NewFlagSet("new", flag.ExitOnError)
//
//// Account subcommand flag pointers
//// Adding a new choice for --metric of 'substring' and a new --substring flag
//accountNewPtr := accountNewCommand.Bool("new", false, "N/A")
//accountListPtr := accountNewCommand.Bool("new", false, "N/A")
//
//// Transaction subcommand flag pointers
//transactionNewPtr := transactionNewCommand.String("text", "", "Text to parse. (Required)")
// Verify that a subcommand has been provided
// os.Arg[0] is the main command
// os.Arg[1] will be the subcommand
if len(os.Args) < 2 {
fmt.Println("account or transaction subcommand is required")
os.Exit(1)
}
// Switch on the subcommand
// Parse the flags for appropriate FlagSet
// FlagSet.Parse() requires a set of arguments to parse as input
// os.Args[2:] will be all arguments starting after the subcommand at os.Args[1]
switch os.Args[1] {
case "account":
switch os.Args[2] {
case "new":
fmt.Println("Creating new account...")
randomBytes := [32]byte{}
_, err := io.ReadFull(rand.Reader, randomBytes[:])
if err != nil {
fmt.Println("Failed to create a new private key...")
return
}
priKey := crypto.Ed25519Curve.Scalar().SetBytes(randomBytes[:])
pubKey := pki.GetPublicKeyFromScalar(priKey)
address := pki.GetAddressFromPublicKey(pubKey)
fmt.Printf("New account created:\nAddress: {%x}\n", address)
}
case "transaction":
switch os.Args[2] {
case "new":
fmt.Println("Creating new transaction...")
}
default:
flag.PrintDefaults()
os.Exit(1)
}
}

@ -101,7 +101,6 @@ func (config *DistributionConfig) ReadConfigFile(filename string) error {
entry := ConfigEntry{p[0], p[1], p[2], p[3]}
result = append(result, entry)
}
log.Println(result)
config.config = result
return nil
}

Loading…
Cancel
Save