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"
|
||||
@ -37,10 +38,11 @@ import (
|
||||
|
||||
// PublicEthAPI is the eth_ prefixed set of APIs in the Web3 JSON-RPC spec.
|
||||
type PublicEthAPI struct {
|
||||
cliCtx context.CLIContext
|
||||
key emintcrypto.PrivKeySecp256k1
|
||||
nonceLock *AddrLocker
|
||||
gasLimit *int64
|
||||
cliCtx context.CLIContext
|
||||
key emintcrypto.PrivKeySecp256k1
|
||||
nonceLock *AddrLocker
|
||||
keybaseLock sync.Mutex
|
||||
gasLimit *int64
|
||||
}
|
||||
|
||||
// NewPublicEthAPI creates an instance of the public ETH Web3 API.
|
||||
@ -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))
|
||||
|
@ -77,4 +77,4 @@ func returnLogs(logs []*ethtypes.Log) []*ethtypes.Log {
|
||||
return []*ethtypes.Log{}
|
||||
}
|
||||
return logs
|
||||
}
|
||||
}
|
||||
|
@ -17,7 +17,7 @@ type Filter struct {
|
||||
addresses []common.Address
|
||||
topics [][]common.Hash
|
||||
|
||||
block common.Hash // Block hash if filtering a single block
|
||||
block common.Hash // Block hash if filtering a single block
|
||||
}
|
||||
|
||||
// NewBlockFilter creates a new filter which directly inspects the contents of
|
||||
|
@ -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