402 bug asset query does not repsect lookupperiodinmin value (#405)

* chore: remove unused asset.proto and asset.pb.go files
* feat: add AssetByAddress store functionality
* fix: asset query now returns numElements passed in req
* chore: add migration for new store mechanics
* chore: set upgradehandler for assetmodule migration
* chore: removed obsolete GetCIDsByAddress function
* chore: adjust cmd usage
---------

Signed-off-by: Lorenz Herzberger <lorenzherzberger@gmail.com>
This commit is contained in:
Lorenz Herzberger 2024-06-06 14:39:05 +02:00 committed by GitHub
parent 1462b6ee88
commit 468fbb5305
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
17 changed files with 241 additions and 407 deletions

View File

@ -996,4 +996,7 @@ func (app *App) setupUpgradeHandlers() {
fromVM[machinemoduletypes.ModuleName] = machinemodule.AppModule{}.ConsensusVersion()
return app.mm.RunMigrations(ctx, app.configurator, fromVM)
})
app.UpgradeKeeper.SetUpgradeHandler("v0.10.0", func(ctx sdk.Context, _ upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) {
return app.mm.RunMigrations(ctx, app.configurator, fromVM)
})
}

View File

@ -46437,7 +46437,7 @@ paths:
}
tags:
- Query
/planetmint/asset/address/{address}/{lookupPeriodInMin}:
/planetmint/asset/address/{address}/{numElements}:
get:
summary: Queries a list of GetCIDsByAddress items.
operationId: PlanetmintgoAssetGetCIDsByAddress
@ -46502,7 +46502,7 @@ paths:
in: path
required: true
type: string
- name: lookupPeriodInMin
- name: numElements
in: path
required: true
type: string

View File

@ -1,8 +0,0 @@
syntax = "proto3";
package planetmintgo.asset;
option go_package = "github.com/planetmint/planetmint-go/x/asset/types";
message Asset {
string cid = 1;
}

View File

@ -20,7 +20,7 @@ service Query {
// Queries a list of GetCIDsByAddress items.
rpc GetCIDsByAddress (QueryGetCIDsByAddressRequest) returns (QueryGetCIDsByAddressResponse) {
option (google.api.http).get = "/planetmint/asset/address/{address}/{lookupPeriodInMin}";
option (google.api.http).get = "/planetmint/asset/address/{address}/{numElements}";
}
@ -42,7 +42,7 @@ message QueryParamsResponse {
message QueryGetCIDsByAddressRequest {
string address = 1;
uint64 lookupPeriodInMin = 2;
uint64 numElements = 2;
cosmos.base.query.v1beta1.PageRequest pagination = 3;
}

View File

@ -19,6 +19,19 @@ func DeserializeInt64(value []byte) int64 {
return int64(integer - 1)
}
func SerializeUint64(value uint64) []byte {
buf := make([]byte, 8)
// Adding 1 because 0 will be interpreted as nil, which is an invalid key
binary.BigEndian.PutUint64(buf, value+1)
return buf
}
func DeserializeUint64(value []byte) uint64 {
integer := binary.BigEndian.Uint64(value)
// Subtract 1 because addition in serialization
return integer - 1
}
func SerializeString(value string) []byte {
byteArray := []byte(value)
return byteArray

View File

@ -14,12 +14,12 @@ var _ = strconv.Itoa(0)
func CmdGetByAddress() *cobra.Command {
cmd := &cobra.Command{
Use: "address [address] [lookup-period-in-min]",
Use: "address [address] [num-elements]",
Short: "Query for assets by address",
Args: cobra.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) (err error) {
reqAddress := args[0]
reqLookupPeriodInMin, err := cast.ToUint64E(args[1])
reqNumElements, err := cast.ToUint64E(args[1])
if err != nil {
return err
}
@ -34,7 +34,7 @@ func CmdGetByAddress() *cobra.Command {
params := &types.QueryGetCIDsByAddressRequest{
Address: reqAddress,
LookupPeriodInMin: reqLookupPeriodInMin,
NumElements: reqNumElements,
}
pageReq, err := client.ReadPageRequest(cmd.Flags())

View File

@ -8,9 +8,36 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
)
func (k Keeper) setAddresAssetCount(ctx sdk.Context, address string, count uint64) {
store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.AssetKey))
store.Set(types.AddressCountKey(address), util.SerializeUint64(count))
}
func (k Keeper) GetAddressAssetCount(ctx sdk.Context, address string) (count uint64, found bool) {
store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.AssetKey))
countBytes := store.Get(types.AddressCountKey(address))
if countBytes == nil {
return 0, false
}
return util.DeserializeUint64(countBytes), true
}
func (k Keeper) incrementAddressAssetCount(ctx sdk.Context, address string) uint64 {
count, _ := k.GetAddressAssetCount(ctx, address)
k.setAddresAssetCount(ctx, address, count+1)
return count + 1
}
func (k Keeper) StoreAddressAsset(ctx sdk.Context, msg types.MsgNotarizeAsset) {
store := prefix.NewStore(ctx.KVStore(k.storeKey), types.AddressPrefix(msg.GetCreator()))
count := k.incrementAddressAssetCount(ctx, msg.GetCreator())
store.Set(util.SerializeUint64(count), []byte(msg.GetCid()))
}
func (k Keeper) StoreAsset(ctx sdk.Context, msg types.MsgNotarizeAsset) {
store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.AssetKey))
store.Set(util.SerializeString(msg.GetCid()), []byte(msg.GetCreator()))
k.StoreAddressAsset(ctx, msg)
}
func (k Keeper) GetAsset(ctx sdk.Context, cid string) (msg types.MsgNotarizeAsset, found bool) {
@ -24,19 +51,23 @@ func (k Keeper) GetAsset(ctx sdk.Context, cid string) (msg types.MsgNotarizeAsse
return msg, true
}
func (k Keeper) GetCidsByAddress(ctx sdk.Context, address string) (cids []string, found bool) {
store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.AssetKey))
reverseIterator := store.ReverseIterator(nil, nil)
defer reverseIterator.Close()
for ; reverseIterator.Valid(); reverseIterator.Next() {
addressBytes := reverseIterator.Value()
cidBytes := reverseIterator.Key()
if string(addressBytes) == address {
cids = append(cids, string(cidBytes))
break
func (k Keeper) GetAssetByAddressAndID(ctx sdk.Context, address string, id uint64) (cid string, found bool) {
store := prefix.NewStore(ctx.KVStore(k.storeKey), types.AddressPrefix(address))
cidBytes := store.Get(util.SerializeUint64(id))
if cidBytes == nil {
return cid, false
}
return string(cidBytes), true
}
func (k Keeper) GetAssetsByAddress(ctx sdk.Context, address string, start []byte, end []byte) (cids []string, found bool) {
store := prefix.NewStore(ctx.KVStore(k.storeKey), types.AddressPrefix(address))
iterator := store.ReverseIterator(start, end)
defer iterator.Close()
for ; iterator.Valid(); iterator.Next() {
cidBytes := iterator.Value()
cids = append(cids, string(cidBytes))
}
return cids, len(cids) > 0
}

View File

@ -6,6 +6,7 @@ import (
"testing"
keepertest "github.com/planetmint/planetmint-go/testutil/keeper"
"github.com/planetmint/planetmint-go/util"
"github.com/planetmint/planetmint-go/x/asset/keeper"
"github.com/planetmint/planetmint-go/x/asset/types"
@ -39,14 +40,43 @@ func TestGetAssetbyCid(t *testing.T) {
}
}
func TestGetAssetByPubKeys(t *testing.T) {
func TestAssetCount(t *testing.T) {
t.Parallel()
keeper, ctx := keepertest.AssetKeeper(t)
_ = createNAsset(keeper, ctx, 10)
assets, found := keeper.GetCidsByAddress(ctx, "plmnt_address")
numItems := 10
items := createNAsset(keeper, ctx, numItems)
count, found := keeper.GetAddressAssetCount(ctx, items[0].Creator)
assert.True(t, found)
assert.Equal(t, len(assets), 1) // TODO: just for HF: before 5
assets, found = keeper.GetCidsByAddress(ctx, "plmnt_address1")
assert.Equal(t, uint64(5), count)
count, found = keeper.GetAddressAssetCount(ctx, items[1].Creator)
assert.True(t, found)
assert.Equal(t, len(assets), 1) // TODO: just for HF: before 5
assert.Equal(t, uint64(5), count)
}
func TestGetAssetByAddressAndID(t *testing.T) {
t.Parallel()
keeper, ctx := keepertest.AssetKeeper(t)
items := createNAsset(keeper, ctx, 1)
cid, found := keeper.GetAssetByAddressAndID(ctx, items[0].Creator, 1)
assert.True(t, found)
assert.Equal(t, items[0].Cid, cid)
}
func TestGetAssetsByAddress(t *testing.T) {
t.Parallel()
keeper, ctx := keepertest.AssetKeeper(t)
items := createNAsset(keeper, ctx, 10)
cids, found := keeper.GetAssetsByAddress(ctx, items[0].Creator, nil, nil)
assert.True(t, found)
assert.Equal(t, items[8].Cid, cids[0])
assert.Equal(t, items[4].Cid, cids[2])
cids, found = keeper.GetAssetsByAddress(ctx, items[1].Creator, nil, nil)
assert.True(t, found)
assert.Equal(t, items[9].Cid, cids[0])
assert.Equal(t, items[5].Cid, cids[2])
cids, found = keeper.GetAssetsByAddress(ctx, items[0].Creator, util.SerializeUint64(3), nil)
assert.True(t, found)
assert.Equal(t, 3, len(cids))
assert.Equal(t, items[8].Cid, cids[0])
}

View File

@ -0,0 +1,18 @@
package keeper
import (
sdk "github.com/cosmos/cosmos-sdk/types"
v2 "github.com/planetmint/planetmint-go/x/asset/migrations/v2"
)
type Migrator struct {
keeper Keeper
}
func NewMigrator(keeper Keeper) Migrator {
return Migrator{keeper: keeper}
}
func (m Migrator) Migrate1to2(ctx sdk.Context) error {
return v2.MigrateStore(ctx, m.keeper.storeKey, m.keeper.cdc)
}

View File

@ -5,6 +5,7 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/planetmint/planetmint-go/errormsg"
"github.com/planetmint/planetmint-go/util"
"github.com/planetmint/planetmint-go/x/asset/types"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
@ -17,7 +18,7 @@ func (k Keeper) GetCIDsByAddress(goCtx context.Context, req *types.QueryGetCIDsB
ctx := sdk.UnwrapSDKContext(goCtx)
cids, found := k.GetCidsByAddress(ctx, req.GetAddress())
cids, found := k.GetAssetsByAddress(ctx, req.GetAddress(), nil, util.SerializeUint64(req.GetNumElements()))
if !found {
return nil, status.Error(codes.NotFound, "no CIDs found")
}

View File

@ -4,6 +4,7 @@ import (
"testing"
keepertest "github.com/planetmint/planetmint-go/testutil/keeper"
"github.com/planetmint/planetmint-go/util"
"github.com/planetmint/planetmint-go/x/asset/types"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
@ -16,7 +17,7 @@ func TestGetNotarizedAssetByAddress(t *testing.T) {
keeper, ctx := keepertest.AssetKeeper(t)
wctx := sdk.WrapSDKContext(ctx)
_ = createNAsset(keeper, ctx, 10)
assets, _ := keeper.GetCidsByAddress(ctx, "plmnt_address")
assets, _ := keeper.GetAssetsByAddress(ctx, "plmnt_address", nil, util.SerializeUint64(3))
for _, tc := range []struct {
desc string
request *types.QueryGetCIDsByAddressRequest
@ -25,7 +26,7 @@ func TestGetNotarizedAssetByAddress(t *testing.T) {
}{
{
desc: "cid found",
request: &types.QueryGetCIDsByAddressRequest{Address: "plmnt_address"},
request: &types.QueryGetCIDsByAddressRequest{Address: "plmnt_address", NumElements: 3},
response: &types.QueryGetCIDsByAddressResponse{Cids: assets},
},
{

View File

@ -0,0 +1,39 @@
package v2
import (
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/store/prefix"
storetypes "github.com/cosmos/cosmos-sdk/store/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/planetmint/planetmint-go/util"
"github.com/planetmint/planetmint-go/x/asset/types"
)
func MigrateStore(ctx sdk.Context, storeKey storetypes.StoreKey, _ codec.BinaryCodec) error {
store := prefix.NewStore(ctx.KVStore(storeKey), types.KeyPrefix(types.AssetKey))
mapping := make(map[string][][]byte)
// read all cids
iterator := store.Iterator(nil, nil)
defer iterator.Close()
for ; iterator.Valid(); iterator.Next() {
addressBytes := iterator.Value()
cidBytes := iterator.Key()
// map all cids by address
mapping[string(addressBytes)] = append(mapping[string(addressBytes)], cidBytes)
}
// store all cids with new key
for address, cids := range mapping {
assetByAddressStore := prefix.NewStore(ctx.KVStore(storeKey), types.AddressPrefix(address))
for i, cid := range cids {
assetByAddressStore.Set(util.SerializeUint64(uint64(i)), cid)
}
addressAssetCountStore := prefix.NewStore(ctx.KVStore(storeKey), types.KeyPrefix(types.AssetKey))
addressAssetCountStore.Set(types.AddressCountKey(address), util.SerializeUint64(uint64(len(cids))))
}
return nil
}

View File

@ -116,6 +116,11 @@ func NewAppModule(
func (am AppModule) RegisterServices(cfg module.Configurator) {
types.RegisterMsgServer(cfg.MsgServer(), keeper.NewMsgServerImpl(am.keeper))
types.RegisterQueryServer(cfg.QueryServer(), am.keeper)
m := keeper.NewMigrator(am.keeper)
if err := cfg.RegisterMigration(types.ModuleName, 1, m.Migrate1to2); err != nil {
panic(fmt.Errorf("failed to register migration of %s to v2: %w", types.ModuleName, err))
}
}
// RegisterInvariants registers the invariants of the module. If an invariant deviates from its predicted value, the InvariantRegistry triggers appropriate logic (most often the chain will be halted)
@ -141,7 +146,7 @@ func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.Raw
}
// ConsensusVersion is a sequence number for state-breaking change of the module. It should be incremented on each consensus-breaking change introduced by the module. To avoid wrong/empty versions, the initial version should be set to 1
func (AppModule) ConsensusVersion() uint64 { return 1 }
func (AppModule) ConsensusVersion() uint64 { return 2 }
// BeginBlock contains the logic that is automatically triggered at the beginning of each block
func (am AppModule) BeginBlock(_ sdk.Context, _ abci.RequestBeginBlock) {

View File

@ -1,313 +0,0 @@
// Code generated by protoc-gen-gogo. DO NOT EDIT.
// source: planetmintgo/asset/asset.proto
package types
import (
fmt "fmt"
proto "github.com/cosmos/gogoproto/proto"
io "io"
math "math"
math_bits "math/bits"
)
// Reference imports to suppress errors if they are not otherwise used.
var _ = proto.Marshal
var _ = fmt.Errorf
var _ = math.Inf
// This is a compile-time assertion to ensure that this generated file
// is compatible with the proto package it is being compiled against.
// A compilation error at this line likely means your copy of the
// proto package needs to be updated.
const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package
type Asset struct {
Cid string `protobuf:"bytes,1,opt,name=cid,proto3" json:"cid,omitempty"`
}
func (m *Asset) Reset() { *m = Asset{} }
func (m *Asset) String() string { return proto.CompactTextString(m) }
func (*Asset) ProtoMessage() {}
func (*Asset) Descriptor() ([]byte, []int) {
return fileDescriptor_03dd37a25f684e6e, []int{0}
}
func (m *Asset) XXX_Unmarshal(b []byte) error {
return m.Unmarshal(b)
}
func (m *Asset) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
if deterministic {
return xxx_messageInfo_Asset.Marshal(b, m, deterministic)
} else {
b = b[:cap(b)]
n, err := m.MarshalToSizedBuffer(b)
if err != nil {
return nil, err
}
return b[:n], nil
}
}
func (m *Asset) XXX_Merge(src proto.Message) {
xxx_messageInfo_Asset.Merge(m, src)
}
func (m *Asset) XXX_Size() int {
return m.Size()
}
func (m *Asset) XXX_DiscardUnknown() {
xxx_messageInfo_Asset.DiscardUnknown(m)
}
var xxx_messageInfo_Asset proto.InternalMessageInfo
func (m *Asset) GetCid() string {
if m != nil {
return m.Cid
}
return ""
}
func init() {
proto.RegisterType((*Asset)(nil), "planetmintgo.asset.Asset")
}
func init() { proto.RegisterFile("planetmintgo/asset/asset.proto", fileDescriptor_03dd37a25f684e6e) }
var fileDescriptor_03dd37a25f684e6e = []byte{
// 143 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x92, 0x2b, 0xc8, 0x49, 0xcc,
0x4b, 0x2d, 0xc9, 0xcd, 0xcc, 0x2b, 0x49, 0xcf, 0xd7, 0x4f, 0x2c, 0x2e, 0x4e, 0x2d, 0x81, 0x90,
0x7a, 0x05, 0x45, 0xf9, 0x25, 0xf9, 0x42, 0x42, 0xc8, 0xf2, 0x7a, 0x60, 0x19, 0x25, 0x49, 0x2e,
0x56, 0x47, 0x10, 0x43, 0x48, 0x80, 0x8b, 0x39, 0x39, 0x33, 0x45, 0x82, 0x51, 0x81, 0x51, 0x83,
0x33, 0x08, 0xc4, 0x74, 0xf2, 0x3e, 0xf1, 0x48, 0x8e, 0xf1, 0xc2, 0x23, 0x39, 0xc6, 0x07, 0x8f,
0xe4, 0x18, 0x27, 0x3c, 0x96, 0x63, 0xb8, 0xf0, 0x58, 0x8e, 0xe1, 0xc6, 0x63, 0x39, 0x86, 0x28,
0xc3, 0xf4, 0xcc, 0x92, 0x8c, 0xd2, 0x24, 0xbd, 0xe4, 0xfc, 0x5c, 0x7d, 0x84, 0x99, 0x48, 0x4c,
0xdd, 0xf4, 0x7c, 0xfd, 0x0a, 0xa8, 0x0b, 0x4a, 0x2a, 0x0b, 0x52, 0x8b, 0x93, 0xd8, 0xc0, 0x4e,
0x30, 0x06, 0x04, 0x00, 0x00, 0xff, 0xff, 0xbc, 0x38, 0x8c, 0xdf, 0xa4, 0x00, 0x00, 0x00,
}
func (m *Asset) Marshal() (dAtA []byte, err error) {
size := m.Size()
dAtA = make([]byte, size)
n, err := m.MarshalToSizedBuffer(dAtA[:size])
if err != nil {
return nil, err
}
return dAtA[:n], nil
}
func (m *Asset) MarshalTo(dAtA []byte) (int, error) {
size := m.Size()
return m.MarshalToSizedBuffer(dAtA[:size])
}
func (m *Asset) MarshalToSizedBuffer(dAtA []byte) (int, error) {
i := len(dAtA)
_ = i
var l int
_ = l
if len(m.Cid) > 0 {
i -= len(m.Cid)
copy(dAtA[i:], m.Cid)
i = encodeVarintAsset(dAtA, i, uint64(len(m.Cid)))
i--
dAtA[i] = 0xa
}
return len(dAtA) - i, nil
}
func encodeVarintAsset(dAtA []byte, offset int, v uint64) int {
offset -= sovAsset(v)
base := offset
for v >= 1<<7 {
dAtA[offset] = uint8(v&0x7f | 0x80)
v >>= 7
offset++
}
dAtA[offset] = uint8(v)
return base
}
func (m *Asset) Size() (n int) {
if m == nil {
return 0
}
var l int
_ = l
l = len(m.Cid)
if l > 0 {
n += 1 + l + sovAsset(uint64(l))
}
return n
}
func sovAsset(x uint64) (n int) {
return (math_bits.Len64(x|1) + 6) / 7
}
func sozAsset(x uint64) (n int) {
return sovAsset(uint64((x << 1) ^ uint64((int64(x) >> 63))))
}
func (m *Asset) Unmarshal(dAtA []byte) error {
l := len(dAtA)
iNdEx := 0
for iNdEx < l {
preIndex := iNdEx
var wire uint64
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowAsset
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
wire |= uint64(b&0x7F) << shift
if b < 0x80 {
break
}
}
fieldNum := int32(wire >> 3)
wireType := int(wire & 0x7)
if wireType == 4 {
return fmt.Errorf("proto: Asset: wiretype end group for non-group")
}
if fieldNum <= 0 {
return fmt.Errorf("proto: Asset: illegal tag %d (wire type %d)", fieldNum, wire)
}
switch fieldNum {
case 1:
if wireType != 2 {
return fmt.Errorf("proto: wrong wireType = %d for field Cid", wireType)
}
var stringLen uint64
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowAsset
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
stringLen |= uint64(b&0x7F) << shift
if b < 0x80 {
break
}
}
intStringLen := int(stringLen)
if intStringLen < 0 {
return ErrInvalidLengthAsset
}
postIndex := iNdEx + intStringLen
if postIndex < 0 {
return ErrInvalidLengthAsset
}
if postIndex > l {
return io.ErrUnexpectedEOF
}
m.Cid = string(dAtA[iNdEx:postIndex])
iNdEx = postIndex
default:
iNdEx = preIndex
skippy, err := skipAsset(dAtA[iNdEx:])
if err != nil {
return err
}
if (skippy < 0) || (iNdEx+skippy) < 0 {
return ErrInvalidLengthAsset
}
if (iNdEx + skippy) > l {
return io.ErrUnexpectedEOF
}
iNdEx += skippy
}
}
if iNdEx > l {
return io.ErrUnexpectedEOF
}
return nil
}
func skipAsset(dAtA []byte) (n int, err error) {
l := len(dAtA)
iNdEx := 0
depth := 0
for iNdEx < l {
var wire uint64
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return 0, ErrIntOverflowAsset
}
if iNdEx >= l {
return 0, io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
wire |= (uint64(b) & 0x7F) << shift
if b < 0x80 {
break
}
}
wireType := int(wire & 0x7)
switch wireType {
case 0:
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return 0, ErrIntOverflowAsset
}
if iNdEx >= l {
return 0, io.ErrUnexpectedEOF
}
iNdEx++
if dAtA[iNdEx-1] < 0x80 {
break
}
}
case 1:
iNdEx += 8
case 2:
var length int
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return 0, ErrIntOverflowAsset
}
if iNdEx >= l {
return 0, io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
length |= (int(b) & 0x7F) << shift
if b < 0x80 {
break
}
}
if length < 0 {
return 0, ErrInvalidLengthAsset
}
iNdEx += length
case 3:
depth++
case 4:
if depth == 0 {
return 0, ErrUnexpectedEndOfGroupAsset
}
depth--
case 5:
iNdEx += 4
default:
return 0, fmt.Errorf("proto: illegal wireType %d", wireType)
}
if iNdEx < 0 {
return 0, ErrInvalidLengthAsset
}
if depth == 0 {
return iNdEx, nil
}
}
return 0, io.ErrUnexpectedEOF
}
var (
ErrInvalidLengthAsset = fmt.Errorf("proto: negative length found during unmarshaling")
ErrIntOverflowAsset = fmt.Errorf("proto: integer overflow")
ErrUnexpectedEndOfGroupAsset = fmt.Errorf("proto: unexpected end of group")
)

View File

@ -14,8 +14,23 @@ const (
MemStoreKey = "mem_asset"
AssetKey = "Asset/value/"
CountKey = "count/"
)
func AddressCountKey(address string) (prefix []byte) {
addressPrefix := AddressPrefix(address)
prefix = append(prefix, addressPrefix...)
prefix = append(prefix, []byte(CountKey)...)
return
}
func AddressPrefix(address string) (prefix []byte) {
addressBytes := []byte(address)
prefix = append(prefix, addressBytes...)
prefix = append(prefix, []byte("/")...)
return
}
func KeyPrefix(p string) []byte {
return []byte(p)
}

View File

@ -115,7 +115,7 @@ func (m *QueryParamsResponse) GetParams() Params {
type QueryGetCIDsByAddressRequest struct {
Address string `protobuf:"bytes,1,opt,name=address,proto3" json:"address,omitempty"`
LookupPeriodInMin uint64 `protobuf:"varint,2,opt,name=lookupPeriodInMin,proto3" json:"lookupPeriodInMin,omitempty"`
NumElements uint64 `protobuf:"varint,2,opt,name=numElements,proto3" json:"numElements,omitempty"`
Pagination *query.PageRequest `protobuf:"bytes,3,opt,name=pagination,proto3" json:"pagination,omitempty"`
}
@ -159,9 +159,9 @@ func (m *QueryGetCIDsByAddressRequest) GetAddress() string {
return ""
}
func (m *QueryGetCIDsByAddressRequest) GetLookupPeriodInMin() uint64 {
func (m *QueryGetCIDsByAddressRequest) GetNumElements() uint64 {
if m != nil {
return m.LookupPeriodInMin
return m.NumElements
}
return 0
}
@ -333,42 +333,41 @@ func init() {
func init() { proto.RegisterFile("planetmintgo/asset/query.proto", fileDescriptor_5832a953a81817c0) }
var fileDescriptor_5832a953a81817c0 = []byte{
// 547 bytes of a gzipped FileDescriptorProto
// 541 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x54, 0xcf, 0x6e, 0xd3, 0x30,
0x18, 0x6f, 0xda, 0x52, 0x34, 0x73, 0xd9, 0xcc, 0x0e, 0x51, 0xd8, 0xb2, 0x2a, 0x48, 0x5b, 0x85,
0x20, 0x26, 0xe5, 0x00, 0x9c, 0xd0, 0x0a, 0x62, 0x9a, 0xf8, 0x57, 0x72, 0xe4, 0xe6, 0x26, 0x56,
0xb0, 0x68, 0xed, 0x2c, 0x76, 0x11, 0xa5, 0xf4, 0xc2, 0x13, 0x20, 0xf1, 0x00, 0xbc, 0x01, 0x67,
0x1e, 0x61, 0xc7, 0x49, 0x5c, 0x38, 0x21, 0x68, 0x79, 0x10, 0x14, 0xdb, 0x55, 0x1b, 0xd2, 0x32,
0xed, 0xf6, 0xd5, 0xdf, 0xf7, 0xfb, 0xd3, 0xdf, 0xf7, 0x29, 0xc0, 0x4d, 0xfb, 0x98, 0x11, 0x39,
0xa0, 0x4c, 0x26, 0x1c, 0x61, 0x21, 0x88, 0x44, 0x27, 0x43, 0x92, 0x8d, 0xfc, 0x34, 0xe3, 0x92,
0x43, 0xb8, 0xdc, 0xf7, 0x55, 0xdf, 0xd9, 0x4e, 0x78, 0xc2, 0x55, 0x1b, 0xe5, 0x95, 0x9e, 0x74,
0x76, 0x12, 0xce, 0x93, 0x3e, 0x41, 0x38, 0xa5, 0x08, 0x33, 0xc6, 0x25, 0x96, 0x94, 0x33, 0x61,
0xba, 0x37, 0x22, 0x2e, 0x06, 0x5c, 0xa0, 0x1e, 0x16, 0x44, 0x0b, 0xa0, 0xb7, 0x41, 0x8f, 0x48,
0x1c, 0xa0, 0x14, 0x27, 0x94, 0xa9, 0x61, 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 0x00, 0xff, 0xff, 0x76, 0xa1, 0xdb, 0x5c, 0x05,
0x05, 0x00, 0x00,
0x18, 0x6f, 0xda, 0x51, 0x34, 0xef, 0x32, 0xcc, 0x0e, 0x51, 0xd8, 0xb2, 0x2a, 0x48, 0x5b, 0x85,
0x44, 0x4c, 0xba, 0x0b, 0x1c, 0x57, 0xfe, 0x4c, 0x08, 0x04, 0x23, 0x47, 0x6e, 0x6e, 0x62, 0x05,
0x4b, 0x8d, 0x9d, 0xc5, 0x2e, 0xa2, 0x94, 0x5e, 0x78, 0x02, 0x24, 0x1e, 0x00, 0x89, 0x47, 0xe0,
0x29, 0x76, 0x9c, 0xc4, 0x05, 0x09, 0x09, 0xa1, 0x96, 0x07, 0x41, 0xb1, 0x5d, 0x35, 0x21, 0x2d,
0xd3, 0x6e, 0x5f, 0xec, 0xef, 0xf7, 0xc7, 0xbf, 0xef, 0x53, 0x80, 0x9b, 0x0d, 0x31, 0x23, 0x32,
0xa5, 0x4c, 0x26, 0x1c, 0x61, 0x21, 0x88, 0x44, 0x67, 0x23, 0x92, 0x8f, 0xfd, 0x2c, 0xe7, 0x92,
0x43, 0x58, 0xbe, 0xf7, 0xd5, 0xbd, 0xb3, 0x93, 0xf0, 0x84, 0xab, 0x6b, 0x54, 0x54, 0xba, 0xd3,
0xd9, 0x4d, 0x38, 0x4f, 0x86, 0x04, 0xe1, 0x8c, 0x22, 0xcc, 0x18, 0x97, 0x58, 0x52, 0xce, 0x84,
0xb9, 0xbd, 0x13, 0x71, 0x91, 0x72, 0x81, 0x06, 0x58, 0x10, 0x2d, 0x80, 0xde, 0x06, 0x03, 0x22,
0x71, 0x80, 0x32, 0x9c, 0x50, 0xa6, 0x9a, 0x4d, 0xef, 0xfe, 0x0a, 0x4f, 0x19, 0xce, 0x71, 0x6a,
0xc8, 0xbc, 0x1d, 0x00, 0x5f, 0x15, 0x14, 0xa7, 0xea, 0x30, 0x24, 0x67, 0x23, 0x22, 0xa4, 0xf7,
0x12, 0xdc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80, 0xb6, 0x9e, 0x22, 0x3c, 0x58,
0x35, 0xe1, 0xfa, 0xc2, 0x38, 0x87, 0x97, 0xf6, 0x69, 0x43, 0x5e, 0xe7, 0xe3, 0xf7, 0x3f, 0x9f,
0x9b, 0x0e, 0xb4, 0xd1, 0x12, 0x50, 0xd9, 0x4b, 0xf8, 0xcd, 0x02, 0xdb, 0xff, 0x4e, 0x00, 0xde,
0x5b, 0xcb, 0xbf, 0x66, 0xa1, 0x9c, 0xe0, 0x0a, 0x08, 0xe3, 0xed, 0x81, 0xf2, 0x76, 0x04, 0x83,
0xba, 0x37, 0x93, 0x11, 0x9a, 0x98, 0x62, 0x8a, 0x26, 0xa5, 0x0d, 0x9c, 0xc2, 0x2f, 0x16, 0xb8,
0x51, 0x9b, 0x02, 0xfc, 0xaf, 0x87, 0x95, 0x43, 0x76, 0x7a, 0x57, 0x81, 0x18, 0xdf, 0xb7, 0x95,
0xef, 0x3d, 0x78, 0xab, 0xee, 0x3b, 0xa2, 0x31, 0x9a, 0x44, 0x34, 0x9e, 0xf6, 0x9f, 0x9d, 0xcf,
0x5c, 0xeb, 0x62, 0xe6, 0x5a, 0xbf, 0x67, 0xae, 0xf5, 0x69, 0xee, 0x36, 0x2e, 0xe6, 0x6e, 0xe3,
0xc7, 0xdc, 0x6d, 0xbc, 0x0e, 0x12, 0x2a, 0xdf, 0x8c, 0x06, 0x7e, 0xc4, 0xd3, 0x32, 0xc1, 0xb2,
0xbc, 0x9b, 0x70, 0xf4, 0xce, 0x10, 0xca, 0x71, 0x46, 0xc4, 0xa0, 0xad, 0x7e, 0x1e, 0x47, 0x7f,
0x03, 0x00, 0x00, 0xff, 0xff, 0xb3, 0x7e, 0xf6, 0x2a, 0xf3, 0x04, 0x00, 0x00,
}
// Reference imports to suppress errors if they are not otherwise used.
@ -617,8 +616,8 @@ func (m *QueryGetCIDsByAddressRequest) MarshalToSizedBuffer(dAtA []byte) (int, e
i--
dAtA[i] = 0x1a
}
if m.LookupPeriodInMin != 0 {
i = encodeVarintQuery(dAtA, i, uint64(m.LookupPeriodInMin))
if m.NumElements != 0 {
i = encodeVarintQuery(dAtA, i, uint64(m.NumElements))
i--
dAtA[i] = 0x10
}
@ -784,8 +783,8 @@ func (m *QueryGetCIDsByAddressRequest) Size() (n int) {
if l > 0 {
n += 1 + l + sovQuery(uint64(l))
}
if m.LookupPeriodInMin != 0 {
n += 1 + sovQuery(uint64(m.LookupPeriodInMin))
if m.NumElements != 0 {
n += 1 + sovQuery(uint64(m.NumElements))
}
if m.Pagination != nil {
l = m.Pagination.Size()
@ -1045,9 +1044,9 @@ func (m *QueryGetCIDsByAddressRequest) Unmarshal(dAtA []byte) error {
iNdEx = postIndex
case 2:
if wireType != 0 {
return fmt.Errorf("proto: wrong wireType = %d for field LookupPeriodInMin", wireType)
return fmt.Errorf("proto: wrong wireType = %d for field NumElements", wireType)
}
m.LookupPeriodInMin = 0
m.NumElements = 0
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowQuery
@ -1057,7 +1056,7 @@ func (m *QueryGetCIDsByAddressRequest) Unmarshal(dAtA []byte) error {
}
b := dAtA[iNdEx]
iNdEx++
m.LookupPeriodInMin |= uint64(b&0x7F) << shift
m.NumElements |= uint64(b&0x7F) << shift
if b < 0x80 {
break
}

View File

@ -52,7 +52,7 @@ func local_request_Query_Params_0(ctx context.Context, marshaler runtime.Marshal
}
var (
filter_Query_GetCIDsByAddress_0 = &utilities.DoubleArray{Encoding: map[string]int{"address": 0, "lookupPeriodInMin": 1}, Base: []int{1, 1, 2, 0, 0}, Check: []int{0, 1, 1, 2, 3}}
filter_Query_GetCIDsByAddress_0 = &utilities.DoubleArray{Encoding: map[string]int{"address": 0, "numElements": 1}, Base: []int{1, 1, 2, 0, 0}, Check: []int{0, 1, 1, 2, 3}}
)
func request_Query_GetCIDsByAddress_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
@ -77,15 +77,15 @@ func request_Query_GetCIDsByAddress_0(ctx context.Context, marshaler runtime.Mar
return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "address", err)
}
val, ok = pathParams["lookupPeriodInMin"]
val, ok = pathParams["numElements"]
if !ok {
return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "lookupPeriodInMin")
return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "numElements")
}
protoReq.LookupPeriodInMin, err = runtime.Uint64(val)
protoReq.NumElements, err = runtime.Uint64(val)
if err != nil {
return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "lookupPeriodInMin", err)
return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "numElements", err)
}
if err := req.ParseForm(); err != nil {
@ -122,15 +122,15 @@ func local_request_Query_GetCIDsByAddress_0(ctx context.Context, marshaler runti
return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "address", err)
}
val, ok = pathParams["lookupPeriodInMin"]
val, ok = pathParams["numElements"]
if !ok {
return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "lookupPeriodInMin")
return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "numElements")
}
protoReq.LookupPeriodInMin, err = runtime.Uint64(val)
protoReq.NumElements, err = runtime.Uint64(val)
if err != nil {
return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "lookupPeriodInMin", err)
return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "numElements", err)
}
if err := req.ParseForm(); err != nil {
@ -381,7 +381,7 @@ func RegisterQueryHandlerClient(ctx context.Context, mux *runtime.ServeMux, clie
var (
pattern_Query_Params_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"planetmint", "asset", "params"}, "", runtime.AssumeColonVerbOpt(true)))
pattern_Query_GetCIDsByAddress_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 1, 0, 4, 1, 5, 2, 1, 0, 4, 1, 5, 3}, []string{"planetmint", "asset", "address", "lookupPeriodInMin"}, "", runtime.AssumeColonVerbOpt(true)))
pattern_Query_GetCIDsByAddress_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 1, 0, 4, 1, 5, 2, 1, 0, 4, 1, 5, 3}, []string{"planetmint", "asset", "address", "numElements"}, "", runtime.AssumeColonVerbOpt(true)))
pattern_Query_GetNotarizedAsset_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 1, 0, 4, 1, 5, 2}, []string{"planetmint", "asset", "cid"}, "", runtime.AssumeColonVerbOpt(true)))
)