laconicd-deprecated/rpc/config.go
Federico Kunze 4d609b2a22
bump Cosmos SDK version to v0.38.2 (#183)
* evm: move Keeper and Querier to /keeper package

* keeper: update keeper_test.go

* fix format

* evm: use aliased types

* bump SDK version to v0.38.1

* app: updates from new version

* errors: switch sdk.Error -> error

* errors: switch sdk.Error -> error. Continuation

* more fixes

* update app/

* update keys and client pkgs

* build

* fix tests

* lint

* minor changes

* changelog

* address @austinbell comments

* Fix keyring usage in rpc API and CLI

* fix keyring

* break line

* Misc cleanup (#188)

* evm: move Begin and EndBlock to abci.go

* evm: use expected keeper interfaces

* app: use EthermintApp for integration and unit test setup

* evm: remove count type; update codec

* go mod verify

* evm: rename msgs for consistency

* evm: events

* minor cleanup

* lint

* ante: update tests

* changelog

* nolint

* evm: update statedb to create ethermint Account instead of BaseAccount

* fix importer test

* address @austinabell comments

* update README

* changelog

* evm: update codec

* fix event sender

* store logs in keeper after transition (#210)

* add some comments

* begin log handler test

* update TransitionCSDB to return ReturnData

* use rlp for result data encode/decode

* update tests

* implement SetBlockLogs

* implement GetBlockLogs

* test log set/get

* update keeper get/set logs to use hash as key

* fix test

* move logsKey to csdb

* attempt to fix test

* attempt to fix test

* attempt to fix test

* lint

* lint

* lint

* save logs after handling msg

* update k.Logs

* cleanup

* remove unused

* fix issues

* comment out handler test

* address comments

* lint

* fix handler test

* address comments

* use amino

* lint

* address comments

* merge

* fix encoding bug

* minor fix

* rpc: error handling

* rpc: simulate only returns gasConsumed

* rpc: error ineffassign

* go: bump version to 1.14 and SDK version to latest master

* rpc: fix simulation return value

* breaking changes from SDK

* sdk: breaking changes; build

* tests: fixes

* minor fix

* proto: ethermint types attempt

* proto: define EthAccount proto type and extend sdk std.Codec

* evm: fix panic on handler test

* evm: minor state object changes

* cleanup

* tests: update test-importer

* fix pubkey registration

* lint

* cleanup

* more test checks for importer

* minor change

* codec fixes

* rm init func

* fix importer test build

* fix marshaling for TxDecoder

* use amino codec for evm

* fix marshaling for SimulationResponse

* use jsonpb for unmarshaling

* fix method handler crashed

* return err on VerifySig

* switch stateObject balance to sdk.Int

* fixes to codec and encoding

* cleanup

* set tmhash -> ethhash in state transition

* add tmhash->ethereumhash to csdb.GetLogs

* attempt to  fix tests

* update GetLogs to switch with Has

* ante panic

* diff changes

* update SetLogs

* evm/cli: use ethermint codec

* use LengthPrefixed for encoding

* add check for nil *big.Int

* add balance to UpdateAccounts

* fix previous balance

* fix balance bug

* prevent panic on make test-import

Co-authored-by: austinabell <austinabell8@gmail.com>
Co-authored-by: noot <36753753+noot@users.noreply.github.com>
Co-authored-by: noot <elizabethjbinks@gmail.com>
2020-04-22 15:26:01 -04:00

132 lines
3.7 KiB
Go

package rpc
import (
"bufio"
"fmt"
"os"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/client/input"
"github.com/cosmos/cosmos-sdk/client/lcd"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/crypto/keyring"
sdk "github.com/cosmos/cosmos-sdk/types"
authrest "github.com/cosmos/cosmos-sdk/x/auth/client/rest"
"github.com/cosmos/ethermint/app"
emintcrypto "github.com/cosmos/ethermint/crypto"
"github.com/ethereum/go-ethereum/rpc"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)
const (
flagUnlockKey = "unlock-key"
)
// Config contains configuration fields that determine the behavior of the RPC HTTP server.
// TODO: These may become irrelevant if HTTP config is handled by the SDK
type Config struct {
// EnableRPC defines whether or not to enable the RPC server
EnableRPC bool
// RPCAddr defines the IP address to listen on
RPCAddr string
// RPCPort defines the port to listen on
RPCPort int
// RPCCORSDomains defines list of domains to enable CORS headers for (used by browsers)
RPCCORSDomains []string
// RPCVhosts defines list of domains to listen on (useful if Tendermint is addressable via DNS)
RPCVHosts []string
}
// EmintServeCmd creates a CLI command to start Cosmos REST server with web3 RPC API and
// Cosmos rest-server endpoints
func EmintServeCmd(cdc *codec.Codec) *cobra.Command {
cmd := lcd.ServeCommand(cdc, registerRoutes)
cmd.Flags().String(flagUnlockKey, "", "Select a key to unlock on the RPC server")
cmd.Flags().StringP(flags.FlagBroadcastMode, "b", flags.BroadcastSync, "Transaction broadcasting mode (sync|async|block)")
return cmd
}
// registerRoutes creates a new server and registers the `/rpc` endpoint.
// Rpc calls are enabled based on their associated module (eg. "eth").
func registerRoutes(rs *lcd.RestServer) {
s := rpc.NewServer()
accountName := viper.GetString(flagUnlockKey)
var emintKey emintcrypto.PrivKeySecp256k1
if len(accountName) > 0 {
var err error
inBuf := bufio.NewReader(os.Stdin)
keyringBackend := viper.GetString(flags.FlagKeyringBackend)
passphrase := ""
switch keyringBackend {
case keyring.BackendOS:
break
case keyring.BackendFile:
passphrase, err = input.GetPassword(
"Enter password to unlock key for RPC API: ",
inBuf)
if err != nil {
panic(err)
}
}
emintKey, err = unlockKeyFromNameAndPassphrase(accountName, passphrase)
if err != nil {
panic(err)
}
}
apis := GetRPCAPIs(rs.CliCtx, emintKey)
// TODO: Allow cli to configure modules https://github.com/ChainSafe/ethermint/issues/74
whitelist := make(map[string]bool)
// Register all the APIs exposed by the services
for _, api := range apis {
if whitelist[api.Namespace] || (len(whitelist) == 0 && api.Public) {
if err := s.RegisterName(api.Namespace, api.Service); err != nil {
panic(err)
}
}
}
// Web3 RPC API route
rs.Mux.HandleFunc("/", s.ServeHTTP).Methods("POST", "OPTIONS")
// Register all other Cosmos routes
client.RegisterRoutes(rs.CliCtx, rs.Mux)
authrest.RegisterTxRoutes(rs.CliCtx, rs.Mux)
app.ModuleBasics.RegisterRESTRoutes(rs.CliCtx, rs.Mux)
}
func unlockKeyFromNameAndPassphrase(accountName, passphrase string) (emintKey emintcrypto.PrivKeySecp256k1, err error) {
keybase, err := keyring.NewKeyring(
sdk.KeyringServiceName(),
viper.GetString(flags.FlagKeyringBackend),
viper.GetString(flags.FlagHome),
os.Stdin,
)
if err != nil {
return
}
// With keyring keybase, password is not required as it is pulled from the OS prompt
privKey, err := keybase.ExportPrivateKeyObject(accountName, passphrase)
if err != nil {
return
}
var ok bool
emintKey, ok = privKey.(emintcrypto.PrivKeySecp256k1)
if !ok {
panic(fmt.Sprintf("invalid private key type: %T", privKey))
}
return
}