From cac7b224134771fcd52004b00fd6b5d192448655 Mon Sep 17 00:00:00 2001 From: gopherjk121 Date: Tue, 29 Dec 2020 12:28:02 +1000 Subject: [PATCH 01/11] copy erc20bridge types --- chain/erc20bridge/types/codec.go | 36 + chain/erc20bridge/types/errors.go | 15 + chain/erc20bridge/types/keys.go | 26 + chain/erc20bridge/types/msg_inithub.go | 38 + chain/erc20bridge/types/msg_mint.go | 56 ++ chain/erc20bridge/types/params.go | 49 ++ chain/erc20bridge/types/params.pb.go | 502 +++++++++++++ chain/erc20bridge/types/proposal.go | 39 + chain/erc20bridge/types/proposal.pb.go | 767 +++++++++++++++++++ chain/erc20bridge/types/query.pb.go | 896 +++++++++++++++++++++++ chain/erc20bridge/types/query.pb.gw.go | 210 ++++++ chain/erc20bridge/types/token_mapping.go | 21 + chain/erc20bridge/types/tx.pb.go | 718 ++++++++++++++++++ 13 files changed, 3373 insertions(+) create mode 100644 chain/erc20bridge/types/codec.go create mode 100644 chain/erc20bridge/types/errors.go create mode 100644 chain/erc20bridge/types/keys.go create mode 100644 chain/erc20bridge/types/msg_inithub.go create mode 100644 chain/erc20bridge/types/msg_mint.go create mode 100644 chain/erc20bridge/types/params.go create mode 100644 chain/erc20bridge/types/params.pb.go create mode 100644 chain/erc20bridge/types/proposal.go create mode 100644 chain/erc20bridge/types/proposal.pb.go create mode 100644 chain/erc20bridge/types/query.pb.go create mode 100644 chain/erc20bridge/types/query.pb.gw.go create mode 100644 chain/erc20bridge/types/token_mapping.go create mode 100644 chain/erc20bridge/types/tx.pb.go diff --git a/chain/erc20bridge/types/codec.go b/chain/erc20bridge/types/codec.go new file mode 100644 index 00000000..f927af6b --- /dev/null +++ b/chain/erc20bridge/types/codec.go @@ -0,0 +1,36 @@ +package types + +import ( + "github.com/cosmos/cosmos-sdk/codec" + codectypes "github.com/cosmos/cosmos-sdk/codec/types" + sdk "github.com/cosmos/cosmos-sdk/types" + govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" +) + +var ( + // ModuleCdc references the global erc20bridge module codec. Note, the codec should + // ONLY be used in certain instances of tests and for JSON encoding. + // + // The actual codec used for serialization should be provided to modules/erc20bridge and + // defined at the application level. + ModuleCdc = codec.NewProtoCodec(codectypes.NewInterfaceRegistry()) +) + +// RegisterLegacyAminoCodec registers concrete types on the LegacyAmino codec +func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { + cdc.RegisterConcrete(TokenMapping{}, "cosmos-sdk/TokenMapping", nil) + cdc.RegisterConcrete(&RegisterTokenMappingProposal{}, "cosmos-sdk/RegisterTokenMappingProposal", nil) +} + +// RegisterInterfaces register implementations +func RegisterInterfaces(registry codectypes.InterfaceRegistry) { + registry.RegisterImplementations( + (*sdk.Msg)(nil), + &MsgERC20BridgeMint{}, + &MsgInitHub{}, + ) + registry.RegisterImplementations( + (*govtypes.Content)(nil), + &RegisterTokenMappingProposal{}, + ) +} diff --git a/chain/erc20bridge/types/errors.go b/chain/erc20bridge/types/errors.go new file mode 100644 index 00000000..830545a6 --- /dev/null +++ b/chain/erc20bridge/types/errors.go @@ -0,0 +1,15 @@ +package types + +import ( + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" +) + +// errors +var ( + ErrInvalidErc20Address = sdkerrors.Register(ModuleName, 1, "invalid erc20 address") + ErrUnmatchingCosmosDenom = sdkerrors.Register(ModuleName, 2, "unmatching cosmos denom") + ErrNotAllowedBridge = sdkerrors.Register(ModuleName, 3, "not allowed bridge") + ErrInternalEthMinting = sdkerrors.Register(ModuleName, 4, "internal ethereum minting error") + ErrInitHubABI = sdkerrors.Register(ModuleName, 5, "init hub abi error") + ErrWritingEthTxPayload = sdkerrors.Register(ModuleName, 6, "writing ethereum tx payload error") +) diff --git a/chain/erc20bridge/types/keys.go b/chain/erc20bridge/types/keys.go new file mode 100644 index 00000000..34dd8648 --- /dev/null +++ b/chain/erc20bridge/types/keys.go @@ -0,0 +1,26 @@ +package types + +// constants +const ( + // module name + ModuleName = "erc20bridge" + + // StoreKey to be used when creating the KVStore + StoreKey = ModuleName + + // RouterKey to be used for message routing + RouterKey = ModuleName + + // events + EventTypeTemplateCreation = "template_creation" + EventTypeBurn = "burn" + + AttributeKeyAddress = "address" + AttributeKeyProposedCosmosCoin = "propsed_cosmos_coin" + AttributeKeyContractAddress = "burn_contract_address" + AttributeKeyBurnEthAddress = "burn_eth_address" + AttributeKeyRecipientCosmosAddress = "recipient_cosmos_address" + AttributeKeyAmount = "amount" + + TypeMsgMint = "mint_erc20" +) diff --git a/chain/erc20bridge/types/msg_inithub.go b/chain/erc20bridge/types/msg_inithub.go new file mode 100644 index 00000000..03520bcc --- /dev/null +++ b/chain/erc20bridge/types/msg_inithub.go @@ -0,0 +1,38 @@ +package types + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" +) + +var ( + _ sdk.Msg = &MsgInitHub{} +) + +// NewMsgInitHub returns init hub msg instance +func NewMsgInitHub(hub string, proposer sdk.AccAddress) *MsgInitHub { + return &MsgInitHub{ + HubAddress: hub, + Proposer: proposer, + } +} + +// Route should return the name of the module +func (msg MsgInitHub) Route() string { return RouterKey } + +// Type should return the action +func (msg MsgInitHub) Type() string { return "inithub" } + +// ValidateBasic runs stateless checks on the message +func (msg MsgInitHub) ValidateBasic() error { + return nil +} + +// GetSignBytes encodes the message for signing +func (msg *MsgInitHub) GetSignBytes() []byte { + return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(msg)) +} + +// GetSigners defines whose signature is required +func (msg MsgInitHub) GetSigners() []sdk.AccAddress { + return []sdk.AccAddress{msg.Proposer} +} diff --git a/chain/erc20bridge/types/msg_mint.go b/chain/erc20bridge/types/msg_mint.go new file mode 100644 index 00000000..0b416084 --- /dev/null +++ b/chain/erc20bridge/types/msg_mint.go @@ -0,0 +1,56 @@ +package types + +import ( + "errors" + + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/ethereum/go-ethereum/common" +) + +var ( + _ sdk.Msg = &MsgERC20BridgeMint{} +) + +// NewMsgERC20BridgeMint returns init hub msg instance +func NewMsgERC20BridgeMint(mapping string, amount string, address string, proposer sdk.AccAddress) *MsgERC20BridgeMint { + return &MsgERC20BridgeMint{ + MappingId: mapping, + Amount: amount, + Address: address, + Proposer: proposer, + } +} + +// Route should return the name of the module +func (msg MsgERC20BridgeMint) Route() string { return RouterKey } + +// Type should return the action +func (msg MsgERC20BridgeMint) Type() string { return TypeMsgMint } + +// ValidateBasic runs stateless checks on the message +func (msg MsgERC20BridgeMint) ValidateBasic() error { + _, ok := sdk.NewIntFromString(msg.Amount) + if !ok { + return errors.New("invalid amount field") + } + if msg.Proposer.Empty() { + return errors.New("empty proposer") + } + if msg.MappingId == "" { + return errors.New("empty mapping id") + } + if !common.IsHexAddress(msg.Address) { + return errors.New("invalid eth address") + } + return nil +} + +// GetSignBytes encodes the message for signing +func (msg *MsgERC20BridgeMint) GetSignBytes() []byte { + return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(msg)) +} + +// GetSigners defines whose signature is required +func (msg MsgERC20BridgeMint) GetSigners() []sdk.AccAddress { + return []sdk.AccAddress{msg.Proposer} +} diff --git a/chain/erc20bridge/types/params.go b/chain/erc20bridge/types/params.go new file mode 100644 index 00000000..0136cbc8 --- /dev/null +++ b/chain/erc20bridge/types/params.go @@ -0,0 +1,49 @@ +package types + +import ( + fmt "fmt" + + paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" + "github.com/ethereum/go-ethereum/common" +) + +// Parameter store key +var ( + ParamStoreKeyHubParams = []byte("hubparams") + // DefaultGasLimit is gas limit we use for erc20bridge internal ethereum transactions + DefaultGasLimit = uint64(100_000_000) // 100M +) + +// ParamKeyTable - Key declaration for parameters +func ParamKeyTable() paramtypes.KeyTable { + return paramtypes.NewKeyTable( + paramtypes.NewParamSetPair(ParamStoreKeyHubParams, HubParams{}, validateHubParams), + ) +} + +// NewParams creates a new Params object +func NewParams(hp HubParams) Params { + return Params{ + HubParams: hp, + } +} + +func validateHubParams(i interface{}) error { + v, ok := i.(HubParams) + if !ok { + return fmt.Errorf("invalid parameter type: %T", i) + } + + if len(v.HubAddress) != common.AddressLength { + return fmt.Errorf("invalid hub address: %s", v.HubAddress) + } + + return nil +} + +// ParamSetPairs returns the parameter set pairs. +func (p *Params) ParamSetPairs() paramtypes.ParamSetPairs { + return paramtypes.ParamSetPairs{ + paramtypes.NewParamSetPair(ParamStoreKeyHubParams, &p.HubParams, validateHubParams), + } +} diff --git a/chain/erc20bridge/types/params.pb.go b/chain/erc20bridge/types/params.pb.go new file mode 100644 index 00000000..e3ee414c --- /dev/null +++ b/chain/erc20bridge/types/params.pb.go @@ -0,0 +1,502 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: injective/erc20bridge/params.proto + +package types + +import ( + fmt "fmt" + _ "github.com/gogo/protobuf/gogoproto" + proto "github.com/gogo/protobuf/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 HubParams struct { + HubAddress string `protobuf:"bytes,1,opt,name=hub_address,json=hubAddress,proto3" json:"hub_address,omitempty" yaml:"hub_address"` +} + +func (m *HubParams) Reset() { *m = HubParams{} } +func (m *HubParams) String() string { return proto.CompactTextString(m) } +func (*HubParams) ProtoMessage() {} +func (*HubParams) Descriptor() ([]byte, []int) { + return fileDescriptor_3b0ff8e9e8aae87d, []int{0} +} +func (m *HubParams) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *HubParams) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_HubParams.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 *HubParams) XXX_Merge(src proto.Message) { + xxx_messageInfo_HubParams.Merge(m, src) +} +func (m *HubParams) XXX_Size() int { + return m.Size() +} +func (m *HubParams) XXX_DiscardUnknown() { + xxx_messageInfo_HubParams.DiscardUnknown(m) +} + +var xxx_messageInfo_HubParams proto.InternalMessageInfo + +func (m *HubParams) GetHubAddress() string { + if m != nil { + return m.HubAddress + } + return "" +} + +type Params struct { + HubParams HubParams `protobuf:"bytes,1,opt,name=hub_params,json=hubParams,proto3" json:"hub_params"` +} + +func (m *Params) Reset() { *m = Params{} } +func (m *Params) String() string { return proto.CompactTextString(m) } +func (*Params) ProtoMessage() {} +func (*Params) Descriptor() ([]byte, []int) { + return fileDescriptor_3b0ff8e9e8aae87d, []int{1} +} +func (m *Params) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *Params) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_Params.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 *Params) XXX_Merge(src proto.Message) { + xxx_messageInfo_Params.Merge(m, src) +} +func (m *Params) XXX_Size() int { + return m.Size() +} +func (m *Params) XXX_DiscardUnknown() { + xxx_messageInfo_Params.DiscardUnknown(m) +} + +var xxx_messageInfo_Params proto.InternalMessageInfo + +func (m *Params) GetHubParams() HubParams { + if m != nil { + return m.HubParams + } + return HubParams{} +} + +func init() { + proto.RegisterType((*HubParams)(nil), "injective.erc20bridge.v1beta1.HubParams") + proto.RegisterType((*Params)(nil), "injective.erc20bridge.v1beta1.Params") +} + +func init() { + proto.RegisterFile("injective/erc20bridge/params.proto", fileDescriptor_3b0ff8e9e8aae87d) +} + +var fileDescriptor_3b0ff8e9e8aae87d = []byte{ + // 259 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x52, 0xca, 0xcc, 0xcb, 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4, 0x92, 0xf3, 0x73, 0xf5, 0x3d, 0x61, 0xc6, 0xfb, 0x24, + 0x26, 0x15, 0xeb, 0xc3, 0x2d, 0xd3, 0x4d, 0xce, 0x2f, 0x4a, 0x45, 0xe6, 0x66, 0x24, 0x66, 0xe6, + 0xe9, 0xe7, 0xe6, 0xa7, 0x94, 0xe6, 0xa4, 0x16, 0xa3, 0x84, 0x63, 0x49, 0x65, 0x41, 0x6a, 0x71, + 0x12, 0x1b, 0x38, 0x48, 0x8c, 0x01, 0x01, 0x00, 0x00, 0xff, 0xff, 0xf5, 0x12, 0x1e, 0x76, 0x6d, + 0x01, 0x00, 0x00, +} + +func (m *HubParams) 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 *HubParams) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *HubParams) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.HubAddress) > 0 { + i -= len(m.HubAddress) + copy(dAtA[i:], m.HubAddress) + i = encodeVarintParams(dAtA, i, uint64(len(m.HubAddress))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *Params) 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 *Params) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Params) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size, err := m.HubParams.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintParams(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + return len(dAtA) - i, nil +} + +func encodeVarintParams(dAtA []byte, offset int, v uint64) int { + offset -= sovParams(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *HubParams) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.HubAddress) + if l > 0 { + n += 1 + l + sovParams(uint64(l)) + } + return n +} + +func (m *Params) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = m.HubParams.Size() + n += 1 + l + sovParams(uint64(l)) + return n +} + +func sovParams(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozParams(x uint64) (n int) { + return sovParams(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *HubParams) 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 ErrIntOverflowParams + } + 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: HubParams: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: HubParams: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field HubAddress", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowParams + } + 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 ErrInvalidLengthParams + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthParams + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.HubAddress = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipParams(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthParams + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthParams + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *Params) 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 ErrIntOverflowParams + } + 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: Params: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: Params: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field HubParams", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowParams + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthParams + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthParams + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.HubParams.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipParams(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthParams + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthParams + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipParams(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, ErrIntOverflowParams + } + 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, ErrIntOverflowParams + } + 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, ErrIntOverflowParams + } + 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, ErrInvalidLengthParams + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupParams + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthParams + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthParams = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowParams = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupParams = fmt.Errorf("proto: unexpected end of group") +) diff --git a/chain/erc20bridge/types/proposal.go b/chain/erc20bridge/types/proposal.go new file mode 100644 index 00000000..7f56d7cf --- /dev/null +++ b/chain/erc20bridge/types/proposal.go @@ -0,0 +1,39 @@ +package types + +import ( + gov "github.com/cosmos/cosmos-sdk/x/gov/types" +) + +// constants +const ( + ProposalTypeRegisterTokenMapping string = "RegisterTokenMapping" +) + +// NewRegisterTokenMappingProposal returns new instance of TokenMappingProposal +func NewRegisterTokenMappingProposal(title, description string, mapping TokenMapping) gov.Content { + return &RegisterTokenMappingProposal{title, description, mapping} +} + +// Implements Proposal Interface +var _ gov.Content = &RegisterTokenMappingProposal{} + +func init() { + gov.RegisterProposalType(ProposalTypeRegisterTokenMapping) + gov.RegisterProposalTypeCodec(&RegisterTokenMappingProposal{}, "cosmos-sdk/RegisterTokenMappingProposal") +} + +// ProposalRoute returns router key for this proposal +func (sup *RegisterTokenMappingProposal) ProposalRoute() string { return RouterKey } + +// ProposalType returns proposal type for this proposal +func (sup *RegisterTokenMappingProposal) ProposalType() string { + return ProposalTypeRegisterTokenMapping +} + +// ValidateBasic returns ValidateBasic result for this proposal +func (sup *RegisterTokenMappingProposal) ValidateBasic() error { + if err := sup.Mapping.ValidateBasic(); err != nil { + return err + } + return gov.ValidateAbstract(sup) +} diff --git a/chain/erc20bridge/types/proposal.pb.go b/chain/erc20bridge/types/proposal.pb.go new file mode 100644 index 00000000..bb0383ce --- /dev/null +++ b/chain/erc20bridge/types/proposal.pb.go @@ -0,0 +1,767 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: injective/erc20bridge/proposal.proto + +package types + +import ( + fmt "fmt" + _ "github.com/gogo/protobuf/gogoproto" + proto "github.com/gogo/protobuf/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 + +// TokenMapping defines a mapping for cosmos denom and erc20 address. +type TokenMapping struct { + // address of ERC20 contract token + Erc20Address string `protobuf:"bytes,1,opt,name=erc20_address,json=erc20Address,proto3" json:"erc20_address,omitempty" yaml:"erc20_address"` + // cosmos-native denominator to mapped to ERC20 + CosmosDenom string `protobuf:"bytes,2,opt,name=cosmos_denom,json=cosmosDenom,proto3" json:"cosmos_denom,omitempty"` + // shows token mapping bridge enable status + Enabled bool `protobuf:"varint,3,opt,name=enabled,proto3" json:"enabled,omitempty"` +} + +func (m *TokenMapping) Reset() { *m = TokenMapping{} } +func (m *TokenMapping) String() string { return proto.CompactTextString(m) } +func (*TokenMapping) ProtoMessage() {} +func (*TokenMapping) Descriptor() ([]byte, []int) { + return fileDescriptor_725522d902d0cf82, []int{0} +} +func (m *TokenMapping) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *TokenMapping) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_TokenMapping.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 *TokenMapping) XXX_Merge(src proto.Message) { + xxx_messageInfo_TokenMapping.Merge(m, src) +} +func (m *TokenMapping) XXX_Size() int { + return m.Size() +} +func (m *TokenMapping) XXX_DiscardUnknown() { + xxx_messageInfo_TokenMapping.DiscardUnknown(m) +} + +var xxx_messageInfo_TokenMapping proto.InternalMessageInfo + +func (m *TokenMapping) GetErc20Address() string { + if m != nil { + return m.Erc20Address + } + return "" +} + +func (m *TokenMapping) GetCosmosDenom() string { + if m != nil { + return m.CosmosDenom + } + return "" +} + +func (m *TokenMapping) GetEnabled() bool { + if m != nil { + return m.Enabled + } + return false +} + +// RegisterTokenMappingProposal is a gov Content type to register a token mapping +type RegisterTokenMappingProposal struct { + Title string `protobuf:"bytes,1,opt,name=title,proto3" json:"title,omitempty"` + Description string `protobuf:"bytes,2,opt,name=description,proto3" json:"description,omitempty"` + Mapping TokenMapping `protobuf:"bytes,3,opt,name=mapping,proto3" json:"mapping"` +} + +func (m *RegisterTokenMappingProposal) Reset() { *m = RegisterTokenMappingProposal{} } +func (m *RegisterTokenMappingProposal) String() string { return proto.CompactTextString(m) } +func (*RegisterTokenMappingProposal) ProtoMessage() {} +func (*RegisterTokenMappingProposal) Descriptor() ([]byte, []int) { + return fileDescriptor_725522d902d0cf82, []int{1} +} +func (m *RegisterTokenMappingProposal) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *RegisterTokenMappingProposal) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_RegisterTokenMappingProposal.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 *RegisterTokenMappingProposal) XXX_Merge(src proto.Message) { + xxx_messageInfo_RegisterTokenMappingProposal.Merge(m, src) +} +func (m *RegisterTokenMappingProposal) XXX_Size() int { + return m.Size() +} +func (m *RegisterTokenMappingProposal) XXX_DiscardUnknown() { + xxx_messageInfo_RegisterTokenMappingProposal.DiscardUnknown(m) +} + +var xxx_messageInfo_RegisterTokenMappingProposal proto.InternalMessageInfo + +func (m *RegisterTokenMappingProposal) GetTitle() string { + if m != nil { + return m.Title + } + return "" +} + +func (m *RegisterTokenMappingProposal) GetDescription() string { + if m != nil { + return m.Description + } + return "" +} + +func (m *RegisterTokenMappingProposal) GetMapping() TokenMapping { + if m != nil { + return m.Mapping + } + return TokenMapping{} +} + +func init() { + proto.RegisterType((*TokenMapping)(nil), "injective.erc20bridge.v1beta1.TokenMapping") + proto.RegisterType((*RegisterTokenMappingProposal)(nil), "injective.erc20bridge.v1beta1.RegisterTokenMappingProposal") +} + +func init() { + proto.RegisterFile("injective/erc20bridge/proposal.proto", fileDescriptor_725522d902d0cf82) +} + +var fileDescriptor_725522d902d0cf82 = []byte{ + // 360 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x7c, 0x51, 0xb1, 0x4e, 0xe3, 0x40, + 0x14, 0xf4, 0xde, 0xe5, 0x2e, 0x77, 0x9b, 0xd0, 0x58, 0x29, 0x2c, 0x04, 0x4e, 0xb0, 0x28, 0x22, + 0x21, 0x6c, 0x12, 0xba, 0x48, 0x14, 0x44, 0x34, 0x08, 0x90, 0xc0, 0xa2, 0xa2, 0x89, 0xd6, 0xf6, + 0x93, 0xb3, 0xc4, 0xf6, 0xb3, 0x76, 0x37, 0x91, 0xf2, 0x17, 0xf9, 0x04, 0x5a, 0xfe, 0x24, 0x65, + 0x4a, 0xaa, 0x08, 0x25, 0x0d, 0x35, 0x5f, 0x80, 0x62, 0xe3, 0xc8, 0x69, 0xe8, 0x76, 0x66, 0x67, + 0xde, 0xcc, 0xee, 0xa3, 0xc7, 0x3c, 0x79, 0x06, 0x5f, 0xf1, 0x09, 0x38, 0x20, 0xfc, 0xee, 0x99, + 0x27, 0x78, 0x10, 0x82, 0x93, 0x0a, 0x4c, 0x51, 0xb2, 0xc8, 0x4e, 0x05, 0x2a, 0xd4, 0x0f, 0xb7, + 0x2a, 0xbb, 0xa4, 0xb2, 0x27, 0x1d, 0x0f, 0x14, 0xeb, 0xec, 0x37, 0x42, 0x0c, 0x31, 0x53, 0x3a, + 0x9b, 0x53, 0x6e, 0xb2, 0x66, 0x84, 0xd6, 0x1f, 0x71, 0x04, 0xc9, 0x1d, 0x4b, 0x53, 0x9e, 0x84, + 0xfa, 0x05, 0xdd, 0xcb, 0xdc, 0x03, 0x16, 0x04, 0x02, 0xa4, 0x34, 0x48, 0x8b, 0xb4, 0xff, 0xf7, + 0x8d, 0xcf, 0x65, 0xb3, 0x31, 0x65, 0x71, 0xd4, 0xb3, 0x76, 0xae, 0x2d, 0xb7, 0x9e, 0xe1, 0xcb, + 0x1c, 0xea, 0x47, 0xb4, 0xee, 0xa3, 0x8c, 0x51, 0x0e, 0x02, 0x48, 0x30, 0x36, 0x7e, 0x6d, 0xdc, + 0x6e, 0x2d, 0xe7, 0xae, 0x36, 0x94, 0x6e, 0xd0, 0x2a, 0x24, 0xcc, 0x8b, 0x20, 0x30, 0x7e, 0xb7, + 0x48, 0xfb, 0x9f, 0x5b, 0xc0, 0x5e, 0xe5, 0xe3, 0xa5, 0x49, 0xac, 0x57, 0x42, 0x0f, 0x5c, 0x08, + 0xb9, 0x54, 0x20, 0xca, 0xd5, 0xee, 0xbf, 0x9f, 0xab, 0x37, 0xe8, 0x1f, 0xc5, 0x55, 0x04, 0x79, + 0x35, 0x37, 0x07, 0x7a, 0x8b, 0xd6, 0x02, 0x90, 0xbe, 0xe0, 0xa9, 0xe2, 0x98, 0x14, 0xc1, 0x25, + 0x4a, 0xbf, 0xa1, 0xd5, 0x38, 0x1f, 0x95, 0x05, 0xd7, 0xba, 0x27, 0xf6, 0x8f, 0x5f, 0x66, 0x97, + 0xd3, 0xfb, 0x95, 0xf9, 0xb2, 0xa9, 0xb9, 0xc5, 0x84, 0xbc, 0x6b, 0x7f, 0x34, 0x5f, 0x99, 0x64, + 0xb1, 0x32, 0xc9, 0xfb, 0xca, 0x24, 0xb3, 0xb5, 0xa9, 0x2d, 0xd6, 0xa6, 0xf6, 0xb6, 0x36, 0xb5, + 0xa7, 0x87, 0x90, 0xab, 0xe1, 0xd8, 0xb3, 0x7d, 0x8c, 0x9d, 0xeb, 0x22, 0xe5, 0x96, 0x79, 0xd2, + 0xd9, 0x66, 0x9e, 0xfa, 0x28, 0xa0, 0x0c, 0x87, 0x8c, 0x27, 0x4e, 0x8c, 0xc1, 0x38, 0x02, 0xb9, + 0xb3, 0x69, 0x35, 0x4d, 0x41, 0x7a, 0x7f, 0xb3, 0x95, 0x9d, 0x7f, 0x05, 0x00, 0x00, 0xff, 0xff, + 0x7f, 0x45, 0x6b, 0x22, 0x0f, 0x02, 0x00, 0x00, +} + +func (this *TokenMapping) Equal(that interface{}) bool { + if that == nil { + return this == nil + } + + that1, ok := that.(*TokenMapping) + if !ok { + that2, ok := that.(TokenMapping) + if ok { + that1 = &that2 + } else { + return false + } + } + if that1 == nil { + return this == nil + } else if this == nil { + return false + } + if this.Erc20Address != that1.Erc20Address { + return false + } + if this.CosmosDenom != that1.CosmosDenom { + return false + } + if this.Enabled != that1.Enabled { + return false + } + return true +} +func (this *RegisterTokenMappingProposal) Equal(that interface{}) bool { + if that == nil { + return this == nil + } + + that1, ok := that.(*RegisterTokenMappingProposal) + if !ok { + that2, ok := that.(RegisterTokenMappingProposal) + if ok { + that1 = &that2 + } else { + return false + } + } + if that1 == nil { + return this == nil + } else if this == nil { + return false + } + if this.Title != that1.Title { + return false + } + if this.Description != that1.Description { + return false + } + if !this.Mapping.Equal(&that1.Mapping) { + return false + } + return true +} +func (m *TokenMapping) 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 *TokenMapping) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *TokenMapping) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Enabled { + i-- + if m.Enabled { + dAtA[i] = 1 + } else { + dAtA[i] = 0 + } + i-- + dAtA[i] = 0x18 + } + if len(m.CosmosDenom) > 0 { + i -= len(m.CosmosDenom) + copy(dAtA[i:], m.CosmosDenom) + i = encodeVarintProposal(dAtA, i, uint64(len(m.CosmosDenom))) + i-- + dAtA[i] = 0x12 + } + if len(m.Erc20Address) > 0 { + i -= len(m.Erc20Address) + copy(dAtA[i:], m.Erc20Address) + i = encodeVarintProposal(dAtA, i, uint64(len(m.Erc20Address))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *RegisterTokenMappingProposal) 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 *RegisterTokenMappingProposal) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *RegisterTokenMappingProposal) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size, err := m.Mapping.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintProposal(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1a + if len(m.Description) > 0 { + i -= len(m.Description) + copy(dAtA[i:], m.Description) + i = encodeVarintProposal(dAtA, i, uint64(len(m.Description))) + i-- + dAtA[i] = 0x12 + } + if len(m.Title) > 0 { + i -= len(m.Title) + copy(dAtA[i:], m.Title) + i = encodeVarintProposal(dAtA, i, uint64(len(m.Title))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func encodeVarintProposal(dAtA []byte, offset int, v uint64) int { + offset -= sovProposal(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *TokenMapping) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Erc20Address) + if l > 0 { + n += 1 + l + sovProposal(uint64(l)) + } + l = len(m.CosmosDenom) + if l > 0 { + n += 1 + l + sovProposal(uint64(l)) + } + if m.Enabled { + n += 2 + } + return n +} + +func (m *RegisterTokenMappingProposal) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Title) + if l > 0 { + n += 1 + l + sovProposal(uint64(l)) + } + l = len(m.Description) + if l > 0 { + n += 1 + l + sovProposal(uint64(l)) + } + l = m.Mapping.Size() + n += 1 + l + sovProposal(uint64(l)) + return n +} + +func sovProposal(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozProposal(x uint64) (n int) { + return sovProposal(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *TokenMapping) 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 ErrIntOverflowProposal + } + 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: TokenMapping: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: TokenMapping: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Erc20Address", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowProposal + } + 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 ErrInvalidLengthProposal + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthProposal + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Erc20Address = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field CosmosDenom", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowProposal + } + 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 ErrInvalidLengthProposal + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthProposal + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.CosmosDenom = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 3: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Enabled", wireType) + } + var v int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowProposal + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + v |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + m.Enabled = bool(v != 0) + default: + iNdEx = preIndex + skippy, err := skipProposal(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthProposal + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthProposal + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *RegisterTokenMappingProposal) 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 ErrIntOverflowProposal + } + 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: RegisterTokenMappingProposal: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: RegisterTokenMappingProposal: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Title", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowProposal + } + 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 ErrInvalidLengthProposal + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthProposal + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Title = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Description", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowProposal + } + 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 ErrInvalidLengthProposal + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthProposal + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Description = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Mapping", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowProposal + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthProposal + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthProposal + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.Mapping.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipProposal(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthProposal + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthProposal + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipProposal(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, ErrIntOverflowProposal + } + 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, ErrIntOverflowProposal + } + 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, ErrIntOverflowProposal + } + 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, ErrInvalidLengthProposal + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupProposal + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthProposal + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthProposal = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowProposal = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupProposal = fmt.Errorf("proto: unexpected end of group") +) diff --git a/chain/erc20bridge/types/query.pb.go b/chain/erc20bridge/types/query.pb.go new file mode 100644 index 00000000..b012ac65 --- /dev/null +++ b/chain/erc20bridge/types/query.pb.go @@ -0,0 +1,896 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: injective/erc20bridge/query.proto + +package types + +import ( + context "context" + fmt "fmt" + _ "github.com/gogo/protobuf/gogoproto" + grpc1 "github.com/gogo/protobuf/grpc" + proto "github.com/gogo/protobuf/proto" + _ "google.golang.org/genproto/googleapis/api/annotations" + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" + 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 + +// QueryBridgesRequest is the request type for the Query/Storage RPC method. +type QueryBridgesRequest struct { +} + +func (m *QueryBridgesRequest) Reset() { *m = QueryBridgesRequest{} } +func (m *QueryBridgesRequest) String() string { return proto.CompactTextString(m) } +func (*QueryBridgesRequest) ProtoMessage() {} +func (*QueryBridgesRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_53a294784115eb11, []int{0} +} +func (m *QueryBridgesRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryBridgesRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryBridgesRequest.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 *QueryBridgesRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryBridgesRequest.Merge(m, src) +} +func (m *QueryBridgesRequest) XXX_Size() int { + return m.Size() +} +func (m *QueryBridgesRequest) XXX_DiscardUnknown() { + xxx_messageInfo_QueryBridgesRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryBridgesRequest proto.InternalMessageInfo + +// QueryBridgesResponse is the response type for the Query/Storage RPC +// method. +type QueryBridgesResponse struct { + Data []TokenMapping `protobuf:"bytes,1,rep,name=data,proto3" json:"data"` +} + +func (m *QueryBridgesResponse) Reset() { *m = QueryBridgesResponse{} } +func (m *QueryBridgesResponse) String() string { return proto.CompactTextString(m) } +func (*QueryBridgesResponse) ProtoMessage() {} +func (*QueryBridgesResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_53a294784115eb11, []int{1} +} +func (m *QueryBridgesResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryBridgesResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryBridgesResponse.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 *QueryBridgesResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryBridgesResponse.Merge(m, src) +} +func (m *QueryBridgesResponse) XXX_Size() int { + return m.Size() +} +func (m *QueryBridgesResponse) XXX_DiscardUnknown() { + xxx_messageInfo_QueryBridgesResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryBridgesResponse proto.InternalMessageInfo + +func (m *QueryBridgesResponse) GetData() []TokenMapping { + if m != nil { + return m.Data + } + return nil +} + +// QueryHubParamsRequest is the request type for the Query/Storage RPC method. +type QueryHubParamsRequest struct { +} + +func (m *QueryHubParamsRequest) Reset() { *m = QueryHubParamsRequest{} } +func (m *QueryHubParamsRequest) String() string { return proto.CompactTextString(m) } +func (*QueryHubParamsRequest) ProtoMessage() {} +func (*QueryHubParamsRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_53a294784115eb11, []int{2} +} +func (m *QueryHubParamsRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryHubParamsRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryHubParamsRequest.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 *QueryHubParamsRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryHubParamsRequest.Merge(m, src) +} +func (m *QueryHubParamsRequest) XXX_Size() int { + return m.Size() +} +func (m *QueryHubParamsRequest) XXX_DiscardUnknown() { + xxx_messageInfo_QueryHubParamsRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryHubParamsRequest proto.InternalMessageInfo + +// QueryHubParamsResponse is the response type for the Query/Storage RPC +// method. +type QueryHubParamsResponse struct { + Data HubParams `protobuf:"bytes,1,opt,name=data,proto3" json:"data"` +} + +func (m *QueryHubParamsResponse) Reset() { *m = QueryHubParamsResponse{} } +func (m *QueryHubParamsResponse) String() string { return proto.CompactTextString(m) } +func (*QueryHubParamsResponse) ProtoMessage() {} +func (*QueryHubParamsResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_53a294784115eb11, []int{3} +} +func (m *QueryHubParamsResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryHubParamsResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryHubParamsResponse.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 *QueryHubParamsResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryHubParamsResponse.Merge(m, src) +} +func (m *QueryHubParamsResponse) XXX_Size() int { + return m.Size() +} +func (m *QueryHubParamsResponse) XXX_DiscardUnknown() { + xxx_messageInfo_QueryHubParamsResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryHubParamsResponse proto.InternalMessageInfo + +func (m *QueryHubParamsResponse) GetData() HubParams { + if m != nil { + return m.Data + } + return HubParams{} +} + +func init() { + proto.RegisterType((*QueryBridgesRequest)(nil), "injective.erc20bridge.v1beta1.QueryBridgesRequest") + proto.RegisterType((*QueryBridgesResponse)(nil), "injective.erc20bridge.v1beta1.QueryBridgesResponse") + proto.RegisterType((*QueryHubParamsRequest)(nil), "injective.erc20bridge.v1beta1.QueryHubParamsRequest") + proto.RegisterType((*QueryHubParamsResponse)(nil), "injective.erc20bridge.v1beta1.QueryHubParamsResponse") +} + +func init() { proto.RegisterFile("injective/erc20bridge/query.proto", fileDescriptor_53a294784115eb11) } + +var fileDescriptor_53a294784115eb11 = []byte{ + // 408 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x52, 0xcc, 0xcc, 0xcb, 0x4a, + 0x4d, 0x2e, 0xc9, 0x2c, 0x4b, 0xd5, 0x4f, 0x2d, 0x4a, 0x36, 0x32, 0x48, 0x2a, 0xca, 0x4c, 0x49, + 0x4f, 0xd5, 0x2f, 0x2c, 0x4d, 0x2d, 0xaa, 0xd4, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x92, 0x85, + 0x2b, 0xd1, 0x43, 0x52, 0xa2, 0x57, 0x66, 0x98, 0x94, 0x5a, 0x92, 0x68, 0x28, 0xa5, 0x82, 0xdd, + 0x84, 0x82, 0xa2, 0xfc, 0x82, 0xfc, 0xe2, 0xc4, 0x1c, 0x88, 0x21, 0x52, 0x4a, 0x38, 0x54, 0x25, + 0x16, 0x25, 0xe6, 0x16, 0x43, 0xd5, 0xc8, 0xa4, 0xe7, 0xe7, 0xa7, 0xe7, 0xa4, 0xea, 0x27, 0x16, + 0x64, 0xea, 0x27, 0xe6, 0xe5, 0xe5, 0x97, 0x24, 0x96, 0x64, 0xe6, 0xe7, 0xc1, 0x64, 0x45, 0xd2, + 0xf3, 0xd3, 0xf3, 0xc1, 0x4c, 0x7d, 0x10, 0x0b, 0x22, 0xaa, 0x24, 0xca, 0x25, 0x1c, 0x08, 0x72, + 0xab, 0x13, 0xd8, 0xbc, 0xe2, 0xa0, 0xd4, 0xc2, 0xd2, 0xd4, 0xe2, 0x12, 0xa5, 0x58, 0x2e, 0x11, + 0x54, 0xe1, 0xe2, 0x82, 0xfc, 0xbc, 0xe2, 0x54, 0x21, 0x57, 0x2e, 0x96, 0x94, 0xc4, 0x92, 0x44, + 0x09, 0x46, 0x05, 0x66, 0x0d, 0x6e, 0x23, 0x6d, 0x3d, 0xbc, 0x5e, 0xd3, 0x0b, 0xc9, 0xcf, 0x4e, + 0xcd, 0xf3, 0x4d, 0x2c, 0x28, 0xc8, 0xcc, 0x4b, 0x77, 0x62, 0x39, 0x71, 0x4f, 0x9e, 0x21, 0x08, + 0xac, 0x5d, 0x49, 0x9c, 0x4b, 0x14, 0x6c, 0xbc, 0x47, 0x69, 0x52, 0x00, 0xd8, 0x07, 0x30, 0x7b, + 0x63, 0xb8, 0xc4, 0xd0, 0x25, 0xa0, 0x36, 0x3b, 0xc1, 0x6d, 0x66, 0xd4, 0xe0, 0x36, 0xd2, 0x20, + 0x60, 0x33, 0x5c, 0x3f, 0xb2, 0xb5, 0x46, 0x37, 0x99, 0xb8, 0x58, 0xc1, 0xc6, 0x0b, 0x2d, 0x62, + 0xe4, 0x62, 0x87, 0xfa, 0x4d, 0xc8, 0x88, 0x80, 0x59, 0x58, 0xc2, 0x47, 0xca, 0x98, 0x24, 0x3d, + 0x10, 0x2f, 0x28, 0xe9, 0x35, 0x5d, 0x7e, 0x32, 0x99, 0x49, 0x43, 0x48, 0x4d, 0x1f, 0x7b, 0x64, + 0x42, 0x35, 0xeb, 0x27, 0x41, 0x1d, 0xb6, 0x8a, 0x91, 0x8b, 0x13, 0xee, 0x11, 0x21, 0x13, 0x62, + 0xac, 0x44, 0x0f, 0x50, 0x29, 0x53, 0x12, 0x75, 0x41, 0x9d, 0x6a, 0x00, 0x76, 0xaa, 0x96, 0x90, + 0x06, 0x01, 0xa7, 0x66, 0x94, 0x26, 0x41, 0x92, 0xa0, 0x53, 0xf6, 0x89, 0x47, 0x72, 0x8c, 0x17, + 0x1e, 0xc9, 0x31, 0x3e, 0x78, 0x24, 0xc7, 0x38, 0xe1, 0xb1, 0x1c, 0xc3, 0x85, 0xc7, 0x72, 0x0c, + 0x37, 0x1e, 0xcb, 0x31, 0x44, 0x05, 0xa6, 0x67, 0x96, 0x64, 0x94, 0x26, 0xe9, 0x25, 0xe7, 0xe7, + 0xea, 0x7b, 0xc2, 0x4c, 0xf3, 0x49, 0x4c, 0x2a, 0x46, 0x98, 0xad, 0x9b, 0x9c, 0x5f, 0x94, 0x8a, + 0xcc, 0xcd, 0x48, 0xcc, 0xcc, 0xd3, 0xcf, 0xcd, 0x4f, 0x29, 0xcd, 0x49, 0x2d, 0x46, 0xb1, 0xb8, + 0xa4, 0xb2, 0x20, 0xb5, 0x38, 0x89, 0x0d, 0x9c, 0x78, 0x8d, 0x01, 0x01, 0x00, 0x00, 0xff, 0xff, + 0x84, 0x33, 0xc5, 0x03, 0x7e, 0x03, 0x00, 0x00, +} + +// Reference imports to suppress errors if they are not otherwise used. +var _ context.Context +var _ grpc.ClientConn + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +const _ = grpc.SupportPackageIsVersion4 + +// QueryClient is the client API for Query service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. +type QueryClient interface { + // Retrieves registered bridges + Bridges(ctx context.Context, in *QueryBridgesRequest, opts ...grpc.CallOption) (*QueryBridgesResponse, error) + // Retrieves hub params + HubParams(ctx context.Context, in *QueryHubParamsRequest, opts ...grpc.CallOption) (*QueryHubParamsResponse, error) +} + +type queryClient struct { + cc grpc1.ClientConn +} + +func NewQueryClient(cc grpc1.ClientConn) QueryClient { + return &queryClient{cc} +} + +func (c *queryClient) Bridges(ctx context.Context, in *QueryBridgesRequest, opts ...grpc.CallOption) (*QueryBridgesResponse, error) { + out := new(QueryBridgesResponse) + err := c.cc.Invoke(ctx, "/injective.erc20bridge.v1beta1.Query/Bridges", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *queryClient) HubParams(ctx context.Context, in *QueryHubParamsRequest, opts ...grpc.CallOption) (*QueryHubParamsResponse, error) { + out := new(QueryHubParamsResponse) + err := c.cc.Invoke(ctx, "/injective.erc20bridge.v1beta1.Query/HubParams", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// QueryServer is the server API for Query service. +type QueryServer interface { + // Retrieves registered bridges + Bridges(context.Context, *QueryBridgesRequest) (*QueryBridgesResponse, error) + // Retrieves hub params + HubParams(context.Context, *QueryHubParamsRequest) (*QueryHubParamsResponse, error) +} + +// UnimplementedQueryServer can be embedded to have forward compatible implementations. +type UnimplementedQueryServer struct { +} + +func (*UnimplementedQueryServer) Bridges(ctx context.Context, req *QueryBridgesRequest) (*QueryBridgesResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Bridges not implemented") +} +func (*UnimplementedQueryServer) HubParams(ctx context.Context, req *QueryHubParamsRequest) (*QueryHubParamsResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method HubParams not implemented") +} + +func RegisterQueryServer(s grpc1.Server, srv QueryServer) { + s.RegisterService(&_Query_serviceDesc, srv) +} + +func _Query_Bridges_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(QueryBridgesRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(QueryServer).Bridges(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/injective.erc20bridge.v1beta1.Query/Bridges", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(QueryServer).Bridges(ctx, req.(*QueryBridgesRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Query_HubParams_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(QueryHubParamsRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(QueryServer).HubParams(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/injective.erc20bridge.v1beta1.Query/HubParams", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(QueryServer).HubParams(ctx, req.(*QueryHubParamsRequest)) + } + return interceptor(ctx, in, info, handler) +} + +var _Query_serviceDesc = grpc.ServiceDesc{ + ServiceName: "injective.erc20bridge.v1beta1.Query", + HandlerType: (*QueryServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "Bridges", + Handler: _Query_Bridges_Handler, + }, + { + MethodName: "HubParams", + Handler: _Query_HubParams_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "injective/erc20bridge/query.proto", +} + +func (m *QueryBridgesRequest) 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 *QueryBridgesRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryBridgesRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + return len(dAtA) - i, nil +} + +func (m *QueryBridgesResponse) 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 *QueryBridgesResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryBridgesResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Data) > 0 { + for iNdEx := len(m.Data) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.Data[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + } + return len(dAtA) - i, nil +} + +func (m *QueryHubParamsRequest) 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 *QueryHubParamsRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryHubParamsRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + return len(dAtA) - i, nil +} + +func (m *QueryHubParamsResponse) 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 *QueryHubParamsResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryHubParamsResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size, err := m.Data.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + return len(dAtA) - i, nil +} + +func encodeVarintQuery(dAtA []byte, offset int, v uint64) int { + offset -= sovQuery(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *QueryBridgesRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + +func (m *QueryBridgesResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if len(m.Data) > 0 { + for _, e := range m.Data { + l = e.Size() + n += 1 + l + sovQuery(uint64(l)) + } + } + return n +} + +func (m *QueryHubParamsRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + +func (m *QueryHubParamsResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = m.Data.Size() + n += 1 + l + sovQuery(uint64(l)) + return n +} + +func sovQuery(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozQuery(x uint64) (n int) { + return sovQuery(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *QueryBridgesRequest) 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 ErrIntOverflowQuery + } + 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: QueryBridgesRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryBridgesRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryBridgesResponse) 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 ErrIntOverflowQuery + } + 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: QueryBridgesResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryBridgesResponse: 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 msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Data = append(m.Data, TokenMapping{}) + if err := m.Data[len(m.Data)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryHubParamsRequest) 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 ErrIntOverflowQuery + } + 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: QueryHubParamsRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryHubParamsRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryHubParamsResponse) 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 ErrIntOverflowQuery + } + 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: QueryHubParamsResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryHubParamsResponse: 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 msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.Data.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipQuery(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, ErrIntOverflowQuery + } + 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, ErrIntOverflowQuery + } + 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, ErrIntOverflowQuery + } + 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, ErrInvalidLengthQuery + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupQuery + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthQuery + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthQuery = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowQuery = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupQuery = fmt.Errorf("proto: unexpected end of group") +) diff --git a/chain/erc20bridge/types/query.pb.gw.go b/chain/erc20bridge/types/query.pb.gw.go new file mode 100644 index 00000000..e9882907 --- /dev/null +++ b/chain/erc20bridge/types/query.pb.gw.go @@ -0,0 +1,210 @@ +// Code generated by protoc-gen-grpc-gateway. DO NOT EDIT. +// source: injective/erc20bridge/query.proto + +/* +Package types is a reverse proxy. + +It translates gRPC into RESTful JSON APIs. +*/ +package types + +import ( + "context" + "io" + "net/http" + + "github.com/golang/protobuf/descriptor" + "github.com/golang/protobuf/proto" + "github.com/grpc-ecosystem/grpc-gateway/runtime" + "github.com/grpc-ecosystem/grpc-gateway/utilities" + "google.golang.org/grpc" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/grpclog" + "google.golang.org/grpc/status" +) + +// Suppress "imported and not used" errors +var _ codes.Code +var _ io.Reader +var _ status.Status +var _ = runtime.String +var _ = utilities.NewDoubleArray +var _ = descriptor.ForMessage + +func request_Query_Bridges_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryBridgesRequest + var metadata runtime.ServerMetadata + + msg, err := client.Bridges(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Query_Bridges_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryBridgesRequest + var metadata runtime.ServerMetadata + + msg, err := server.Bridges(ctx, &protoReq) + return msg, metadata, err + +} + +func request_Query_HubParams_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryHubParamsRequest + var metadata runtime.ServerMetadata + + msg, err := client.HubParams(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Query_HubParams_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryHubParamsRequest + var metadata runtime.ServerMetadata + + msg, err := server.HubParams(ctx, &protoReq) + return msg, metadata, err + +} + +// RegisterQueryHandlerServer registers the http handlers for service Query to "mux". +// UnaryRPC :call QueryServer directly. +// StreamingRPC :currently unsupported pending https://github.com/grpc/grpc-go/issues/906. +// Note that using this registration option will cause many gRPC library features (such as grpc.SendHeader, etc) to stop working. Consider using RegisterQueryHandlerFromEndpoint instead. +func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, server QueryServer) error { + + mux.Handle("GET", pattern_Query_Bridges_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_Query_Bridges_0(rctx, inboundMarshaler, server, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_Bridges_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_HubParams_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_Query_HubParams_0(rctx, inboundMarshaler, server, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_HubParams_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + return nil +} + +// RegisterQueryHandlerFromEndpoint is same as RegisterQueryHandler but +// automatically dials to "endpoint" and closes the connection when "ctx" gets done. +func RegisterQueryHandlerFromEndpoint(ctx context.Context, mux *runtime.ServeMux, endpoint string, opts []grpc.DialOption) (err error) { + conn, err := grpc.Dial(endpoint, opts...) + if err != nil { + return err + } + defer func() { + if err != nil { + if cerr := conn.Close(); cerr != nil { + grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr) + } + return + } + go func() { + <-ctx.Done() + if cerr := conn.Close(); cerr != nil { + grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr) + } + }() + }() + + return RegisterQueryHandler(ctx, mux, conn) +} + +// RegisterQueryHandler registers the http handlers for service Query to "mux". +// The handlers forward requests to the grpc endpoint over "conn". +func RegisterQueryHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error { + return RegisterQueryHandlerClient(ctx, mux, NewQueryClient(conn)) +} + +// RegisterQueryHandlerClient registers the http handlers for service Query +// to "mux". The handlers forward requests to the grpc endpoint over the given implementation of "QueryClient". +// Note: the gRPC framework executes interceptors within the gRPC handler. If the passed in "QueryClient" +// doesn't go through the normal gRPC flow (creating a gRPC client etc.) then it will be up to the passed in +// "QueryClient" to call the correct interceptors. +func RegisterQueryHandlerClient(ctx context.Context, mux *runtime.ServeMux, client QueryClient) error { + + mux.Handle("GET", pattern_Query_Bridges_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_Query_Bridges_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_Bridges_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_HubParams_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_Query_HubParams_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_HubParams_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + return nil +} + +var ( + pattern_Query_Bridges_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"injective", "erc20bridge", "v1beta1", "bridges"}, "", runtime.AssumeColonVerbOpt(true))) + + pattern_Query_HubParams_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"injective", "erc20bridge", "v1beta1", "hubparams"}, "", runtime.AssumeColonVerbOpt(true))) +) + +var ( + forward_Query_Bridges_0 = runtime.ForwardResponseMessage + + forward_Query_HubParams_0 = runtime.ForwardResponseMessage +) diff --git a/chain/erc20bridge/types/token_mapping.go b/chain/erc20bridge/types/token_mapping.go new file mode 100644 index 00000000..d514d2f1 --- /dev/null +++ b/chain/erc20bridge/types/token_mapping.go @@ -0,0 +1,21 @@ +package types + +import ( + fmt "fmt" + + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/ethereum/go-ethereum/common" +) + +// ValidateBasic does basic validation of a TokenMapping +func (v TokenMapping) ValidateBasic() error { + if err := sdk.ValidateDenom(v.CosmosDenom); err != nil { + return fmt.Errorf("invalid cosmos denom: %s: %s", v.CosmosDenom, err.Error()) + } + + if !common.IsHexAddress(v.Erc20Address) { + return fmt.Errorf("invalid child address: %s", v.Erc20Address) + } + + return nil +} diff --git a/chain/erc20bridge/types/tx.pb.go b/chain/erc20bridge/types/tx.pb.go new file mode 100644 index 00000000..5c919e44 --- /dev/null +++ b/chain/erc20bridge/types/tx.pb.go @@ -0,0 +1,718 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: injective/erc20bridge/tx.proto + +package types + +import ( + fmt "fmt" + github_com_cosmos_cosmos_sdk_types "github.com/cosmos/cosmos-sdk/types" + _ "github.com/gogo/protobuf/gogoproto" + proto "github.com/gogo/protobuf/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 + +// MsgInitHub describes a message to init ERC20 parent contract inside bridge keeper +type MsgInitHub struct { + HubAddress string `protobuf:"bytes,1,opt,name=hub_address,json=hubAddress,proto3" json:"hub_address,omitempty" yaml:"hub_address"` + Proposer github_com_cosmos_cosmos_sdk_types.AccAddress `protobuf:"bytes,2,opt,name=proposer,proto3,casttype=github.com/cosmos/cosmos-sdk/types.AccAddress" json:"proposer,omitempty" yaml:"proposer"` +} + +func (m *MsgInitHub) Reset() { *m = MsgInitHub{} } +func (m *MsgInitHub) String() string { return proto.CompactTextString(m) } +func (*MsgInitHub) ProtoMessage() {} +func (*MsgInitHub) Descriptor() ([]byte, []int) { + return fileDescriptor_f3d69c0f4664bc25, []int{0} +} +func (m *MsgInitHub) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgInitHub) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgInitHub.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 *MsgInitHub) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgInitHub.Merge(m, src) +} +func (m *MsgInitHub) XXX_Size() int { + return m.Size() +} +func (m *MsgInitHub) XXX_DiscardUnknown() { + xxx_messageInfo_MsgInitHub.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgInitHub proto.InternalMessageInfo + +func (m *MsgInitHub) GetHubAddress() string { + if m != nil { + return m.HubAddress + } + return "" +} + +func (m *MsgInitHub) GetProposer() github_com_cosmos_cosmos_sdk_types.AccAddress { + if m != nil { + return m.Proposer + } + return nil +} + +type MsgERC20BridgeMint struct { + // ID of token mapping registered on bridge + MappingId string `protobuf:"bytes,1,opt,name=mapping_id,json=mappingId,proto3" json:"mapping_id,omitempty"` + // amount of token to mint + Amount string `protobuf:"bytes,2,opt,name=amount,proto3" json:"amount,omitempty"` + // iEVM address to receive ERC20 token + Address string `protobuf:"bytes,3,opt,name=address,proto3" json:"address,omitempty" yaml:"address"` + // cosmos address + Proposer github_com_cosmos_cosmos_sdk_types.AccAddress `protobuf:"bytes,4,opt,name=proposer,proto3,casttype=github.com/cosmos/cosmos-sdk/types.AccAddress" json:"proposer,omitempty" yaml:"proposer"` +} + +func (m *MsgERC20BridgeMint) Reset() { *m = MsgERC20BridgeMint{} } +func (m *MsgERC20BridgeMint) String() string { return proto.CompactTextString(m) } +func (*MsgERC20BridgeMint) ProtoMessage() {} +func (*MsgERC20BridgeMint) Descriptor() ([]byte, []int) { + return fileDescriptor_f3d69c0f4664bc25, []int{1} +} +func (m *MsgERC20BridgeMint) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgERC20BridgeMint) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgERC20BridgeMint.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 *MsgERC20BridgeMint) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgERC20BridgeMint.Merge(m, src) +} +func (m *MsgERC20BridgeMint) XXX_Size() int { + return m.Size() +} +func (m *MsgERC20BridgeMint) XXX_DiscardUnknown() { + xxx_messageInfo_MsgERC20BridgeMint.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgERC20BridgeMint proto.InternalMessageInfo + +func (m *MsgERC20BridgeMint) GetMappingId() string { + if m != nil { + return m.MappingId + } + return "" +} + +func (m *MsgERC20BridgeMint) GetAmount() string { + if m != nil { + return m.Amount + } + return "" +} + +func (m *MsgERC20BridgeMint) GetAddress() string { + if m != nil { + return m.Address + } + return "" +} + +func (m *MsgERC20BridgeMint) GetProposer() github_com_cosmos_cosmos_sdk_types.AccAddress { + if m != nil { + return m.Proposer + } + return nil +} + +func init() { + proto.RegisterType((*MsgInitHub)(nil), "injective.erc20bridge.v1beta1.MsgInitHub") + proto.RegisterType((*MsgERC20BridgeMint)(nil), "injective.erc20bridge.v1beta1.MsgERC20BridgeMint") +} + +func init() { proto.RegisterFile("injective/erc20bridge/tx.proto", fileDescriptor_f3d69c0f4664bc25) } + +var fileDescriptor_f3d69c0f4664bc25 = []byte{ + // 367 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x92, 0xcf, 0x4a, 0xeb, 0x40, + 0x14, 0xc6, 0x3b, 0xf7, 0x5e, 0x7a, 0xed, 0x28, 0x0a, 0x83, 0x94, 0x22, 0x34, 0x29, 0x59, 0x75, + 0x61, 0x93, 0xb6, 0x2e, 0x04, 0x77, 0x8d, 0x0a, 0x16, 0xec, 0xc2, 0x2c, 0xdd, 0xd4, 0x4c, 0x32, + 0x24, 0x63, 0x9b, 0x4c, 0x98, 0x99, 0x14, 0xfb, 0x16, 0xbe, 0x85, 0xaf, 0xe2, 0xb2, 0x4b, 0x41, + 0x08, 0xd2, 0xbe, 0x41, 0x97, 0xae, 0xa4, 0xf9, 0x47, 0xfa, 0x00, 0xae, 0x66, 0xce, 0x7c, 0xe7, + 0x1c, 0xbe, 0x1f, 0xdf, 0x40, 0x85, 0x86, 0xcf, 0xc4, 0x91, 0x74, 0x41, 0x0c, 0xc2, 0x9d, 0x61, + 0x1f, 0x73, 0xea, 0x7a, 0xc4, 0x90, 0x2f, 0x7a, 0xc4, 0x99, 0x64, 0xa8, 0x5d, 0xea, 0x7a, 0x45, + 0xd7, 0x17, 0x03, 0x4c, 0xa4, 0x3d, 0x38, 0x3b, 0xf5, 0x98, 0xc7, 0xd2, 0x4e, 0x63, 0x77, 0xcb, + 0x86, 0xb4, 0x37, 0x00, 0xe1, 0x44, 0x78, 0xe3, 0x90, 0xca, 0xbb, 0x18, 0xa3, 0x4b, 0x78, 0xe8, + 0xc7, 0x78, 0x6a, 0xbb, 0x2e, 0x27, 0x42, 0xb4, 0x40, 0x07, 0x74, 0x1b, 0x66, 0x73, 0x9b, 0xa8, + 0x68, 0x69, 0x07, 0xf3, 0x2b, 0xad, 0x22, 0x6a, 0x16, 0xf4, 0x63, 0x3c, 0xca, 0x0a, 0xf4, 0x04, + 0x0f, 0x22, 0xce, 0x22, 0x26, 0x08, 0x6f, 0xfd, 0xe9, 0x80, 0xee, 0x91, 0x79, 0xb3, 0x4d, 0xd4, + 0x93, 0x6c, 0xaa, 0x50, 0xb4, 0xef, 0x44, 0xed, 0x79, 0x54, 0xfa, 0x31, 0xd6, 0x1d, 0x16, 0x18, + 0x0e, 0x13, 0x01, 0x13, 0xf9, 0xd1, 0x13, 0xee, 0xcc, 0x90, 0xcb, 0x88, 0x08, 0x7d, 0xe4, 0x38, + 0xf9, 0x5e, 0xab, 0xdc, 0xaa, 0x7d, 0x02, 0x88, 0x26, 0xc2, 0xbb, 0xb5, 0xae, 0x87, 0x7d, 0x33, + 0x45, 0x9b, 0xd0, 0x50, 0xa2, 0x36, 0x84, 0x81, 0x1d, 0x45, 0x34, 0xf4, 0xa6, 0xd4, 0xcd, 0x0c, + 0x5b, 0x8d, 0xfc, 0x65, 0xec, 0xa2, 0x26, 0xac, 0xdb, 0x01, 0x8b, 0x43, 0x99, 0xba, 0x6a, 0x58, + 0x79, 0x85, 0xce, 0xe1, 0xff, 0x02, 0xf2, 0x6f, 0x0a, 0x89, 0xb6, 0x89, 0x7a, 0x9c, 0xd9, 0x2d, + 0x01, 0x8b, 0x96, 0x3d, 0xba, 0x7f, 0xbf, 0x41, 0x67, 0xce, 0xde, 0xd7, 0x0a, 0x58, 0xad, 0x15, + 0xf0, 0xb5, 0x56, 0xc0, 0xeb, 0x46, 0xa9, 0xad, 0x36, 0x4a, 0xed, 0x63, 0xa3, 0xd4, 0x1e, 0x1f, + 0x2a, 0x2b, 0xc7, 0x45, 0xc2, 0xf7, 0x36, 0x16, 0x46, 0x99, 0x77, 0xcf, 0x61, 0x9c, 0x54, 0x4b, + 0xdf, 0xa6, 0xa1, 0x11, 0x30, 0x37, 0x9e, 0x13, 0xb1, 0xff, 0x59, 0x76, 0x0e, 0x70, 0x3d, 0xcd, + 0xfe, 0xe2, 0x27, 0x00, 0x00, 0xff, 0xff, 0x61, 0x6a, 0x65, 0x85, 0x52, 0x02, 0x00, 0x00, +} + +func (m *MsgInitHub) 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 *MsgInitHub) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgInitHub) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Proposer) > 0 { + i -= len(m.Proposer) + copy(dAtA[i:], m.Proposer) + i = encodeVarintTx(dAtA, i, uint64(len(m.Proposer))) + i-- + dAtA[i] = 0x12 + } + if len(m.HubAddress) > 0 { + i -= len(m.HubAddress) + copy(dAtA[i:], m.HubAddress) + i = encodeVarintTx(dAtA, i, uint64(len(m.HubAddress))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *MsgERC20BridgeMint) 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 *MsgERC20BridgeMint) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgERC20BridgeMint) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Proposer) > 0 { + i -= len(m.Proposer) + copy(dAtA[i:], m.Proposer) + i = encodeVarintTx(dAtA, i, uint64(len(m.Proposer))) + i-- + dAtA[i] = 0x22 + } + if len(m.Address) > 0 { + i -= len(m.Address) + copy(dAtA[i:], m.Address) + i = encodeVarintTx(dAtA, i, uint64(len(m.Address))) + i-- + dAtA[i] = 0x1a + } + if len(m.Amount) > 0 { + i -= len(m.Amount) + copy(dAtA[i:], m.Amount) + i = encodeVarintTx(dAtA, i, uint64(len(m.Amount))) + i-- + dAtA[i] = 0x12 + } + if len(m.MappingId) > 0 { + i -= len(m.MappingId) + copy(dAtA[i:], m.MappingId) + i = encodeVarintTx(dAtA, i, uint64(len(m.MappingId))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func encodeVarintTx(dAtA []byte, offset int, v uint64) int { + offset -= sovTx(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *MsgInitHub) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.HubAddress) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + l = len(m.Proposer) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + return n +} + +func (m *MsgERC20BridgeMint) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.MappingId) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + l = len(m.Amount) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + l = len(m.Address) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + l = len(m.Proposer) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + return n +} + +func sovTx(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozTx(x uint64) (n int) { + return sovTx(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *MsgInitHub) 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 ErrIntOverflowTx + } + 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: MsgInitHub: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgInitHub: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field HubAddress", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + 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 ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.HubAddress = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Proposer", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Proposer = append(m.Proposer[:0], dAtA[iNdEx:postIndex]...) + if m.Proposer == nil { + m.Proposer = []byte{} + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MsgERC20BridgeMint) 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 ErrIntOverflowTx + } + 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: MsgERC20BridgeMint: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgERC20BridgeMint: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field MappingId", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + 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 ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.MappingId = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Amount", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + 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 ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Amount = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Address", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + 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 ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Address = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 4: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Proposer", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Proposer = append(m.Proposer[:0], dAtA[iNdEx:postIndex]...) + if m.Proposer == nil { + m.Proposer = []byte{} + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipTx(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, ErrIntOverflowTx + } + 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, ErrIntOverflowTx + } + 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, ErrIntOverflowTx + } + 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, ErrInvalidLengthTx + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupTx + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthTx + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthTx = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowTx = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupTx = fmt.Errorf("proto: unexpected end of group") +) From ae4884fcf465a5b345a916a10cee95adb0cf94ae Mon Sep 17 00:00:00 2001 From: gopherjk121 Date: Wed, 6 Jan 2021 23:20:46 +1000 Subject: [PATCH 02/11] add cli commands, ethereum/rpc utility, modify evm query types for evm static call --- chain/erc20bridge/client/cli/query.go | 88 ++++ chain/evm/client/cli/query.go | 162 ++++++++ chain/evm/client/cli/utils.go | 63 +++ chain/evm/types/query.pb.go | 553 +++++++++++++++++++++++--- ethereum/rpc/block.go | 19 + 5 files changed, 832 insertions(+), 53 deletions(-) create mode 100644 chain/erc20bridge/client/cli/query.go create mode 100644 chain/evm/client/cli/query.go create mode 100644 chain/evm/client/cli/utils.go create mode 100644 ethereum/rpc/block.go diff --git a/chain/erc20bridge/client/cli/query.go b/chain/erc20bridge/client/cli/query.go new file mode 100644 index 00000000..d920f94d --- /dev/null +++ b/chain/erc20bridge/client/cli/query.go @@ -0,0 +1,88 @@ +package cli + +import ( + "github.com/InjectiveLabs/sdk-go/chain/erc20bridge/types" + "github.com/InjectiveLabs/sdk-go/ethereum/rpc" + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/client/flags" + "github.com/spf13/cobra" +) + +// GetQueryCmd returns the parent command for all modules/bank CLi query commands. +func GetQueryCmd() *cobra.Command { + cmd := &cobra.Command{ + Use: types.ModuleName, + Short: "Querying commands for the erc20bridge module", + DisableFlagParsing: true, + SuggestionsMinimumDistance: 2, + RunE: client.ValidateCmd, + } + + cmd.AddCommand( + GetBridgesCmd(), + GetHubParamsCmd(), + ) + return cmd +} + +// GetBridgesCmd queries a bridges registered +func GetBridgesCmd() *cobra.Command { + cmd := &cobra.Command{ + Use: "bridges", + Short: "Gets bridges registered", + Long: "Gets bridges registered.", + Args: cobra.ExactArgs(0), + RunE: func(cmd *cobra.Command, args []string) error { + clientCtx := client.GetClientContextFromCmd(cmd) + clientCtx, err := client.ReadQueryCommandFlags(clientCtx, cmd.Flags()) + if err != nil { + return err + } + + queryClient := types.NewQueryClient(clientCtx) + + req := &types.QueryBridgesRequest{} + + res, err := queryClient.Bridges(rpc.ContextWithHeight(clientCtx.Height), req) + if err != nil { + return err + } + + return clientCtx.PrintOutput(res) + }, + } + + flags.AddQueryFlagsToCmd(cmd) + return cmd +} + +// GetHubParamsCmd queries hub info +func GetHubParamsCmd() *cobra.Command { + cmd := &cobra.Command{ + Use: "hubparams", + Short: "Gets hub info.", + Long: "Gets hub info.", + Args: cobra.ExactArgs(0), + RunE: func(cmd *cobra.Command, args []string) error { + clientCtx := client.GetClientContextFromCmd(cmd) + clientCtx, err := client.ReadQueryCommandFlags(clientCtx, cmd.Flags()) + if err != nil { + return err + } + + queryClient := types.NewQueryClient(clientCtx) + + req := &types.QueryHubParamsRequest{} + + res, err := queryClient.HubParams(rpc.ContextWithHeight(clientCtx.Height), req) + if err != nil { + return err + } + + return clientCtx.PrintOutput(res) + }, + } + + flags.AddQueryFlagsToCmd(cmd) + return cmd +} diff --git a/chain/evm/client/cli/query.go b/chain/evm/client/cli/query.go new file mode 100644 index 00000000..6f8ef581 --- /dev/null +++ b/chain/evm/client/cli/query.go @@ -0,0 +1,162 @@ +package cli + +import ( + "math/big" + "strings" + + "github.com/ethereum/go-ethereum/accounts/abi" + "github.com/ethereum/go-ethereum/common" + "github.com/spf13/cobra" + + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/client/flags" + + "github.com/InjectiveLabs/sdk-go/chain/evm/types" + "github.com/InjectiveLabs/sdk-go/ethereum/rpc" + "github.com/InjectiveLabs/sdk-go/wrappers" +) + +// GetQueryCmd returns the parent command for all modules/bank CLi query commands. +func GetQueryCmd() *cobra.Command { + cmd := &cobra.Command{ + Use: types.ModuleName, + Short: "Querying commands for the evm module", + DisableFlagParsing: true, + SuggestionsMinimumDistance: 2, + RunE: client.ValidateCmd, + } + + cmd.AddCommand( + GetStorageCmd(), + GetCodeCmd(), + GetErc20Balance(), + ) + return cmd +} + +// GetStorageCmd queries a key in an accounts storage +func GetStorageCmd() *cobra.Command { + cmd := &cobra.Command{ + Use: "storage [address] [key]", + Short: "Gets storage for an account with a given key and height", + Long: "Gets storage for an account with a given key and height. If the height is not provided, it will use the latest height from context.", + Args: cobra.ExactArgs(2), + RunE: func(cmd *cobra.Command, args []string) error { + clientCtx := client.GetClientContextFromCmd(cmd) + clientCtx, err := client.ReadQueryCommandFlags(clientCtx, cmd.Flags()) + if err != nil { + return err + } + + queryClient := types.NewQueryClient(clientCtx) + + address, err := accountToHex(args[0]) + if err != nil { + return err + } + + key := formatKeyToHash(args[1]) + + req := &types.QueryStorageRequest{ + Address: address, + Key: key, + } + + res, err := queryClient.Storage(rpc.ContextWithHeight(clientCtx.Height), req) + if err != nil { + return err + } + + return clientCtx.PrintOutput(res) + }, + } + + flags.AddQueryFlagsToCmd(cmd) + return cmd +} + +// GetCodeCmd queries the code field of a given address +func GetCodeCmd() *cobra.Command { + cmd := &cobra.Command{ + Use: "code [address]", + Short: "Gets code from an account", + Long: "Gets code from an account. If the height is not provided, it will use the latest height from context.", + Args: cobra.ExactArgs(1), + RunE: func(cmd *cobra.Command, args []string) error { + clientCtx := client.GetClientContextFromCmd(cmd) + clientCtx, err := client.ReadQueryCommandFlags(clientCtx, cmd.Flags()) + if err != nil { + return err + } + + queryClient := types.NewQueryClient(clientCtx) + + address, err := accountToHex(args[0]) + if err != nil { + return err + } + + req := &types.QueryCodeRequest{ + Address: address, + } + + res, err := queryClient.Code(rpc.ContextWithHeight(clientCtx.Height), req) + if err != nil { + return err + } + + return clientCtx.PrintOutput(res) + }, + } + + flags.AddQueryFlagsToCmd(cmd) + return cmd +} + +// GetErc20Balance queries the erc20 balance of an address +func GetErc20Balance() *cobra.Command { + cmd := &cobra.Command{ + Use: "erc20balance [contract] [address]", + Short: "Gets erc20 balance of an account", + Long: "Gets erc20 balance of an account.", + Args: cobra.ExactArgs(2), + RunE: func(cmd *cobra.Command, args []string) error { + clientCtx := client.GetClientContextFromCmd(cmd) + clientCtx, err := client.ReadQueryCommandFlags(clientCtx, cmd.Flags()) + if err != nil { + return err + } + + queryClient := types.NewQueryClient(clientCtx) + + contract := args[0] + address := args[1] + + erc20ABI, err := abi.JSON(strings.NewReader(wrappers.ERC20ABI)) + if err != nil { + return err + } + input, err := erc20ABI.Pack("balanceOf", common.HexToAddress(address)) + if err != nil { + return err + } + + req := &types.QueryStaticCallRequest{ + Address: contract, + Input: input, + } + + res, err := queryClient.StaticCall(rpc.ContextWithHeight(clientCtx.Height), req) + if err != nil { + return err + } + ret := big.NewInt(0) + err = erc20ABI.Unpack(&ret, "balanceOf", res.Data) + + return clientCtx.PrintString(ret.String()) + }, + } + + flags.AddQueryFlagsToCmd(cmd) + return cmd +} diff --git a/chain/evm/client/cli/utils.go b/chain/evm/client/cli/utils.go new file mode 100644 index 00000000..6114246c --- /dev/null +++ b/chain/evm/client/cli/utils.go @@ -0,0 +1,63 @@ +package cli + +import ( + "fmt" + "strings" + + "github.com/pkg/errors" + + "github.com/ethereum/go-ethereum/common" + + sdk "github.com/cosmos/cosmos-sdk/types" +) + +func accountToHex(addr string) (string, error) { + if strings.HasPrefix(addr, sdk.GetConfig().GetBech32AccountAddrPrefix()) { + // Check to see if address is Cosmos bech32 formatted + toAddr, err := sdk.AccAddressFromBech32(addr) + if err != nil { + return "", errors.Wrap(err, "must provide a valid Bech32 address") + } + ethAddr := common.BytesToAddress(toAddr.Bytes()) + return ethAddr.Hex(), nil + } + + if !strings.HasPrefix(addr, "0x") { + addr = "0x" + addr + } + + valid := common.IsHexAddress(addr) + if !valid { + return "", fmt.Errorf("%s is not a valid Ethereum or Cosmos address", addr) + } + + ethAddr := common.HexToAddress(addr) + + return ethAddr.Hex(), nil +} + +func formatKeyToHash(key string) string { + if !strings.HasPrefix(key, "0x") { + key = "0x" + key + } + + ethkey := common.HexToHash(key) + + return ethkey.Hex() +} + +func cosmosAddressFromArg(addr string) (sdk.AccAddress, error) { + if strings.HasPrefix(addr, sdk.GetConfig().GetBech32AccountAddrPrefix()) { + // Check to see if address is Cosmos bech32 formatted + toAddr, err := sdk.AccAddressFromBech32(addr) + if err != nil { + return nil, errors.Wrap(err, "invalid bech32 formatted address") + } + return toAddr, nil + } + + // Strip 0x prefix if exists + addr = strings.TrimPrefix(addr, "0x") + + return sdk.AccAddressFromHex(addr) +} diff --git a/chain/evm/types/query.pb.go b/chain/evm/types/query.pb.go index 702446b7..5d6b9f85 100644 --- a/chain/evm/types/query.pb.go +++ b/chain/evm/types/query.pb.go @@ -737,6 +737,106 @@ func (m *QueryParamsResponse) GetParams() Params { return Params{} } +// QueryStaticCallRequest defines static call request +type QueryStaticCallRequest struct { + // address is the ethereum contract hex address to for static call. + Address string `protobuf:"bytes,1,opt,name=address,proto3" json:"address,omitempty"` + // static call input generated from abi + Input []byte `protobuf:"bytes,2,opt,name=input,proto3" json:"input,omitempty"` +} + +func (m *QueryStaticCallRequest) Reset() { *m = QueryStaticCallRequest{} } +func (m *QueryStaticCallRequest) String() string { return proto.CompactTextString(m) } +func (*QueryStaticCallRequest) ProtoMessage() {} +func (*QueryStaticCallRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_b35cda93d73bda44, []int{16} +} +func (m *QueryStaticCallRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryStaticCallRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryStaticCallRequest.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 *QueryStaticCallRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryStaticCallRequest.Merge(m, src) +} +func (m *QueryStaticCallRequest) XXX_Size() int { + return m.Size() +} +func (m *QueryStaticCallRequest) XXX_DiscardUnknown() { + xxx_messageInfo_QueryStaticCallRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryStaticCallRequest proto.InternalMessageInfo + +func (m *QueryStaticCallRequest) GetAddress() string { + if m != nil { + return m.Address + } + return "" +} + +func (m *QueryStaticCallRequest) GetInput() []byte { + if m != nil { + return m.Input + } + return nil +} + +// // QueryStaticCallRequest defines static call response +type QueryStaticCallResponse struct { + Data []byte `protobuf:"bytes,1,opt,name=data,proto3" json:"data,omitempty"` +} + +func (m *QueryStaticCallResponse) Reset() { *m = QueryStaticCallResponse{} } +func (m *QueryStaticCallResponse) String() string { return proto.CompactTextString(m) } +func (*QueryStaticCallResponse) ProtoMessage() {} +func (*QueryStaticCallResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_b35cda93d73bda44, []int{17} +} +func (m *QueryStaticCallResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryStaticCallResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryStaticCallResponse.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 *QueryStaticCallResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryStaticCallResponse.Merge(m, src) +} +func (m *QueryStaticCallResponse) XXX_Size() int { + return m.Size() +} +func (m *QueryStaticCallResponse) XXX_DiscardUnknown() { + xxx_messageInfo_QueryStaticCallResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryStaticCallResponse proto.InternalMessageInfo + +func (m *QueryStaticCallResponse) GetData() []byte { + if m != nil { + return m.Data + } + return nil +} + func init() { proto.RegisterType((*QueryAccountRequest)(nil), "injective.evm.v1beta1.QueryAccountRequest") proto.RegisterType((*QueryAccountResponse)(nil), "injective.evm.v1beta1.QueryAccountResponse") @@ -754,64 +854,70 @@ func init() { proto.RegisterType((*QueryBlockBloomResponse)(nil), "injective.evm.v1beta1.QueryBlockBloomResponse") proto.RegisterType((*QueryParamsRequest)(nil), "injective.evm.v1beta1.QueryParamsRequest") proto.RegisterType((*QueryParamsResponse)(nil), "injective.evm.v1beta1.QueryParamsResponse") + proto.RegisterType((*QueryStaticCallRequest)(nil), "injective.evm.v1beta1.QueryStaticCallRequest") + proto.RegisterType((*QueryStaticCallResponse)(nil), "injective.evm.v1beta1.QueryStaticCallResponse") } func init() { proto.RegisterFile("injective/evm/v1beta1/query.proto", fileDescriptor_b35cda93d73bda44) } var fileDescriptor_b35cda93d73bda44 = []byte{ - // 831 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x96, 0x4f, 0x4f, 0x13, 0x4f, - 0x18, 0xc7, 0xbb, 0xb4, 0xb4, 0x74, 0xe0, 0xc0, 0x6f, 0x7e, 0x05, 0xc9, 0x2a, 0x2d, 0x6e, 0x04, - 0x4a, 0x81, 0xdd, 0x52, 0x23, 0x89, 0x7a, 0xb2, 0x86, 0x44, 0x22, 0x07, 0x5d, 0x39, 0x79, 0x21, - 0xd3, 0xed, 0x64, 0x5b, 0x69, 0x77, 0x4a, 0x67, 0xdb, 0xd0, 0x10, 0x2e, 0x1e, 0x8c, 0x5e, 0x8c, - 0x89, 0x1a, 0x13, 0x4f, 0xbc, 0x04, 0x5f, 0x06, 0x47, 0x12, 0x2f, 0x9e, 0x8c, 0x01, 0x0f, 0xbe, - 0x0c, 0x33, 0x7f, 0xb6, 0xdd, 0xd6, 0xee, 0xb6, 0xdc, 0x76, 0xb6, 0xdf, 0xe7, 0xf9, 0x7e, 0x66, - 0x66, 0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x07, 0xe1, 0xd4, 0x78, 0x09, 0x00, 0x00, + // 893 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x96, 0xcf, 0x6f, 0xe3, 0x44, + 0x14, 0xc7, 0xe3, 0xcd, 0xaf, 0xcd, 0xec, 0x1e, 0x96, 0x21, 0xbb, 0x54, 0x86, 0x4d, 0xca, 0x88, + 0x6d, 0xd3, 0xb4, 0xb1, 0xd3, 0x20, 0x2a, 0x01, 0x27, 0x52, 0x55, 0x6a, 0x45, 0x0f, 0xe0, 0xf6, + 0xc4, 0x25, 0x9a, 0x38, 0x23, 0xc7, 0xd4, 0xf1, 0xa4, 0x19, 0x27, 0x6a, 0x54, 0xf5, 0xc2, 0x01, + 0xc1, 0x05, 0x21, 0x01, 0x42, 0xe2, 0xd4, 0x3f, 0xa7, 0xe2, 0x54, 0x89, 0x0b, 0x27, 0x84, 0x5a, + 0x0e, 0xfc, 0x19, 0xab, 0xf9, 0xe1, 0xc4, 0x49, 0x63, 0x27, 0xbd, 0xcd, 0x73, 0xdf, 0x7b, 0xdf, + 0xcf, 0x7b, 0x33, 0xf9, 0xaa, 0xe0, 0x43, 0xd7, 0xff, 0x96, 0xd8, 0x81, 0x3b, 0x22, 0x26, 0x19, + 0xf5, 0xcc, 0xd1, 0x6e, 0x9b, 0x04, 0x78, 0xd7, 0x3c, 0x1f, 0x92, 0xc1, 0xd8, 0xe8, 0x0f, 0x68, + 0x40, 0xe1, 0xcb, 0x49, 0x8a, 0x41, 0x46, 0x3d, 0x43, 0xa5, 0xe8, 0x45, 0x87, 0x3a, 0x54, 0x64, + 0x98, 0xfc, 0x24, 0x93, 0xf5, 0x0f, 0x1c, 0x4a, 0x1d, 0x8f, 0x98, 0xb8, 0xef, 0x9a, 0xd8, 0xf7, + 0x69, 0x80, 0x03, 0x97, 0xfa, 0x4c, 0xfd, 0xb5, 0xbc, 0x58, 0x8d, 0xb7,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 0x9d, 0xc4, + 0x77, 0x32, 0xe7, 0x79, 0x7a, 0x6d, 0xc5, 0xec, 0x15, 0x9f, 0x7b, 0x9b, 0x57, 0xcc, 0xc0, 0xfd, + 0xae, 0x01, 0x30, 0xf5, 0x27, 0xb8, 0x5c, 0x2f, 0xea, 0x7c, 0xba, 0xb1, 0x6a, 0xba, 0xe2, 0xab, + 0x0a, 0xbe, 0x8f, 0x20, 0x4a, 0xe4, 0x13, 0x66, 0x08, 0xbf, 0xd7, 0x40, 0x4e, 0x7a, 0x57, 0xf2, + 0x3d, 0xce, 0x98, 0x65, 0xf2, 0x3d, 0xce, 0x3a, 0x28, 0x7a, 0x23, 0x68, 0xca, 0xf0, 0x75, 0x0c, + 0x8d, 0xf4, 0x4a, 0xb1, 0xa2, 0xa9, 0xbb, 0x25, 0xaf, 0xe8, 0x81, 0x9f, 0x26, 0xaf, 0xe8, 0xa1, + 0x69, 0x2e, 0x5d, 0x11, 0x13, 0x25, 0x2d, 0x1b, 0x7b, 0x5e, 0xd3, 0xbe, 0xb9, 0x2b, 0x69, 0xb7, + 0x77, 0x25, 0xed, 0xdf, 0xbb, 0x92, 0xf6, 0xf3, 0x7d, 0x29, 0x75, 0x7b, 0x5f, 0x4a, 0xfd, 0x7d, + 0x5f, 0x4a, 0x7d, 0x73, 0xe4, 0xb8, 0x41, 0x77, 0xd8, 0x36, 0x6c, 0xda, 0x33, 0x8f, 0xc2, 0x3e, + 0xc7, 0xb8, 0xcd, 0xa6, 0x5d, 0x6b, 0x36, 0x1d, 0x90, 0x68, 0xd8, 0xc5, 0xae, 0x6f, 0xf6, 0x68, + 0x67, 0xe8, 0x11, 0x26, 0x24, 0x83, 0x71, 0x9f, 0xb0, 0x76, 0x4e, 0xfc, 0xeb, 0xf7, 0xf1, 0xdb, + 0x00, 0x00, 0x00, 0xff, 0xff, 0xf8, 0x7c, 0x95, 0x83, 0x8b, 0x0a, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -843,6 +949,8 @@ type QueryClient interface { BlockBloom(ctx context.Context, in *QueryBlockBloomRequest, opts ...grpc.CallOption) (*QueryBlockBloomResponse, error) // Params queries the parameters of x/evm module. Params(ctx context.Context, in *QueryParamsRequest, opts ...grpc.CallOption) (*QueryParamsResponse, error) + // StaticCall queries the static call value of x/evm module. + StaticCall(ctx context.Context, in *QueryStaticCallRequest, opts ...grpc.CallOption) (*QueryStaticCallResponse, error) } type queryClient struct { @@ -925,6 +1033,15 @@ func (c *queryClient) Params(ctx context.Context, in *QueryParamsRequest, opts . return out, nil } +func (c *queryClient) StaticCall(ctx context.Context, in *QueryStaticCallRequest, opts ...grpc.CallOption) (*QueryStaticCallResponse, error) { + out := new(QueryStaticCallResponse) + err := c.cc.Invoke(ctx, "/injective.evm.v1beta1.Query/StaticCall", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + // QueryServer is the server API for Query service. type QueryServer interface { // Account queries an Ethereum account. @@ -944,6 +1061,8 @@ type QueryServer interface { BlockBloom(context.Context, *QueryBlockBloomRequest) (*QueryBlockBloomResponse, error) // Params queries the parameters of x/evm module. Params(context.Context, *QueryParamsRequest) (*QueryParamsResponse, error) + // StaticCall queries the static call value of x/evm module. + StaticCall(context.Context, *QueryStaticCallRequest) (*QueryStaticCallResponse, error) } // UnimplementedQueryServer can be embedded to have forward compatible implementations. @@ -974,6 +1093,9 @@ func (*UnimplementedQueryServer) BlockBloom(ctx context.Context, req *QueryBlock func (*UnimplementedQueryServer) Params(ctx context.Context, req *QueryParamsRequest) (*QueryParamsResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method Params not implemented") } +func (*UnimplementedQueryServer) StaticCall(ctx context.Context, req *QueryStaticCallRequest) (*QueryStaticCallResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method StaticCall not implemented") +} func RegisterQueryServer(s grpc1.Server, srv QueryServer) { s.RegisterService(&_Query_serviceDesc, srv) @@ -1123,6 +1245,24 @@ func _Query_Params_Handler(srv interface{}, ctx context.Context, dec func(interf return interceptor(ctx, in, info, handler) } +func _Query_StaticCall_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(QueryStaticCallRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(QueryServer).StaticCall(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/injective.evm.v1beta1.Query/StaticCall", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(QueryServer).StaticCall(ctx, req.(*QueryStaticCallRequest)) + } + return interceptor(ctx, in, info, handler) +} + var _Query_serviceDesc = grpc.ServiceDesc{ ServiceName: "injective.evm.v1beta1.Query", HandlerType: (*QueryServer)(nil), @@ -1159,6 +1299,10 @@ var _Query_serviceDesc = grpc.ServiceDesc{ MethodName: "Params", Handler: _Query_Params_Handler, }, + { + MethodName: "StaticCall", + Handler: _Query_StaticCall_Handler, + }, }, Streams: []grpc.StreamDesc{}, Metadata: "injective/evm/v1beta1/query.proto", @@ -1671,6 +1815,73 @@ func (m *QueryParamsResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { return len(dAtA) - i, nil } +func (m *QueryStaticCallRequest) 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 *QueryStaticCallRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryStaticCallRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Input) > 0 { + i -= len(m.Input) + copy(dAtA[i:], m.Input) + i = encodeVarintQuery(dAtA, i, uint64(len(m.Input))) + i-- + dAtA[i] = 0x12 + } + if len(m.Address) > 0 { + i -= len(m.Address) + copy(dAtA[i:], m.Address) + i = encodeVarintQuery(dAtA, i, uint64(len(m.Address))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *QueryStaticCallResponse) 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 *QueryStaticCallResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryStaticCallResponse) 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 = encodeVarintQuery(dAtA, i, uint64(len(m.Data))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + func encodeVarintQuery(dAtA []byte, offset int, v uint64) int { offset -= sovQuery(v) base := offset @@ -1898,6 +2109,36 @@ func (m *QueryParamsResponse) Size() (n int) { return n } +func (m *QueryStaticCallRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Address) + if l > 0 { + n += 1 + l + sovQuery(uint64(l)) + } + l = len(m.Input) + if l > 0 { + n += 1 + l + sovQuery(uint64(l)) + } + return n +} + +func (m *QueryStaticCallResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Data) + if l > 0 { + n += 1 + l + sovQuery(uint64(l)) + } + return n +} + func sovQuery(x uint64) (n int) { return (math_bits.Len64(x|1) + 6) / 7 } @@ -3313,6 +3554,212 @@ func (m *QueryParamsResponse) Unmarshal(dAtA []byte) error { } return nil } +func (m *QueryStaticCallRequest) 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 ErrIntOverflowQuery + } + 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: QueryStaticCallRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryStaticCallRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Address", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + 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 ErrInvalidLengthQuery + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Address = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Input", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Input = append(m.Input[:0], dAtA[iNdEx:postIndex]...) + if m.Input == nil { + m.Input = []byte{} + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryStaticCallResponse) 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 ErrIntOverflowQuery + } + 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: QueryStaticCallResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryStaticCallResponse: 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 ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + 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 := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} func skipQuery(dAtA []byte) (n int, err error) { l := len(dAtA) iNdEx := 0 diff --git a/ethereum/rpc/block.go b/ethereum/rpc/block.go new file mode 100644 index 00000000..6a73b154 --- /dev/null +++ b/ethereum/rpc/block.go @@ -0,0 +1,19 @@ +package rpc + +import ( + "context" + "fmt" + + grpctypes "github.com/cosmos/cosmos-sdk/types/grpc" + "google.golang.org/grpc/metadata" +) + +// ContextWithHeight wraps a context with the a gRPC block height header. If the provided height is +// 0, it will return an empty context and the gRPC query will use the latest block height for querying. +func ContextWithHeight(height int64) context.Context { + if height == 0 { + return context.Background() + } + + return metadata.AppendToOutgoingContext(context.Background(), grpctypes.GRPCBlockHeightHeader, fmt.Sprintf("%d", height)) +} From 50455ceedd39635b61681decac9e9a407820d663 Mon Sep 17 00:00:00 2001 From: gopherjk121 Date: Fri, 8 Jan 2021 19:52:33 +1000 Subject: [PATCH 03/11] add get account query on evm and ethereum util --- chain/evm/client/cli/query.go | 35 +++++++ ethereum/util/amounts.go | 163 +++++++++++++++++++++++++++++++++ ethereum/util/contract.go | 110 ++++++++++++++++++++++ ethereum/util/keycache.go | 158 ++++++++++++++++++++++++++++++++ ethereum/util/noncecache.go | 135 +++++++++++++++++++++++++++ ethereum/util/uniquify.go | 70 ++++++++++++++ ethereum/util/uniquify_test.go | 13 +++ 7 files changed, 684 insertions(+) create mode 100644 ethereum/util/amounts.go create mode 100644 ethereum/util/contract.go create mode 100644 ethereum/util/keycache.go create mode 100644 ethereum/util/noncecache.go create mode 100644 ethereum/util/uniquify.go create mode 100644 ethereum/util/uniquify_test.go diff --git a/chain/evm/client/cli/query.go b/chain/evm/client/cli/query.go index 6f8ef581..dce90aa8 100644 --- a/chain/evm/client/cli/query.go +++ b/chain/evm/client/cli/query.go @@ -30,6 +30,7 @@ func GetQueryCmd() *cobra.Command { GetStorageCmd(), GetCodeCmd(), GetErc20Balance(), + GetAccount(), ) return cmd } @@ -160,3 +161,37 @@ func GetErc20Balance() *cobra.Command { flags.AddQueryFlagsToCmd(cmd) return cmd } + +// GetAccount queries the account by address +func GetAccount() *cobra.Command { + cmd := &cobra.Command{ + Use: "account [address]", + Short: "Get an account by address", + Long: "Get an account by address", + Args: cobra.ExactArgs(1), + RunE: func(cmd *cobra.Command, args []string) error { + clientCtx := client.GetClientContextFromCmd(cmd) + clientCtx, err := client.ReadQueryCommandFlags(clientCtx, cmd.Flags()) + if err != nil { + return err + } + + queryClient := types.NewQueryClient(clientCtx) + address := args[0] + + req := &types.QueryAccountRequest{ + Address: address, + } + + res, err := queryClient.Account(rpc.ContextWithHeight(clientCtx.Height), req) + if err != nil { + return err + } + + return clientCtx.PrintOutput(res) + }, + } + + flags.AddQueryFlagsToCmd(cmd) + return cmd +} diff --git a/ethereum/util/amounts.go b/ethereum/util/amounts.go new file mode 100644 index 00000000..b195b404 --- /dev/null +++ b/ethereum/util/amounts.go @@ -0,0 +1,163 @@ +package util + +import ( + "fmt" + "math/big" + + "github.com/shopspring/decimal" +) + +type Wei decimal.Decimal + +func (w Wei) String() string { + return (decimal.Decimal)(w).String() +} + +func (w Wei) StringGwei() string { + d := (decimal.Decimal)(w).Div(decimal.NewFromFloat(1e9)) + return d.String() +} + +func (w Wei) Bytes() []byte { + return []byte((decimal.Decimal)(w).String()) +} + +func (w *Wei) Scan(v interface{}) error { + if v == nil { + return nil + } + var source string + switch v.(type) { + case string: + source = v.(string) + case []byte: + source = string(v.([]byte)) + default: + return fmt.Errorf("incompatible type for decimal.Decimal: %T", v) + } + d, err := decimal.NewFromString(source) + if err != nil { + err := fmt.Errorf("failed to parse decimal.Decimal from %s, error: %v", source, err) + return err + } else { + *w = (Wei)(d) + } + return nil +} + +func (w *Wei) Ether() float64 { + if w == nil { + return 0 + } + f, _ := (*decimal.Decimal)(w).Div(decimal.NewFromFloat(1e18)).Float64() + return f +} + +func (w *Wei) Tokens() float64 { + return w.Ether() +} + +func (w *Wei) ToInt() *big.Int { + i := big.NewInt(0) + i.SetString((*decimal.Decimal)(w).String(), 10) + return i +} + +// Gwei is an unsafe way to represent Wei as uint64, used for +// gas price reporting and should not be used for math. +func (w *Wei) Gwei() uint64 { + if w == nil { + return 0 + } + r := big.NewInt(0).Set(w.ToInt()) + m := big.NewInt(0).SetUint64(1e9) + return r.Div(r, m).Uint64() +} + +func Gwei(gwei uint64) *Wei { + w := big.NewInt(0).SetUint64(gwei) + m := big.NewInt(0).SetUint64(1e9) + return BigWei(w.Mul(w, m)) +} + +func (w *Wei) Mul(m int64) *Wei { + d := (*decimal.Decimal)(w) + result := d.Mul(decimal.NewFromBigInt(big.NewInt(m), 0)) + return (*Wei)(&result) +} + +func (w *Wei) Div(m int64) *Wei { + d := (*decimal.Decimal)(w) + result := d.Div(decimal.NewFromBigInt(big.NewInt(m), 0)) + return (*Wei)(&result) +} + +// ToWei converts ether or tokens amount into Wei amount. +func ToWei(amount float64) *Wei { + d := decimal.NewFromFloat(amount).Mul(decimal.NewFromFloat(1e18)) + return (*Wei)(&d) +} + +func DecimalToWei(d decimal.Decimal) *Wei { + d = d.Mul(decimal.NewFromFloat(1e18)) + return (*Wei)(&d) +} + +func DecimalWei(d decimal.Decimal) *Wei { + return (*Wei)(&d) +} + +func BigWei(w *big.Int) *Wei { + d := decimal.NewFromBigInt(w, 0) + return (*Wei)(&d) +} + +func StringWei(str string) *Wei { + d, err := decimal.NewFromString(str) + if err != nil { + return nil + } + return (*Wei)(&d) +} + +// Add adds two amounts together and returns a new amount. +func (w *Wei) Add(amount *Wei) *Wei { + d1 := (*decimal.Decimal)(w) + d2 := (*decimal.Decimal)(amount) + result := d1.Add(*d2) + return (*Wei)(&result) +} + +// Sub substracts two amounts and returns a new amount. +func (w *Wei) Sub(amount *Wei) *Wei { + d1 := (*decimal.Decimal)(w) + d2 := (*decimal.Decimal)(amount) + result := d1.Sub(*d2) + return (*Wei)(&result) +} + +// SplitEqual splits the amount into n-1 equal amounts and one remainder. +// Example: (1000).SplitEqual(7) yields [142 142 142 142 142 142 148] +func (w *Wei) SplitEqual(parts int) []*Wei { + if parts == 0 { + return nil + } + total := big.NewInt(0).Set(w.ToInt()) + q, m := big.NewInt(0).DivMod(total, big.NewInt(int64(parts)), big.NewInt(0)) + if q.Cmp(big.NewInt(0)) == 0 { + result := make([]*Wei, parts) + for i := 0; i < parts; i++ { + result[i] = ToWei(0) + } + result[parts-1] = BigWei(m) + return result + } + result := make([]*Wei, 0, parts) + for total.Cmp(q) >= 0 { + total.Sub(total, q) + amount := BigWei(big.NewInt(0).Set(q)) + result = append(result, amount) + } + result[len(result)-1] = result[len(result)-1].Add(BigWei(m)) + return result +} diff --git a/ethereum/util/contract.go b/ethereum/util/contract.go new file mode 100644 index 00000000..c3c66568 --- /dev/null +++ b/ethereum/util/contract.go @@ -0,0 +1,110 @@ +package util + +import ( + "bytes" + "errors" + "fmt" + + "github.com/ethereum/go-ethereum/accounts/abi" + "github.com/ethereum/go-ethereum/accounts/abi/bind" + "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/core/types" + "github.com/ethereum/go-ethereum/ethclient" +) + +type Contract struct { + Name string + SourcePath string + CompilerVersion string + Address common.Address + + ABI []byte + Bin string +} + +type TransactFunc func(opts *bind.TransactOpts, contract *common.Address, input []byte) (*types.Transaction, error) + +type BoundContract struct { + *bind.BoundContract + + transactFn TransactFunc + client *ethclient.Client + address common.Address + src *Contract + abi abi.ABI +} + +func BindContract(client *ethclient.Client, contract *Contract) (*BoundContract, error) { + if contract == nil { + err := errors.New("contract must not be nil") + return nil, err + } + parsedABI, err := abi.JSON(bytes.NewReader(contract.ABI)) + if err != nil { + err = fmt.Errorf("failed to parse contract ABI: %v", err) + return nil, err + } + bound := &BoundContract{ + BoundContract: bind.NewBoundContract(contract.Address, parsedABI, client, client, client), + client: client, + + address: contract.Address, + abi: parsedABI, + src: contract, + } + return bound, nil +} + +func (contract *BoundContract) SetTransact(fn TransactFunc) { + contract.transactFn = fn +} + +func (contract *BoundContract) SetClient(client *ethclient.Client) { + contract.client = client + contract.BoundContract = bind.NewBoundContract( + contract.address, contract.abi, client, client, client) +} + +func (contract *BoundContract) Client() *ethclient.Client { + return contract.client +} + +func (contract *BoundContract) Address() common.Address { + return contract.address +} + +func (contract *BoundContract) SetAddress(address common.Address) { + contract.address = address + contract.BoundContract = bind.NewBoundContract( + address, contract.abi, contract.client, contract.client, contract.client) +} + +func (contract *BoundContract) Source() *Contract { + return contract.src +} + +func (contract *BoundContract) ABI() abi.ABI { + return contract.abi +} + +func (c *BoundContract) DeployContract(opts *bind.TransactOpts, params ...interface{}) (common.Address, *types.Transaction, error) { + panic("not implemented") +} + +func (c *BoundContract) Transact(opts *bind.TransactOpts, method string, params ...interface{}) (*types.Transaction, error) { + if c.transactFn == nil { + return c.BoundContract.Transact(opts, method, params...) + } + input, err := c.abi.Pack(method, params...) + if err != nil { + return nil, err + } + return c.transactFn(opts, &c.address, input) +} + +func (c *BoundContract) Transfer(opts *bind.TransactOpts) (*types.Transaction, error) { + if c.transactFn == nil { + return c.BoundContract.Transfer(opts) + } + return c.transactFn(opts, &c.address, nil) +} diff --git a/ethereum/util/keycache.go b/ethereum/util/keycache.go new file mode 100644 index 00000000..dfb0bc69 --- /dev/null +++ b/ethereum/util/keycache.go @@ -0,0 +1,158 @@ +package util + +import ( + "crypto/ecdsa" + "crypto/sha1" + "errors" + "io/ioutil" + "strings" + "sync" + + "github.com/ethereum/go-ethereum/accounts/abi/bind" + "github.com/ethereum/go-ethereum/accounts/keystore" + "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/core/types" + "github.com/ethereum/go-ethereum/crypto" +) + +type KeyCache interface { + SetPath(account common.Address, path string) bool + UnsetPath(account common.Address, path string) + PrivateKey(account common.Address, password string) (key *ecdsa.PrivateKey, ok bool) + SetPrivateKey(account common.Address, pk *ecdsa.PrivateKey) + UnsetKey(account common.Address, password string) + SignerFn(account common.Address, password string) bind.SignerFn +} + +func NewKeyCache() KeyCache { + return &keyCache{ + paths: make(map[common.Address]string), + pathsMux: new(sync.RWMutex), + keys: make(map[string]*ecdsa.PrivateKey), + keysMux: new(sync.RWMutex), + guard: NewUniquify(), + } +} + +type keyCache struct { + paths map[common.Address]string + pathsMux *sync.RWMutex + keys map[string]*ecdsa.PrivateKey + keysMux *sync.RWMutex + guard Uniquify +} + +// SetPath sets the wallet path for a given account. Returns true if the new path +// has been added or was changed. +func (k *keyCache) SetPath(account common.Address, path string) bool { + k.pathsMux.Lock() + prevPath, existing := k.paths[account] + k.paths[account] = path + k.pathsMux.Unlock() + return !existing || prevPath != path +} + +func (k *keyCache) UnsetPath(account common.Address, path string) { + k.pathsMux.Lock() + delete(k.paths, account) + k.pathsMux.Unlock() +} + +var ( + ErrNoKeyStore = errors.New("no keystore or file for account") + ErrKeyDecrypt = errors.New("private key decryption failed") +) + +func (k *keyCache) UnsetKey(account common.Address, password string) { + h := hashAccountPass(account, password) + k.keysMux.Lock() + delete(k.keys, string(h)) + k.keysMux.Unlock() +} + +func (k *keyCache) SetPrivateKey(account common.Address, pk *ecdsa.PrivateKey) { + h := hashAccountPass(account, "") + k.keysMux.Lock() + k.keys[string(h)] = pk + k.keysMux.Unlock() +} + +func (k *keyCache) PrivateKey(account common.Address, password string) (key *ecdsa.PrivateKey, ok bool) { + h := hashAccountPass(account, password) + if err := k.guard.Call(string(h), func() error { + k.keysMux.RLock() + key, ok = k.keys[string(h)] + k.keysMux.RUnlock() + if ok { + return nil + } + k.pathsMux.RLock() + path, pathOk := k.paths[account] + k.pathsMux.RUnlock() + if !pathOk { + return ErrNoKeyStore + } + if strings.HasPrefix(path, "keystore://") { + path = strings.TrimPrefix(path, "keystore://") + } + keyJSON, err := ioutil.ReadFile(path) + if err != nil { + return ErrNoKeyStore + } + pk, err := keystore.DecryptKey(keyJSON, password) + if err != nil { + return ErrKeyDecrypt + } + k.keysMux.Lock() + k.keys[string(h)] = pk.PrivateKey + k.keysMux.Unlock() + key = pk.PrivateKey + ok = true + return nil + }); err != nil { + return nil, false + } + return key, ok +} + +func (k *keyCache) SignerFn(account common.Address, password string) bind.SignerFn { + key, ok := k.PrivateKey(account, password) + if !ok { + return nil + } + keyAddr := crypto.PubkeyToAddress(key.PublicKey) + return func(signer types.Signer, address common.Address, tx *types.Transaction) (*types.Transaction, error) { + if address != keyAddr { + return nil, errors.New("not authorized to sign this account") + } + signature, err := crypto.Sign(signer.Hash(tx).Bytes(), key) + if err != nil { + return nil, err + } + return tx.WithSignature(signer, signature) + } +} + +func SignerFnForPk(privKey *ecdsa.PrivateKey) bind.SignerFn { + keyAddr := crypto.PubkeyToAddress(privKey.PublicKey) + return func(signer types.Signer, address common.Address, tx *types.Transaction) (*types.Transaction, error) { + if address != keyAddr { + return nil, errors.New("not authorized to sign this account") + } + signature, err := crypto.Sign(signer.Hash(tx).Bytes(), privKey) + if err != nil { + return nil, err + } + return tx.WithSignature(signer, signature) + } +} + +var hashSep = []byte("-") + +func hashAccountPass(account common.Address, password string) []byte { + h := sha1.New() + h.Write(account[:]) + h.Write(hashSep) + h.Write([]byte(password)) + return h.Sum(nil) +} diff --git a/ethereum/util/noncecache.go b/ethereum/util/noncecache.go new file mode 100644 index 00000000..1b904566 --- /dev/null +++ b/ethereum/util/noncecache.go @@ -0,0 +1,135 @@ +package util + +import ( + "sync" + + "github.com/ethereum/go-ethereum/common" +) + +type NonceCache interface { + Serialize(account common.Address, fn func() error) error + Sync(account common.Address, syncFn func() (uint64, error)) + + Set(account common.Address, nonce int64) + Get(account common.Address) int64 + Incr(account common.Address) int64 + Decr(account common.Address) int64 +} + +func NewNonceCache() NonceCache { + return &nonceCache{ + mux: new(sync.RWMutex), + nonces: make(map[common.Address]int64), + locks: make(map[common.Address]*sync.RWMutex), + guard: NewUniquify(), + } +} + +type nonceCache struct { + mux *sync.RWMutex + nonces map[common.Address]int64 + locks map[common.Address]*sync.RWMutex + guard Uniquify +} + +// Serialize serializes access to the nonce cache for all goroutines, all nonce increments should be done +// in this context. If a transaction increments nonce, but has not been submitted, +// it will have exclusive right to decrease nonce back for other transactions. +func (n nonceCache) Serialize(account common.Address, fn func() error) error { + return n.guard.Call(account.Hex(), fn) +} + +func (n nonceCache) Get(account common.Address) int64 { + n.mux.RLock() + lock, ok := n.locks[account] + if !ok { + n.mux.RUnlock() + return 0 + } + lock.RLock() + n.mux.RUnlock() + nonce := n.nonces[account] + lock.RUnlock() + return nonce +} + +func (n nonceCache) Set(account common.Address, nonce int64) { + n.mux.Lock() + lock, ok := n.locks[account] + if !ok { + n.locks[account] = new(sync.RWMutex) + n.nonces[account] = nonce + n.mux.Unlock() + return + } + lock.Lock() + n.mux.Unlock() + n.nonces[account] = nonce + lock.Unlock() +} + +func (n nonceCache) Incr(account common.Address) int64 { + n.mux.Lock() + lock, ok := n.locks[account] + if !ok { + n.nonces[account] = 1 + n.locks[account] = new(sync.RWMutex) + n.mux.Unlock() + return 0 + } + lock.Lock() + n.mux.Unlock() + nonce := n.nonces[account] + n.nonces[account]++ + lock.Unlock() + return nonce +} + +func (n nonceCache) Decr(account common.Address) int64 { + n.mux.Lock() + lock, ok := n.locks[account] + if !ok { + n.nonces[account] = 0 + n.locks[account] = new(sync.RWMutex) + n.mux.Unlock() + return 0 + } + lock.Lock() + n.mux.Unlock() + nonce := n.nonces[account] + n.nonces[account]-- + lock.Unlock() + return nonce +} + +func (n nonceCache) Sync(account common.Address, syncFn func() (uint64, error)) { + n.mux.Lock() + lock, ok := n.locks[account] + if !ok { + n.nonces[account] = 0 + n.locks[account] = new(sync.RWMutex) + lock = n.locks[account] + } + lock.Lock() + n.mux.Unlock() + prevNonce, prevOk := n.nonces[account] + { + n.mux.RLock() + nextNonce, nextOk := n.nonces[account] + n.mux.RUnlock() + if !prevOk && nextOk { + // we're not fist here to sync - skip + lock.Unlock() + return + } else if nextNonce != prevNonce { + lock.Unlock() + return + } + if nonce, err := syncFn(); err == nil { + n.mux.Lock() + n.nonces[account] = int64(nonce) + n.mux.Unlock() + } + } + lock.Unlock() +} diff --git a/ethereum/util/uniquify.go b/ethereum/util/uniquify.go new file mode 100644 index 00000000..b0a5269f --- /dev/null +++ b/ethereum/util/uniquify.go @@ -0,0 +1,70 @@ +package util + +import ( + "fmt" + "sync" +) + +// Uniquify is a type of advanced mutex. It allows to create named resource locks. +type Uniquify interface { + // Call executes only one callable with same id at a time. + // Multilpe asynchronous calls with same id will be executed sequentally. + Call(id string, callable func() error) error +} + +// NewUniquify returns a new thread-safe uniquify object. +func NewUniquify() Uniquify { + return &uniquify{ + tasks: make(map[string]*sync.WaitGroup), + } +} + +type uniquify struct { + lock sync.Mutex + tasks map[string]*sync.WaitGroup +} + +func (u *uniquify) Call(id string, callable func() error) error { + var errC = make(chan error) + func() { + u.lock.Lock() + defer u.lock.Unlock() + oldWg := u.tasks[id] + if oldWg != nil { + go func() { + oldWg.Wait() + go func() { + errC <- u.Call(id, callable) + }() + }() + return + } + wg := new(sync.WaitGroup) + wg.Add(1) + u.tasks[id] = wg + + go func() { + var err error + defer func() { + errC <- err + + u.lock.Lock() + defer u.lock.Unlock() + delete(u.tasks, id) + }() + defer wg.Done() + defer func(err *error) { + if panicData := recover(); panicData != nil { + if e, ok := panicData.(error); ok { + *err = e + return + } + *err = fmt.Errorf("%+v", panicData) + } + }(&err) + err = callable() + }() + }() + + return <-errC +} diff --git a/ethereum/util/uniquify_test.go b/ethereum/util/uniquify_test.go new file mode 100644 index 00000000..8ca89d76 --- /dev/null +++ b/ethereum/util/uniquify_test.go @@ -0,0 +1,13 @@ +package util + +import "testing" + +func TestNewUniquify(t *testing.T) { + u := NewUniquify() + err := u.Call("kek", func() error { + return nil + }) + if err != nil { + t.Fatal(err) + } +} From 38eae3cc6ae5e9a7e52680448a96ed89ee68ec60 Mon Sep 17 00:00:00 2001 From: gopherjk121 Date: Fri, 8 Jan 2021 19:59:42 +1000 Subject: [PATCH 04/11] remove write protection --- wrappers/futures.go | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 wrappers/futures.go diff --git a/wrappers/futures.go b/wrappers/futures.go old mode 100644 new mode 100755 From 4ed4b99790a58af1f5611c04ae0282f919bbb170 Mon Sep 17 00:00:00 2001 From: gopherjk121 Date: Tue, 12 Jan 2021 12:22:19 +1000 Subject: [PATCH 05/11] Add NewEIP155Signer utility --- chain/evm/types/msg.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/chain/evm/types/msg.go b/chain/evm/types/msg.go index 41404286..1ad1e017 100644 --- a/chain/evm/types/msg.go +++ b/chain/evm/types/msg.go @@ -354,3 +354,11 @@ func deriveChainID(v *big.Int) *big.Int { v = new(big.Int).Sub(v, big.NewInt(35)) return v.Div(v, big.NewInt(2)) } + +// NewEIP155Signer returns instance of evmtypes.EIP155Signer +func NewEIP155Signer(chainID []byte, chainIDMul []byte) *EIP155Signer { + return &EIP155Signer{ + chainId: chainID, + chainIdMul: chainIDMul, + } +} From fc6d57c8fc3cc2a3d0c9bd50ed4f6e6edbd29f6f Mon Sep 17 00:00:00 2001 From: gopherjk121 Date: Sat, 16 Jan 2021 03:20:43 +1000 Subject: [PATCH 06/11] sdk-go modification for ResetHubProposal --- chain/erc20bridge/types/codec.go | 2 + chain/erc20bridge/types/errors.go | 1 + chain/erc20bridge/types/proposal.go | 40 ++- chain/erc20bridge/types/proposal.pb.go | 358 +++++++++++++++++++++++-- 4 files changed, 372 insertions(+), 29 deletions(-) diff --git a/chain/erc20bridge/types/codec.go b/chain/erc20bridge/types/codec.go index f927af6b..396b908b 100644 --- a/chain/erc20bridge/types/codec.go +++ b/chain/erc20bridge/types/codec.go @@ -20,6 +20,7 @@ var ( func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { cdc.RegisterConcrete(TokenMapping{}, "cosmos-sdk/TokenMapping", nil) cdc.RegisterConcrete(&RegisterTokenMappingProposal{}, "cosmos-sdk/RegisterTokenMappingProposal", nil) + cdc.RegisterConcrete(&ResetHubProposal{}, "cosmos-sdk/ResetHubProposal", nil) } // RegisterInterfaces register implementations @@ -32,5 +33,6 @@ func RegisterInterfaces(registry codectypes.InterfaceRegistry) { registry.RegisterImplementations( (*govtypes.Content)(nil), &RegisterTokenMappingProposal{}, + &ResetHubProposal{}, ) } diff --git a/chain/erc20bridge/types/errors.go b/chain/erc20bridge/types/errors.go index 830545a6..dff8324a 100644 --- a/chain/erc20bridge/types/errors.go +++ b/chain/erc20bridge/types/errors.go @@ -12,4 +12,5 @@ var ( ErrInternalEthMinting = sdkerrors.Register(ModuleName, 4, "internal ethereum minting error") ErrInitHubABI = sdkerrors.Register(ModuleName, 5, "init hub abi error") ErrWritingEthTxPayload = sdkerrors.Register(ModuleName, 6, "writing ethereum tx payload error") + ErrHubAlreadySet = sdkerrors.Register(ModuleName, 7, "hub already set") ) diff --git a/chain/erc20bridge/types/proposal.go b/chain/erc20bridge/types/proposal.go index 7f56d7cf..617565e1 100644 --- a/chain/erc20bridge/types/proposal.go +++ b/chain/erc20bridge/types/proposal.go @@ -1,14 +1,25 @@ package types import ( + fmt "fmt" + gov "github.com/cosmos/cosmos-sdk/x/gov/types" + "github.com/ethereum/go-ethereum/common" ) // constants const ( ProposalTypeRegisterTokenMapping string = "RegisterTokenMapping" + ProposalTypeResetHub string = "ResetHub" ) +func init() { + gov.RegisterProposalType(ProposalTypeRegisterTokenMapping) + gov.RegisterProposalType(ProposalTypeResetHub) + gov.RegisterProposalTypeCodec(&RegisterTokenMappingProposal{}, "cosmos-sdk/RegisterTokenMappingProposal") + gov.RegisterProposalTypeCodec(&ResetHubProposal{}, "cosmos-sdk/ResetHubProposal") +} + // NewRegisterTokenMappingProposal returns new instance of TokenMappingProposal func NewRegisterTokenMappingProposal(title, description string, mapping TokenMapping) gov.Content { return &RegisterTokenMappingProposal{title, description, mapping} @@ -17,11 +28,6 @@ func NewRegisterTokenMappingProposal(title, description string, mapping TokenMap // Implements Proposal Interface var _ gov.Content = &RegisterTokenMappingProposal{} -func init() { - gov.RegisterProposalType(ProposalTypeRegisterTokenMapping) - gov.RegisterProposalTypeCodec(&RegisterTokenMappingProposal{}, "cosmos-sdk/RegisterTokenMappingProposal") -} - // ProposalRoute returns router key for this proposal func (sup *RegisterTokenMappingProposal) ProposalRoute() string { return RouterKey } @@ -37,3 +43,27 @@ func (sup *RegisterTokenMappingProposal) ValidateBasic() error { } return gov.ValidateAbstract(sup) } + +// NewResetHubProposal returns new instance of ResetHubProposal +func NewResetHubProposal(title, description string, hub string) gov.Content { + return &ResetHubProposal{title, description, hub} +} + +// Implements Proposal Interface +var _ gov.Content = &ResetHubProposal{} + +// ProposalRoute returns router key for this proposal +func (rh *ResetHubProposal) ProposalRoute() string { return RouterKey } + +// ProposalType returns proposal type for this proposal +func (rh *ResetHubProposal) ProposalType() string { + return ProposalTypeResetHub +} + +// ValidateBasic returns ValidateBasic result for this proposal +func (rh *ResetHubProposal) ValidateBasic() error { + if !common.IsHexAddress(rh.HubAddress) { + return fmt.Errorf("invalid hub address: %s", rh.HubAddress) + } + return gov.ValidateAbstract(rh) +} diff --git a/chain/erc20bridge/types/proposal.pb.go b/chain/erc20bridge/types/proposal.pb.go index bb0383ce..3c9bcc33 100644 --- a/chain/erc20bridge/types/proposal.pb.go +++ b/chain/erc20bridge/types/proposal.pb.go @@ -148,9 +148,72 @@ func (m *RegisterTokenMappingProposal) GetMapping() TokenMapping { return TokenMapping{} } +// ResetHubProposal is a gov Content type to reset hub +// when reset hub, all the bridges from previous version are derivated +type ResetHubProposal struct { + Title string `protobuf:"bytes,1,opt,name=title,proto3" json:"title,omitempty"` + Description string `protobuf:"bytes,2,opt,name=description,proto3" json:"description,omitempty"` + HubAddress string `protobuf:"bytes,3,opt,name=hub_address,json=hubAddress,proto3" json:"hub_address,omitempty" yaml:"hub_address"` +} + +func (m *ResetHubProposal) Reset() { *m = ResetHubProposal{} } +func (m *ResetHubProposal) String() string { return proto.CompactTextString(m) } +func (*ResetHubProposal) ProtoMessage() {} +func (*ResetHubProposal) Descriptor() ([]byte, []int) { + return fileDescriptor_725522d902d0cf82, []int{2} +} +func (m *ResetHubProposal) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *ResetHubProposal) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_ResetHubProposal.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 *ResetHubProposal) XXX_Merge(src proto.Message) { + xxx_messageInfo_ResetHubProposal.Merge(m, src) +} +func (m *ResetHubProposal) XXX_Size() int { + return m.Size() +} +func (m *ResetHubProposal) XXX_DiscardUnknown() { + xxx_messageInfo_ResetHubProposal.DiscardUnknown(m) +} + +var xxx_messageInfo_ResetHubProposal proto.InternalMessageInfo + +func (m *ResetHubProposal) GetTitle() string { + if m != nil { + return m.Title + } + return "" +} + +func (m *ResetHubProposal) GetDescription() string { + if m != nil { + return m.Description + } + return "" +} + +func (m *ResetHubProposal) GetHubAddress() string { + if m != nil { + return m.HubAddress + } + return "" +} + func init() { proto.RegisterType((*TokenMapping)(nil), "injective.erc20bridge.v1beta1.TokenMapping") proto.RegisterType((*RegisterTokenMappingProposal)(nil), "injective.erc20bridge.v1beta1.RegisterTokenMappingProposal") + proto.RegisterType((*ResetHubProposal)(nil), "injective.erc20bridge.v1beta1.ResetHubProposal") } func init() { @@ -158,30 +221,33 @@ func init() { } var fileDescriptor_725522d902d0cf82 = []byte{ - // 360 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x7c, 0x51, 0xb1, 0x4e, 0xe3, 0x40, - 0x14, 0xf4, 0xde, 0xe5, 0x2e, 0x77, 0x9b, 0xd0, 0x58, 0x29, 0x2c, 0x04, 0x4e, 0xb0, 0x28, 0x22, - 0x21, 0x6c, 0x12, 0xba, 0x48, 0x14, 0x44, 0x34, 0x08, 0x90, 0xc0, 0xa2, 0xa2, 0x89, 0xd6, 0xf6, - 0x93, 0xb3, 0xc4, 0xf6, 0xb3, 0x76, 0x37, 0x91, 0xf2, 0x17, 0xf9, 0x04, 0x5a, 0xfe, 0x24, 0x65, - 0x4a, 0xaa, 0x08, 0x25, 0x0d, 0x35, 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0x14, 0xc1, 0x25, - 0x4a, 0xbf, 0xa1, 0xd5, 0x38, 0x1f, 0x95, 0x05, 0xd7, 0xba, 0x27, 0xf6, 0x8f, 0x5f, 0x66, 0x97, - 0xd3, 0xfb, 0x95, 0xf9, 0xb2, 0xa9, 0xb9, 0xc5, 0x84, 0xbc, 0x6b, 0x7f, 0x34, 0x5f, 0x99, 0x64, - 0xb1, 0x32, 0xc9, 0xfb, 0xca, 0x24, 0xb3, 0xb5, 0xa9, 0x2d, 0xd6, 0xa6, 0xf6, 0xb6, 0x36, 0xb5, - 0xa7, 0x87, 0x90, 0xab, 0xe1, 0xd8, 0xb3, 0x7d, 0x8c, 0x9d, 0xeb, 0x22, 0xe5, 0x96, 0x79, 0xd2, - 0xd9, 0x66, 0x9e, 0xfa, 0x28, 0xa0, 0x0c, 0x87, 0x8c, 0x27, 0x4e, 0x8c, 0xc1, 0x38, 0x02, 0xb9, - 0xb3, 0x69, 0x35, 0x4d, 0x41, 0x7a, 0x7f, 0xb3, 0x95, 0x9d, 0x7f, 0x05, 0x00, 0x00, 0xff, 0xff, - 0x7f, 0x45, 0x6b, 0x22, 0x0f, 0x02, 0x00, 0x00, + // 405 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xa4, 0x52, 0x4f, 0x8b, 0xd3, 0x40, + 0x14, 0xcf, 0xb8, 0xab, 0xab, 0x93, 0x0a, 0x32, 0x14, 0x09, 0xa2, 0x49, 0x0d, 0x1e, 0x16, 0xc4, + 0xc4, 0x5d, 0x0f, 0xc2, 0x82, 0x07, 0x8b, 0x07, 0x45, 0x05, 0x1d, 0x3c, 0x79, 0x59, 0x66, 0x92, + 0x47, 0x32, 0x36, 0xc9, 0x84, 0x99, 0x49, 0xa1, 0x1f, 0xc1, 0x5b, 0x3f, 0x82, 0x57, 0xbf, 0x49, + 0x8f, 0x3d, 0x7a, 0x2a, 0xd2, 0x5e, 0x3c, 0x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x82, 0x4e, 0x94, + 0xa8, 0x8d, 0x90, 0x55, 0x47, 0xdc, 0x2b, 0x91, 0xf7, 0xf8, 0xac, 0xb4, 0xab, 0x5a, 0x62, 0xf7, + 0xf2, 0x69, 0xf4, 0xcf, 0xc8, 0xa2, 0x3e, 0xfb, 0xf8, 0x74, 0xb1, 0x0a, 0x1c, 0xda, 0x6d, 0xd8, + 0x6b, 0xfd, 0x8e, 0xf0, 0x3d, 0x0a, 0x1a, 0xcc, 0xdb, 0x86, 0xff, 0xb7, 0xbe, 0x97, 0xd8, 0xcd, + 0x1b, 0x7e, 0x08, 0xfe, 0xa4, 0x0d, 0xfe, 0xfe, 0x76, 0x15, 0x10, 0x1b, 0x7c, 0xef, 0x33, 0xa4, + 0x38, 0x6f, 0xf8, 0x3e, 0x74, 0xab, 0x65, 0x3c, 0x59, 0xac, 0x7d, 0xb4, 0x5c, 0xfb, 0xe8, 0xf7, + 0xda, 0x47, 0xf3, 0x8d, 0xef, 0x2c, 0x37, 0xbe, 0xf3, 0x6b, 0xe3, 0x3b, 0x5f, 0x3f, 0x67, 0xc2, + 0xe4, 0x0d, 0x8f, 0x12, 0x59, 0xc6, 0xef, 0x3a, 0xc7, 0x1f, 0x18, 0xd7, 0xf1, 0xc1, 0xff, 0xb3, + 0x44, 0x2a, 0xe8, 0xc3, 0x9c, 0x89, 0x2a, 0x2e, 0x65, 0xda, 0x14, 0xa0, 0x8f, 0xae, 0xce, 0xcc, + 0x6a, 0xd0, 0xfc, 0x56, 0x7b, 0x3e, 0x2f, 0xfe, 0x06, 0x00, 0x00, 0xff, 0xff, 0x16, 0x49, 0x04, + 0xd6, 0x9b, 0x02, 0x00, 0x00, } func (this *TokenMapping) Equal(that interface{}) bool { @@ -244,6 +310,36 @@ func (this *RegisterTokenMappingProposal) Equal(that interface{}) bool { } return true } +func (this *ResetHubProposal) Equal(that interface{}) bool { + if that == nil { + return this == nil + } + + that1, ok := that.(*ResetHubProposal) + if !ok { + that2, ok := that.(ResetHubProposal) + if ok { + that1 = &that2 + } else { + return false + } + } + if that1 == nil { + return this == nil + } else if this == nil { + return false + } + if this.Title != that1.Title { + return false + } + if this.Description != that1.Description { + return false + } + if this.HubAddress != that1.HubAddress { + return false + } + return true +} func (m *TokenMapping) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) @@ -338,6 +434,50 @@ func (m *RegisterTokenMappingProposal) MarshalToSizedBuffer(dAtA []byte) (int, e return len(dAtA) - i, nil } +func (m *ResetHubProposal) 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 *ResetHubProposal) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *ResetHubProposal) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.HubAddress) > 0 { + i -= len(m.HubAddress) + copy(dAtA[i:], m.HubAddress) + i = encodeVarintProposal(dAtA, i, uint64(len(m.HubAddress))) + i-- + dAtA[i] = 0x1a + } + if len(m.Description) > 0 { + i -= len(m.Description) + copy(dAtA[i:], m.Description) + i = encodeVarintProposal(dAtA, i, uint64(len(m.Description))) + i-- + dAtA[i] = 0x12 + } + if len(m.Title) > 0 { + i -= len(m.Title) + copy(dAtA[i:], m.Title) + i = encodeVarintProposal(dAtA, i, uint64(len(m.Title))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + func encodeVarintProposal(dAtA []byte, offset int, v uint64) int { offset -= sovProposal(v) base := offset @@ -388,6 +528,27 @@ func (m *RegisterTokenMappingProposal) Size() (n int) { return n } +func (m *ResetHubProposal) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Title) + if l > 0 { + n += 1 + l + sovProposal(uint64(l)) + } + l = len(m.Description) + if l > 0 { + n += 1 + l + sovProposal(uint64(l)) + } + l = len(m.HubAddress) + if l > 0 { + n += 1 + l + sovProposal(uint64(l)) + } + return n +} + func sovProposal(x uint64) (n int) { return (math_bits.Len64(x|1) + 6) / 7 } @@ -681,6 +842,155 @@ func (m *RegisterTokenMappingProposal) Unmarshal(dAtA []byte) error { } return nil } +func (m *ResetHubProposal) 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 ErrIntOverflowProposal + } + 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: ResetHubProposal: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: ResetHubProposal: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Title", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowProposal + } + 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 ErrInvalidLengthProposal + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthProposal + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Title = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Description", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowProposal + } + 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 ErrInvalidLengthProposal + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthProposal + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Description = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field HubAddress", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowProposal + } + 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 ErrInvalidLengthProposal + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthProposal + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.HubAddress = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipProposal(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthProposal + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthProposal + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} func skipProposal(dAtA []byte) (n int, err error) { l := len(dAtA) iNdEx := 0 From 9bc9a9015f9e9f92b3f1d28cb3fdc88cc35dcf9c Mon Sep 17 00:00:00 2001 From: gopherjk121 Date: Wed, 20 Jan 2021 10:08:31 +1000 Subject: [PATCH 07/11] update for token mapping registration modification --- chain/erc20bridge/types/proposal.pb.go | 163 +++++++++++++++++++------ 1 file changed, 129 insertions(+), 34 deletions(-) diff --git a/chain/erc20bridge/types/proposal.pb.go b/chain/erc20bridge/types/proposal.pb.go index 3c9bcc33..7a96eb09 100644 --- a/chain/erc20bridge/types/proposal.pb.go +++ b/chain/erc20bridge/types/proposal.pb.go @@ -25,12 +25,16 @@ const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package // TokenMapping defines a mapping for cosmos denom and erc20 address. type TokenMapping struct { + // bridge name + Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` // address of ERC20 contract token - Erc20Address string `protobuf:"bytes,1,opt,name=erc20_address,json=erc20Address,proto3" json:"erc20_address,omitempty" yaml:"erc20_address"` + Erc20Address string `protobuf:"bytes,2,opt,name=erc20_address,json=erc20Address,proto3" json:"erc20_address,omitempty"` // cosmos-native denominator to mapped to ERC20 - CosmosDenom string `protobuf:"bytes,2,opt,name=cosmos_denom,json=cosmosDenom,proto3" json:"cosmos_denom,omitempty"` + CosmosDenom string `protobuf:"bytes,3,opt,name=cosmos_denom,json=cosmosDenom,proto3" json:"cosmos_denom,omitempty"` + // scaling factor between erc20 token and cosmos denom, e.g. 12 means 1 Native Token = 10^12 ERC20 token + ScalingFactor int64 `protobuf:"varint,4,opt,name=scaling_factor,json=scalingFactor,proto3" json:"scaling_factor,omitempty"` // shows token mapping bridge enable status - Enabled bool `protobuf:"varint,3,opt,name=enabled,proto3" json:"enabled,omitempty"` + Enabled bool `protobuf:"varint,5,opt,name=enabled,proto3" json:"enabled,omitempty"` } func (m *TokenMapping) Reset() { *m = TokenMapping{} } @@ -66,6 +70,13 @@ func (m *TokenMapping) XXX_DiscardUnknown() { var xxx_messageInfo_TokenMapping proto.InternalMessageInfo +func (m *TokenMapping) GetName() string { + if m != nil { + return m.Name + } + return "" +} + func (m *TokenMapping) GetErc20Address() string { if m != nil { return m.Erc20Address @@ -80,6 +91,13 @@ func (m *TokenMapping) GetCosmosDenom() string { return "" } +func (m *TokenMapping) GetScalingFactor() int64 { + if m != nil { + return m.ScalingFactor + } + return 0 +} + func (m *TokenMapping) GetEnabled() bool { if m != nil { return m.Enabled @@ -221,33 +239,34 @@ func init() { } var fileDescriptor_725522d902d0cf82 = []byte{ - // 405 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xa4, 0x52, 0x4f, 0x8b, 0xd3, 0x40, - 0x14, 0xcf, 0xb8, 0xab, 0xab, 0x93, 0x0a, 0x32, 0x14, 0x09, 0xa2, 0x49, 0x0d, 0x1e, 0x16, 0xc4, - 0xc4, 0x5d, 0x0f, 0xc2, 0x82, 0x07, 0x8b, 0x07, 0x45, 0x05, 0x1d, 0x3c, 0x79, 0x59, 0x66, 0x92, - 0x47, 0x32, 0x36, 0xc9, 0x84, 0x99, 0x49, 0xa1, 0x1f, 0xc1, 0x5b, 0x3f, 0x82, 0x57, 0xbf, 0x49, - 0x8f, 0x3d, 0x7a, 0x2a, 0xd2, 0x5e, 0x3c, 0xf7, 0x13, 0x48, 0x33, 0x4d, 0x49, 0x2f, 0x5e, 0xbc, - 0xcd, 0xef, 0xcd, 0x7b, 0xef, 0xf7, 0x87, 0x87, 0x9f, 0x88, 0xea, 0x1b, 0x24, 0x46, 0x4c, 0x21, - 0x06, 0x95, 0x5c, 0x3e, 0xe7, 0x4a, 0xa4, 0x19, 0xc4, 0xb5, 0x92, 0xb5, 0xd4, 0xac, 0x88, 0x6a, - 0x25, 0x8d, 0x24, 0x8f, 0x0e, 0x5d, 0x51, 0xaf, 0x2b, 0x9a, 0x5e, 0x70, 0x30, 0xec, 0xe2, 0xc1, - 0x30, 0x93, 0x99, 0x6c, 0x3b, 0xe3, 0xdd, 0xcb, 0x0e, 0x85, 0x73, 0x84, 0x07, 0x5f, 0xe4, 0x04, - 0xaa, 0x8f, 0xac, 0xae, 0x45, 0x95, 0x91, 0x57, 0xf8, 0x6e, 0x3b, 0x7d, 0xcd, 0xd2, 0x54, 0x81, - 0xd6, 0x1e, 0x1a, 0xa1, 0xf3, 0x3b, 0x63, 0x6f, 0xbb, 0x0a, 0x86, 0x33, 0x56, 0x16, 0x57, 0xe1, - 0xd1, 0x77, 0x48, 0x07, 0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a, 0xc7, 0x1f, 0x18, 0xd7, 0xf1, 0xc1, 0xff, 0xb3, - 0x44, 0x2a, 0xe8, 0xc3, 0x9c, 0x89, 0x2a, 0x2e, 0x65, 0xda, 0x14, 0xa0, 0x8f, 0xae, 0xce, 0xcc, - 0x6a, 0xd0, 0xfc, 0x56, 0x7b, 0x3e, 0x2f, 0xfe, 0x06, 0x00, 0x00, 0xff, 0xff, 0x16, 0x49, 0x04, - 0xd6, 0x9b, 0x02, 0x00, 0x00, + // 430 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xa4, 0x52, 0xb1, 0x6e, 0xd4, 0x40, + 0x10, 0xbd, 0x25, 0x0e, 0x81, 0xf5, 0x05, 0xa1, 0x55, 0x84, 0x2c, 0x04, 0x3e, 0x63, 0x40, 0x3a, + 0x09, 0x61, 0x93, 0x50, 0x20, 0xa5, 0xe3, 0x84, 0x10, 0x08, 0x90, 0xc0, 0xa2, 0xa2, 0x39, 0xed, + 0xae, 0x07, 0x7b, 0x89, 0xbd, 0x6b, 0xed, 0xae, 0x23, 0xe5, 0x13, 0xe8, 0xf8, 0x04, 0x5a, 0x4a, + 0xfe, 0x22, 0x65, 0x4a, 0xaa, 0x08, 0xdd, 0x35, 0xd4, 0x7c, 0x01, 0xca, 0xda, 0x3e, 0x99, 0x86, + 0x86, 0x6e, 0xe6, 0xcd, 0xdb, 0xd9, 0xf7, 0x66, 0x06, 0xdf, 0x13, 0xf2, 0x13, 0x70, 0x2b, 0x8e, + 0x21, 0x05, 0xcd, 0x0f, 0x1e, 0x31, 0x2d, 0xf2, 0x02, 0xd2, 0x46, 0xab, 0x46, 0x19, 0x5a, 0x25, + 0x8d, 0x56, 0x56, 0x91, 0xdb, 0x1b, 0x56, 0x32, 0x62, 0x25, 0xc7, 0xfb, 0x0c, 0x2c, 0xdd, 0xbf, + 0xb9, 0x57, 0xa8, 0x42, 0x39, 0x66, 0x7a, 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 0x5a, 0xf6, 0xdf, + 0xfa, 0x9e, 0x60, 0xbf, 0x6c, 0xd9, 0x66, 0x0b, 0x6e, 0xc2, 0x8b, 0x1b, 0xbf, 0xcf, 0x67, 0xe4, + 0x84, 0xd6, 0xd5, 0x61, 0x3c, 0x2a, 0xc6, 0x19, 0x2e, 0x5b, 0xd6, 0xef, 0xa6, 0xd3, 0xb2, 0x38, + 0x3a, 0x5d, 0x85, 0xe8, 0x6c, 0x15, 0xa2, 0x9f, 0xab, 0x10, 0x7d, 0x59, 0x87, 0x93, 0xb3, 0x75, + 0x38, 0xf9, 0xb1, 0x0e, 0x27, 0x1f, 0xde, 0x15, 0xc2, 0x96, 0x2d, 0x4b, 0xb8, 0xaa, 0xd3, 0x97, + 0x83, 0xe3, 0xd7, 0x94, 0x99, 0x74, 0xe3, 0xff, 0x21, 0x57, 0x1a, 0xc6, 0x69, 0x49, 0x85, 0x4c, + 0x6b, 0x95, 0xb7, 0x15, 0x98, 0xbf, 0xce, 0xd2, 0x9e, 0x34, 0x60, 0xd8, 0x65, 0x77, 0x5f, 0x8f, + 0xff, 0x04, 0x00, 0x00, 0xff, 0xff, 0x55, 0x8d, 0x91, 0x3c, 0xbc, 0x02, 0x00, 0x00, } func (this *TokenMapping) Equal(that interface{}) bool { @@ -269,12 +288,18 @@ func (this *TokenMapping) Equal(that interface{}) bool { } else if this == nil { return false } + if this.Name != that1.Name { + return false + } if this.Erc20Address != that1.Erc20Address { return false } if this.CosmosDenom != that1.CosmosDenom { return false } + if this.ScalingFactor != that1.ScalingFactor { + return false + } if this.Enabled != that1.Enabled { return false } @@ -368,20 +393,32 @@ func (m *TokenMapping) MarshalToSizedBuffer(dAtA []byte) (int, error) { dAtA[i] = 0 } i-- - dAtA[i] = 0x18 + dAtA[i] = 0x28 + } + if m.ScalingFactor != 0 { + i = encodeVarintProposal(dAtA, i, uint64(m.ScalingFactor)) + i-- + dAtA[i] = 0x20 } if len(m.CosmosDenom) > 0 { i -= len(m.CosmosDenom) copy(dAtA[i:], m.CosmosDenom) i = encodeVarintProposal(dAtA, i, uint64(len(m.CosmosDenom))) i-- - dAtA[i] = 0x12 + dAtA[i] = 0x1a } if len(m.Erc20Address) > 0 { i -= len(m.Erc20Address) copy(dAtA[i:], m.Erc20Address) i = encodeVarintProposal(dAtA, i, uint64(len(m.Erc20Address))) i-- + dAtA[i] = 0x12 + } + if len(m.Name) > 0 { + i -= len(m.Name) + copy(dAtA[i:], m.Name) + i = encodeVarintProposal(dAtA, i, uint64(len(m.Name))) + i-- dAtA[i] = 0xa } return len(dAtA) - i, nil @@ -495,6 +532,10 @@ func (m *TokenMapping) Size() (n int) { } var l int _ = l + l = len(m.Name) + if l > 0 { + n += 1 + l + sovProposal(uint64(l)) + } l = len(m.Erc20Address) if l > 0 { n += 1 + l + sovProposal(uint64(l)) @@ -503,6 +544,9 @@ func (m *TokenMapping) Size() (n int) { if l > 0 { n += 1 + l + sovProposal(uint64(l)) } + if m.ScalingFactor != 0 { + n += 1 + sovProposal(uint64(m.ScalingFactor)) + } if m.Enabled { n += 2 } @@ -585,6 +629,38 @@ func (m *TokenMapping) Unmarshal(dAtA []byte) error { } switch fieldNum { case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Name", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowProposal + } + 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 ErrInvalidLengthProposal + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthProposal + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Name = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field Erc20Address", wireType) } @@ -616,7 +692,7 @@ func (m *TokenMapping) Unmarshal(dAtA []byte) error { } m.Erc20Address = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex - case 2: + case 3: if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field CosmosDenom", wireType) } @@ -648,7 +724,26 @@ func (m *TokenMapping) Unmarshal(dAtA []byte) error { } m.CosmosDenom = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex - case 3: + case 4: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field ScalingFactor", wireType) + } + m.ScalingFactor = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowProposal + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.ScalingFactor |= int64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 5: if wireType != 0 { return fmt.Errorf("proto: wrong wireType = %d for field Enabled", wireType) } From 37fcb12641a5497fde35ceeee86ee393e675bc14 Mon Sep 17 00:00:00 2001 From: gopherjk121 Date: Tue, 26 Jan 2021 11:11:03 +1000 Subject: [PATCH 08/11] modify bridge types from latest core/erc20bridge --- chain/erc20bridge/types/msg_mint.go | 10 +++++++--- chain/erc20bridge/types/proposal.go | 11 +++++++++++ 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/chain/erc20bridge/types/msg_mint.go b/chain/erc20bridge/types/msg_mint.go index 0b416084..b90afed4 100644 --- a/chain/erc20bridge/types/msg_mint.go +++ b/chain/erc20bridge/types/msg_mint.go @@ -2,6 +2,7 @@ package types import ( "errors" + "fmt" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/ethereum/go-ethereum/common" @@ -29,9 +30,12 @@ func (msg MsgERC20BridgeMint) Type() string { return TypeMsgMint } // ValidateBasic runs stateless checks on the message func (msg MsgERC20BridgeMint) ValidateBasic() error { - _, ok := sdk.NewIntFromString(msg.Amount) - if !ok { - return errors.New("invalid amount field") + coins, err := sdk.ParseCoinsNormalized(msg.Amount) + if err != nil { + return err + } + if len(coins) > 1 || coins.Empty() { + return fmt.Errorf("invalid coins field: %s", coins.String()) } if msg.Proposer.Empty() { return errors.New("empty proposer") diff --git a/chain/erc20bridge/types/proposal.go b/chain/erc20bridge/types/proposal.go index 617565e1..fe6e4b0f 100644 --- a/chain/erc20bridge/types/proposal.go +++ b/chain/erc20bridge/types/proposal.go @@ -20,6 +20,17 @@ func init() { gov.RegisterProposalTypeCodec(&ResetHubProposal{}, "cosmos-sdk/ResetHubProposal") } +// NewTokenMapping returns an instance of TokenMapping +func NewTokenMapping(name string, erc20Address string, cosmosDenom string, scalingFactor int64, enabled bool) TokenMapping { + return TokenMapping{ + Name: name, + Erc20Address: erc20Address, + CosmosDenom: cosmosDenom, + ScalingFactor: scalingFactor, + Enabled: true, + } +} + // NewRegisterTokenMappingProposal returns new instance of TokenMappingProposal func NewRegisterTokenMappingProposal(title, description string, mapping TokenMapping) gov.Content { return &RegisterTokenMappingProposal{title, description, mapping} From 759507420b61f2dbed6b6db23ee188318d0acf2a Mon Sep 17 00:00:00 2001 From: gopherjk121 Date: Tue, 26 Jan 2021 12:28:36 +1000 Subject: [PATCH 09/11] modify evm and erc20bridge query to latest --- chain/erc20bridge/client/cli/query.go | 15 +++++++------- chain/evm/client/cli/query.go | 28 ++++++++++++++------------- 2 files changed, 23 insertions(+), 20 deletions(-) diff --git a/chain/erc20bridge/client/cli/query.go b/chain/erc20bridge/client/cli/query.go index d920f94d..31985b8d 100644 --- a/chain/erc20bridge/client/cli/query.go +++ b/chain/erc20bridge/client/cli/query.go @@ -1,8 +1,9 @@ package cli import ( + "context" + "github.com/InjectiveLabs/sdk-go/chain/erc20bridge/types" - "github.com/InjectiveLabs/sdk-go/ethereum/rpc" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" "github.com/spf13/cobra" @@ -34,7 +35,7 @@ func GetBridgesCmd() *cobra.Command { Args: cobra.ExactArgs(0), RunE: func(cmd *cobra.Command, args []string) error { clientCtx := client.GetClientContextFromCmd(cmd) - clientCtx, err := client.ReadQueryCommandFlags(clientCtx, cmd.Flags()) + clientCtx, err := client.GetClientQueryContext(cmd) if err != nil { return err } @@ -43,12 +44,12 @@ func GetBridgesCmd() *cobra.Command { req := &types.QueryBridgesRequest{} - res, err := queryClient.Bridges(rpc.ContextWithHeight(clientCtx.Height), req) + res, err := queryClient.Bridges(context.Background(), req) if err != nil { return err } - return clientCtx.PrintOutput(res) + return clientCtx.PrintProto(res) }, } @@ -65,7 +66,7 @@ func GetHubParamsCmd() *cobra.Command { Args: cobra.ExactArgs(0), RunE: func(cmd *cobra.Command, args []string) error { clientCtx := client.GetClientContextFromCmd(cmd) - clientCtx, err := client.ReadQueryCommandFlags(clientCtx, cmd.Flags()) + clientCtx, err := client.GetClientQueryContext(cmd) if err != nil { return err } @@ -74,12 +75,12 @@ func GetHubParamsCmd() *cobra.Command { req := &types.QueryHubParamsRequest{} - res, err := queryClient.HubParams(rpc.ContextWithHeight(clientCtx.Height), req) + res, err := queryClient.HubParams(context.Background(), req) if err != nil { return err } - return clientCtx.PrintOutput(res) + return clientCtx.PrintProto(res) }, } diff --git a/chain/evm/client/cli/query.go b/chain/evm/client/cli/query.go index dce90aa8..ecce7b05 100644 --- a/chain/evm/client/cli/query.go +++ b/chain/evm/client/cli/query.go @@ -4,6 +4,7 @@ import ( "math/big" "strings" + rpctypes "github.com/InjectiveLabs/injective-core/ethereum/rpc/types" "github.com/ethereum/go-ethereum/accounts/abi" "github.com/ethereum/go-ethereum/common" "github.com/spf13/cobra" @@ -16,7 +17,7 @@ import ( "github.com/InjectiveLabs/sdk-go/wrappers" ) -// GetQueryCmd returns the parent command for all modules/bank CLi query commands. +// GetQueryCmd returns the parent command for all x/bank CLi query commands. func GetQueryCmd() *cobra.Command { cmd := &cobra.Command{ Use: types.ModuleName, @@ -43,8 +44,7 @@ func GetStorageCmd() *cobra.Command { Long: "Gets storage for an account with a given key and height. If the height is not provided, it will use the latest height from context.", Args: cobra.ExactArgs(2), RunE: func(cmd *cobra.Command, args []string) error { - clientCtx := client.GetClientContextFromCmd(cmd) - clientCtx, err := client.ReadQueryCommandFlags(clientCtx, cmd.Flags()) + clientCtx, err := client.GetClientQueryContext(cmd) if err != nil { return err } @@ -63,12 +63,12 @@ func GetStorageCmd() *cobra.Command { Key: key, } - res, err := queryClient.Storage(rpc.ContextWithHeight(clientCtx.Height), req) + res, err := queryClient.Storage(rpctypes.ContextWithHeight(clientCtx.Height), req) if err != nil { return err } - return clientCtx.PrintOutput(res) + return clientCtx.PrintProto(res) }, } @@ -84,8 +84,7 @@ func GetCodeCmd() *cobra.Command { Long: "Gets code from an account. If the height is not provided, it will use the latest height from context.", Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { - clientCtx := client.GetClientContextFromCmd(cmd) - clientCtx, err := client.ReadQueryCommandFlags(clientCtx, cmd.Flags()) + clientCtx, err := client.GetClientQueryContext(cmd) if err != nil { return err } @@ -101,12 +100,12 @@ func GetCodeCmd() *cobra.Command { Address: address, } - res, err := queryClient.Code(rpc.ContextWithHeight(clientCtx.Height), req) + res, err := queryClient.Code(rpctypes.ContextWithHeight(clientCtx.Height), req) if err != nil { return err } - return clientCtx.PrintOutput(res) + return clientCtx.PrintProto(res) }, } @@ -123,7 +122,7 @@ func GetErc20Balance() *cobra.Command { Args: cobra.ExactArgs(2), RunE: func(cmd *cobra.Command, args []string) error { clientCtx := client.GetClientContextFromCmd(cmd) - clientCtx, err := client.ReadQueryCommandFlags(clientCtx, cmd.Flags()) + clientCtx, err := client.GetClientQueryContext(cmd) if err != nil { return err } @@ -152,7 +151,10 @@ func GetErc20Balance() *cobra.Command { return err } ret := big.NewInt(0) - err = erc20ABI.Unpack(&ret, "balanceOf", res.Data) + err = erc20ABI.UnpackIntoInterface(&ret, "balanceOf", res.Data) + if err != nil { + return err + } return clientCtx.PrintString(ret.String()) }, @@ -171,7 +173,7 @@ func GetAccount() *cobra.Command { Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { clientCtx := client.GetClientContextFromCmd(cmd) - clientCtx, err := client.ReadQueryCommandFlags(clientCtx, cmd.Flags()) + clientCtx, err := client.GetClientQueryContext(cmd) if err != nil { return err } @@ -188,7 +190,7 @@ func GetAccount() *cobra.Command { return err } - return clientCtx.PrintOutput(res) + return clientCtx.PrintProto(res) }, } From ab95ca04adef32959042c16a4228d44450ebbde1 Mon Sep 17 00:00:00 2001 From: gopherjk121 Date: Tue, 26 Jan 2021 12:32:07 +1000 Subject: [PATCH 10/11] query import update --- chain/evm/client/cli/query.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/chain/evm/client/cli/query.go b/chain/evm/client/cli/query.go index ecce7b05..5110bd37 100644 --- a/chain/evm/client/cli/query.go +++ b/chain/evm/client/cli/query.go @@ -4,7 +4,6 @@ import ( "math/big" "strings" - rpctypes "github.com/InjectiveLabs/injective-core/ethereum/rpc/types" "github.com/ethereum/go-ethereum/accounts/abi" "github.com/ethereum/go-ethereum/common" "github.com/spf13/cobra" @@ -63,7 +62,7 @@ func GetStorageCmd() *cobra.Command { Key: key, } - res, err := queryClient.Storage(rpctypes.ContextWithHeight(clientCtx.Height), req) + res, err := queryClient.Storage(rpc.ContextWithHeight(clientCtx.Height), req) if err != nil { return err } @@ -100,7 +99,7 @@ func GetCodeCmd() *cobra.Command { Address: address, } - res, err := queryClient.Code(rpctypes.ContextWithHeight(clientCtx.Height), req) + res, err := queryClient.Code(rpc.ContextWithHeight(clientCtx.Height), req) if err != nil { return err } From 59b51145dfdfb77f56213cc352b8b975ae0ea4d3 Mon Sep 17 00:00:00 2001 From: gopherjk121 Date: Tue, 26 Jan 2021 13:03:09 +1000 Subject: [PATCH 11/11] remove keycache --- ethereum/util/keycache.go | 158 -------------------------------------- 1 file changed, 158 deletions(-) delete mode 100644 ethereum/util/keycache.go diff --git a/ethereum/util/keycache.go b/ethereum/util/keycache.go deleted file mode 100644 index dfb0bc69..00000000 --- a/ethereum/util/keycache.go +++ /dev/null @@ -1,158 +0,0 @@ -package util - -import ( - "crypto/ecdsa" - "crypto/sha1" - "errors" - "io/ioutil" - "strings" - "sync" - - "github.com/ethereum/go-ethereum/accounts/abi/bind" - "github.com/ethereum/go-ethereum/accounts/keystore" - "github.com/ethereum/go-ethereum/common" - "github.com/ethereum/go-ethereum/core/types" - "github.com/ethereum/go-ethereum/crypto" -) - -type KeyCache interface { - SetPath(account common.Address, path string) bool - UnsetPath(account common.Address, path string) - PrivateKey(account common.Address, password string) (key *ecdsa.PrivateKey, ok bool) - SetPrivateKey(account common.Address, pk *ecdsa.PrivateKey) - UnsetKey(account common.Address, password string) - SignerFn(account common.Address, password string) bind.SignerFn -} - -func NewKeyCache() KeyCache { - return &keyCache{ - paths: make(map[common.Address]string), - pathsMux: new(sync.RWMutex), - keys: make(map[string]*ecdsa.PrivateKey), - keysMux: new(sync.RWMutex), - guard: NewUniquify(), - } -} - -type keyCache struct { - paths map[common.Address]string - pathsMux *sync.RWMutex - keys map[string]*ecdsa.PrivateKey - keysMux *sync.RWMutex - guard Uniquify -} - -// SetPath sets the wallet path for a given account. Returns true if the new path -// has been added or was changed. -func (k *keyCache) SetPath(account common.Address, path string) bool { - k.pathsMux.Lock() - prevPath, existing := k.paths[account] - k.paths[account] = path - k.pathsMux.Unlock() - return !existing || prevPath != path -} - -func (k *keyCache) UnsetPath(account common.Address, path string) { - k.pathsMux.Lock() - delete(k.paths, account) - k.pathsMux.Unlock() -} - -var ( - ErrNoKeyStore = errors.New("no keystore or file for account") - ErrKeyDecrypt = errors.New("private key decryption failed") -) - -func (k *keyCache) UnsetKey(account common.Address, password string) { - h := hashAccountPass(account, password) - k.keysMux.Lock() - delete(k.keys, string(h)) - k.keysMux.Unlock() -} - -func (k *keyCache) SetPrivateKey(account common.Address, pk *ecdsa.PrivateKey) { - h := hashAccountPass(account, "") - k.keysMux.Lock() - k.keys[string(h)] = pk - k.keysMux.Unlock() -} - -func (k *keyCache) PrivateKey(account common.Address, password string) (key *ecdsa.PrivateKey, ok bool) { - h := hashAccountPass(account, password) - if err := k.guard.Call(string(h), func() error { - k.keysMux.RLock() - key, ok = k.keys[string(h)] - k.keysMux.RUnlock() - if ok { - return nil - } - k.pathsMux.RLock() - path, pathOk := k.paths[account] - k.pathsMux.RUnlock() - if !pathOk { - return ErrNoKeyStore - } - if strings.HasPrefix(path, "keystore://") { - path = strings.TrimPrefix(path, "keystore://") - } - keyJSON, err := ioutil.ReadFile(path) - if err != nil { - return ErrNoKeyStore - } - pk, err := keystore.DecryptKey(keyJSON, password) - if err != nil { - return ErrKeyDecrypt - } - k.keysMux.Lock() - k.keys[string(h)] = pk.PrivateKey - k.keysMux.Unlock() - key = pk.PrivateKey - ok = true - return nil - }); err != nil { - return nil, false - } - return key, ok -} - -func (k *keyCache) SignerFn(account common.Address, password string) bind.SignerFn { - key, ok := k.PrivateKey(account, password) - if !ok { - return nil - } - keyAddr := crypto.PubkeyToAddress(key.PublicKey) - return func(signer types.Signer, address common.Address, tx *types.Transaction) (*types.Transaction, error) { - if address != keyAddr { - return nil, errors.New("not authorized to sign this account") - } - signature, err := crypto.Sign(signer.Hash(tx).Bytes(), key) - if err != nil { - return nil, err - } - return tx.WithSignature(signer, signature) - } -} - -func SignerFnForPk(privKey *ecdsa.PrivateKey) bind.SignerFn { - keyAddr := crypto.PubkeyToAddress(privKey.PublicKey) - return func(signer types.Signer, address common.Address, tx *types.Transaction) (*types.Transaction, error) { - if address != keyAddr { - return nil, errors.New("not authorized to sign this account") - } - signature, err := crypto.Sign(signer.Hash(tx).Bytes(), privKey) - if err != nil { - return nil, err - } - return tx.WithSignature(signer, signature) - } -} - -var hashSep = []byte("-") - -func hashAccountPass(account common.Address, password string) []byte { - h := sha1.New() - h.Write(account[:]) - h.Write(hashSep) - h.Write([]byte(password)) - return h.Sum(nil) -}