diff --git a/proto/kujira/oracle/extension.proto b/proto/kujira/oracle/extension.proto index 18d477b1..a680b229 100644 --- a/proto/kujira/oracle/extension.proto +++ b/proto/kujira/oracle/extension.proto @@ -7,12 +7,13 @@ import "tendermint/abci/types.proto"; option go_package = "github.com/Team-Kujira/core/x/oracle/types"; +message Decimal { + bytes data = 1; +} + message DenomPrice { string denom = 1; - string price = 2 [ - (gogoproto.nullable) = false, - (gogoproto.customtype) = "cosmossdk.io/math.Int" - ]; + Decimal price = 2 [(gogoproto.nullable) = false]; } message VoteExtension { diff --git a/x/oracle/abci/proposal.go b/x/oracle/abci/proposal.go index ce67de7e..f50bc78c 100644 --- a/x/oracle/abci/proposal.go +++ b/x/oracle/abci/proposal.go @@ -257,7 +257,7 @@ func (h *ProposalHandler) GetBallotByDenom(ci abci.ExtendedCommitInfo, validator for _, denomPrice := range voteExt.Prices { base := denomPrice.Denom - price := math.LegacyNewDecFromBigIntWithPrec(denomPrice.Price.BigInt(), math.LegacyPrecision) + price := denomPrice.Price.ToMathDec() tmpPower := power if !price.IsPositive() { // Make the power of abstain vote zero diff --git a/x/oracle/abci/proposal_test.go b/x/oracle/abci/proposal_test.go index 86ca661c..fbe888ab 100644 --- a/x/oracle/abci/proposal_test.go +++ b/x/oracle/abci/proposal_test.go @@ -83,11 +83,11 @@ func TestGetBallotByDenom(t *testing.T) { Prices: []types.DenomPrice{ { Denom: "BTC", - Price: math.NewIntFromBigInt(math.LegacyNewDec(25000).BigInt()), + Price: types.NewDecimal(math.LegacyNewDec(25000)), }, { Denom: "ETH", - Price: math.NewIntFromBigInt(math.LegacyNewDec(2200).BigInt()), + Price: types.NewDecimal(math.LegacyNewDec(2200)), }, }, } @@ -96,11 +96,11 @@ func TestGetBallotByDenom(t *testing.T) { Prices: []types.DenomPrice{ { Denom: "BTC", - Price: math.NewIntFromBigInt(math.LegacyNewDec(25030).BigInt()), + Price: types.NewDecimal(math.LegacyNewDec(25030)), }, { Denom: "ETH", - Price: math.NewIntFromBigInt(math.LegacyNewDec(2180).BigInt()), + Price: types.NewDecimal(math.LegacyNewDec(2180)), }, }, } @@ -174,11 +174,11 @@ func TestComputeStakeWeightedPricesAndMissMap(t *testing.T) { Prices: []types.DenomPrice{ { Denom: "BTC", - Price: math.NewIntFromBigInt(math.LegacyNewDec(25000).BigInt()), + Price: types.NewDecimal(math.LegacyNewDec(25000)), }, { Denom: "ETH", - Price: math.NewIntFromBigInt(math.LegacyNewDec(2200).BigInt()), + Price: types.NewDecimal(math.LegacyNewDec(2200)), }, }, } @@ -187,11 +187,11 @@ func TestComputeStakeWeightedPricesAndMissMap(t *testing.T) { Prices: []types.DenomPrice{ { Denom: "BTC", - Price: math.NewIntFromBigInt(math.LegacyNewDec(25030).BigInt()), + Price: types.NewDecimal(math.LegacyNewDec(25030)), }, { Denom: "ETH", - Price: math.NewIntFromBigInt(math.LegacyNewDec(2180).BigInt()), + Price: types.NewDecimal(math.LegacyNewDec(2180)), }, }, } @@ -463,11 +463,11 @@ func TestPrepareProposal(t *testing.T) { Prices: []types.DenomPrice{ { Denom: "BTC", - Price: math.NewIntFromBigInt(math.LegacyNewDec(25000).BigInt()), + Price: types.NewDecimal(math.LegacyNewDec(25000)), }, { Denom: "ETH", - Price: math.NewIntFromBigInt(math.LegacyNewDec(2200).BigInt()), + Price: types.NewDecimal(math.LegacyNewDec(2200)), }, }, } @@ -476,11 +476,11 @@ func TestPrepareProposal(t *testing.T) { Prices: []types.DenomPrice{ { Denom: "BTC", - Price: math.NewIntFromBigInt(math.LegacyNewDec(25030).BigInt()), + Price: types.NewDecimal(math.LegacyNewDec(25030)), }, { Denom: "ETH", - Price: math.NewIntFromBigInt(math.LegacyNewDec(2180).BigInt()), + Price: types.NewDecimal(math.LegacyNewDec(2180)), }, }, } @@ -616,11 +616,11 @@ func TestProcessProposal(t *testing.T) { Prices: []types.DenomPrice{ { Denom: "BTC", - Price: math.NewIntFromBigInt(math.LegacyNewDec(25000).BigInt()), + Price: types.NewDecimal(math.LegacyNewDec(25000)), }, { Denom: "ETH", - Price: math.NewIntFromBigInt(math.LegacyNewDec(2200).BigInt()), + Price: types.NewDecimal(math.LegacyNewDec(2200)), }, }, } @@ -629,11 +629,11 @@ func TestProcessProposal(t *testing.T) { Prices: []types.DenomPrice{ { Denom: "BTC", - Price: math.NewIntFromBigInt(math.LegacyNewDec(25030).BigInt()), + Price: types.NewDecimal(math.LegacyNewDec(25030)), }, { Denom: "ETH", - Price: math.NewIntFromBigInt(math.LegacyNewDec(2180).BigInt()), + Price: types.NewDecimal(math.LegacyNewDec(2180)), }, }, } @@ -831,11 +831,11 @@ func TestPreBlocker(t *testing.T) { Prices: []types.DenomPrice{ { Denom: "BTC", - Price: math.NewIntFromBigInt(math.LegacyNewDec(25000).BigInt()), + Price: types.NewDecimal(math.LegacyNewDec(25000)), }, { Denom: "ETH", - Price: math.NewIntFromBigInt(math.LegacyNewDec(2200).BigInt()), + Price: types.NewDecimal(math.LegacyNewDec(2200)), }, }, } @@ -844,11 +844,11 @@ func TestPreBlocker(t *testing.T) { Prices: []types.DenomPrice{ { Denom: "BTC", - Price: math.NewIntFromBigInt(math.LegacyNewDec(25030).BigInt()), + Price: types.NewDecimal(math.LegacyNewDec(25030)), }, { Denom: "ETH", - Price: math.NewIntFromBigInt(math.LegacyNewDec(2180).BigInt()), + Price: types.NewDecimal(math.LegacyNewDec(2180)), }, }, } @@ -943,8 +943,10 @@ func TestPreBlocker(t *testing.T) { require.Equal(t, res.ConsensusParamsChanged, false) ethPrice, err := input.OracleKeeper.GetExchangeRate(input.Ctx, "ETH") + require.NoError(t, err) require.Equal(t, ethPrice.String(), injectedVoteExtTx.StakeWeightedPrices["ETH"].String()) btcPrice, err := input.OracleKeeper.GetExchangeRate(input.Ctx, "BTC") + require.NoError(t, err) require.Equal(t, btcPrice.String(), injectedVoteExtTx.StakeWeightedPrices["BTC"].String()) _, err = input.OracleKeeper.GetExchangeRate(input.Ctx, "LTC") require.Error(t, err) diff --git a/x/oracle/abci/vote_extensions.go b/x/oracle/abci/vote_extensions.go index e30fdcdf..c6c3e5c1 100644 --- a/x/oracle/abci/vote_extensions.go +++ b/x/oracle/abci/vote_extensions.go @@ -80,7 +80,7 @@ func (h *VoteExtHandler) ExtendVoteHandler(oracleConfig OracleConfig) sdk.Extend for denom, price := range prices.Prices { computedPrices = append(computedPrices, types.DenomPrice{ Denom: denom, - Price: math.NewIntFromBigInt(price.BigInt()), + Price: types.NewDecimal(price), }) } diff --git a/x/oracle/abci/vote_extensions_test.go b/x/oracle/abci/vote_extensions_test.go index ff0d2623..7d87ccf8 100644 --- a/x/oracle/abci/vote_extensions_test.go +++ b/x/oracle/abci/vote_extensions_test.go @@ -55,11 +55,11 @@ func TestExtendVoteHandler(t *testing.T) { prices := make(map[string]math.LegacyDec) for _, price := range voteExt.Prices { - prices[price.Denom] = math.LegacyNewDecFromBigIntWithPrec(price.Price.BigInt(), math.LegacyPrecision) + prices[price.Denom] = price.Price.ToMathDec() } - require.Equal(t, prices["BTC"].String(), "47375.706652541026694000") - require.Equal(t, prices["ETH"].String(), "2649.328939436595054949") - require.Equal(t, prices["USDT"].String(), "1.000661260343873178") + require.Equal(t, prices["BTC"].String(), "47375.706600000000000000") + require.Equal(t, prices["ETH"].String(), "2649.328930000000000000") + require.Equal(t, prices["USDT"].String(), "1.000661260000000000") } func TestVerifyVoteExtensionHandler(t *testing.T) { @@ -76,12 +76,9 @@ func TestVerifyVoteExtensionHandler(t *testing.T) { Endpoint: testServer.URL, }) - btcPrice, ok := math.NewIntFromString("47375706652541026694000") - require.True(t, ok) - ethPrice, ok := math.NewIntFromString("2649328939436595054949") - require.True(t, ok) - usdtPrice, ok := math.NewIntFromString("1000661260343873178") - require.True(t, ok) + btcPrice := types.NewDecimal(math.LegacyMustNewDecFromStr("47375.706652541026694000")) + ethPrice := types.NewDecimal(math.LegacyMustNewDecFromStr("2649.328939436595054949")) + usdtPrice := types.NewDecimal(math.LegacyMustNewDecFromStr("1.000661260343873178")) voteExt := types.VoteExtension{ Height: 3, Prices: []types.DenomPrice{ @@ -121,3 +118,21 @@ func TestVerifyVoteExtensionHandler(t *testing.T) { }) require.Error(t, err) } + +func TestVoteExtensionMarshalLength(t *testing.T) { + voteExt := types.VoteExtension{ + Height: 1, + Prices: []types.DenomPrice{}, + } + + denoms := []string{"AKT", "AMPKUJI", "ARB", "ATOM", "AVAX", "AXL", "BAND", "BNB", "BTC", "CRO", "DOT", "DYM", "ETH", "FET", "FTM", "FUZN", "GLMR", "HNT", "INJ", "JUNO", "KAVA", "KUJI", "LINK", "LUNA", "LUNC", "MATIC", "MNTA", "NSTK", "NTRN", "OSMO", "PAXG", "QCKUJI", "QCMNTA", "RIO", "RLB", "SCRT", "SHD", "SOL", "SOMM", "STARS", "STATOM", "STKATOM", "STOSMO", "TIA", "UNI", "USDC", "USK", "WBTC", "WHALE", "WINK", "WSTETH"} + for _, denom := range denoms { + voteExt.Prices = append(voteExt.Prices, types.DenomPrice{ + Denom: denom, + Price: types.NewDecimal(math.LegacyOneDec()), + }) + } + voteExtBytes, err := proto.Marshal(&voteExt) + require.NoError(t, err) + require.Len(t, voteExtBytes, 868) +} diff --git a/x/oracle/types/extension.go b/x/oracle/types/extension.go new file mode 100644 index 00000000..f04686e3 --- /dev/null +++ b/x/oracle/types/extension.go @@ -0,0 +1,39 @@ +package types + +import ( + "bytes" + "encoding/binary" + "math/big" + + "cosmossdk.io/math" +) + +var tenInt = big.NewInt(10) + +func (d Decimal) ToMathDec() math.LegacyDec { + var num uint32 + err := binary.Read(bytes.NewBuffer(d.Data[:4]), binary.LittleEndian, &num) + if err != nil { + panic(err) + } + var digit = int64(d.Data[4]) + number := math.LegacyNewDecWithPrec(int64(num), 18) + multiplier := new(big.Int).Exp(tenInt, big.NewInt(digit), nil) + return number.MulInt(math.NewIntFromBigInt(multiplier)) +} + +func NewDecimal(d math.LegacyDec) Decimal { + number := d.BigInt() + digit := uint32(0) + for number.Cmp(big.NewInt(2_000_000_000)) == 1 { + number = new(big.Int).Div(number, tenInt) + digit += 1 + } + + data := make([]byte, 4) + binary.LittleEndian.PutUint32(data, uint32(number.Uint64())) + data = append(data, byte(digit)) + return Decimal{ + Data: data, + } +} diff --git a/x/oracle/types/extension.pb.go b/x/oracle/types/extension.pb.go index cd8c63dc..f84617a1 100644 --- a/x/oracle/types/extension.pb.go +++ b/x/oracle/types/extension.pb.go @@ -4,7 +4,6 @@ package types import ( - cosmossdk_io_math "cosmossdk.io/math" fmt "fmt" types "github.com/cometbft/cometbft/abci/types" _ "github.com/cosmos/gogoproto/gogoproto" @@ -25,16 +24,60 @@ var _ = math.Inf // proto package needs to be updated. const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package +type Decimal struct { + Data []byte `protobuf:"bytes,1,opt,name=data,proto3" json:"data,omitempty"` +} + +func (m *Decimal) Reset() { *m = Decimal{} } +func (m *Decimal) String() string { return proto.CompactTextString(m) } +func (*Decimal) ProtoMessage() {} +func (*Decimal) Descriptor() ([]byte, []int) { + return fileDescriptor_fbcc462c4867c7ca, []int{0} +} +func (m *Decimal) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *Decimal) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_Decimal.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 *Decimal) XXX_Merge(src proto.Message) { + xxx_messageInfo_Decimal.Merge(m, src) +} +func (m *Decimal) XXX_Size() int { + return m.Size() +} +func (m *Decimal) XXX_DiscardUnknown() { + xxx_messageInfo_Decimal.DiscardUnknown(m) +} + +var xxx_messageInfo_Decimal proto.InternalMessageInfo + +func (m *Decimal) GetData() []byte { + if m != nil { + return m.Data + } + return nil +} + type DenomPrice struct { - Denom string `protobuf:"bytes,1,opt,name=denom,proto3" json:"denom,omitempty"` - Price cosmossdk_io_math.Int `protobuf:"bytes,2,opt,name=price,proto3,customtype=cosmossdk.io/math.Int" json:"price"` + Denom string `protobuf:"bytes,1,opt,name=denom,proto3" json:"denom,omitempty"` + Price Decimal `protobuf:"bytes,2,opt,name=price,proto3" json:"price"` } func (m *DenomPrice) Reset() { *m = DenomPrice{} } func (m *DenomPrice) String() string { return proto.CompactTextString(m) } func (*DenomPrice) ProtoMessage() {} func (*DenomPrice) Descriptor() ([]byte, []int) { - return fileDescriptor_fbcc462c4867c7ca, []int{0} + return fileDescriptor_fbcc462c4867c7ca, []int{1} } func (m *DenomPrice) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -70,6 +113,13 @@ func (m *DenomPrice) GetDenom() string { return "" } +func (m *DenomPrice) GetPrice() Decimal { + if m != nil { + return m.Price + } + return Decimal{} +} + type VoteExtension struct { Height int64 `protobuf:"varint,1,opt,name=height,proto3" json:"height,omitempty"` Prices []DenomPrice `protobuf:"bytes,2,rep,name=prices,proto3" json:"prices"` @@ -79,7 +129,7 @@ func (m *VoteExtension) Reset() { *m = VoteExtension{} } func (m *VoteExtension) String() string { return proto.CompactTextString(m) } func (*VoteExtension) ProtoMessage() {} func (*VoteExtension) Descriptor() ([]byte, []int) { - return fileDescriptor_fbcc462c4867c7ca, []int{1} + return fileDescriptor_fbcc462c4867c7ca, []int{2} } func (m *VoteExtension) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -133,7 +183,7 @@ func (m *VoteExtensionTx) Reset() { *m = VoteExtensionTx{} } func (m *VoteExtensionTx) String() string { return proto.CompactTextString(m) } func (*VoteExtensionTx) ProtoMessage() {} func (*VoteExtensionTx) Descriptor() ([]byte, []int) { - return fileDescriptor_fbcc462c4867c7ca, []int{2} + return fileDescriptor_fbcc462c4867c7ca, []int{3} } func (m *VoteExtensionTx) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -184,6 +234,7 @@ func (m *VoteExtensionTx) GetExtendedCommitInfo() types.ExtendedCommitInfo { } func init() { + proto.RegisterType((*Decimal)(nil), "kujira.oracle.Decimal") proto.RegisterType((*DenomPrice)(nil), "kujira.oracle.DenomPrice") proto.RegisterType((*VoteExtension)(nil), "kujira.oracle.VoteExtension") proto.RegisterType((*VoteExtensionTx)(nil), "kujira.oracle.VoteExtensionTx") @@ -192,33 +243,63 @@ func init() { func init() { proto.RegisterFile("kujira/oracle/extension.proto", fileDescriptor_fbcc462c4867c7ca) } var fileDescriptor_fbcc462c4867c7ca = []byte{ - // 414 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x92, 0x41, 0x6f, 0xd3, 0x30, - 0x14, 0xc7, 0x93, 0x96, 0x55, 0xc2, 0x65, 0x42, 0x32, 0x1d, 0x0a, 0x45, 0xcb, 0xa6, 0x72, 0x99, - 0x90, 0xb0, 0xa5, 0xed, 0xc0, 0x7d, 0xdd, 0x0e, 0x13, 0x42, 0x42, 0x61, 0x62, 0x12, 0x1c, 0x42, - 0xea, 0xbc, 0x26, 0xa6, 0xd8, 0xaf, 0x8a, 0x5d, 0x51, 0xbe, 0x01, 0x47, 0x3e, 0x56, 0x8f, 0x3d, - 0x22, 0x0e, 0x15, 0x6a, 0xbf, 0x08, 0x8a, 0xe3, 0xaa, 0x2a, 0x5c, 0x76, 0xcb, 0xf3, 0xff, 0xff, - 0x7e, 0xce, 0xf3, 0xfb, 0x93, 0xe3, 0xc9, 0xec, 0x8b, 0xac, 0x32, 0x8e, 0x55, 0x26, 0xbe, 0x02, - 0x87, 0xb9, 0x05, 0x6d, 0x24, 0x6a, 0x36, 0xad, 0xd0, 0x22, 0x3d, 0x6c, 0x64, 0xd6, 0xc8, 0xfd, - 0x5e, 0x81, 0x05, 0x3a, 0x85, 0xd7, 0x5f, 0x8d, 0xa9, 0xff, 0x7c, 0x9f, 0x51, 0x80, 0x06, 0x23, - 0xcd, 0x56, 0xb4, 0xa0, 0x73, 0xa8, 0x94, 0xd4, 0x96, 0x67, 0x23, 0x21, 0xb9, 0xfd, 0x3e, 0x05, - 0x2f, 0x0e, 0xee, 0x08, 0xb9, 0x02, 0x8d, 0xea, 0x5d, 0x25, 0x05, 0xd0, 0x1e, 0x39, 0xc8, 0xeb, - 0x2a, 0x0a, 0x4f, 0xc3, 0xb3, 0x87, 0x49, 0x53, 0xd0, 0x0b, 0x72, 0x30, 0xad, 0xe5, 0xa8, 0x55, - 0x9f, 0x5e, 0x1e, 0x2f, 0x56, 0x27, 0xc1, 0xef, 0xd5, 0xc9, 0x91, 0x40, 0xa3, 0xd0, 0x98, 0x7c, - 0xc2, 0x24, 0x72, 0x95, 0xd9, 0x92, 0xdd, 0x68, 0x9b, 0x34, 0xde, 0xc1, 0x67, 0x72, 0xf8, 0x01, - 0x2d, 0x5c, 0x6f, 0xc7, 0xa1, 0x4f, 0x49, 0xa7, 0x04, 0x59, 0x94, 0xd6, 0xc1, 0xdb, 0x89, 0xaf, - 0xe8, 0x6b, 0xd2, 0x71, 0x1d, 0x26, 0x6a, 0x9d, 0xb6, 0xcf, 0xba, 0xe7, 0xcf, 0xd8, 0xde, 0xc4, - 0x6c, 0xf7, 0x7b, 0x97, 0x0f, 0xea, 0x9b, 0x13, 0x6f, 0x1f, 0xfc, 0x68, 0x91, 0xc7, 0x7b, 0x57, - 0xdc, 0xce, 0xe9, 0x7b, 0x72, 0x64, 0x6c, 0x36, 0x81, 0xf4, 0x9b, 0x83, 0x43, 0x9e, 0x7a, 0x76, - 0x78, 0x3f, 0xf6, 0x13, 0xd7, 0x7d, 0xe7, 0x9b, 0x9d, 0x62, 0xe8, 0x90, 0x3c, 0x52, 0xd2, 0x98, - 0x54, 0xe0, 0x4c, 0x5b, 0xa8, 0xdc, 0x33, 0x74, 0xcf, 0xfb, 0xff, 0xb0, 0xde, 0x4a, 0x63, 0x86, - 0x8d, 0xc3, 0xc3, 0xba, 0x6a, 0x77, 0x44, 0x3f, 0x91, 0x9e, 0x5b, 0x6d, 0x0e, 0x79, 0x2a, 0x50, - 0x29, 0x69, 0x53, 0xa9, 0xc7, 0x18, 0xb5, 0x1d, 0xec, 0x05, 0xdb, 0x2d, 0x89, 0xd5, 0x4b, 0x62, - 0xd7, 0xde, 0x3c, 0x74, 0xde, 0x1b, 0x3d, 0x46, 0x4f, 0xa5, 0xf0, 0xbf, 0x72, 0xb5, 0x58, 0xc7, - 0xe1, 0x72, 0x1d, 0x87, 0x7f, 0xd6, 0x71, 0xf8, 0x73, 0x13, 0x07, 0xcb, 0x4d, 0x1c, 0xfc, 0xda, - 0xc4, 0xc1, 0xc7, 0x97, 0x85, 0xb4, 0xe5, 0x6c, 0xc4, 0x04, 0x2a, 0x7e, 0x0b, 0x99, 0x7a, 0xf5, - 0xa6, 0x49, 0x8a, 0xc0, 0x0a, 0xf8, 0x7c, 0x1b, 0x18, 0x97, 0x88, 0x51, 0xc7, 0x45, 0xe2, 0xe2, - 0x6f, 0x00, 0x00, 0x00, 0xff, 0xff, 0x3a, 0x01, 0x99, 0x19, 0x92, 0x02, 0x00, 0x00, + // 415 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x92, 0x41, 0x8f, 0xd2, 0x40, + 0x14, 0xc7, 0x5b, 0xd8, 0xc5, 0x38, 0xec, 0xc6, 0x64, 0xc4, 0x4d, 0xc5, 0x6c, 0x25, 0xf5, 0x42, + 0x4c, 0x9c, 0x26, 0x78, 0xf0, 0x2e, 0xec, 0xc1, 0x18, 0x13, 0x53, 0x09, 0x26, 0x7a, 0xa8, 0xc3, + 0xf4, 0x51, 0x46, 0x98, 0x19, 0xd2, 0x19, 0x22, 0x7e, 0x03, 0x8f, 0x7e, 0x2c, 0x8e, 0x1c, 0x3d, + 0x19, 0x03, 0x5f, 0xc4, 0x74, 0x3a, 0x0d, 0x41, 0x2e, 0xde, 0xe6, 0xf5, 0xff, 0x7f, 0xbf, 0x79, + 0x9d, 0xf7, 0x47, 0xb7, 0x8b, 0xf5, 0x57, 0x5e, 0xd0, 0x58, 0x15, 0x94, 0x2d, 0x21, 0x86, 0x8d, + 0x01, 0xa9, 0xb9, 0x92, 0x64, 0x55, 0x28, 0xa3, 0xf0, 0x75, 0x25, 0x93, 0x4a, 0xee, 0x76, 0x72, + 0x95, 0x2b, 0xab, 0xc4, 0xe5, 0xa9, 0x32, 0x75, 0x9f, 0x9c, 0x32, 0x72, 0x90, 0xa0, 0xb9, 0xae, + 0x45, 0x03, 0x32, 0x83, 0x42, 0x70, 0x69, 0x62, 0x3a, 0x65, 0x3c, 0x36, 0xdf, 0x57, 0xe0, 0xc4, + 0xe8, 0x16, 0xdd, 0x1b, 0x01, 0xe3, 0x82, 0x2e, 0x31, 0x46, 0x17, 0x19, 0x35, 0x34, 0xf0, 0x7b, + 0x7e, 0xff, 0x2a, 0xb1, 0xe7, 0x68, 0x82, 0xd0, 0x08, 0xa4, 0x12, 0xef, 0x0b, 0xce, 0x00, 0x77, + 0xd0, 0x65, 0x56, 0x56, 0xd6, 0x72, 0x3f, 0xa9, 0x0a, 0x3c, 0x40, 0x97, 0xab, 0x52, 0x0e, 0x1a, + 0x3d, 0xbf, 0xdf, 0x1e, 0xdc, 0x90, 0x93, 0x89, 0x89, 0xc3, 0xbf, 0xbe, 0xd8, 0xfe, 0x7e, 0xea, + 0x25, 0x95, 0x35, 0xfa, 0x82, 0xae, 0x27, 0xca, 0xc0, 0x5d, 0xfd, 0xb3, 0xf8, 0x06, 0xb5, 0xe6, + 0xc0, 0xf3, 0xb9, 0xb1, 0xec, 0x66, 0xe2, 0x2a, 0xfc, 0x0a, 0xb5, 0x6c, 0x87, 0x0e, 0x1a, 0xbd, + 0x66, 0xbf, 0x3d, 0x78, 0x7c, 0x46, 0xaf, 0xa7, 0x73, 0x17, 0x38, 0x7b, 0xf4, 0xa3, 0x81, 0x1e, + 0x9c, 0x5c, 0x31, 0xde, 0xe0, 0x0f, 0xe8, 0x91, 0x36, 0x74, 0x01, 0xe9, 0x37, 0x0b, 0x87, 0x2c, + 0x75, 0x6c, 0xff, 0xff, 0xd8, 0x0f, 0x6d, 0xf7, 0x47, 0xd7, 0x6c, 0x15, 0x8d, 0x87, 0xe8, 0x4a, + 0x70, 0xad, 0x53, 0xa6, 0xd6, 0xd2, 0x40, 0xe1, 0x5e, 0xa1, 0xfb, 0x0f, 0xeb, 0x1d, 0xd7, 0x7a, + 0x58, 0x39, 0x1c, 0xac, 0x2d, 0x8e, 0x9f, 0xf0, 0x67, 0xd4, 0xb1, 0x8b, 0xcf, 0x20, 0x4b, 0x99, + 0x12, 0x82, 0x9b, 0x94, 0xcb, 0x99, 0x0a, 0x9a, 0x16, 0xf6, 0x8c, 0x1c, 0x57, 0x48, 0xca, 0x15, + 0x92, 0x3b, 0x67, 0x1e, 0x5a, 0xef, 0x1b, 0x39, 0x53, 0x8e, 0x8a, 0xe1, 0x5c, 0x19, 0x6d, 0xf7, + 0xa1, 0xbf, 0xdb, 0x87, 0xfe, 0x9f, 0x7d, 0xe8, 0xff, 0x3c, 0x84, 0xde, 0xee, 0x10, 0x7a, 0xbf, + 0x0e, 0xa1, 0xf7, 0xe9, 0x79, 0xce, 0xcd, 0x7c, 0x3d, 0x25, 0x4c, 0x89, 0x78, 0x0c, 0x54, 0xbc, + 0x78, 0x5b, 0xe5, 0x88, 0xa9, 0x02, 0xe2, 0x4d, 0x1d, 0x27, 0x9b, 0x97, 0x69, 0xcb, 0x06, 0xe6, + 0xe5, 0xdf, 0x00, 0x00, 0x00, 0xff, 0xff, 0xfa, 0x73, 0xaa, 0xd6, 0xb0, 0x02, 0x00, 0x00, +} + +func (m *Decimal) 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 *Decimal) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Decimal) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Data) > 0 { + i -= len(m.Data) + copy(dAtA[i:], m.Data) + i = encodeVarintExtension(dAtA, i, uint64(len(m.Data))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil } func (m *DenomPrice) Marshal() (dAtA []byte, err error) { @@ -242,11 +323,11 @@ func (m *DenomPrice) MarshalToSizedBuffer(dAtA []byte) (int, error) { var l int _ = l { - size := m.Price.Size() - i -= size - if _, err := m.Price.MarshalTo(dAtA[i:]); err != nil { + size, err := m.Price.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { return 0, err } + i -= size i = encodeVarintExtension(dAtA, i, uint64(size)) } i-- @@ -371,6 +452,19 @@ func encodeVarintExtension(dAtA []byte, offset int, v uint64) int { dAtA[offset] = uint8(v) return base } +func (m *Decimal) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Data) + if l > 0 { + n += 1 + l + sovExtension(uint64(l)) + } + return n +} + func (m *DenomPrice) Size() (n int) { if m == nil { return 0 @@ -429,6 +523,90 @@ func sovExtension(x uint64) (n int) { func sozExtension(x uint64) (n int) { return sovExtension(uint64((x << 1) ^ uint64((int64(x) >> 63)))) } +func (m *Decimal) 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 ErrIntOverflowExtension + } + 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: Decimal: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: Decimal: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Data", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowExtension + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthExtension + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthExtension + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Data = append(m.Data[:0], dAtA[iNdEx:postIndex]...) + if m.Data == nil { + m.Data = []byte{} + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipExtension(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthExtension + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} func (m *DenomPrice) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 @@ -494,7 +672,7 @@ func (m *DenomPrice) Unmarshal(dAtA []byte) error { if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field Price", wireType) } - var stringLen uint64 + var msglen int for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowExtension @@ -504,16 +682,15 @@ func (m *DenomPrice) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - stringLen |= uint64(b&0x7F) << shift + msglen |= int(b&0x7F) << shift if b < 0x80 { break } } - intStringLen := int(stringLen) - if intStringLen < 0 { + if msglen < 0 { return ErrInvalidLengthExtension } - postIndex := iNdEx + intStringLen + postIndex := iNdEx + msglen if postIndex < 0 { return ErrInvalidLengthExtension }