mirror of
https://gitlab.com/pulsechaincom/go-pulse.git
synced 2024-12-22 19:40:36 +00:00
unlocking coinbase without knowing address
- accounts: remove Manager.getKey - cli: for -unlock coinbase, use account manager Coinbase()
This commit is contained in:
parent
4ec38e3932
commit
11d2ebc06f
@ -36,9 +36,8 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"crypto/ecdsa"
|
"crypto/ecdsa"
|
||||||
crand "crypto/rand"
|
crand "crypto/rand"
|
||||||
"os"
|
|
||||||
|
|
||||||
"errors"
|
"errors"
|
||||||
|
"os"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -101,17 +100,6 @@ func (am *Manager) firstAddr() ([]byte, error) {
|
|||||||
return addrs[0], nil
|
return addrs[0], nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (am *Manager) getKey(addr []byte, keyAuth string) (*crypto.Key, error) {
|
|
||||||
if len(addr) == 0 {
|
|
||||||
var err error
|
|
||||||
addr, err = am.firstAddr()
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return am.keyStore.GetKey(addr, keyAuth)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (am *Manager) DeleteAccount(address []byte, auth string) error {
|
func (am *Manager) DeleteAccount(address []byte, auth string) error {
|
||||||
return am.keyStore.DeleteKey(address, auth)
|
return am.keyStore.DeleteKey(address, auth)
|
||||||
}
|
}
|
||||||
@ -130,7 +118,7 @@ func (am *Manager) Sign(a Account, toSign []byte) (signature []byte, err error)
|
|||||||
// TimedUnlock unlocks the account with the given address.
|
// TimedUnlock unlocks the account with the given address.
|
||||||
// When timeout has passed, the account will be locked again.
|
// When timeout has passed, the account will be locked again.
|
||||||
func (am *Manager) TimedUnlock(addr []byte, keyAuth string, timeout time.Duration) error {
|
func (am *Manager) TimedUnlock(addr []byte, keyAuth string, timeout time.Duration) error {
|
||||||
key, err := am.getKey(addr, keyAuth)
|
key, err := am.keyStore.GetKey(addr, keyAuth)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -143,7 +131,7 @@ func (am *Manager) TimedUnlock(addr []byte, keyAuth string, timeout time.Duratio
|
|||||||
// stays unlocked until the program exits or until a TimedUnlock
|
// stays unlocked until the program exits or until a TimedUnlock
|
||||||
// timeout (started after the call to Unlock) expires.
|
// timeout (started after the call to Unlock) expires.
|
||||||
func (am *Manager) Unlock(addr []byte, keyAuth string) error {
|
func (am *Manager) Unlock(addr []byte, keyAuth string) error {
|
||||||
key, err := am.getKey(addr, keyAuth)
|
key, err := am.keyStore.GetKey(addr, keyAuth)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -294,7 +294,7 @@ func unlockAccount(ctx *cli.Context, am *accounts.Manager, account string) (pass
|
|||||||
var err error
|
var err error
|
||||||
// Load startup keys. XXX we are going to need a different format
|
// Load startup keys. XXX we are going to need a different format
|
||||||
// Attempt to unlock the account
|
// Attempt to unlock the account
|
||||||
passphrase := getPassPhrase(ctx, "", false)
|
passphrase = getPassPhrase(ctx, "", false)
|
||||||
err = am.Unlock(common.FromHex(account), passphrase)
|
err = am.Unlock(common.FromHex(account), passphrase)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
utils.Fatalf("Unlock account failed '%v'", err)
|
utils.Fatalf("Unlock account failed '%v'", err)
|
||||||
@ -310,7 +310,11 @@ func startEth(ctx *cli.Context, eth *eth.Ethereum) {
|
|||||||
account := ctx.GlobalString(utils.UnlockedAccountFlag.Name)
|
account := ctx.GlobalString(utils.UnlockedAccountFlag.Name)
|
||||||
if len(account) > 0 {
|
if len(account) > 0 {
|
||||||
if account == "coinbase" {
|
if account == "coinbase" {
|
||||||
account = ""
|
accbytes, err := am.Coinbase()
|
||||||
|
if err != nil {
|
||||||
|
utils.Fatalf("no coinbase account: %v", err)
|
||||||
|
}
|
||||||
|
account = common.ToHex(accbytes)
|
||||||
}
|
}
|
||||||
unlockAccount(ctx, am, account)
|
unlockAccount(ctx, am, account)
|
||||||
}
|
}
|
||||||
@ -420,6 +424,7 @@ func accountExport(ctx *cli.Context) {
|
|||||||
}
|
}
|
||||||
am := utils.GetAccountManager(ctx)
|
am := utils.GetAccountManager(ctx)
|
||||||
auth := unlockAccount(ctx, am, account)
|
auth := unlockAccount(ctx, am, account)
|
||||||
|
|
||||||
err := am.Export(keyfile, common.FromHex(account), auth)
|
err := am.Export(keyfile, common.FromHex(account), auth)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
utils.Fatalf("Account export failed: %v", err)
|
utils.Fatalf("Account export failed: %v", err)
|
||||||
|
Loading…
Reference in New Issue
Block a user