Skip to content

Commit

Permalink
Merge branch 'master' into improve_feegrant_error_message
Browse files Browse the repository at this point in the history
  • Loading branch information
fkneeland-figure authored Sep 14, 2021
2 parents 8c9d6cf + a70f39e commit 6d2b81e
Show file tree
Hide file tree
Showing 9 changed files with 58 additions and 25 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ Ref: https://keepachangelog.com/en/1.0.0/

### Improvements

* (x/bank) [\#10134](https://github.com/cosmos/cosmos-sdk/pull/10134) Add `HasDenomMetadata` function to bank `Keeper` to check if a client coin denom metadata exists in state.
* (store) [\#10026](https://github.com/cosmos/cosmos-sdk/pull/10026) Improve CacheKVStore datastructures / algorithms, to no longer take O(N^2) time when interleaving iterators and insertions.
* (types) [\#10076](https://github.com/cosmos/cosmos-sdk/pull/10076) Significantly speedup and lower allocations for `Coins.String()`.
* (x/bank) [\#10022](https://github.com/cosmos/cosmos-sdk/pull/10022) `BankKeeper.SendCoins` now takes less execution time.
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ should convene to rectify the situation by either:
**Approval Committee & Decision Making**
In absense of general consensus, decision making requires 1/2 vote from the two members
In absence of general consensus, decision making requires 1/2 vote from the two members
of the **Concept Approval Committee**.
**Committee Members**
Expand Down
28 changes: 26 additions & 2 deletions docs/run-node/txs.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,30 @@ You may optionally pass the `--broadcast-mode` flag to specify which response to
- `sync`: the CLI waits for a CheckTx execution response only.
- `async`: the CLI returns immediately (transaction might fail).

### Encoding a Transaction

In order to broadcast a transaction using the gRPC or REST endpoints, the transaction will need to be encoded first. This can be done using the CLI.

Encoding a transaction is done using the following command:

```bash
simd tx encode tx_signed.json
```

This will read the transaction from the file, serialize it using Protobuf, and output the transaction bytes as base64 in the console.

### Decoding a Transaction

The CLI can also be used to decode transaction bytes.

Decoding a transaction is done using the following command:

```bash
simd tx decode [protobuf-byte-string]
```

This will decode the transaction bytes and output the transaction as JSON in the console. You can also save the transaction to a file by appending `> tx.json` to the above command.

## Programmatically with Go

It is possible to manipulate transactions programmatically via Go using the Cosmos SDK's `TxBuilder` interface.
Expand Down Expand Up @@ -326,7 +350,7 @@ func simulateTx() error {

## Using gRPC

It is not possible to generate or sign a transaction using gRPC, only to broadcast one.
It is not possible to generate or sign a transaction using gRPC, only to broadcast one. In order to broadcast a transaction using gRPC, you will need to generate, sign, and encode the transaction using either the CLI or programmatically with Go.

### Broadcasting a Transaction

Expand All @@ -341,7 +365,7 @@ grpcurl -plaintext \

## Using REST

It is not possible to generate or sign a transaction using REST, only to broadcast one.
It is not possible to generate or sign a transaction using REST, only to broadcast one. In order to broadcast a transaction using REST, you will need to generate, sign, and encode the transaction using either the CLI or programmatically with Go.

### Broadcasting a Transaction

Expand Down
2 changes: 1 addition & 1 deletion types/dec_coin.go
Original file line number Diff line number Diff line change
Expand Up @@ -628,7 +628,7 @@ func ParseDecCoin(coinStr string) (coin DecCoin, err error) {
}

if err := ValidateDenom(denomStr); err != nil {
return DecCoin{}, fmt.Errorf("invalid denom cannot contain upper case characters or spaces: %s", err)
return DecCoin{}, fmt.Errorf("invalid denom cannot contain spaces: %s", err)
}

return NewDecCoinFromDec(denomStr, amount), nil
Expand Down
12 changes: 5 additions & 7 deletions types/dec_coin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -671,7 +671,7 @@ func (s *decCoinTestSuite) TestDecCoins_IsAllPositive() {

{"One Coin - Zero value", sdk.DecCoins{sdk.DecCoin{testDenom1, sdk.NewDec(0)}}, false},

{"One Coin - Postive value", sdk.DecCoins{sdk.DecCoin{testDenom1, sdk.NewDec(5)}}, true},
{"One Coin - Positive value", sdk.DecCoins{sdk.DecCoin{testDenom1, sdk.NewDec(5)}}, true},

{"One Coin - Negative value", sdk.DecCoins{sdk.DecCoin{testDenom1, sdk.NewDec(-15)}}, false},

Expand Down Expand Up @@ -789,7 +789,7 @@ func (s *decCoinTestSuite) TestDecCoins_IsZero() {

{"One Coin - Zero value", sdk.DecCoins{sdk.DecCoin{testDenom1, sdk.NewDec(0)}}, true},

{"One Coin - Postive value", sdk.DecCoins{sdk.DecCoin{testDenom1, sdk.NewDec(5)}}, false},
{"One Coin - Positive value", sdk.DecCoins{sdk.DecCoin{testDenom1, sdk.NewDec(5)}}, false},

{"Multiple Coins - All zero value", sdk.DecCoins{
sdk.DecCoin{testDenom1, sdk.NewDec(0)},
Expand Down Expand Up @@ -1084,7 +1084,7 @@ func (s *decCoinTestSuite) TestDecCoin_Validate() {
input sdk.DecCoin
expectedPass bool
}{
{"Uninitalized deccoin", empty, false},
{"Uninitialized deccoin", empty, false},

{"Invalid denom string", sdk.DecCoin{"(){9**&})", sdk.NewDec(33)}, false},

Expand Down Expand Up @@ -1121,11 +1121,9 @@ func (s *decCoinTestSuite) TestDecCoin_ParseDecCoin() {

{"Precision over limit", "9.11111111111111111111stake", empty, true},

// TODO - Clarify - According to error message for ValidateDenom call, supposed to
// throw error when upper case characters are used. Currently uppercase denoms are allowed.
{"Invalid denom", "9.3STAKE", sdk.DecCoin{"STAKE", sdk.NewDecWithPrec(93, 1)}, false},
{"Valid upper case denom", "9.3STAKE", sdk.DecCoin{"STAKE", sdk.NewDecWithPrec(93, 1)}, false},

{"Valid input - amount and denom seperated by space", "9.3 stake", sdk.DecCoin{"stake", sdk.NewDecWithPrec(93, 1)}, false},
{"Valid input - amount and denom separated by space", "9.3 stake", sdk.DecCoin{"stake", sdk.NewDecWithPrec(93, 1)}, false},

{"Valid input - amount and denom concatenated", "9.3stake", sdk.DecCoin{"stake", sdk.NewDecWithPrec(93, 1)}, false},
}
Expand Down
2 changes: 1 addition & 1 deletion x/auth/client/cli/decode.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const flagHex = "hex"
// it into a JSON-encoded transaction.
func GetDecodeCommand() *cobra.Command {
cmd := &cobra.Command{
Use: "decode [amino-byte-string]",
Use: "decode [protobuf-byte-string]",
Short: "Decode a binary encoded transaction string",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) (err error) {
Expand Down
2 changes: 1 addition & 1 deletion x/auth/client/cli/encode.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func GetEncodeCommand() *cobra.Command {
Use: "encode [file]",
Short: "Encode transactions generated offline",
Long: `Encode transactions created with the --generate-only flag and signed with the sign command.
Read a transaction from <file>, serialize it to the Amino wire protocol, and output it as base64.
Read a transaction from <file>, serialize it to the Protobuf wire protocol, and output it as base64.
If you supply a dash (-) argument in place of an input filename, the command reads from standard input.`,
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
Expand Down
9 changes: 8 additions & 1 deletion x/bank/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ type Keeper interface {
GetPaginatedTotalSupply(ctx sdk.Context, pagination *query.PageRequest) (sdk.Coins, *query.PageResponse, error)
IterateTotalSupply(ctx sdk.Context, cb func(sdk.Coin) bool)
GetDenomMetaData(ctx sdk.Context, denom string) (types.Metadata, bool)
HasDenomMetaData(ctx sdk.Context, denom string) bool
SetDenomMetaData(ctx sdk.Context, denomMetaData types.Metadata)
IterateAllDenomMetaData(ctx sdk.Context, cb func(types.Metadata) bool)

Expand Down Expand Up @@ -73,7 +74,6 @@ func (k BaseKeeper) GetPaginatedTotalSupply(ctx sdk.Context, pagination *query.P
supply = supply.Add(sdk.NewCoin(string(key), amount))
return nil
})

if err != nil {
return nil, nil, err
}
Expand Down Expand Up @@ -231,6 +231,13 @@ func (k BaseKeeper) GetDenomMetaData(ctx sdk.Context, denom string) (types.Metad
return metadata, true
}

// HasDenomMetaData checks if the denomination metadata exists in store.
func (k BaseKeeper) HasDenomMetaData(ctx sdk.Context, denom string) bool {
store := ctx.KVStore(k.storeKey)
store = prefix.NewStore(store, types.DenomMetadataPrefix)
return store.Has([]byte(denom))
}

// GetAllDenomMetaData retrieves all denominations metadata
func (k BaseKeeper) GetAllDenomMetaData(ctx sdk.Context) []types.Metadata {
denomMetaData := make([]types.Metadata, 0)
Expand Down
25 changes: 14 additions & 11 deletions x/bank/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1001,6 +1001,8 @@ func (suite *IntegrationTestSuite) TestSetDenomMetaData() {

actualMetadata, found := app.BankKeeper.GetDenomMetaData(ctx, metadata[1].Base)
suite.Require().True(found)
found = app.BankKeeper.HasDenomMetaData(ctx, metadata[1].Base)
suite.Require().True(found)
suite.Require().Equal(metadata[1].GetBase(), actualMetadata.GetBase())
suite.Require().Equal(metadata[1].GetDisplay(), actualMetadata.GetDisplay())
suite.Require().Equal(metadata[1].GetDescription(), actualMetadata.GetDescription())
Expand Down Expand Up @@ -1132,18 +1134,19 @@ func (suite *IntegrationTestSuite) TestBalanceTrackingEvents() {
}

func (suite *IntegrationTestSuite) getTestMetadata() []types.Metadata {
return []types.Metadata{{
Name: "Cosmos Hub Atom",
Symbol: "ATOM",
Description: "The native staking token of the Cosmos Hub.",
DenomUnits: []*types.DenomUnit{
{"uatom", uint32(0), []string{"microatom"}},
{"matom", uint32(3), []string{"milliatom"}},
{"atom", uint32(6), nil},
return []types.Metadata{
{
Name: "Cosmos Hub Atom",
Symbol: "ATOM",
Description: "The native staking token of the Cosmos Hub.",
DenomUnits: []*types.DenomUnit{
{"uatom", uint32(0), []string{"microatom"}},
{"matom", uint32(3), []string{"milliatom"}},
{"atom", uint32(6), nil},
},
Base: "uatom",
Display: "atom",
},
Base: "uatom",
Display: "atom",
},
{
Name: "Token",
Symbol: "TOKEN",
Expand Down

0 comments on commit 6d2b81e

Please sign in to comment.