merged in master

This commit is contained in:
Sunny Aggarwal
2021-04-06 19:19:59 -04:00
264 changed files with 8719 additions and 17032 deletions
+16 -92
View File
@@ -11,7 +11,6 @@ import (
yaml "gopkg.in/yaml.v2"
"github.com/cosmos/cosmos-sdk/codec/legacy"
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
"github.com/cosmos/cosmos-sdk/internal/conv"
"github.com/cosmos/cosmos-sdk/types/address"
@@ -78,11 +77,11 @@ const (
var (
// AccAddress.String() is expensive and if unoptimized dominantly showed up in profiles,
// yet has no mechanisms to trivially cache the result given that AccAddress is a []byte type.
accAddrMu sync.RWMutex
accAddrMu sync.Mutex
accAddrCache *simplelru.LRU
consAddrMu sync.RWMutex
consAddrMu sync.Mutex
consAddrCache *simplelru.LRU
valAddrMu sync.RWMutex
valAddrMu sync.Mutex
valAddrCache *simplelru.LRU
)
@@ -268,13 +267,13 @@ func (aa AccAddress) String() string {
}
var key = conv.UnsafeBytesToStr(aa)
accAddrMu.RLock()
accAddrMu.Lock()
defer accAddrMu.Unlock()
addr, ok := accAddrCache.Get(key)
accAddrMu.RUnlock()
if ok {
return addr.(string)
}
return cacheBech32Addr(GetConfig().GetBech32AccountAddrPrefix(), aa, accAddrCache, key, &accAddrMu)
return cacheBech32Addr(GetConfig().GetBech32AccountAddrPrefix(), aa, accAddrCache, key)
}
// Format implements the fmt.Formatter interface.
@@ -418,13 +417,13 @@ func (va ValAddress) String() string {
}
var key = conv.UnsafeBytesToStr(va)
valAddrMu.RLock()
valAddrMu.Lock()
defer valAddrMu.Unlock()
addr, ok := valAddrCache.Get(key)
valAddrMu.RUnlock()
if ok {
return addr.(string)
}
return cacheBech32Addr(GetConfig().GetBech32ValidatorAddrPrefix(), va, valAddrCache, key, &valAddrMu)
return cacheBech32Addr(GetConfig().GetBech32ValidatorAddrPrefix(), va, valAddrCache, key)
}
// Format implements the fmt.Formatter interface.
@@ -573,13 +572,13 @@ func (ca ConsAddress) String() string {
}
var key = conv.UnsafeBytesToStr(ca)
consAddrMu.RLock()
consAddrMu.Lock()
defer consAddrMu.Unlock()
addr, ok := consAddrCache.Get(key)
consAddrMu.RUnlock()
if ok {
return addr.(string)
}
return cacheBech32Addr(GetConfig().GetBech32ConsensusAddrPrefix(), ca, consAddrCache, key, &consAddrMu)
return cacheBech32Addr(GetConfig().GetBech32ConsensusAddrPrefix(), ca, consAddrCache, key)
}
// Bech32ifyAddressBytes returns a bech32 representation of address bytes.
@@ -623,86 +622,12 @@ func (ca ConsAddress) Format(s fmt.State, verb rune) {
// auxiliary
// ----------------------------------------------------------------------------
// Bech32PubKeyType defines a string type alias for a Bech32 public key type.
type Bech32PubKeyType string
// Bech32 conversion constants
const (
Bech32PubKeyTypeAccPub Bech32PubKeyType = "accpub"
Bech32PubKeyTypeValPub Bech32PubKeyType = "valpub"
Bech32PubKeyTypeConsPub Bech32PubKeyType = "conspub"
)
// Bech32ifyPubKey returns a Bech32 encoded string containing the appropriate
// prefix based on the key type provided for a given PublicKey.
// TODO: Remove Bech32ifyPubKey and all usages (cosmos/cosmos-sdk/issues/#7357)
func Bech32ifyPubKey(pkt Bech32PubKeyType, pubkey cryptotypes.PubKey) (string, error) {
var bech32Prefix string
switch pkt {
case Bech32PubKeyTypeAccPub:
bech32Prefix = GetConfig().GetBech32AccountPubPrefix()
case Bech32PubKeyTypeValPub:
bech32Prefix = GetConfig().GetBech32ValidatorPubPrefix()
case Bech32PubKeyTypeConsPub:
bech32Prefix = GetConfig().GetBech32ConsensusPubPrefix()
}
return bech32.ConvertAndEncode(bech32Prefix, legacy.Cdc.MustMarshalBinaryBare(pubkey))
}
// MustBech32ifyPubKey calls Bech32ifyPubKey except it panics on error.
func MustBech32ifyPubKey(pkt Bech32PubKeyType, pubkey cryptotypes.PubKey) string {
res, err := Bech32ifyPubKey(pkt, pubkey)
if err != nil {
panic(err)
}
return res
}
// GetPubKeyFromBech32 returns a PublicKey from a bech32-encoded PublicKey with
// a given key type.
func GetPubKeyFromBech32(pkt Bech32PubKeyType, pubkeyStr string) (cryptotypes.PubKey, error) {
var bech32Prefix string
switch pkt {
case Bech32PubKeyTypeAccPub:
bech32Prefix = GetConfig().GetBech32AccountPubPrefix()
case Bech32PubKeyTypeValPub:
bech32Prefix = GetConfig().GetBech32ValidatorPubPrefix()
case Bech32PubKeyTypeConsPub:
bech32Prefix = GetConfig().GetBech32ConsensusPubPrefix()
}
bz, err := GetFromBech32(pubkeyStr, bech32Prefix)
if err != nil {
return nil, err
}
return legacy.PubKeyFromBytes(bz)
}
// MustGetPubKeyFromBech32 calls GetPubKeyFromBech32 except it panics on error.
func MustGetPubKeyFromBech32(pkt Bech32PubKeyType, pubkeyStr string) cryptotypes.PubKey {
res, err := GetPubKeyFromBech32(pkt, pubkeyStr)
if err != nil {
panic(err)
}
return res
}
var errBech32EmptyAddress = errors.New("decoding Bech32 address failed: must provide a non empty address")
// GetFromBech32 decodes a bytestring from a Bech32 encoded string.
func GetFromBech32(bech32str, prefix string) ([]byte, error) {
if len(bech32str) == 0 {
return nil, errors.New("decoding Bech32 address failed: must provide an address")
return nil, errBech32EmptyAddress
}
hrp, bz, err := bech32.DecodeAndConvert(bech32str)
@@ -725,13 +650,12 @@ func addressBytesFromHexString(address string) ([]byte, error) {
return hex.DecodeString(address)
}
func cacheBech32Addr(prefix string, addr []byte, cache *simplelru.LRU, cacheKey string, m sync.Locker) string {
// cacheBech32Addr is not concurrency safe. Concurrent access to cache causes race condition.
func cacheBech32Addr(prefix string, addr []byte, cache *simplelru.LRU, cacheKey string) string {
bech32Addr, err := bech32.ConvertAndEncode(prefix, addr)
if err != nil {
panic(err)
}
m.Lock()
cache.Add(cacheKey, bech32Addr)
m.Unlock()
return bech32Addr
}
+55
View File
@@ -0,0 +1,55 @@
package types_test
import (
"encoding/binary"
"fmt"
"testing"
"time"
"github.com/cosmos/cosmos-sdk/types"
"github.com/stretchr/testify/require"
)
// generates AccAddress with `prefix` and calls String method
func addressStringCaller(require *require.Assertions, prefix byte, max uint32, cancel chan bool, done chan<- bool) {
bz := make([]byte, 5) // prefix + 4 bytes for uint
bz[0] = prefix
for i := uint32(0); ; i++ {
if i >= max {
i = 0
}
select {
case <-cancel:
done <- true
return
default:
binary.BigEndian.PutUint32(bz[1:], i)
str := types.AccAddress(bz).String()
require.True(str != "")
}
}
}
func (s *addressTestSuite) TestAddressRace() {
fmt.Println("starting test")
if testing.Short() {
s.T().Skip("AddressRace test is not short")
}
workers := 4
done := make(chan bool, workers)
cancel := make(chan bool)
for i := byte(1); i <= 2; i++ { // workes which will loop in first 100 addresses
go addressStringCaller(s.Require(), i, 100, cancel, done)
}
for i := byte(1); i <= 2; i++ { // workes which will generate 1e6 new addresses
go addressStringCaller(s.Require(), i, 1000000, cancel, done)
}
<-time.After(time.Millisecond * 30)
close(cancel)
// cleanup
for i := 0; i < 4; i++ {
<-done
}
}
+5 -46
View File
@@ -16,6 +16,7 @@ import (
"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1"
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
"github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/bech32/legacybech32"
)
type addressTestSuite struct {
@@ -68,48 +69,6 @@ func (s *addressTestSuite) TestEmptyAddresses() {
s.Require().Error(err)
}
func (s *addressTestSuite) TestRandBech32PubkeyConsistency() {
pubBz := make([]byte, ed25519.PubKeySize)
pub := &ed25519.PubKey{Key: pubBz}
for i := 0; i < 1000; i++ {
rand.Read(pub.Key)
mustBech32AccPub := types.MustBech32ifyPubKey(types.Bech32PubKeyTypeAccPub, pub)
bech32AccPub, err := types.Bech32ifyPubKey(types.Bech32PubKeyTypeAccPub, pub)
s.Require().Nil(err)
s.Require().Equal(bech32AccPub, mustBech32AccPub)
mustBech32ValPub := types.MustBech32ifyPubKey(types.Bech32PubKeyTypeValPub, pub)
bech32ValPub, err := types.Bech32ifyPubKey(types.Bech32PubKeyTypeValPub, pub)
s.Require().Nil(err)
s.Require().Equal(bech32ValPub, mustBech32ValPub)
mustBech32ConsPub := types.MustBech32ifyPubKey(types.Bech32PubKeyTypeConsPub, pub)
bech32ConsPub, err := types.Bech32ifyPubKey(types.Bech32PubKeyTypeConsPub, pub)
s.Require().Nil(err)
s.Require().Equal(bech32ConsPub, mustBech32ConsPub)
mustAccPub := types.MustGetPubKeyFromBech32(types.Bech32PubKeyTypeAccPub, bech32AccPub)
accPub, err := types.GetPubKeyFromBech32(types.Bech32PubKeyTypeAccPub, bech32AccPub)
s.Require().Nil(err)
s.Require().Equal(accPub, mustAccPub)
mustValPub := types.MustGetPubKeyFromBech32(types.Bech32PubKeyTypeValPub, bech32ValPub)
valPub, err := types.GetPubKeyFromBech32(types.Bech32PubKeyTypeValPub, bech32ValPub)
s.Require().Nil(err)
s.Require().Equal(valPub, mustValPub)
mustConsPub := types.MustGetPubKeyFromBech32(types.Bech32PubKeyTypeConsPub, bech32ConsPub)
consPub, err := types.GetPubKeyFromBech32(types.Bech32PubKeyTypeConsPub, bech32ConsPub)
s.Require().Nil(err)
s.Require().Equal(consPub, mustConsPub)
s.Require().Equal(valPub, accPub)
s.Require().Equal(valPub, consPub)
}
}
func (s *addressTestSuite) TestYAMLMarshalers() {
addr := secp256k1.GenPrivKey().PubKey().Address()
@@ -277,7 +236,7 @@ func (s *addressTestSuite) TestConfiguredPrefix() {
acc.String(),
prefix+types.PrefixAccount), acc.String())
bech32Pub := types.MustBech32ifyPubKey(types.Bech32PubKeyTypeAccPub, pub)
bech32Pub := legacybech32.MustMarshalPubKey(legacybech32.AccPK, pub)
s.Require().True(strings.HasPrefix(
bech32Pub,
prefix+types.PrefixPublic))
@@ -291,7 +250,7 @@ func (s *addressTestSuite) TestConfiguredPrefix() {
val.String(),
prefix+types.PrefixValidator+types.PrefixAddress))
bech32ValPub := types.MustBech32ifyPubKey(types.Bech32PubKeyTypeValPub, pub)
bech32ValPub := legacybech32.MustMarshalPubKey(legacybech32.ValPK, pub)
s.Require().True(strings.HasPrefix(
bech32ValPub,
prefix+types.PrefixValidator+types.PrefixPublic))
@@ -305,7 +264,7 @@ func (s *addressTestSuite) TestConfiguredPrefix() {
cons.String(),
prefix+types.PrefixConsensus+types.PrefixAddress))
bech32ConsPub := types.MustBech32ifyPubKey(types.Bech32PubKeyTypeConsPub, pub)
bech32ConsPub := legacybech32.MustMarshalPubKey(legacybech32.ConsPK, pub)
s.Require().True(strings.HasPrefix(
bech32ConsPub,
prefix+types.PrefixConsensus+types.PrefixPublic))
@@ -523,7 +482,7 @@ func (s *addressTestSuite) TestGetConsAddress() {
func (s *addressTestSuite) TestGetFromBech32() {
_, err := types.GetFromBech32("", "prefix")
s.Require().Error(err)
s.Require().Equal("decoding Bech32 address failed: must provide an address", err.Error())
s.Require().Equal("decoding Bech32 address failed: must provide a non empty address", err.Error())
_, err = types.GetFromBech32("cosmos1qqqsyqcyq5rqwzqfys8f67", "x")
s.Require().Error(err)
s.Require().Equal("invalid Bech32 prefix; expected x, got cosmos", err.Error())
+68
View File
@@ -0,0 +1,68 @@
// Deprecated: The module provides legacy bech32 functions which will be removed in a future
// release.
package legacybech32
import (
"github.com/cosmos/cosmos-sdk/codec/legacy"
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/bech32"
)
// TODO: when removing this package remove:
// + sdk:config.GetBech32AccountPubPrefix (and other related functions)
// + Bech32PrefixAccAddr and other related constants
// Deprecated: Bech32PubKeyType defines a string type alias for a Bech32 public key type.
type Bech32PubKeyType string
// Bech32 conversion constants
const (
AccPK Bech32PubKeyType = "accpub"
ValPK Bech32PubKeyType = "valpub"
ConsPK Bech32PubKeyType = "conspub"
)
// Deprecated: MarshalPubKey returns a Bech32 encoded string containing the appropriate
// prefix based on the key type provided for a given PublicKey.
func MarshalPubKey(pkt Bech32PubKeyType, pubkey cryptotypes.PubKey) (string, error) {
bech32Prefix := getPrefix(pkt)
return bech32.ConvertAndEncode(bech32Prefix, legacy.Cdc.MustMarshalBinaryBare(pubkey))
}
// Deprecated: MustMarshalPubKey calls MarshalPubKey and panics on error.
func MustMarshalPubKey(pkt Bech32PubKeyType, pubkey cryptotypes.PubKey) string {
res, err := MarshalPubKey(pkt, pubkey)
if err != nil {
panic(err)
}
return res
}
func getPrefix(pkt Bech32PubKeyType) string {
cfg := sdk.GetConfig()
switch pkt {
case AccPK:
return cfg.GetBech32AccountPubPrefix()
case ValPK:
return cfg.GetBech32ValidatorPubPrefix()
case ConsPK:
return cfg.GetBech32ConsensusPubPrefix()
}
return ""
}
// Deprecated: UnmarshalPubKey returns a PublicKey from a bech32-encoded PublicKey with
// a given key type.
func UnmarshalPubKey(pkt Bech32PubKeyType, pubkeyStr string) (cryptotypes.PubKey, error) {
bech32Prefix := getPrefix(pkt)
bz, err := sdk.GetFromBech32(pubkeyStr, bech32Prefix)
if err != nil {
return nil, err
}
return legacy.PubKeyFromBytes(bz)
}
@@ -1,4 +1,4 @@
package types_test
package legacybech32
import (
"math/rand"
@@ -8,7 +8,6 @@ import (
"github.com/stretchr/testify/require"
"github.com/cosmos/cosmos-sdk/crypto/keys/ed25519"
"github.com/cosmos/cosmos-sdk/types"
)
func BenchmarkAccAddressString(b *testing.B) {
@@ -30,7 +29,7 @@ func BenchmarkAccAddressString(b *testing.B) {
require.NotEmpty(b, str2)
}
func BenchmarkBech32ifyPubKey(b *testing.B) {
func BenchmarkMarshalPubKey(b *testing.B) {
b.ReportAllocs()
pkBz := make([]byte, ed25519.PubKeySize)
pk := &ed25519.PubKey{Key: pkBz}
@@ -43,7 +42,7 @@ func BenchmarkBech32ifyPubKey(b *testing.B) {
rng.Read(pk.Key)
b.StartTimer()
_, err := types.Bech32ifyPubKey(types.Bech32PubKeyTypeConsPub, pk)
_, err := MarshalPubKey(ConsPK, pk)
require.NoError(b, err)
}
}
@@ -60,11 +59,11 @@ func BenchmarkGetPubKeyFromBech32(b *testing.B) {
b.StopTimer()
rng.Read(pk.Key)
pkStr, err := types.Bech32ifyPubKey(types.Bech32PubKeyTypeConsPub, pk)
pkStr, err := MarshalPubKey(ConsPK, pk)
require.NoError(b, err)
b.StartTimer()
pk2, err := types.GetPubKeyFromBech32(types.Bech32PubKeyTypeConsPub, pkStr)
pk2, err := UnmarshalPubKey(ConsPK, pkStr)
require.NoError(b, err)
require.Equal(b, pk, pk2)
}
+26
View File
@@ -0,0 +1,26 @@
package legacybech32
import (
"testing"
"github.com/stretchr/testify/require"
"github.com/cosmos/cosmos-sdk/crypto/hd"
"github.com/cosmos/cosmos-sdk/crypto/ledger"
"github.com/cosmos/cosmos-sdk/testutil"
sdk "github.com/cosmos/cosmos-sdk/types"
)
func TestBeach32ifPbKey(t *testing.T) {
require := require.New(t)
path := *hd.NewFundraiserParams(0, sdk.CoinType, 0)
priv, err := ledger.NewPrivKeySecp256k1Unsafe(path)
require.Nil(err, "%s", err)
require.NotNil(priv)
pubKeyAddr, err := MarshalPubKey(AccPK, priv.PubKey())
require.NoError(err)
require.Equal("cosmospub1addwnpepqd87l8xhcnrrtzxnkql7k55ph8fr9jarf4hn6udwukfprlalu8lgw0urza0",
pubKeyAddr, "Is your device using test mnemonic: %s ?", testutil.TestMnemonic)
}
+15
View File
@@ -137,6 +137,10 @@ var (
// ErrNotFound defines an error when requested entity doesn't exist in the state.
ErrNotFound = Register(RootCodespace, 38, "not found")
// ErrIO should be used to wrap internal errors caused by external operation.
// Examples: not DB domain error, file writing etc...
ErrIO = Register(RootCodespace, 39, "Internal IO error")
// ErrPanic is only set when we recover from a panic, so we know to
// redact potentially sensitive system info
ErrPanic = Register(UndefinedCodespace, 111222, "panic")
@@ -367,6 +371,17 @@ func WithType(err error, obj interface{}) error {
return Wrap(err, fmt.Sprintf("%T", obj))
}
// IsOf checks if a received error is caused by one of the target errors.
// It extends the errors.Is functionality to a list of errors.
func IsOf(received error, targets ...error) bool {
for _, t := range targets {
if errors.Is(received, t) {
return true
}
}
return false
}
// causer is an interface implemented by an error that supports wrapping. Use
// it to test if an error wraps another error instance.
type causer interface {
+21
View File
@@ -149,6 +149,27 @@ func (s *errorsTestSuite) TestErrorIs() {
}
}
func (s *errorsTestSuite) TestIsOf() {
require := s.Require()
var errNil *Error
var err = ErrInvalidAddress
var errW = Wrap(ErrLogic, "more info")
require.False(IsOf(errNil), "nil error should always have no causer")
require.False(IsOf(errNil, err), "nil error should always have no causer")
require.False(IsOf(err))
require.False(IsOf(err, nil))
require.False(IsOf(err, ErrLogic))
require.True(IsOf(errW, ErrLogic))
require.True(IsOf(errW, err, ErrLogic))
require.True(IsOf(errW, nil, errW), "error should much itself")
var err2 = errors.New("other error")
require.True(IsOf(err2, nil, err2), "error should much itself")
}
type customError struct {
}
+7
View File
@@ -37,6 +37,8 @@ func mod(i *big.Int, i2 *big.Int) *big.Int { return new(big.Int).Mod(i, i2) }
func neg(i *big.Int) *big.Int { return new(big.Int).Neg(i) }
func abs(i *big.Int) *big.Int { return new(big.Int).Abs(i) }
func min(i *big.Int, i2 *big.Int) *big.Int {
if i.Cmp(i2) == 1 {
return new(big.Int).Set(i2)
@@ -304,6 +306,11 @@ func (i Int) Neg() (res Int) {
return Int{neg(i.i)}
}
// Abs returns the absolute value of Int.
func (i Int) Abs() Int {
return Int{abs(i.i)}
}
// return the minimum of the ints
func MinInt(i1, i2 Int) Int {
return Int{min(i1.BigInt(), i2.BigInt())}
+3
View File
@@ -159,6 +159,8 @@ func (s *intTestSuite) TestArithInt() {
{sdk.MinInt(i1, i2), minint(n1, n2)},
{sdk.MaxInt(i1, i2), maxint(n1, n2)},
{i1.Neg(), -n1},
{i1.Abs(), n1},
{i1.Neg().Abs(), n1},
}
for tcnum, tc := range cases {
@@ -206,6 +208,7 @@ func (s *intTestSuite) TestImmutabilityAllInt() {
func(i *sdk.Int) { _ = i.MulRaw(rand.Int63()) },
func(i *sdk.Int) { _ = i.QuoRaw(rand.Int63()) },
func(i *sdk.Int) { _ = i.Neg() },
func(i *sdk.Int) { _ = i.Abs() },
func(i *sdk.Int) { _ = i.IsZero() },
func(i *sdk.Int) { _ = i.Sign() },
func(i *sdk.Int) { _ = i.Equal(randint()) },
+4 -1
View File
@@ -3,6 +3,7 @@ package module
import (
"github.com/gogo/protobuf/grpc"
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
)
@@ -34,6 +35,7 @@ type Configurator interface {
}
type configurator struct {
cdc codec.Marshaler
msgServer grpc.Server
queryServer grpc.Server
@@ -42,8 +44,9 @@ type configurator struct {
}
// NewConfigurator returns a new Configurator instance
func NewConfigurator(msgServer grpc.Server, queryServer grpc.Server) Configurator {
func NewConfigurator(cdc codec.Marshaler, msgServer grpc.Server, queryServer grpc.Server) Configurator {
return configurator{
cdc: cdc,
msgServer: msgServer,
queryServer: queryServer,
migrations: map[string]map[uint64]MigrationHandler{},
+78 -5
View File
@@ -337,7 +337,51 @@ type MigrationHandler func(sdk.Context) error
// version from which we should perform the migration for each module.
type VersionMap map[string]uint64
// RunMigrations performs in-place store migrations for all modules.
// RunMigrations performs in-place store migrations for all modules. This
// function MUST be called insde an x/upgrade UpgradeHandler.
//
// Recall that in an upgrade handler, the `fromVM` VersionMap is retrieved from
// x/upgrade's store, and the function needs to return the target VersionMap
// that will in turn be persisted to the x/upgrade's store. In general,
// returning RunMigrations should be enough:
//
// Example:
// cfg := module.NewConfigurator(...)
// app.UpgradeKeeper.SetUpgradeHandler("my-plan", func(ctx sdk.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) {
// return app.mm.RunMigrations(ctx, cfg, fromVM)
// })
//
// Internally, RunMigrations will perform the following steps:
// - create an `updatedVM` VersionMap of module with their latest ConsensusVersion
// - make a diff of `fromVM` and `udpatedVM`, and for each module:
// - if the module's `fromVM` version is less than its `updatedVM` version,
// then run in-place store migrations for that module between those versions.
// - if the module's `fromVM` is 0 (which means that it's a new module,
// because it was not in the previous x/upgrade's store), then run
// `InitGenesis` on that module.
// - return the `updatedVM` to be persisted in the x/upgrade's store.
//
// As an app developer, if you wish to skip running InitGenesis for your new
// module "foo", you need to manually pass a `fromVM` argument to this function
// foo's module version set to its latest ConsensusVersion. That way, the diff
// between the function's `fromVM` and `udpatedVM` will be empty, hence not
// running anything for foo.
//
// Example:
// cfg := module.NewConfigurator(...)
// app.UpgradeKeeper.SetUpgradeHandler("my-plan", func(ctx sdk.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) {
// // Assume "foo" is a new module.
// // `fromVM` is fetched from existing x/upgrade store. Since foo didn't exist
// // before this upgrade, `fromVM["foo"] == 0`, and RunMigration will by default
// // run InitGenesis on foo.
// // To skip running foo's InitGenesis, you need set `fromVM`'s foo to its latest
// // consensus version:
// fromVM["foo"] = foo.AppModule{}.ConsensusVersion()
//
// return app.mm.RunMigrations(ctx, cfg, fromVM)
// })
//
// Please also refer to docs/core/upgrade.md for more information.
func (m Manager) RunMigrations(ctx sdk.Context, cfg Configurator, fromVM VersionMap) (VersionMap, error) {
c, ok := cfg.(configurator)
if !ok {
@@ -346,11 +390,40 @@ func (m Manager) RunMigrations(ctx sdk.Context, cfg Configurator, fromVM Version
updatedVM := make(VersionMap)
for moduleName, module := range m.Modules {
err := c.runModuleMigrations(ctx, moduleName, fromVM[moduleName], module.ConsensusVersion())
updatedVM[moduleName] = module.ConsensusVersion()
if err != nil {
return nil, err
fromVersion := fromVM[moduleName]
toVersion := module.ConsensusVersion()
// Only run migrations when the fromVersion is > 0, or run InitGenesis
// if fromVersion == 0.
//
// fromVersion will be 0 in two cases:
// 1. If a new module is added. In this case we run InitGenesis with an
// empty genesis state.
// 2. If the app developer is running in-place store migrations for the
// first time. In this case, it is the app developer's responsibility
// to set their module's fromVersions to a version that suits them.
if fromVersion > 0 {
err := c.runModuleMigrations(ctx, moduleName, fromVersion, toVersion)
if err != nil {
return nil, err
}
} else {
cfgtor, ok := cfg.(configurator)
if !ok {
// Currently, the only implementator of Configurator (the interface)
// is configurator (the struct).
return nil, sdkerrors.Wrapf(sdkerrors.ErrInvalidType, "expected %T, got %T", configurator{}, cfg)
}
moduleValUpdates := module.InitGenesis(ctx, cfgtor.cdc, module.DefaultGenesis(cfgtor.cdc))
// The module manager assumes only one module will update the
// validator set, and that it will not be by a new module.
if len(moduleValUpdates) > 0 {
return nil, sdkerrors.Wrapf(sdkerrors.ErrLogic, "validator InitGenesis updates already set by a previous module")
}
}
updatedVM[moduleName] = toVersion
}
return updatedVM, nil
+3 -1
View File
@@ -179,7 +179,9 @@ func TestManager_RegisterQueryServices(t *testing.T) {
msgRouter := mocks.NewMockServer(mockCtrl)
queryRouter := mocks.NewMockServer(mockCtrl)
cfg := module.NewConfigurator(msgRouter, queryRouter)
interfaceRegistry := types.NewInterfaceRegistry()
cdc := codec.NewProtoCodec(interfaceRegistry)
cfg := module.NewConfigurator(cdc, msgRouter, queryRouter)
mockAppModule1.EXPECT().RegisterServices(cfg).Times(1)
mockAppModule2.EXPECT().RegisterServices(cfg).Times(1)
+3 -2
View File
@@ -29,6 +29,7 @@ func FilteredPaginate(
key := pageRequest.Key
limit := pageRequest.Limit
countTotal := pageRequest.CountTotal
reverse := pageRequest.Reverse
if offset > 0 && key != nil {
return nil, fmt.Errorf("invalid request, either offset or key is expected, got both")
@@ -42,7 +43,7 @@ func FilteredPaginate(
}
if len(key) != 0 {
iterator := prefixStore.Iterator(key, nil)
iterator := getIterator(prefixStore, key, reverse)
defer iterator.Close()
var numHits uint64
@@ -73,7 +74,7 @@ func FilteredPaginate(
}, nil
}
iterator := prefixStore.Iterator(nil, nil)
iterator := getIterator(prefixStore, nil, reverse)
defer iterator.Close()
end := offset + limit
+81
View File
@@ -89,6 +89,87 @@ func (s *paginationTestSuite) TestFilteredPaginations() {
s.Require().LessOrEqual(len(balances), 2)
}
func (s *paginationTestSuite) TestReverseFilteredPaginations() {
app, ctx, appCodec := setupTest()
var balances sdk.Coins
for i := 0; i < numBalances; i++ {
denom := fmt.Sprintf("foo%ddenom", i)
balances = append(balances, sdk.NewInt64Coin(denom, 100))
}
for i := 0; i < 10; i++ {
denom := fmt.Sprintf("test%ddenom", i)
balances = append(balances, sdk.NewInt64Coin(denom, 250))
}
balances = balances.Sort()
addr1 := sdk.AccAddress([]byte("addr1"))
acc1 := app.AccountKeeper.NewAccountWithAddress(ctx, addr1)
app.AccountKeeper.SetAccount(ctx, acc1)
s.Require().NoError(simapp.FundAccount(app, ctx, addr1, balances))
store := ctx.KVStore(app.GetKey(types.StoreKey))
// verify pagination with limit > total values
pageReq := &query.PageRequest{Key: nil, Limit: 5, CountTotal: true, Reverse: true}
balns, res, err := execFilterPaginate(store, pageReq, appCodec)
s.Require().NoError(err)
s.Require().NotNil(res)
s.Require().Equal(5, len(balns))
s.T().Log("verify empty request")
balns, res, err = execFilterPaginate(store, nil, appCodec)
s.Require().NoError(err)
s.Require().NotNil(res)
s.Require().Equal(10, len(balns))
s.Require().Equal(uint64(10), res.Total)
s.Require().Nil(res.NextKey)
s.T().Log("verify default limit")
pageReq = &query.PageRequest{Reverse: true}
balns, res, err = execFilterPaginate(store, pageReq, appCodec)
s.Require().NoError(err)
s.Require().NotNil(res)
s.Require().Equal(10, len(balns))
s.Require().Equal(uint64(10), res.Total)
s.T().Log("verify nextKey is returned if there are more results")
pageReq = &query.PageRequest{Limit: 2, CountTotal: true, Reverse: true}
balns, res, err = execFilterPaginate(store, pageReq, appCodec)
s.Require().NoError(err)
s.Require().NotNil(res)
s.Require().Equal(2, len(balns))
s.Require().NotNil(res.NextKey)
s.Require().Equal(string(res.NextKey), fmt.Sprintf("test7denom"))
s.Require().Equal(uint64(10), res.Total)
s.T().Log("verify both key and offset can't be given")
pageReq = &query.PageRequest{Key: res.NextKey, Limit: 1, Offset: 2, Reverse: true}
_, _, err = execFilterPaginate(store, pageReq, appCodec)
s.Require().Error(err)
s.T().Log("use nextKey for query and reverse true")
pageReq = &query.PageRequest{Key: res.NextKey, Limit: 2, Reverse: true}
balns, res, err = execFilterPaginate(store, pageReq, appCodec)
s.Require().NoError(err)
s.Require().NotNil(res)
s.Require().Equal(2, len(balns))
s.Require().NotNil(res.NextKey)
s.Require().Equal(string(res.NextKey), fmt.Sprintf("test5denom"))
s.T().Log("verify last page records, nextKey for query and reverse true")
pageReq = &query.PageRequest{Key: res.NextKey, Reverse: true}
balns, res, err = execFilterPaginate(store, pageReq, appCodec)
s.Require().NoError(err)
s.Require().NotNil(res)
s.Require().Equal(6, len(balns))
s.Require().Nil(res.NextKey)
s.T().Log("verify Reverse pagination returns valid result")
s.Require().Equal(balances[235:241].String(), balns.Sort().String())
}
func ExampleFilteredPaginate() {
app, ctx, appCodec := setupTest()
+26 -2
View File
@@ -2,17 +2,23 @@ package query
import (
"fmt"
"math"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"github.com/cosmos/cosmos-sdk/store/types"
db "github.com/tendermint/tm-db"
)
// DefaultLimit is the default `limit` for queries
// if the `limit` is not supplied, paginate will use `DefaultLimit`
const DefaultLimit = 100
// MaxLimit is the maximum limit the paginate function can handle
// which equals the maximum value that can be stored in uint64
const MaxLimit = math.MaxUint64
// ParsePagination validate PageRequest and returns page number & limit.
func ParsePagination(pageReq *PageRequest) (page, limit int, err error) {
offset := 0
@@ -54,6 +60,7 @@ func Paginate(
key := pageRequest.Key
limit := pageRequest.Limit
countTotal := pageRequest.CountTotal
reverse := pageRequest.Reverse
if offset > 0 && key != nil {
return nil, fmt.Errorf("invalid request, either offset or key is expected, got both")
@@ -67,13 +74,14 @@ func Paginate(
}
if len(key) != 0 {
iterator := prefixStore.Iterator(key, nil)
iterator := getIterator(prefixStore, key, reverse)
defer iterator.Close()
var count uint64
var nextKey []byte
for ; iterator.Valid(); iterator.Next() {
if count == limit {
nextKey = iterator.Key()
break
@@ -94,7 +102,7 @@ func Paginate(
}, nil
}
iterator := prefixStore.Iterator(nil, nil)
iterator := getIterator(prefixStore, nil, reverse)
defer iterator.Close()
end := offset + limit
@@ -132,3 +140,19 @@ func Paginate(
return res, nil
}
func getIterator(prefixStore types.KVStore, start []byte, reverse bool) db.Iterator {
if reverse {
var end []byte
if start != nil {
itr := prefixStore.Iterator(start, nil)
defer itr.Close()
if itr.Valid() {
itr.Next()
end = itr.Key()
}
}
return prefixStore.ReverseIterator(nil, end)
}
return prefixStore.Iterator(start, nil)
}
+61 -18
View File
@@ -46,6 +46,8 @@ type PageRequest struct {
// count_total is only respected when offset is used. It is ignored when key
// is set.
CountTotal bool `protobuf:"varint,4,opt,name=count_total,json=countTotal,proto3" json:"count_total,omitempty"`
// reverse is set to true indicates that, results to be returned in the descending order.
Reverse bool `protobuf:"varint,5,opt,name=reverse,proto3" json:"reverse,omitempty"`
}
func (m *PageRequest) Reset() { *m = PageRequest{} }
@@ -109,6 +111,13 @@ func (m *PageRequest) GetCountTotal() bool {
return false
}
func (m *PageRequest) GetReverse() bool {
if m != nil {
return m.Reverse
}
return false
}
// PageResponse is to be embedded in gRPC response messages where the
// corresponding request message has used PageRequest.
//
@@ -182,24 +191,25 @@ func init() {
}
var fileDescriptor_53d6d609fe6828af = []byte{
// 266 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x44, 0x90, 0xc1, 0x4a, 0xc3, 0x40,
0x14, 0x45, 0x33, 0xb6, 0xd6, 0x32, 0xed, 0x42, 0x06, 0x91, 0x74, 0x33, 0x86, 0xae, 0x82, 0x60,
0x86, 0xe2, 0x07, 0x08, 0xdd, 0xba, 0x91, 0xe0, 0xca, 0x4d, 0x99, 0xc4, 0xd7, 0x18, 0xda, 0xcc,
0x4b, 0x3b, 0x2f, 0x62, 0xfe, 0xc2, 0xcf, 0x72, 0xd9, 0xa5, 0x4b, 0x49, 0x7e, 0x44, 0x92, 0x09,
0x74, 0x35, 0x73, 0x2f, 0x87, 0x77, 0xe0, 0xf2, 0xfb, 0x14, 0x6d, 0x81, 0x56, 0x25, 0xda, 0x82,
0x3a, 0x54, 0x70, 0xac, 0xd5, 0xe7, 0x2a, 0x01, 0xd2, 0x2b, 0x55, 0xea, 0x2c, 0x37, 0x9a, 0x72,
0x34, 0x51, 0x79, 0x44, 0x42, 0xb1, 0x70, 0x6c, 0xd4, 0xb1, 0x51, 0xcf, 0x46, 0x03, 0xbb, 0x34,
0x7c, 0xf6, 0xa2, 0x33, 0x88, 0xe1, 0x50, 0x81, 0x25, 0x71, 0xcd, 0x47, 0x3b, 0xa8, 0x7d, 0x16,
0xb0, 0x70, 0x1e, 0x77, 0x5f, 0x71, 0xcb, 0x27, 0xb8, 0xdd, 0x5a, 0x20, 0xff, 0x22, 0x60, 0xe1,
0x38, 0x1e, 0x92, 0xb8, 0xe1, 0x97, 0xfb, 0xbc, 0xc8, 0xc9, 0x1f, 0xf5, 0xb5, 0x0b, 0xe2, 0x8e,
0xcf, 0x52, 0xac, 0x0c, 0x6d, 0x08, 0x49, 0xef, 0xfd, 0x71, 0xc0, 0xc2, 0x69, 0xcc, 0xfb, 0xea,
0xb5, 0x6b, 0x96, 0x4f, 0x7c, 0xee, 0x7c, 0xb6, 0x44, 0x63, 0x41, 0x2c, 0xf8, 0xd4, 0xc0, 0x17,
0x6d, 0xce, 0xd6, 0xab, 0x2e, 0x3f, 0x43, 0xdd, 0x19, 0xdc, 0x15, 0x27, 0x76, 0x61, 0xbd, 0xfe,
0x69, 0x24, 0x3b, 0x35, 0x92, 0xfd, 0x35, 0x92, 0x7d, 0xb7, 0xd2, 0x3b, 0xb5, 0xd2, 0xfb, 0x6d,
0xa5, 0xf7, 0x16, 0x66, 0x39, 0x7d, 0x54, 0x49, 0x94, 0x62, 0xa1, 0x86, 0x71, 0xdc, 0xf3, 0x60,
0xdf, 0x77, 0x8a, 0xea, 0x12, 0xac, 0x1b, 0x2a, 0x99, 0xf4, 0xb3, 0x3c, 0xfe, 0x07, 0x00, 0x00,
0xff, 0xff, 0xb5, 0x65, 0x82, 0x18, 0x44, 0x01, 0x00, 0x00,
// 282 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x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 0x1e, 0xe8, 0xc2, 0x25, 0x31, 0x85, 0xce, 0x0d, 0xb0, 0x25, 0x9d, 0xe5, 0xf0, 0x8e, 0xdb,
0xff, 0x3c, 0xd3, 0x8e, 0x1f, 0xa1, 0xee, 0x6e, 0xbb, 0xfd, 0x2e, 0x92, 0x83, 0xcd, 0xe6, 0xab,
0x11, 0xe4, 0xdc, 0x08, 0xf2, 0xd3, 0x08, 0xf2, 0xd9, 0x8a, 0xc1, 0xb9, 0x15, 0x83, 0xef, 0x56,
0x0c, 0x5e, 0xfc, 0x24, 0xc5, 0xb7, 0x2a, 0x0a, 0x62, 0x9d, 0xc9, 0xbe, 0x37, 0xf7, 0xdc, 0x99,
0xd7, 0xbd, 0xc4, 0xba, 0x00, 0xe3, 0x3a, 0x8c, 0x26, 0xb6, 0xb1, 0xfb, 0xdf, 0x00, 0x00, 0x00,
0xff, 0xff, 0x3d, 0x43, 0x85, 0xf7, 0x5f, 0x01, 0x00, 0x00,
}
func (m *PageRequest) Marshal() (dAtA []byte, err error) {
@@ -222,6 +232,16 @@ func (m *PageRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) {
_ = i
var l int
_ = l
if m.Reverse {
i--
if m.Reverse {
dAtA[i] = 1
} else {
dAtA[i] = 0
}
i--
dAtA[i] = 0x28
}
if m.CountTotal {
i--
if m.CountTotal {
@@ -317,6 +337,9 @@ func (m *PageRequest) Size() (n int) {
if m.CountTotal {
n += 2
}
if m.Reverse {
n += 2
}
return n
}
@@ -463,6 +486,26 @@ func (m *PageRequest) Unmarshal(dAtA []byte) error {
}
}
m.CountTotal = bool(v != 0)
case 5:
if wireType != 0 {
return fmt.Errorf("proto: wrong wireType = %d for field Reverse", wireType)
}
var v int
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowPagination
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
v |= int(b&0x7F) << shift
if b < 0x80 {
break
}
}
m.Reverse = bool(v != 0)
default:
iNdEx = preIndex
skippy, err := skipPagination(dAtA[iNdEx:])
+124
View File
@@ -169,6 +169,130 @@ func (s *paginationTestSuite) TestPagination() {
s.Require().Nil(res.Pagination.NextKey)
}
func (s *paginationTestSuite) TestReversePagination() {
app, ctx, _ := setupTest()
queryHelper := baseapp.NewQueryServerTestHelper(ctx, app.InterfaceRegistry())
types.RegisterQueryServer(queryHelper, app.BankKeeper)
queryClient := types.NewQueryClient(queryHelper)
var balances sdk.Coins
for i := 0; i < numBalances; i++ {
denom := fmt.Sprintf("foo%ddenom", i)
balances = append(balances, sdk.NewInt64Coin(denom, 100))
}
balances = balances.Sort()
addr1 := sdk.AccAddress(secp256k1.GenPrivKey().PubKey().Address())
acc1 := app.AccountKeeper.NewAccountWithAddress(ctx, addr1)
app.AccountKeeper.SetAccount(ctx, acc1)
s.Require().NoError(simapp.FundAccount(app, ctx, addr1, balances))
s.T().Log("verify paginate with custom limit and countTotal, Reverse false")
pageReq := &query.PageRequest{Limit: 2, CountTotal: true, Reverse: true, Key: nil}
request := types.NewQueryAllBalancesRequest(addr1, pageReq)
res1, err := queryClient.AllBalances(gocontext.Background(), request)
s.Require().NoError(err)
s.Require().Equal(res1.Balances.Len(), 2)
s.Require().NotNil(res1.Pagination.NextKey)
s.T().Log("verify paginate with custom limit and countTotal, Reverse false")
pageReq = &query.PageRequest{Limit: 150}
request = types.NewQueryAllBalancesRequest(addr1, pageReq)
res1, err = queryClient.AllBalances(gocontext.Background(), request)
s.Require().NoError(err)
s.Require().Equal(res1.Balances.Len(), 150)
s.Require().NotNil(res1.Pagination.NextKey)
s.Require().Equal(res1.Pagination.Total, uint64(0))
s.T().Log("verify paginate with custom limit, key and Reverse true")
pageReq = &query.PageRequest{Limit: defaultLimit, Reverse: true}
request = types.NewQueryAllBalancesRequest(addr1, pageReq)
res, err := queryClient.AllBalances(gocontext.Background(), request)
s.Require().NoError(err)
s.Require().Equal(res.Balances.Len(), defaultLimit)
s.Require().NotNil(res.Pagination.NextKey)
s.Require().Equal(res.Pagination.Total, uint64(0))
s.T().Log("verify paginate with custom limit, key and Reverse true")
pageReq = &query.PageRequest{Offset: 100, Limit: defaultLimit, Reverse: true}
request = types.NewQueryAllBalancesRequest(addr1, pageReq)
res, err = queryClient.AllBalances(gocontext.Background(), request)
s.Require().NoError(err)
s.Require().Equal(res.Balances.Len(), defaultLimit)
s.Require().NotNil(res.Pagination.NextKey)
s.Require().Equal(res.Pagination.Total, uint64(0))
s.T().Log("verify paginate for last page, Reverse true")
pageReq = &query.PageRequest{Offset: 200, Limit: defaultLimit, Reverse: true}
request = types.NewQueryAllBalancesRequest(addr1, pageReq)
res, err = queryClient.AllBalances(gocontext.Background(), request)
s.Require().NoError(err)
s.Require().Equal(res.Balances.Len(), lastPageRecords)
s.Require().Nil(res.Pagination.NextKey)
s.Require().Equal(res.Pagination.Total, uint64(0))
s.T().Log("verify page request with limit > defaultLimit, returns less or equal to `limit` records")
pageReq = &query.PageRequest{Limit: overLimit, Reverse: true}
request = types.NewQueryAllBalancesRequest(addr1, pageReq)
res, err = queryClient.AllBalances(gocontext.Background(), request)
s.Require().NoError(err)
s.Require().Equal(res.Pagination.Total, uint64(0))
s.Require().NotNil(res.Pagination.NextKey)
s.Require().LessOrEqual(res.Balances.Len(), overLimit)
s.T().Log("verify paginate with custom limit, key, countTotal false and Reverse true")
pageReq = &query.PageRequest{Key: res1.Pagination.NextKey, Limit: 50, Reverse: true}
request = types.NewQueryAllBalancesRequest(addr1, pageReq)
res, err = queryClient.AllBalances(gocontext.Background(), request)
s.Require().NoError(err)
s.Require().Equal(res.Balances.Len(), 50)
s.Require().NotNil(res.Pagination.NextKey)
s.Require().Equal(res.Pagination.Total, uint64(0))
s.T().Log("verify Reverse pagination returns valid result")
s.Require().Equal(balances[101:151].String(), res.Balances.Sort().String())
s.T().Log("verify paginate with custom limit, key, countTotal false and Reverse true")
pageReq = &query.PageRequest{Key: res.Pagination.NextKey, Limit: 50, Reverse: true}
request = types.NewQueryAllBalancesRequest(addr1, pageReq)
res, err = queryClient.AllBalances(gocontext.Background(), request)
s.Require().NoError(err)
s.Require().Equal(res.Balances.Len(), 50)
s.Require().NotNil(res.Pagination.NextKey)
s.Require().Equal(res.Pagination.Total, uint64(0))
s.T().Log("verify Reverse pagination returns valid result")
s.Require().Equal(balances[51:101].String(), res.Balances.Sort().String())
s.T().Log("verify paginate for last page Reverse true")
pageReq = &query.PageRequest{Key: res.Pagination.NextKey, Limit: defaultLimit, Reverse: true}
request = types.NewQueryAllBalancesRequest(addr1, pageReq)
res, err = queryClient.AllBalances(gocontext.Background(), request)
s.Require().NoError(err)
s.Require().Equal(res.Balances.Len(), 51)
s.Require().Nil(res.Pagination.NextKey)
s.Require().Equal(res.Pagination.Total, uint64(0))
s.T().Log("verify Reverse pagination returns valid result")
s.Require().Equal(balances[0:51].String(), res.Balances.Sort().String())
s.T().Log("verify paginate with offset and key - error")
pageReq = &query.PageRequest{Key: res1.Pagination.NextKey, Offset: 100, Limit: defaultLimit, CountTotal: false}
request = types.NewQueryAllBalancesRequest(addr1, pageReq)
res, err = queryClient.AllBalances(gocontext.Background(), request)
s.Require().Error(err)
s.Require().Equal("rpc error: code = InvalidArgument desc = paginate: invalid request, either offset or key is expected, got both", err.Error())
s.T().Log("verify paginate with offset greater than total results")
pageReq = &query.PageRequest{Offset: 300, Limit: defaultLimit, CountTotal: false, Reverse: true}
request = types.NewQueryAllBalancesRequest(addr1, pageReq)
res, err = queryClient.AllBalances(gocontext.Background(), request)
s.Require().NoError(err)
s.Require().LessOrEqual(res.Balances.Len(), 0)
s.Require().Nil(res.Pagination.NextKey)
}
func ExamplePaginate() {
app, ctx, _ := setupTest()
+110 -54
View File
@@ -339,7 +339,10 @@ func (m *BroadcastTxResponse) GetTxResponse() *types.TxResponse {
// RPC method.
type SimulateRequest struct {
// tx is the transaction to simulate.
Tx *Tx `protobuf:"bytes,1,opt,name=tx,proto3" json:"tx,omitempty"`
// Deprecated. Send raw tx bytes instead.
Tx *Tx `protobuf:"bytes,1,opt,name=tx,proto3" json:"tx,omitempty"` // Deprecated: Do not use.
// tx_bytes is the raw transaction.
TxBytes []byte `protobuf:"bytes,2,opt,name=tx_bytes,json=txBytes,proto3" json:"tx_bytes,omitempty"`
}
func (m *SimulateRequest) Reset() { *m = SimulateRequest{} }
@@ -375,6 +378,7 @@ func (m *SimulateRequest) XXX_DiscardUnknown() {
var xxx_messageInfo_SimulateRequest proto.InternalMessageInfo
// Deprecated: Do not use.
func (m *SimulateRequest) GetTx() *Tx {
if m != nil {
return m.Tx
@@ -382,6 +386,13 @@ func (m *SimulateRequest) GetTx() *Tx {
return nil
}
func (m *SimulateRequest) GetTxBytes() []byte {
if m != nil {
return m.TxBytes
}
return nil
}
// SimulateResponse is the response type for the
// Service.SimulateRPC method.
type SimulateResponse struct {
@@ -569,59 +580,59 @@ func init() {
}
var fileDescriptor_e0b00a618705eca7 = []byte{
// 817 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x55, 0xcf, 0x6f, 0xe3, 0x44,
0x14, 0x8e, 0x9d, 0xa5, 0xc9, 0xbe, 0xa4, 0x4b, 0x76, 0x5a, 0x96, 0x90, 0x05, 0x37, 0xeb, 0x25,
0x6d, 0x14, 0x09, 0x5b, 0x0d, 0x20, 0x55, 0x88, 0x4b, 0x7e, 0xb5, 0x54, 0xd0, 0xa6, 0x72, 0xca,
0xa1, 0x08, 0x29, 0x72, 0x92, 0xa9, 0x6b, 0xd1, 0x78, 0x52, 0xcf, 0xa4, 0x72, 0xd4, 0x56, 0x48,
0x1c, 0x39, 0x21, 0xf1, 0x67, 0xf0, 0x4f, 0x70, 0xe4, 0x58, 0x89, 0x0b, 0x47, 0xd4, 0xf0, 0x47,
0x70, 0x44, 0x1e, 0x4f, 0x12, 0x27, 0x75, 0xda, 0x8a, 0x53, 0xde, 0x64, 0xbe, 0xf7, 0xbd, 0xef,
0x7d, 0xf3, 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 0x7f, 0x7e, 0x95, 0xf3,
0xea, 0x6b, 0x3d, 0xe2, 0xd9, 0x16, 0xe0, 0x2f, 0xa4, 0x12, 0xba, 0x80, 0x77, 0xf8, 0x79, 0xa2,
0x8d, 0x08, 0xd6, 0xf0, 0x34, 0xe4, 0xf2, 0xcb, 0x01, 0xa2, 0x66, 0x81, 0xd7, 0xdc, 0x40, 0x1f,
0xe9, 0x51, 0x6f, 0x36, 0xd5, 0xaf, 0xfc, 0x09, 0xba, 0x41, 0x3f, 0x42, 0x2a, 0x74, 0x17, 0x51,
0xe1, 0xa1, 0x2b, 0x3c, 0x2b, 0xbf, 0xf9, 0x18, 0x4c, 0x88, 0x78, 0xc3, 0x45, 0xbc, 0x56, 0x5f,
0x45, 0x8b, 0xf0, 0x7b, 0xbe, 0x86, 0x54, 0xe8, 0x15, 0x8d, 0x14, 0x70, 0xff, 0x9b, 0x10, 0x29,
0x20, 0xe2, 0x31, 0x56, 0x15, 0x2e, 0x20, 0x8b, 0x96, 0x08, 0xa8, 0xd6, 0xfe, 0xb8, 0x53, 0xa4,
0xdb, 0x3b, 0x45, 0xfa, 0xfb, 0x4e, 0x91, 0x7e, 0x19, 0x2b, 0xb1, 0xdf, 0xc7, 0x8a, 0x74, 0x3b,
0x56, 0x62, 0x7f, 0x8d, 0x95, 0xd8, 0x77, 0x05, 0xcb, 0x66, 0x67, 0xc3, 0x8e, 0xd6, 0x25, 0xfd,
0x49, 0x7e, 0xf0, 0xf3, 0x09, 0xed, 0xfd, 0xa0, 0xb3, 0xd1, 0x00, 0xfb, 0x84, 0x9d, 0x15, 0xfe,
0xf9, 0xfa, 0xf4, 0xbf, 0x00, 0x00, 0x00, 0xff, 0xff, 0x7b, 0x64, 0xf5, 0xff, 0x95, 0x07, 0x00,
0x00,
// 831 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x55, 0x41, 0x8f, 0xdb, 0x44,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0x40, 0x43, 0x1b, 0x04, 0xd8, 0xcd, 0xdf, 0x2f, 0x75, 0xe5, 0xe2, 0x52,
0x57, 0xfe, 0xba, 0xd4, 0x95, 0x9f, 0x67, 0xfa, 0xd6, 0x6f, 0x33, 0x5d, 0xb9, 0x98, 0xe9, 0x5b,
0x7f, 0xce, 0xf4, 0xad, 0x6f, 0x2b, 0xae, 0xc7, 0x4f, 0x26, 0x7d, 0x73, 0x40, 0x47, 0xf3, 0xfc,
0xf8, 0xe7, 0x43, 0x36, 0xfc, 0xde, 0xe2, 0xd3, 0x31, 0x89, 0x08, 0xfb, 0xdb, 0xe2, 0xeb, 0xf6,
0xd1, 0xbf, 0x01, 0x00, 0x00, 0xff, 0xff, 0xe4, 0x86, 0xcd, 0x5c, 0xb4, 0x07, 0x00, 0x00,
}
// Reference imports to suppress errors if they are not otherwise used.
@@ -1022,6 +1033,13 @@ func (m *SimulateRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) {
_ = i
var l int
_ = l
if len(m.TxBytes) > 0 {
i -= len(m.TxBytes)
copy(dAtA[i:], m.TxBytes)
i = encodeVarintService(dAtA, i, uint64(len(m.TxBytes)))
i--
dAtA[i] = 0x12
}
if m.Tx != nil {
{
size, err := m.Tx.MarshalToSizedBuffer(dAtA[:i])
@@ -1258,6 +1276,10 @@ func (m *SimulateRequest) Size() (n int) {
l = m.Tx.Size()
n += 1 + l + sovService(uint64(l))
}
l = len(m.TxBytes)
if l > 0 {
n += 1 + l + sovService(uint64(l))
}
return n
}
@@ -1859,6 +1881,40 @@ func (m *SimulateRequest) Unmarshal(dAtA []byte) error {
return err
}
iNdEx = postIndex
case 2:
if wireType != 2 {
return fmt.Errorf("proto: wrong wireType = %d for field TxBytes", wireType)
}
var byteLen int
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowService
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
byteLen |= int(b&0x7F) << shift
if b < 0x80 {
break
}
}
if byteLen < 0 {
return ErrInvalidLengthService
}
postIndex := iNdEx + byteLen
if postIndex < 0 {
return ErrInvalidLengthService
}
if postIndex > l {
return io.ErrUnexpectedEOF
}
m.TxBytes = append(m.TxBytes[:0], dAtA[iNdEx:postIndex]...)
if m.TxBytes == nil {
m.TxBytes = []byte{}
}
iNdEx = postIndex
default:
iNdEx = preIndex
skippy, err := skipService(dAtA[iNdEx:])