kaspad/cmd/wallet/create.go
stasatdaglabs 90d4dbcba1
Implement a simple CLI wallet (#1261)
* Copy over the CLI wallet from Kasparov.

* Fix trivial compilation errors.

* Reimplement the balance command.

* Extract isUTXOSpendable to a separate function.

* Reimplement the send command.

* Fix bad transaction ID parsing.

* Add a missing newline in a log.

* Don't use msgTx in send().

* Fix isUTXOSpendable not checking whether a UTXO is of a coinbase transaction.

* Add --devnet, --testnet, etc. to command line flags.

* In `create`, only print the public key of the active network.

* Use coinbase maturity in isUTXOSpendable.

* Add a readme.

* Fix formatting in readme.
2020-12-23 09:41:48 +02:00

38 lines
1.1 KiB
Go

package main
import (
"fmt"
"github.com/kaspanet/go-secp256k1"
"github.com/kaspanet/kaspad/util"
"github.com/pkg/errors"
)
func create(conf *createConfig) error {
privateKey, err := secp256k1.GeneratePrivateKey()
if err != nil {
return errors.Wrap(err, "Failed to generate private key")
}
fmt.Println("This is your private key, granting access to all wallet funds. Keep it safe. Use it only when sending Kaspa.")
fmt.Printf("Private key (hex):\t%s\n\n", privateKey.SerializePrivateKey())
fmt.Println("This is your public address, where money is to be sent.")
publicKey, err := privateKey.SchnorrPublicKey()
if err != nil {
return errors.Wrap(err, "Failed to generate public key")
}
publicKeySerialized, err := publicKey.Serialize()
if err != nil {
return errors.Wrap(err, "Failed to serialize public key")
}
addr, err := util.NewAddressPubKeyHashFromPublicKey(publicKeySerialized[:], conf.ActiveNetParams.Prefix)
if err != nil {
return errors.Wrap(err, "Failed to generate p2pkh address")
}
fmt.Printf("Address (%s):\t%s\n", conf.ActiveNetParams.Name, addr)
return nil
}