aboutsummaryrefslogtreecommitdiffstats
path: root/utils
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2014-05-14 19:55:08 +0800
committerobscuren <geffobscura@gmail.com>2014-05-14 19:55:08 +0800
commitf18ec51cb3959cc662bfc7b84314cd1d3b1541b5 (patch)
tree1c3d99407624dc791db0cb6c135bd2bd1dfc56cf /utils
parente8147cf7c6f508910698e6743ad347c78010ffe3 (diff)
downloaddexon-f18ec51cb3959cc662bfc7b84314cd1d3b1541b5.tar.gz
dexon-f18ec51cb3959cc662bfc7b84314cd1d3b1541b5.tar.zst
dexon-f18ec51cb3959cc662bfc7b84314cd1d3b1541b5.zip
Switched to new keyring methods
Diffstat (limited to 'utils')
-rw-r--r--utils/cmd.go11
-rw-r--r--utils/keys.go57
2 files changed, 60 insertions, 8 deletions
diff --git a/utils/cmd.go b/utils/cmd.go
index a99fd9eed..654014169 100644
--- a/utils/cmd.go
+++ b/utils/cmd.go
@@ -1,9 +1,7 @@
package utils
import (
- "encoding/hex"
"github.com/ethereum/eth-go"
- "github.com/ethereum/eth-go/ethchain"
"github.com/ethereum/eth-go/ethminer"
_ "github.com/ethereum/eth-go/ethrpc"
"github.com/ethereum/eth-go/ethutil"
@@ -18,13 +16,10 @@ func DoMining(ethereum *eth.Ethereum) {
// Fake block mining. It broadcasts a new block every 5 seconds
go func() {
- data, _ := ethutil.Config.Db.Get([]byte("KeyRing"))
- keyRing := ethutil.NewValueFromBytes(data)
- addr := keyRing.Get(0).Bytes()
+ keyPair := ethutil.GetKeyRing().Get(0)
+ addr := keyPair.Address()
- pair, _ := ethchain.NewKeyPairFromSec(ethutil.FromHex(hex.EncodeToString(addr)))
-
- miner := ethminer.NewDefaultMiner(pair.Address(), ethereum)
+ miner := ethminer.NewDefaultMiner(addr, ethereum)
miner.Start()
}()
diff --git a/utils/keys.go b/utils/keys.go
index 2f39c10b2..1c0f6a9d6 100644
--- a/utils/keys.go
+++ b/utils/keys.go
@@ -7,6 +7,60 @@ import (
)
func CreateKeyPair(force bool) {
+ if force {
+ ethutil.GetKeyRing().Reset()
+ fmt.Println("resetting")
+ }
+
+ if ethutil.GetKeyRing().Get(0) == nil {
+ _, prv := secp256k1.GenerateKeyPair()
+
+ keyPair, err := ethutil.GetKeyRing().NewKeyPair(prv)
+ if err != nil {
+ panic(err)
+ }
+
+ mne := ethutil.MnemonicEncode(ethutil.Hex(keyPair.PrivateKey))
+
+ fmt.Printf(`
+Generating new address and keypair.
+Please keep your keys somewhere save.
+
+++++++++++++++++ KeyRing +++++++++++++++++++
+addr: %x
+prvk: %x
+pubk: %x
+++++++++++++++++++++++++++++++++++++++++++++
+save these words so you can restore your account later: %s
+`, keyPair.Address(), keyPair.PrivateKey, keyPair.PublicKey, mne)
+ }
+}
+
+func ImportPrivateKey(sec string) {
+ ethutil.GetKeyRing().Reset()
+
+ keyPair, err := ethutil.GetKeyRing().NewKeyPair(ethutil.FromHex(sec))
+ if err != nil {
+ panic(err)
+ }
+
+ mne := ethutil.MnemonicEncode(ethutil.Hex(keyPair.PrivateKey))
+
+ fmt.Printf(`
+Generating new address and keypair.
+Please keep your keys somewhere save.
+
+++++++++++++++++ KeyRing +++++++++++++++++++
+addr: %x
+prvk: %x
+pubk: %x
+++++++++++++++++++++++++++++++++++++++++++++
+save these words so you can restore your account later: %s
+`, keyPair.Address(), keyPair.PrivateKey, keyPair.PublicKey, mne)
+}
+
+/*
+func CreateKeyPair(force bool) {
data, _ := ethutil.Config.Db.Get([]byte("KeyRing"))
if len(data) == 0 || force {
pub, prv := secp256k1.GenerateKeyPair()
@@ -28,7 +82,9 @@ save these words so you can restore your account later: %s
}
}
+*/
+/*
func ImportPrivateKey(prvKey string) {
key := ethutil.FromHex(prvKey)
msg := []byte("tmp")
@@ -49,3 +105,4 @@ pubk: %x
`, pair.Address(), key, pub)
}
+*/