forked from cerc-io/laconicd-deprecated
Fix edge case for accessing accounts through rpc (#134)
* Add mutex and close keybase database correctly after use * Add options http request to rpc API for remix
This commit is contained in:
parent
c130105b86
commit
9294fa8423
@ -74,7 +74,7 @@ func registerRoutes(rs *lcd.RestServer) {
|
||||
}
|
||||
}
|
||||
|
||||
rs.Mux.HandleFunc("/rpc", s.ServeHTTP).Methods("POST")
|
||||
rs.Mux.HandleFunc("/", s.ServeHTTP).Methods("POST", "OPTIONS")
|
||||
}
|
||||
|
||||
func unlockKeyFromNameAndPassphrase(accountName, passphrase string) (emintKey emintcrypto.PrivKeySecp256k1, err error) {
|
||||
|
@ -6,6 +6,7 @@ import (
|
||||
"log"
|
||||
"math/big"
|
||||
"strconv"
|
||||
"sync"
|
||||
|
||||
emintcrypto "github.com/cosmos/ethermint/crypto"
|
||||
emintkeys "github.com/cosmos/ethermint/keys"
|
||||
@ -40,6 +41,7 @@ type PublicEthAPI struct {
|
||||
cliCtx context.CLIContext
|
||||
key emintcrypto.PrivKeySecp256k1
|
||||
nonceLock *AddrLocker
|
||||
keybaseLock sync.Mutex
|
||||
gasLimit *int64
|
||||
}
|
||||
|
||||
@ -103,6 +105,8 @@ func (e *PublicEthAPI) GasPrice() *hexutil.Big {
|
||||
|
||||
// Accounts returns the list of accounts available to this node.
|
||||
func (e *PublicEthAPI) Accounts() ([]common.Address, error) {
|
||||
e.keybaseLock.Lock()
|
||||
|
||||
addresses := make([]common.Address, 0) // return [] instead of nil if empty
|
||||
keybase, err := emintkeys.NewKeyBaseFromHomeFlag()
|
||||
if err != nil {
|
||||
@ -114,6 +118,9 @@ func (e *PublicEthAPI) Accounts() ([]common.Address, error) {
|
||||
return addresses, err
|
||||
}
|
||||
|
||||
keybase.CloseDB()
|
||||
e.keybaseLock.Unlock()
|
||||
|
||||
for _, info := range infos {
|
||||
addressBytes := info.GetPubKey().Address().Bytes()
|
||||
addresses = append(addresses, common.BytesToAddress(addressBytes))
|
||||
|
@ -27,7 +27,7 @@ const (
|
||||
addrAStoreKey = 0
|
||||
)
|
||||
|
||||
var addr = fmt.Sprintf("http://%s:%d/rpc", host, port)
|
||||
var addr = fmt.Sprintf("http://%s:%d", host, port)
|
||||
|
||||
type Request struct {
|
||||
Version string `json:"jsonrpc"`
|
||||
|
Loading…
Reference in New Issue
Block a user