Skip to content
This repository has been archived by the owner on Apr 4, 2024. It is now read-only.

Commit

Permalink
Cosmos PR changes (#158)
Browse files Browse the repository at this point in the history
* Changes necessary for enforced custom account encoding/decoding and keyring keybase changes

* updates cosmos dependency and fixes inconsistency in gas usage for simulated/real txs

* Update PR changes

* Remove unused password prompt when using OS keyring

* Update from changes to sdk

* Update to merged PR commit :the_horns:

* updated code to handle keyring backend options

* update documentation and replace cosmos-sdk with fork (temporarily)

* update cosmos dependency from fork

* update documentation
  • Loading branch information
austinabell authored Dec 13, 2019
1 parent c2646c7 commit ce8a94a
Show file tree
Hide file tree
Showing 13 changed files with 341 additions and 75 deletions.
101 changes: 93 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,29 +18,114 @@ __**WARNING:**__ Ethermint is under VERY ACTIVE DEVELOPMENT and should be treate

- Have a working implementation that can parse and validate the existing ETH Chain and persist it in a Tendermint store
- Implement Ethereum transactions in the CosmosSDK
- Implement web3 compatible API layer
- Implement the EVM as a CosmosSDK module
- Allow the Ethermint EVM to interact with other Cosmos SDK modules

#### Current Work

- Implement web3 compatible API layer
- Implement the EVM as a CosmosSDK module
- Allow the Ethermint EVM to interact with other [Cosmos SDK modules](https://github.com/cosmos/cosmos-sdk/blob/master/docs/core/app3.md)
- Ethermint is a functioning Cosmos SDK application and can be deployed as its own zone
- Full web3 compatibility to enable existing Ethereum applications to use Ethermint

#### Next Steps

- Hard spoon enablement: The ability to export state from `geth` and import token balances into Ethermint
- Ethermint is a functioning Cosmos SDK application and can be deployed as its own zone
- Full web3 compatibility will enable existing Ethereum applications to use Ethermint

### Building Ethermint

To build, execute the following commands:

```bash
# To build the project and install it in $GOBIN
$ make install

# To build the binary and put the resulting binary in ./build
$ make tools verify build
$ make build
```

# To build the project and install it in $GOBIN
$ make tools verify install
### Starting a Ethermint daemon (node)

First, create a key to use in signing the genesis transaction:

```bash
emintcli keys add mykey
```
> replace mykey with whatever you want to name the key
Then, run these commands to start up a node
```bash
# Set moniker and chain-id for Ethermint (Moniker can be anything, chain-id must be an integer)
emintd init mymoniker --chain-id 8

# Set up config for CLI
emintcli config chain-id 8
emintcli config output json
emintcli config indent true
emintcli config trust-node true

# Allocate genesis accounts (cosmos formatted addresses)
emintd add-genesis-account $(emintcli keys show mykey -a) 1000000000000000000photon,1000000000000000000stake

# Sign genesis transaction
emintd gentx --name mykey

# Collect genesis tx
emintd collect-gentxs

# Run this to ensure everything worked and that the genesis file is setup correctly
emintd validate-genesis

# Start the node (remove the --pruning=nothing flag if historical queries are not needed)
emintd start --pruning=nothing
```
> Note: If you used `make build` instead of make install, and replace all `emintcli` and `emintd` references to `./build/emintcli` and `./build/emintd` respectively
### Starting Ethermint Web3 RPC API

After the daemon is started, run (in another process):

```bash
emintcli rest-server --laddr "tcp://localhost:8545" --unlock-key mykey
```

and to make sure the server has started correctly, try querying the current block number:

```
curl -X POST --data '{"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":1}' -H "Content-Type: application/json" http://localhost:8545
```

or point any dev tooling at `http://localhost:8545` or whatever port is chosen just as you would with an Ethereum node

#### Clearing data from chain

Data for the CLI and Daemon should be stored at `~/.emintd` and `~/.emintcli` by default, to start the node with a fresh state, run:

```bash
rm -rf ~/.emint*
```

To clear all data except key storage (if keyring backend chosen) and then you can rerun the commands to start the node again.

#### Keyring backend options

Ethermint supports using a file or OS keyring backend for key storage. To create and use a file stored key instead of defaulting to the OS keyring, add the flag `--keyring-backend file` to any relevant command and the password prompt will occur through the command line. This can also be saved as a CLI config option with:

```bash
emintcli config keyring-backend file
```

### Exporting Ethereum private key from Ethermint

To export the private key from Ethermint to something like Metamask, run:

```bash
emintcli keys export-eth-key mykey
```

Import account through private key, and to verify that the Ethereum address is correct with:

```bash
emintcli keys parse $(emintcli keys show mykey -a)
```

### Tests
Expand Down
6 changes: 3 additions & 3 deletions app/ethermint.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,10 +190,10 @@ func NewEthermintApp(
bank.NewAppModule(app.bankKeeper, app.accountKeeper),
crisis.NewAppModule(&app.crisisKeeper),
supply.NewAppModule(app.supplyKeeper, app.accountKeeper),
distr.NewAppModule(app.distrKeeper, app.supplyKeeper),
gov.NewAppModule(app.govKeeper, app.supplyKeeper),
distr.NewAppModule(app.distrKeeper, app.accountKeeper, app.supplyKeeper, app.stakingKeeper),
gov.NewAppModule(app.govKeeper, app.accountKeeper, app.supplyKeeper),
mint.NewAppModule(app.mintKeeper),
slashing.NewAppModule(app.slashingKeeper, app.stakingKeeper),
slashing.NewAppModule(app.slashingKeeper, app.accountKeeper, app.stakingKeeper),
staking.NewAppModule(app.stakingKeeper, app.accountKeeper, app.supplyKeeper),
evm.NewAppModule(app.evmKeeper),
)
Expand Down
13 changes: 7 additions & 6 deletions client/genaccounts/main.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package genaccounts

import (
"bufio"
"errors"
"fmt"

Expand Down Expand Up @@ -42,14 +43,15 @@ the address will be looked up in the local Keybase. The list of initial tokens m
contain valid denominations. Accounts may optionally be supplied with vesting parameters.
`,
Args: cobra.ExactArgs(2),
RunE: func(_ *cobra.Command, args []string) error {
RunE: func(cmd *cobra.Command, args []string) error {
config := ctx.Config
config.SetRoot(viper.GetString(cli.HomeFlag))

addr, err := sdk.AccAddressFromBech32(args[0])
inBuf := bufio.NewReader(cmd.InOrStdin())
if err != nil {
// attempt to lookup address from Keybase if no address was provided
kb, err := keys.NewKeyBaseFromDir(viper.GetString(flagClientHome))
kb, err := keys.NewKeyringFromDir(viper.GetString(flagClientHome), inBuf)
if err != nil {
return err
}
Expand Down Expand Up @@ -77,9 +79,9 @@ contain valid denominations. Accounts may optionally be supplied with vesting pa
// create concrete account type based on input parameters
var genAccount authexported.GenesisAccount

baseAcc := auth.NewBaseAccount(addr, coins.Sort(), nil, 0, 0)
baseAccount := auth.NewBaseAccount(addr, coins.Sort(), nil, 0, 0)
if !vestingAmt.IsZero() {
baseVestingAccount, err := authvesting.NewBaseVestingAccount(baseAcc, vestingAmt.Sort(), vestingEnd)
baseVestingAccount, err := authvesting.NewBaseVestingAccount(baseAccount, vestingAmt.Sort(), vestingEnd)
if err != nil {
return fmt.Errorf("failed to create base vesting account: %w", err)
}
Expand All @@ -95,8 +97,7 @@ contain valid denominations. Accounts may optionally be supplied with vesting pa
return errors.New("invalid vesting parameters; must supply start and end time or end time")
}
} else {
// Genesis account is created with Ethermint account type
genAccount = &ethermint.Account{BaseAccount: baseAcc}
genAccount = ethermint.Account{BaseAccount: baseAccount}
}

if err := genAccount.Validate(); err != nil {
Expand Down
23 changes: 17 additions & 6 deletions cmd/emintcli/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ import (
"strings"

"github.com/spf13/cobra"
"github.com/spf13/viper"

"github.com/ethereum/go-ethereum/common/hexutil"
ethcrypto "github.com/ethereum/go-ethereum/crypto"

"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/client/input"
clientkeys "github.com/cosmos/cosmos-sdk/client/keys"
emintcrypto "github.com/cosmos/ethermint/crypto"
Expand All @@ -27,17 +29,26 @@ func exportEthKeyCommand() *cobra.Command {
}

func runExportCmd(cmd *cobra.Command, args []string) error {
kb, err := clientkeys.NewKeyBaseFromHomeFlag()
kb, err := clientkeys.NewKeyringFromHomeFlag(cmd.InOrStdin())
if err != nil {
return err
}

// Get password from input or standard input
buf := bufio.NewReader(cmd.InOrStdin())
decryptPassword, err := input.GetPassword(
"**WARNING this is an unsafe way to export your unencrypted private key**\nEnter key password:",
buf)
if err != nil {
decryptPassword := ""
conf := true
keyringBackend := viper.GetString(flags.FlagKeyringBackend)
switch keyringBackend {
case flags.KeyringBackendFile:
decryptPassword, err = input.GetPassword(
"**WARNING this is an unsafe way to export your unencrypted private key**\nEnter key password:",
buf)
case flags.KeyringBackendOS:
conf, err = input.GetConfirmation(
"**WARNING** this is an unsafe way to export your unencrypted private key, are you sure?",
buf)
}
if err != nil || !conf {
return err
}

Expand Down
12 changes: 8 additions & 4 deletions cmd/emintcli/keys.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package main

import (
"bufio"
"io"

"github.com/cosmos/cosmos-sdk/client/flags"
clientkeys "github.com/cosmos/cosmos-sdk/client/keys"
"github.com/cosmos/cosmos-sdk/crypto/keys"
Expand Down Expand Up @@ -48,21 +51,22 @@ func keyCommands() *cobra.Command {
return cmd
}

func getKeybase(dryrun bool) (keys.Keybase, error) {
func getKeybase(cmd *cobra.Command, dryrun bool, buf io.Reader) (keys.Keybase, error) {
if dryrun {
return keys.NewInMemory(keys.WithKeygenFunc(ethermintKeygenFunc)), nil
}

return clientkeys.NewKeyBaseFromHomeFlag(keys.WithKeygenFunc(ethermintKeygenFunc))
return clientkeys.NewKeyringFromHomeFlag(buf, keys.WithKeygenFunc(ethermintKeygenFunc))
}

func runAddCmd(cmd *cobra.Command, args []string) error {
kb, err := getKeybase(viper.GetBool(flagDryRun))
inBuf := bufio.NewReader(cmd.InOrStdin())
kb, err := getKeybase(cmd, viper.GetBool(flagDryRun), inBuf)
if err != nil {
return err
}

return clientkeys.RunAddCmd(cmd, args, kb)
return clientkeys.RunAddCmd(cmd, args, kb, inBuf)
}

func ethermintKeygenFunc(bz [32]byte) tmcrypto.PrivKey {
Expand Down
22 changes: 8 additions & 14 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ require (
github.com/aristanetworks/goarista v0.0.0-20181101003910-5bb443fba8e0 // indirect
github.com/btcsuite/btcd v0.0.0-20190629003639-c26ffa870fd8 // indirect
github.com/cespare/cp v1.1.1 // indirect
github.com/cosmos/cosmos-sdk v0.34.4-0.20191031200835-02c6c9fafd58
github.com/cosmos/cosmos-sdk v0.34.4-0.20191213112149-d7b0f4b9b4fb
github.com/cosmos/go-bip39 v0.0.0-20180819234021-555e2067c45d // indirect
github.com/deckarep/golang-set v1.7.1 // indirect
github.com/edsrzf/mmap-go v0.0.0-20170320065105-0bce6a688712 // indirect
Expand All @@ -16,17 +16,16 @@ require (
github.com/fjl/memsize v0.0.0-20190710130421-bcb5799ab5e5 // indirect
github.com/gballet/go-libpcsclite v0.0.0-20190607065134-2772fd86a8ff // indirect
github.com/golang/mock v1.3.1 // indirect
github.com/google/uuid v1.0.0 // indirect
github.com/gorilla/mux v1.7.3
github.com/huin/goupnp v1.0.0 // indirect
github.com/jackpal/go-nat-pmp v1.0.1 // indirect
github.com/karalabe/usb v0.0.0-20190703133951-9be757f914c0 // indirect
github.com/mattn/go-colorable v0.1.4 // indirect
github.com/mattn/go-runewidth v0.0.4 // indirect
github.com/olekukonko/tablewriter v0.0.1 // indirect
github.com/onsi/ginkgo v1.10.1 // indirect
github.com/onsi/gomega v1.7.0 // indirect
github.com/pborman/uuid v0.0.0-20180906182336-adf5a7427709 // indirect
github.com/onsi/ginkgo v1.10.3 // indirect
github.com/onsi/gomega v1.7.1 // indirect
github.com/pborman/uuid v1.2.0 // indirect
github.com/pkg/errors v0.8.1
github.com/prometheus/common v0.6.0 // indirect
github.com/prometheus/procfs v0.0.3 // indirect
Expand All @@ -35,28 +34,23 @@ require (
github.com/rjeczalik/notify v0.9.2 // indirect
github.com/spf13/afero v1.2.2 // indirect
github.com/spf13/cobra v0.0.5
github.com/spf13/viper v1.5.0
github.com/spf13/viper v1.6.1
github.com/status-im/keycard-go v0.0.0-20190424133014-d95853db0f48 // indirect
github.com/steakknife/bloomfilter v0.0.0-20180922174646-6819c0d2a570 // indirect
github.com/steakknife/hamming v0.0.0-20180906055917-c99c65617cd3 // indirect
github.com/stretchr/testify v1.4.0
github.com/tendermint/crypto v0.0.0-20191022145703-50d29ede1e15
github.com/tendermint/go-amino v0.15.1
github.com/tendermint/tendermint v0.32.7
github.com/tendermint/tendermint v0.32.8
github.com/tendermint/tm-db v0.2.0
github.com/tyler-smith/go-bip39 v1.0.0 // indirect
github.com/wsddn/go-ecdh v0.0.0-20161211032359-48726bab9208 // indirect
golang.org/x/crypto v0.0.0-20190923035154-9ee001bba392
golang.org/x/net v0.0.0-20190923162816-aa69164e4478 // indirect
golang.org/x/sys v0.0.0-20191010194322-b09406accb47 // indirect
golang.org/x/sys v0.0.0-20191210023423-ac6580df4449 // indirect
golang.org/x/text v0.3.2 // indirect
google.golang.org/genproto v0.0.0-20190708153700-3bdd9d9f5532 // indirect
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect
gopkg.in/natefinch/npipe.v2 v2.0.0-20160621034901-c1b8fa8bdcce // indirect
gopkg.in/urfave/cli.v1 v1.20.0 // indirect
)

replace (
github.com/cosmos/cosmos-sdk v0.34.4-0.20191031200835-02c6c9fafd58 => github.com/chainsafe/cosmos-sdk v0.34.4-0.20191105182341-b5e2a1dfdcf6
github.com/tendermint/tendermint v0.32.7 => github.com/chainsafe/tendermint v0.32.2-0.20191105211315-bd56da568e15
gopkg.in/yaml.v2 v2.2.7
)
Loading

0 comments on commit ce8a94a

Please sign in to comment.