fix keys and glide
This commit is contained in:
parent
fa5d7b30f2
commit
de5506dd8f
@ -99,24 +99,24 @@ const genesisJSON = `{
|
|||||||
|
|
||||||
const key1JSON = `{
|
const key1JSON = `{
|
||||||
"address": "1B1BE55F969F54064628A63B9559E7C21C925165",
|
"address": "1B1BE55F969F54064628A63B9559E7C21C925165",
|
||||||
"priv_key": [
|
"priv_key": {
|
||||||
1,
|
"type": "ed25519",
|
||||||
"C70D6934B4F55F1B7BC33B56B9CA8A2061384AFC19E91E44B40C4BBA182953D1619D3678599971ED29C7529DDD4DA537B97129893598A17C82E3AC9A8BA95279"
|
"data": "C70D6934B4F55F1B7BC33B56B9CA8A2061384AFC19E91E44B40C4BBA182953D1619D3678599971ED29C7529DDD4DA537B97129893598A17C82E3AC9A8BA95279"
|
||||||
],
|
},
|
||||||
"pub_key": [
|
"pub_key": {
|
||||||
1,
|
"type": "ed25519",
|
||||||
"619D3678599971ED29C7529DDD4DA537B97129893598A17C82E3AC9A8BA95279"
|
"data": "619D3678599971ED29C7529DDD4DA537B97129893598A17C82E3AC9A8BA95279"
|
||||||
]
|
}
|
||||||
}`
|
}`
|
||||||
|
|
||||||
const key2JSON = `{
|
const key2JSON = `{
|
||||||
"address": "1DA7C74F9C219229FD54CC9F7386D5A3839F0090",
|
"address": "1DA7C74F9C219229FD54CC9F7386D5A3839F0090",
|
||||||
"priv_key": [
|
"priv_key": {
|
||||||
1,
|
"type": "ed25519",
|
||||||
"34BAE9E65CE8245FAD035A0E3EED9401BDE8785FFB3199ACCF8F5B5DDF7486A8352195DA90CB0B90C24295B90AEBA25A5A71BC61BAB2FE2387241D439698B7B8"
|
"data": "34BAE9E65CE8245FAD035A0E3EED9401BDE8785FFB3199ACCF8F5B5DDF7486A8352195DA90CB0B90C24295B90AEBA25A5A71BC61BAB2FE2387241D439698B7B8"
|
||||||
],
|
},
|
||||||
"pub_key": [
|
"pub_key": {
|
||||||
1,
|
"type": "ed25519",
|
||||||
"352195DA90CB0B90C24295B90AEBA25A5A71BC61BAB2FE2387241D439698B7B8"
|
"data": "352195DA90CB0B90C24295B90AEBA25A5A71BC61BAB2FE2387241D439698B7B8"
|
||||||
]
|
}
|
||||||
}`
|
}`
|
||||||
|
|||||||
@ -1,15 +1,18 @@
|
|||||||
package commands
|
package commands
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/hex"
|
||||||
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"path"
|
"path"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/urfave/cli"
|
"github.com/urfave/cli"
|
||||||
|
|
||||||
cmn "github.com/tendermint/go-common"
|
cmn "github.com/tendermint/go-common"
|
||||||
"github.com/tendermint/go-crypto"
|
"github.com/tendermint/go-crypto"
|
||||||
"github.com/tendermint/go-wire"
|
// "github.com/tendermint/go-wire"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -32,18 +35,37 @@ var (
|
|||||||
|
|
||||||
func cmdNewKey(c *cli.Context) error {
|
func cmdNewKey(c *cli.Context) error {
|
||||||
key := genKey()
|
key := genKey()
|
||||||
keyJSON := wire.JSONBytesPretty(key)
|
// keyJSON := wire.JSONBytesPretty(key)
|
||||||
fmt.Println(string(keyJSON))
|
keyJSON, err := json.MarshalIndent(key, "", "\t")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
fmt.Println(keyJSON)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------
|
//---------------------------------------------
|
||||||
// simple implementation of a key
|
// 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 {
|
type Key struct {
|
||||||
Address []byte `json:"address"`
|
Address Address `json:"address"`
|
||||||
PubKey crypto.PubKey `json:"pub_key"`
|
PubKey crypto.PubKeyS `json:"pub_key"`
|
||||||
PrivKey crypto.PrivKey `json:"priv_key"`
|
PrivKey crypto.PrivKeyS `json:"priv_key"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Implements Signer
|
// Implements Signer
|
||||||
@ -54,10 +76,13 @@ func (k *Key) Sign(msg []byte) crypto.Signature {
|
|||||||
// Generates a new validator with private key.
|
// Generates a new validator with private key.
|
||||||
func genKey() *Key {
|
func genKey() *Key {
|
||||||
privKey := crypto.GenPrivKeyEd25519()
|
privKey := crypto.GenPrivKeyEd25519()
|
||||||
|
addrBytes := privKey.PubKey().Address()
|
||||||
|
var addr Address
|
||||||
|
copy(addr[:], addrBytes)
|
||||||
return &Key{
|
return &Key{
|
||||||
Address: privKey.PubKey().Address(),
|
Address: addr,
|
||||||
PubKey: privKey.PubKey(),
|
PubKey: crypto.PubKeyS{privKey.PubKey()},
|
||||||
PrivKey: privKey,
|
PrivKey: crypto.PrivKeyS{privKey},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -67,7 +92,9 @@ func LoadKey(keyFile string) *Key {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
cmn.Exit(err.Error())
|
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 {
|
if err != nil {
|
||||||
cmn.Exit(cmn.Fmt("Error reading key from %v: %v\n", filePath, err))
|
cmn.Exit(cmn.Fmt("Error reading key from %v: %v\n", filePath, err))
|
||||||
}
|
}
|
||||||
|
|||||||
@ -76,17 +76,25 @@ func cmdStart(c *cli.Context) error {
|
|||||||
basecoinApp.RegisterPlugin(p.newPlugin())
|
basecoinApp.RegisterPlugin(p.newPlugin())
|
||||||
}
|
}
|
||||||
|
|
||||||
// If genesis file exists, set key-value options
|
fmt.Println("CHAIN ID", basecoinApp.GetState().GetChainID())
|
||||||
genesisFile := path.Join(basecoinDir, "genesis.json")
|
|
||||||
if _, err := os.Stat(genesisFile); err == nil {
|
// if chain_id has not been set yet, load the genesis.
|
||||||
err := basecoinApp.LoadGenesis(genesisFile)
|
// else, assume it's been loaded
|
||||||
if err != nil {
|
if basecoinApp.GetState().GetChainID() == "" {
|
||||||
return errors.New(cmn.Fmt("%+v", err))
|
// 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") {
|
if c.Bool("without-tendermint") {
|
||||||
// run just the abci app/server
|
// run just the abci app/server
|
||||||
if err := startBasecoinABCI(c, basecoinApp); err != nil {
|
if err := startBasecoinABCI(c, basecoinApp); err != nil {
|
||||||
|
|||||||
@ -86,7 +86,7 @@ func cmdSendTx(c *cli.Context) error {
|
|||||||
privKey := LoadKey(fromFile)
|
privKey := LoadKey(fromFile)
|
||||||
|
|
||||||
// get the sequence number for the tx
|
// get the sequence number for the tx
|
||||||
sequence, err := getSeq(c, privKey.Address)
|
sequence, err := getSeq(c, privKey.Address[:])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -145,7 +145,7 @@ func AppTx(c *cli.Context, name string, data []byte) error {
|
|||||||
|
|
||||||
privKey := LoadKey(fromFile)
|
privKey := LoadKey(fromFile)
|
||||||
|
|
||||||
sequence, err := getSeq(c, privKey.Address)
|
sequence, err := getSeq(c, privKey.Address[:])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"address": "D397BC62B435F3CF50570FBAB4340FE52C60858F",
|
"address": "D397BC62B435F3CF50570FBAB4340FE52C60858F",
|
||||||
"priv_key": [
|
"priv_key": {
|
||||||
1,
|
"type": "ed25519",
|
||||||
"39E75AA1CF7BC710585977EFC375CD1730519186BD231478C339F2819C3C26E7B3588BDC92015ED3CDB6F57A86379E8C79A7111063610B7E625487C76496F4DF"
|
"data": "39E75AA1CF7BC710585977EFC375CD1730519186BD231478C339F2819C3C26E7B3588BDC92015ED3CDB6F57A86379E8C79A7111063610B7E625487C76496F4DF"
|
||||||
],
|
},
|
||||||
"pub_key": [
|
"pub_key": {
|
||||||
1,
|
"type": "ed25519",
|
||||||
"B3588BDC92015ED3CDB6F57A86379E8C79A7111063610B7E625487C76496F4DF"
|
"data": "B3588BDC92015ED3CDB6F57A86379E8C79A7111063610B7E625487C76496F4DF"
|
||||||
]
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,11 +1,11 @@
|
|||||||
{
|
{
|
||||||
"address": "053BA0F19616AFF975C8756A2CBFF04F408B4D47",
|
"address": "053BA0F19616AFF975C8756A2CBFF04F408B4D47",
|
||||||
"priv_key": [
|
"priv_key": {
|
||||||
1,
|
"type": "ed25519",
|
||||||
"22920C428043D869987F253D7C9B2305E7010642C40CE88A52C9F6CE5ACC42080628C8E6C2D50B15764B443394E06C6A64F3082CE966A2A8C1A55A4D63D0FC5D"
|
"data": "22920C428043D869987F253D7C9B2305E7010642C40CE88A52C9F6CE5ACC42080628C8E6C2D50B15764B443394E06C6A64F3082CE966A2A8C1A55A4D63D0FC5D"
|
||||||
],
|
},
|
||||||
"pub_key": [
|
"pub_key": {
|
||||||
1,
|
"type": "ed25519",
|
||||||
"0628C8E6C2D50B15764B443394E06C6A64F3082CE966A2A8C1A55A4D63D0FC5D"
|
"data": "0628C8E6C2D50B15764B443394E06C6A64F3082CE966A2A8C1A55A4D63D0FC5D"
|
||||||
]
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -84,7 +84,7 @@ Now, let's create a new private key:
|
|||||||
basecoin key new > $BCHOME/key.json
|
basecoin key new > $BCHOME/key.json
|
||||||
```
|
```
|
||||||
|
|
||||||
Here's what my `key.json looks like (TODO: change `keys` so it looks like this ...):
|
Here's what my `key.json looks like:
|
||||||
|
|
||||||
```json
|
```json
|
||||||
{
|
{
|
||||||
|
|||||||
33
glide.lock
generated
33
glide.lock
generated
@ -1,34 +1,34 @@
|
|||||||
hash: 3869944d14a8df914ffcad02c2ef3548173daba51c5ea697767f8af77c07b348
|
hash: c71c0d6c409bfddb4c4b471d8445f59cebd2cd41e1635a90d6facd81bd09a5e0
|
||||||
updated: 2017-03-06T05:37:03.828355251-05:00
|
updated: 2017-03-14T17:02:44.512359631-04:00
|
||||||
imports:
|
imports:
|
||||||
- name: github.com/btcsuite/btcd
|
- name: github.com/btcsuite/btcd
|
||||||
version: d06c0bb181529331be8f8d9350288c420d9e60e4
|
version: 583684b21bfbde9b5fc4403916fd7c807feb0289
|
||||||
subpackages:
|
subpackages:
|
||||||
- btcec
|
- btcec
|
||||||
- name: github.com/BurntSushi/toml
|
- name: github.com/BurntSushi/toml
|
||||||
version: 99064174e013895bbd9b025c31100bd1d9b590ca
|
version: e643e9ef00b049d75de26e61109c5ea01885cd21
|
||||||
- name: github.com/ebuchman/fail-test
|
- name: github.com/ebuchman/fail-test
|
||||||
version: 13f91f14c826314205cdbed1ec8ac8bf08e03381
|
version: 95f809107225be108efcf10a3509e4ea6ceef3c4
|
||||||
- name: github.com/go-stack/stack
|
- name: github.com/go-stack/stack
|
||||||
version: 100eb0c0a9c5b306ca2fb4f165df21d80ada4b82
|
version: 100eb0c0a9c5b306ca2fb4f165df21d80ada4b82
|
||||||
- name: github.com/golang/protobuf
|
- name: github.com/golang/protobuf
|
||||||
version: 8ee79997227bf9b34611aee7946ae64735e6fd93
|
version: c9c7427a2a70d2eb3bafa0ab2dc163e45f143317
|
||||||
subpackages:
|
subpackages:
|
||||||
- proto
|
- proto
|
||||||
- name: github.com/golang/snappy
|
- name: github.com/golang/snappy
|
||||||
version: d9eb7a3d35ec988b8585d4a0068e462c27d28380
|
version: 553a641470496b2327abcac10b36396bd98e45c9
|
||||||
- name: github.com/gorilla/websocket
|
- name: github.com/gorilla/websocket
|
||||||
version: 3ab3a8b8831546bd18fd182c20687ca853b2bb13
|
version: 3ab3a8b8831546bd18fd182c20687ca853b2bb13
|
||||||
- name: github.com/jmhodges/levigo
|
- name: github.com/jmhodges/levigo
|
||||||
version: c42d9e0ca023e2198120196f842701bb4c55d7b9
|
version: c42d9e0ca023e2198120196f842701bb4c55d7b9
|
||||||
- name: github.com/mattn/go-colorable
|
- name: github.com/mattn/go-colorable
|
||||||
version: d228849504861217f796da67fae4f6e347643f15
|
version: a392f450ea64cee2b268dfaacdc2502b50a22b18
|
||||||
- name: github.com/mattn/go-isatty
|
- name: github.com/mattn/go-isatty
|
||||||
version: 30a891c33c7cde7b02a981314b4228ec99380cca
|
version: 57fdcb988a5c543893cc61bce354a6e24ab70022
|
||||||
- name: github.com/pkg/errors
|
- name: github.com/pkg/errors
|
||||||
version: 645ef00459ed84a119197bfb8d8205042c6df63d
|
version: bfd5150e4e41705ded2129ec33379de1cb90b513
|
||||||
- name: github.com/syndtr/goleveldb
|
- name: github.com/syndtr/goleveldb
|
||||||
version: 23851d93a2292dcc56e71a18ec9e0624d84a0f65
|
version: 3c5717caf1475fd25964109a0fc640bd150fce43
|
||||||
subpackages:
|
subpackages:
|
||||||
- leveldb
|
- leveldb
|
||||||
- leveldb/cache
|
- leveldb/cache
|
||||||
@ -43,7 +43,7 @@ imports:
|
|||||||
- leveldb/table
|
- leveldb/table
|
||||||
- leveldb/util
|
- leveldb/util
|
||||||
- name: github.com/tendermint/abci
|
- name: github.com/tendermint/abci
|
||||||
version: 1236e8fb6eee3a63909f4014a8e84385ead7933d
|
version: af792eac777de757cd496349a5f6b5313738fcbc
|
||||||
subpackages:
|
subpackages:
|
||||||
- client
|
- client
|
||||||
- example/dummy
|
- example/dummy
|
||||||
@ -117,7 +117,7 @@ imports:
|
|||||||
- name: github.com/urfave/cli
|
- name: github.com/urfave/cli
|
||||||
version: 0bdeddeeb0f650497d603c4ad7b20cfe685682f6
|
version: 0bdeddeeb0f650497d603c4ad7b20cfe685682f6
|
||||||
- name: golang.org/x/crypto
|
- name: golang.org/x/crypto
|
||||||
version: 7c6cc321c680f03b9ef0764448e780704f486b51
|
version: 728b753d0135da6801d45a38e6f43ff55779c5c2
|
||||||
subpackages:
|
subpackages:
|
||||||
- curve25519
|
- curve25519
|
||||||
- nacl/box
|
- nacl/box
|
||||||
@ -128,7 +128,7 @@ imports:
|
|||||||
- ripemd160
|
- ripemd160
|
||||||
- salsa20/salsa
|
- salsa20/salsa
|
||||||
- name: golang.org/x/net
|
- name: golang.org/x/net
|
||||||
version: 61557ac0112b576429a0df080e1c2cef5dfbb642
|
version: a6577fac2d73be281a500b310739095313165611
|
||||||
subpackages:
|
subpackages:
|
||||||
- context
|
- context
|
||||||
- http2
|
- http2
|
||||||
@ -138,16 +138,17 @@ imports:
|
|||||||
- lex/httplex
|
- lex/httplex
|
||||||
- trace
|
- trace
|
||||||
- name: golang.org/x/sys
|
- name: golang.org/x/sys
|
||||||
version: d75a52659825e75fff6158388dddc6a5b04f9ba5
|
version: 99f16d856c9836c42d24e7ab64ea72916925fa97
|
||||||
subpackages:
|
subpackages:
|
||||||
- unix
|
- unix
|
||||||
- name: google.golang.org/grpc
|
- name: google.golang.org/grpc
|
||||||
version: cbcceb2942a489498cf22b2f918536e819d33f0a
|
version: 0713829b980f4ddd276689a36235c5fcc82a21bf
|
||||||
subpackages:
|
subpackages:
|
||||||
- codes
|
- codes
|
||||||
- credentials
|
- credentials
|
||||||
- grpclog
|
- grpclog
|
||||||
- internal
|
- internal
|
||||||
|
- keepalive
|
||||||
- metadata
|
- metadata
|
||||||
- naming
|
- naming
|
||||||
- peer
|
- peer
|
||||||
|
|||||||
18
glide.yaml
18
glide.yaml
@ -1,22 +1,22 @@
|
|||||||
package: github.com/tendermint/basecoin
|
package: github.com/tendermint/basecoin
|
||||||
import:
|
import:
|
||||||
- package: github.com/tendermint/go-common
|
- package: github.com/tendermint/go-common
|
||||||
version: develop
|
version: master
|
||||||
- package: github.com/tendermint/go-crypto
|
- package: github.com/tendermint/go-crypto
|
||||||
version: develop
|
version: master
|
||||||
- package: github.com/tendermint/go-events
|
- package: github.com/tendermint/go-events
|
||||||
version: develop
|
version: master
|
||||||
- package: github.com/tendermint/go-logger
|
- package: github.com/tendermint/go-logger
|
||||||
version: develop
|
version: master
|
||||||
- package: github.com/tendermint/go-rpc
|
- package: github.com/tendermint/go-rpc
|
||||||
version: develop
|
version: master
|
||||||
- package: github.com/tendermint/go-wire
|
- package: github.com/tendermint/go-wire
|
||||||
version: develop
|
version: master
|
||||||
- package: github.com/tendermint/merkleeyes
|
- package: github.com/tendermint/merkleeyes
|
||||||
version: develop
|
version: master
|
||||||
- package: github.com/tendermint/tendermint
|
- package: github.com/tendermint/tendermint
|
||||||
version: develop
|
version: master
|
||||||
- package: github.com/tendermint/abci
|
- package: github.com/tendermint/abci
|
||||||
version: develop
|
version: master
|
||||||
- package: github.com/gorilla/websocket
|
- package: github.com/gorilla/websocket
|
||||||
version: v1.1.0
|
version: v1.1.0
|
||||||
|
|||||||
@ -28,12 +28,14 @@ func NewState(store types.KVStore) *State {
|
|||||||
|
|
||||||
func (s *State) SetChainID(chainID string) {
|
func (s *State) SetChainID(chainID string) {
|
||||||
s.chainID = chainID
|
s.chainID = chainID
|
||||||
|
s.store.Set([]byte("base/chain_id"), []byte(chainID))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *State) GetChainID() string {
|
func (s *State) GetChainID() string {
|
||||||
if s.chainID == "" {
|
if s.chainID != "" {
|
||||||
PanicSanity("Expected to have set SetChainID")
|
return s.chainID
|
||||||
}
|
}
|
||||||
|
s.chainID = string(s.store.Get([]byte("base/chain_id")))
|
||||||
return s.chainID
|
return s.chainID
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user