fix keys and glide
This commit is contained in:
+16
-16
@@ -99,24 +99,24 @@ const genesisJSON = `{
|
||||
|
||||
const key1JSON = `{
|
||||
"address": "1B1BE55F969F54064628A63B9559E7C21C925165",
|
||||
"priv_key": [
|
||||
1,
|
||||
"C70D6934B4F55F1B7BC33B56B9CA8A2061384AFC19E91E44B40C4BBA182953D1619D3678599971ED29C7529DDD4DA537B97129893598A17C82E3AC9A8BA95279"
|
||||
],
|
||||
"pub_key": [
|
||||
1,
|
||||
"619D3678599971ED29C7529DDD4DA537B97129893598A17C82E3AC9A8BA95279"
|
||||
]
|
||||
"priv_key": {
|
||||
"type": "ed25519",
|
||||
"data": "C70D6934B4F55F1B7BC33B56B9CA8A2061384AFC19E91E44B40C4BBA182953D1619D3678599971ED29C7529DDD4DA537B97129893598A17C82E3AC9A8BA95279"
|
||||
},
|
||||
"pub_key": {
|
||||
"type": "ed25519",
|
||||
"data": "619D3678599971ED29C7529DDD4DA537B97129893598A17C82E3AC9A8BA95279"
|
||||
}
|
||||
}`
|
||||
|
||||
const key2JSON = `{
|
||||
"address": "1DA7C74F9C219229FD54CC9F7386D5A3839F0090",
|
||||
"priv_key": [
|
||||
1,
|
||||
"34BAE9E65CE8245FAD035A0E3EED9401BDE8785FFB3199ACCF8F5B5DDF7486A8352195DA90CB0B90C24295B90AEBA25A5A71BC61BAB2FE2387241D439698B7B8"
|
||||
],
|
||||
"pub_key": [
|
||||
1,
|
||||
"352195DA90CB0B90C24295B90AEBA25A5A71BC61BAB2FE2387241D439698B7B8"
|
||||
]
|
||||
"priv_key": {
|
||||
"type": "ed25519",
|
||||
"data": "34BAE9E65CE8245FAD035A0E3EED9401BDE8785FFB3199ACCF8F5B5DDF7486A8352195DA90CB0B90C24295B90AEBA25A5A71BC61BAB2FE2387241D439698B7B8"
|
||||
},
|
||||
"pub_key": {
|
||||
"type": "ed25519",
|
||||
"data": "352195DA90CB0B90C24295B90AEBA25A5A71BC61BAB2FE2387241D439698B7B8"
|
||||
}
|
||||
}`
|
||||
|
||||
+37
-10
@@ -1,15 +1,18 @@
|
||||
package commands
|
||||
|
||||
import (
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"path"
|
||||
"strings"
|
||||
|
||||
"github.com/urfave/cli"
|
||||
|
||||
cmn "github.com/tendermint/go-common"
|
||||
"github.com/tendermint/go-crypto"
|
||||
"github.com/tendermint/go-wire"
|
||||
// "github.com/tendermint/go-wire"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -32,18 +35,37 @@ var (
|
||||
|
||||
func cmdNewKey(c *cli.Context) error {
|
||||
key := genKey()
|
||||
keyJSON := wire.JSONBytesPretty(key)
|
||||
fmt.Println(string(keyJSON))
|
||||
// keyJSON := wire.JSONBytesPretty(key)
|
||||
keyJSON, err := json.MarshalIndent(key, "", "\t")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
fmt.Println(keyJSON)
|
||||
return nil
|
||||
}
|
||||
|
||||
//---------------------------------------------
|
||||
// simple implementation of a key
|
||||
|
||||
type Address [20]byte
|
||||
|
||||
func (a Address) MarshalJSON() ([]byte, error) {
|
||||
return []byte(fmt.Sprintf(`"%x"`, a[:])), nil
|
||||
}
|
||||
|
||||
func (a *Address) UnmarshalJSON(addrHex []byte) error {
|
||||
addr, err := hex.DecodeString(strings.Trim(string(addrHex), `"`))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
copy(a[:], addr)
|
||||
return nil
|
||||
}
|
||||
|
||||
type Key struct {
|
||||
Address []byte `json:"address"`
|
||||
PubKey crypto.PubKey `json:"pub_key"`
|
||||
PrivKey crypto.PrivKey `json:"priv_key"`
|
||||
Address Address `json:"address"`
|
||||
PubKey crypto.PubKeyS `json:"pub_key"`
|
||||
PrivKey crypto.PrivKeyS `json:"priv_key"`
|
||||
}
|
||||
|
||||
// Implements Signer
|
||||
@@ -54,10 +76,13 @@ func (k *Key) Sign(msg []byte) crypto.Signature {
|
||||
// Generates a new validator with private key.
|
||||
func genKey() *Key {
|
||||
privKey := crypto.GenPrivKeyEd25519()
|
||||
addrBytes := privKey.PubKey().Address()
|
||||
var addr Address
|
||||
copy(addr[:], addrBytes)
|
||||
return &Key{
|
||||
Address: privKey.PubKey().Address(),
|
||||
PubKey: privKey.PubKey(),
|
||||
PrivKey: privKey,
|
||||
Address: addr,
|
||||
PubKey: crypto.PubKeyS{privKey.PubKey()},
|
||||
PrivKey: crypto.PrivKeyS{privKey},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -67,7 +92,9 @@ func LoadKey(keyFile string) *Key {
|
||||
if err != nil {
|
||||
cmn.Exit(err.Error())
|
||||
}
|
||||
key := wire.ReadJSON(&Key{}, keyJSONBytes, &err).(*Key)
|
||||
key := new(Key)
|
||||
err = json.Unmarshal(keyJSONBytes, key)
|
||||
// key := wire.ReadJSON(&Key{}, keyJSONBytes, &err).(*Key)
|
||||
if err != nil {
|
||||
cmn.Exit(cmn.Fmt("Error reading key from %v: %v\n", filePath, err))
|
||||
}
|
||||
|
||||
+16
-8
@@ -76,17 +76,25 @@ func cmdStart(c *cli.Context) error {
|
||||
basecoinApp.RegisterPlugin(p.newPlugin())
|
||||
}
|
||||
|
||||
// If genesis file exists, set key-value options
|
||||
genesisFile := path.Join(basecoinDir, "genesis.json")
|
||||
if _, err := os.Stat(genesisFile); err == nil {
|
||||
err := basecoinApp.LoadGenesis(genesisFile)
|
||||
if err != nil {
|
||||
return errors.New(cmn.Fmt("%+v", err))
|
||||
fmt.Println("CHAIN ID", basecoinApp.GetState().GetChainID())
|
||||
|
||||
// if chain_id has not been set yet, load the genesis.
|
||||
// else, assume it's been loaded
|
||||
if basecoinApp.GetState().GetChainID() == "" {
|
||||
// If genesis file exists, set key-value options
|
||||
genesisFile := path.Join(basecoinDir, "genesis.json")
|
||||
if _, err := os.Stat(genesisFile); err == nil {
|
||||
err := basecoinApp.LoadGenesis(genesisFile)
|
||||
if err != nil {
|
||||
return errors.New(cmn.Fmt("%+v", err))
|
||||
}
|
||||
} else {
|
||||
fmt.Printf("No genesis file at %s, skipping...\n", genesisFile)
|
||||
}
|
||||
} else {
|
||||
fmt.Printf("No genesis file at %s, skipping...\n", genesisFile)
|
||||
}
|
||||
|
||||
fmt.Println("CHAIN ID", basecoinApp.GetState().GetChainID())
|
||||
|
||||
if c.Bool("without-tendermint") {
|
||||
// run just the abci app/server
|
||||
if err := startBasecoinABCI(c, basecoinApp); err != nil {
|
||||
|
||||
+2
-2
@@ -86,7 +86,7 @@ func cmdSendTx(c *cli.Context) error {
|
||||
privKey := LoadKey(fromFile)
|
||||
|
||||
// get the sequence number for the tx
|
||||
sequence, err := getSeq(c, privKey.Address)
|
||||
sequence, err := getSeq(c, privKey.Address[:])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -145,7 +145,7 @@ func AppTx(c *cli.Context, name string, data []byte) error {
|
||||
|
||||
privKey := LoadKey(fromFile)
|
||||
|
||||
sequence, err := getSeq(c, privKey.Address)
|
||||
sequence, err := getSeq(c, privKey.Address[:])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user