Skip to content

Commit

Permalink
Merge branch 'master' into am/protobuf-since
Browse files Browse the repository at this point in the history
  • Loading branch information
amaury1093 committed Oct 26, 2021
2 parents f74fd81 + e01fa1a commit 42d543e
Show file tree
Hide file tree
Showing 16 changed files with 212 additions and 17 deletions.
5 changes: 3 additions & 2 deletions client/keys/add_ledger_test.go
@@ -1,4 +1,5 @@
//+build ledger test_ledger_mock
//go:build ledger || test_ledger_mock
// +build ledger test_ledger_mock

package keys

Expand Down Expand Up @@ -194,7 +195,7 @@ func Test_runAddCmdLedgerDryRun(t *testing.T) {
} else {
_, err = kb.Key("testkey")
require.Error(t, err)
require.Equal(t, "testkey: key not found", err.Error())
require.Equal(t, "testkey.info: key not found", err.Error())
}
})
}
Expand Down
3 changes: 1 addition & 2 deletions client/keys/add_test.go
Expand Up @@ -8,7 +8,6 @@ import (
"testing"

"github.com/stretchr/testify/require"

"github.com/tendermint/tendermint/libs/cli"

"github.com/cosmos/cosmos-sdk/client"
Expand Down Expand Up @@ -226,7 +225,7 @@ func Test_runAddCmdDryRun(t *testing.T) {
} else {
_, err = kb.Key("testkey")
require.Error(t, err)
require.Equal(t, "testkey: key not found", err.Error())
require.Equal(t, "testkey.info: key not found", err.Error())
}
})
}
Expand Down
4 changes: 2 additions & 2 deletions client/keys/delete.go
Expand Up @@ -3,11 +3,11 @@ package keys
import (
"bufio"

"github.com/spf13/cobra"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/input"
"github.com/cosmos/cosmos-sdk/crypto/keyring"

"github.com/spf13/cobra"
)

const (
Expand Down
2 changes: 1 addition & 1 deletion client/keys/delete_test.go
Expand Up @@ -53,7 +53,7 @@ func Test_runDeleteCmd(t *testing.T) {

err = cmd.ExecuteContext(ctx)
require.Error(t, err)
require.EqualError(t, err, "blah: key not found")
require.EqualError(t, err, "blah.info: key not found")

// User confirmation missing
cmd.SetArgs([]string{
Expand Down
3 changes: 2 additions & 1 deletion client/keys/rename.go
Expand Up @@ -4,10 +4,11 @@ import (
"bufio"
"fmt"

"github.com/spf13/cobra"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/input"
"github.com/cosmos/cosmos-sdk/crypto/keyring"
"github.com/spf13/cobra"
)

// RenameKeyCommand renames a key from the key store.
Expand Down
2 changes: 1 addition & 1 deletion client/keys/rename_test.go
Expand Up @@ -49,7 +49,7 @@ func Test_runRenameCmd(t *testing.T) {
cmd.SetArgs([]string{"blah", "blaah", fmt.Sprintf("--%s=%s", flags.FlagHome, kbHome)})
err = cmd.ExecuteContext(ctx)
require.Error(t, err)
require.EqualError(t, err, "blah: key not found")
require.EqualError(t, err, "blah.info: key not found")

// User confirmation missing
cmd.SetArgs([]string{
Expand Down
11 changes: 8 additions & 3 deletions crypto/keyring/keyring.go
Expand Up @@ -11,7 +11,6 @@ import (
"strings"

"github.com/99designs/keyring"
"github.com/cosmos/go-bip39"
"github.com/pkg/errors"
"github.com/tendermint/crypto/bcrypt"
tmcrypto "github.com/tendermint/tendermint/crypto"
Expand All @@ -24,6 +23,7 @@ import (
"github.com/cosmos/cosmos-sdk/crypto/types"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/cosmos/go-bip39"
)

// Backend options for Keyring
Expand Down Expand Up @@ -440,6 +440,8 @@ func (ks keystore) Rename(oldName, newName string) error {
return nil
}

// Delete deletes a key in the keyring. `uid` represents the key name, without
// the `.info` suffix.
func (ks keystore) Delete(uid string) error {
k, err := ks.Key(uid)
if err != nil {
Expand All @@ -456,7 +458,7 @@ func (ks keystore) Delete(uid string) error {
return err
}

err = ks.db.Remove(uid)
err = ks.db.Remove(infoKey(uid))
if err != nil {
return err
}
Expand Down Expand Up @@ -770,7 +772,7 @@ func (ks keystore) writeRecord(k *Record) error {
return err
}

key := k.Name
key := infoKey(k.Name)

exists, err := ks.existsInDb(addr, key)
if err != nil {
Expand Down Expand Up @@ -877,6 +879,9 @@ func (ks keystore) MigrateAll() (bool, error) {

// migrate converts keyring.Item from amino to proto serialization format.
func (ks keystore) migrate(key string) (*Record, bool, error) {
if !(strings.HasSuffix(key, infoSuffix)) && !(strings.HasPrefix(key, sdk.Bech32PrefixAccAddr)) {
key = infoKey(key)
}
item, err := ks.db.Get(key)
if err != nil {
return nil, false, wrapKeyNotFound(err, key)
Expand Down
4 changes: 2 additions & 2 deletions crypto/keyring/keyring_test.go
Expand Up @@ -7,7 +7,7 @@ import (
"testing"

"github.com/99designs/keyring"
bip39 "github.com/cosmos/go-bip39"
"github.com/cosmos/go-bip39"
"github.com/stretchr/testify/require"

"github.com/cosmos/cosmos-sdk/codec"
Expand Down Expand Up @@ -432,7 +432,7 @@ func TestKeyringKeybaseExportImportPrivKey(t *testing.T) {

// try export non existing key
_, err = kb.ExportPrivKeyArmor("john3", "wrongpassword")
require.EqualError(t, err, "john3: key not found")
require.EqualError(t, err, "john3.info: key not found")
}

func TestInMemoryLanguage(t *testing.T) {
Expand Down
2 changes: 2 additions & 0 deletions crypto/keyring/legacy_info.go
Expand Up @@ -43,6 +43,8 @@ type legacyLocalInfo struct {
Algo hd.PubKeyType `json:"algo"`
}

func infoKey(name string) string { return fmt.Sprintf("%s.%s", name, infoSuffix) }

// GetType implements Info interface
func (i legacyLocalInfo) GetType() KeyType {
return TypeLocal
Expand Down
1 change: 1 addition & 0 deletions crypto/keyring/types.go
Expand Up @@ -37,6 +37,7 @@ const (
// bits of entropy to draw when creating a mnemonic
defaultEntropySize = 256
addressSuffix = "address"
infoSuffix = "info"
)

// KeyType reflects a human-readable type for key listing.
Expand Down
2 changes: 2 additions & 0 deletions docs/migrations/chain-upgrade-guide-044.md
Expand Up @@ -18,6 +18,8 @@ You must upgrade to Stargate v0.42 before upgrading to v0.44. If you have not do

Cosmos SDK v0.44 introduces a new way of handling chain upgrades that no longer requires exporting state to JSON, making the necesssary changes, and then creating a new chain with the modified JSON as the new genesis file.

The IBC module for the Cosmos SDK has moved to its [own repository](https://github.com/cosmos/ibc-go) for v0.42 and later versions. If you are using IBC, make sure to also go through the [IBC migration docs](https://github.com/cosmos/ibc-go/blob/main/docs/migrations/ibc-migration-043.md).

Instead of starting a new chain, the upgrade binary will read the existing database and perform in-place store migrations. This new way of handling chain upgrades can be used alongside [Cosmovisor](../run-node/cosmovisor.html) to make the upgrade process seamless.

## In-Place Store Migrations
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Expand Up @@ -7,7 +7,7 @@ require (
github.com/armon/go-metrics v0.3.10
github.com/bgentry/speakeasy v0.1.0
github.com/btcsuite/btcd v0.22.0-beta
github.com/coinbase/rosetta-sdk-go v0.6.10
github.com/coinbase/rosetta-sdk-go v0.7.0
github.com/confio/ics23/go v0.6.6
github.com/cosmos/btcutil v1.0.4
github.com/cosmos/cosmos-proto v0.0.0-20210914142853-23ed61ac79ce
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Expand Up @@ -165,6 +165,8 @@ github.com/cockroachdb/datadriven v0.0.0-20190809214429-80d97fb3cbaa/go.mod h1:z
github.com/codahale/hdrhistogram v0.0.0-20161010025455-3a0bb77429bd/go.mod h1:sE/e/2PUdi/liOCUjSTXgM1o87ZssimdTWN964YiIeI=
github.com/coinbase/rosetta-sdk-go v0.6.10 h1:rgHD/nHjxLh0lMEdfGDqpTtlvtSBwULqrrZ2qPdNaCM=
github.com/coinbase/rosetta-sdk-go v0.6.10/go.mod h1:J/JFMsfcePrjJZkwQFLh+hJErkAmdm9Iyy3D5Y0LfXo=
github.com/coinbase/rosetta-sdk-go v0.7.0 h1:lmTO/JEpCvZgpbkOITL95rA80CPKb5CtMzLaqF2mCNg=
github.com/coinbase/rosetta-sdk-go v0.7.0/go.mod h1:7nD3oBPIiHqhRprqvMgPoGxe/nyq3yftRmpsy29coWE=
github.com/confio/ics23/go v0.0.0-20200817220745-f173e6211efb/go.mod h1:E45NqnlpxGnpfTWL/xauN7MRwEE28T4Dd4uraToOaKg=
github.com/confio/ics23/go v0.6.3/go.mod h1:E45NqnlpxGnpfTWL/xauN7MRwEE28T4Dd4uraToOaKg=
github.com/confio/ics23/go v0.6.6 h1:pkOy18YxxJ/r0XFDCnrl4Bjv6h4LkBSpLS6F38mrKL8=
Expand Down
3 changes: 1 addition & 2 deletions server/init.go
Expand Up @@ -3,9 +3,8 @@ package server
import (
"fmt"

"github.com/cosmos/cosmos-sdk/crypto/keyring"

"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/crypto/keyring"
sdk "github.com/cosmos/cosmos-sdk/types"
)

Expand Down
1 change: 1 addition & 0 deletions server/rosetta/lib/server/server.go
Expand Up @@ -49,6 +49,7 @@ func NewServer(settings Settings) (Server, error) {
[]*types.NetworkIdentifier{settings.Network},
nil,
false,
"",
)
if err != nil {
return Server{}, fmt.Errorf("cannot build asserter: %w", err)
Expand Down
182 changes: 182 additions & 0 deletions x/evidence/spec/07_client.md
@@ -0,0 +1,182 @@
# Client

## CLI

A user can query and interact with the `evidence` module using the CLI.

### Query

The `query` commands allows users to query `evidence` state.

```bash
simd query evidence --help
```
### evidence

The `evidence` command allows users to list all evidence or evidence by hash.

Usage:

```bash
simd query evidence [flags]
```
To query evidence by hash

Example:

```bash
simd query evidence "DF0C23E8634E480F84B9D5674A7CDC9816466DEC28A3358F73260F68D28D7660"
```

Example Output:

```bash
evidence:
consensus_address: cosmosvalcons1ntk8eualewuprz0gamh8hnvcem2nrcdsgz563h
height: 11
power: 100
time: "2021-10-20T16:08:38.194017624Z"
```

To get all evidence

Example:

```bash
simd query evidence
```
Example Output:

```bash
evidence:
consensus_address: cosmosvalcons1ntk8eualewuprz0gamh8hnvcem2nrcdsgz563h
height: 11
power: 100
time: "2021-10-20T16:08:38.194017624Z"
pagination:
next_key: null
total: "1"
```

## REST

A user can query the `evidence` module using REST endpoints.

### Evidence

Get evidence by hash

```bash
/cosmos/evidence/v1beta1/evidence/{evidence_hash}
```

Example:

```bash
curl -X GET "http://localhost:1317/cosmos/evidence/v1beta1/evidence/DF0C23E8634E480F84B9D5674A7CDC9816466DEC28A3358F73260F68D28D7660"
```
Example Output:

```bash
{
"evidence": {
"consensus_address": "cosmosvalcons1ntk8eualewuprz0gamh8hnvcem2nrcdsgz563h",
"height": "11",
"power": "100",
"time": "2021-10-20T16:08:38.194017624Z"
}
}
```

### All evidence

Get all evidence

```bash
/cosmos/evidence/v1beta1/evidence
```

Example:

```bash
curl -X GET "http://localhost:1317/cosmos/evidence/v1beta1/evidence"
```
Example Output:

```bash
{
"evidence": [
{
"consensus_address": "cosmosvalcons1ntk8eualewuprz0gamh8hnvcem2nrcdsgz563h",
"height": "11",
"power": "100",
"time": "2021-10-20T16:08:38.194017624Z"
}
],
"pagination": {
"total": "1"
}
}
```

## gRPC

A user can query the `evidence` module using gRPC endpoints.

### Evidence

Get evidence by hash

```bash
cosmos.evidence.v1beta1.Query/Evidence
```

Example:

```bash
grpcurl -plaintext -d '{"evidence_hash":"DF0C23E8634E480F84B9D5674A7CDC9816466DEC28A3358F73260F68D28D7660"}' localhost:9090 cosmos.evidence.v1beta1.Query/Evidence
```

Example Output:

```bash
{
"evidence": {
"consensus_address": "cosmosvalcons1ntk8eualewuprz0gamh8hnvcem2nrcdsgz563h",
"height": "11",
"power": "100",
"time": "2021-10-20T16:08:38.194017624Z"
}
}
```

### All evidence

Get all evidence

```bash
cosmos.evidence.v1beta1.Query/AllEvidence
```

Example:

```bash
grpcurl -plaintext localhost:9090 cosmos.evidence.v1beta1.Query/AllEvidence
```
Example Output:

```bash
{
"evidence": [
{
"consensus_address": "cosmosvalcons1ntk8eualewuprz0gamh8hnvcem2nrcdsgz563h",
"height": "11",
"power": "100",
"time": "2021-10-20T16:08:38.194017624Z"
}
],
"pagination": {
"total": "1"
}
}
```

0 comments on commit 42d543e

Please sign in to comment.