Skip to content
This repository was archived by the owner on Dec 21, 2021. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions chain/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,9 @@ proto-tools-stamp:
echo "Installing protoc-gen-gocosmos..."
go install github.com/regen-network/cosmos-proto/protoc-gen-gocosmos

echo "Installing protoc-gen-grpc-gateway..."
go install github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway

# Create dummy file to satisfy dependency and avoid
# rebuilding when this Makefile target is hit twice
# in a row
Expand Down
2 changes: 2 additions & 0 deletions chain/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMo
github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4=
github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
github.com/gballet/go-libpcsclite v0.0.0-20190607065134-2772fd86a8ff/go.mod h1:x7DCsMOv1taUwEWCzT4cmDeAkigA5/QCwUodaVOe8Ww=
github.com/ghodss/yaml v1.0.0 h1:wQHKEahhL6wmXdzwWG11gIVCkOv05bNOh+Rxn0yngAk=
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU=
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20200222043503-6f7a984d4dc4/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=
Expand All @@ -222,6 +223,7 @@ github.com/godbus/dbus v0.0.0-20190726142602-4481cbc300e2/go.mod h1:bBOAhwG1umN6
github.com/gogo/gateway v1.1.0 h1:u0SuhL9+Il+UbjM9VIE3ntfRujKbvVpFvNB4HbjeVQ0=
github.com/gogo/gateway v1.1.0/go.mod h1:S7rR8FRQyG3QFESeSv4l2WnsyzlCLG0CzBbUUo/mbic=
github.com/gogo/googleapis v1.1.0/go.mod h1:gf4bu3Q80BeJ6H1S1vYPm8/ELATdvryBaNFGgqEef3s=
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b h1:VKtxabqXZkF25pY9ekfRL6a582T4P37/31XEstQ5p58=
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
github.com/golang/groupcache v0.0.0-20160516000752-02826c3e7903/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
github.com/golang/groupcache v0.0.0-20190129154638-5b532d6fd5ef/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
Expand Down
1 change: 1 addition & 0 deletions chain/proto/minter/v1/attestation.proto
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ enum ClaimType {
CLAIM_TYPE_WITHDRAW = 2 [(gogoproto.enumvalue_customname) = "CLAIM_TYPE_WITHDRAW"];
CLAIM_TYPE_VALSET = 3 [(gogoproto.enumvalue_customname) = "CLAIM_TYPE_VALSET"];
CLAIM_TYPE_SEND_TO_ETH = 4 [(gogoproto.enumvalue_customname) = "CLAIM_TYPE_SEND_TO_ETH"];
CLAIM_TYPE_SWAP_ETH = 5 [(gogoproto.enumvalue_customname) = "CLAIM_TYPE_SWAP_ETH"];
}

// Attestation is an aggregate of `claims` that eventually becomes `observed` by
Expand Down
14 changes: 13 additions & 1 deletion chain/proto/minter/v1/msgs.proto
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ service Msg {
rpc ValsetClaim(MsgValsetClaim) returns(MsgValsetClaimResponse) {
option (google.api.http).post = "/minter/v1/valset_claim";
}
rpc SwapEthClaim(MsgSwapEthClaim) returns(MsgSwapEthClaimResponse) {
option (google.api.http).post = "/minter/v1/swap_eth_claim";
}
}

// MsgValsetConfirm
Expand Down Expand Up @@ -201,4 +204,13 @@ message MsgSendToEthClaim {
}

// TODO: write response data here
message MsgSendToEthClaimResponse {}
message MsgSendToEthClaimResponse {}

message MsgSwapEthClaim {
uint64 event_nonce = 1;
string minter_sender = 2;
string orchestrator = 3;
}

// TODO: write response data here
message MsgSwapEthClaimResponse {}
30 changes: 30 additions & 0 deletions chain/x/minter/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ func NewHandler(keeper keeper.Keeper) sdk.Handler {
return handleValsetClaim(ctx, keeper, msg)
case *types.MsgSendToEthClaim:
return handleSendToEthClaim(ctx, keeper, msg)
case *types.MsgSwapEthClaim:
return handleSwapEthClaim(ctx, keeper, msg)
default:
return nil, sdkerrors.Wrap(sdkerrors.ErrUnknownRequest, fmt.Sprintf("Unrecognized Peggy Msg type: %v", msg.Type()))
}
Expand Down Expand Up @@ -318,3 +320,31 @@ func NewColdStorageTransferProposalHandler(k keeper.Keeper) govtypes.Handler {
}
}
}

func handleSwapEthClaim(ctx sdk.Context, keeper keeper.Keeper, msg *types.MsgSwapEthClaim) (*sdk.Result, error) {
if keeper.IsStopped(ctx) {
return nil, types.ErrServiceStopped
}

var attestationIDs [][]byte
// TODO SECURITY this does not auth the sender in the current validator set!
// anyone can vote! We need to check and reject right here.

orch, _ := sdk.AccAddressFromBech32(msg.Orchestrator)
validator := findValidatorKey(ctx, orch)
if validator == nil {
return nil, sdkerrors.Wrap(types.ErrUnknown, "address")
}

att, err := keeper.AddClaim(ctx, msg.GetType(), msg.GetEventNonce(), validator, msg)
if err != nil {
return nil, sdkerrors.Wrap(err, "create attestation")
}

attestationIDs = append(attestationIDs, types.GetAttestationKey(att.EventNonce, msg))

return &sdk.Result{
Data: bytes.Join(attestationIDs, []byte(", ")),
Events: ctx.EventManager().Events().ToABCIEvents(),
}, nil
}
2 changes: 2 additions & 0 deletions chain/x/minter/keeper/attestation_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,8 @@ func (a *AttestationHandler) Handle(ctx sdk.Context, att types.Attestation, clai
}
}

case *types.MsgSwapEthClaim:
// TODO: implement
case *types.MsgWithdrawClaim:
return a.keeper.OutgoingTxBatchExecuted(ctx, claim.BatchNonce, claim.TxHash)
case *types.MsgValsetClaim:
Expand Down
4 changes: 4 additions & 0 deletions chain/x/minter/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,7 @@ func (k msgServer) SendToEthClaim(c context.Context, msg *types.MsgSendToEthClai
func (k msgServer) ValsetClaim(c context.Context, msg *types.MsgValsetClaim) (*types.MsgValsetClaimResponse, error) {
return nil, nil
}

func (k msgServer) SwapEthClaim(c context.Context, msg *types.MsgSwapEthClaim) (*types.MsgSwapEthClaimResponse, error) {
return nil, nil
}
60 changes: 32 additions & 28 deletions chain/x/minter/types/attestation.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions chain/x/minter/types/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ func RegisterInterfaces(registry types.InterfaceRegistry) {
&MsgValsetClaim{},
&MsgWithdrawClaim{},
&MsgSendToEthClaim{},
&MsgSwapEthClaim{},
)

registry.RegisterInterface(
Expand All @@ -37,6 +38,7 @@ func RegisterInterfaces(registry types.InterfaceRegistry) {
&MsgWithdrawClaim{},
&MsgValsetClaim{},
&MsgSendToEthClaim{},
&MsgSwapEthClaim{},
)

registry.RegisterImplementations(
Expand Down Expand Up @@ -68,4 +70,5 @@ func RegisterCodec(cdc *codec.LegacyAmino) {
cdc.RegisterConcrete(&IDSet{}, "minter/IDSet", nil)
cdc.RegisterConcrete(&Attestation{}, "minter/Attestation", nil)
cdc.RegisterConcrete(&ColdStorageTransferProposal{}, "minter/ColdStorageTransferProposal", nil)
cdc.RegisterConcrete(&MsgSwapEthClaim{}, "minter/MsgSwapEthClaim", nil)
}
60 changes: 60 additions & 0 deletions chain/x/minter/types/msgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ var (
_ sdk.Msg = &MsgSendToMinter{}
_ sdk.Msg = &MsgRequestBatch{}
_ sdk.Msg = &MsgConfirmBatch{}
_ sdk.Msg = &MsgSwapEthClaim{}
)

// NewMsgValsetConfirm returns a new msgValsetConfirm
Expand Down Expand Up @@ -496,3 +497,62 @@ func ValidateEthAddress(a string) error {
}
return nil
}

// ------------------------------------------------

// GetType returns the type of the claim
func (msg *MsgSwapEthClaim) GetType() ClaimType {
return CLAIM_TYPE_SWAP_ETH
}

// ValidateBasic performs stateless checks
func (msg *MsgSwapEthClaim) ValidateBasic() error {
if err := ValidateMinterAddress(msg.MinterSender); err != nil {
return sdkerrors.Wrap(err, "eth sender")
}

if _, err := sdk.AccAddressFromBech32(msg.Orchestrator); err != nil {
return sdkerrors.Wrap(sdkerrors.ErrInvalidAddress, msg.Orchestrator)
}

if msg.EventNonce == 0 {
return fmt.Errorf("nonce == 0")
}

return nil
}

// GetSignBytes encodes the message for signing
func (msg MsgSwapEthClaim) GetSignBytes() []byte {
return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(msg))
}

// GetSigners defines whose signature is required
func (msg MsgSwapEthClaim) GetSigners() []sdk.AccAddress {
acc, err := sdk.AccAddressFromBech32(msg.Orchestrator)
if err != nil {
panic(err)
}

return []sdk.AccAddress{acc}
}

// Type should return the action
func (msg MsgSwapEthClaim) Type() string {
return "swap_eth"
}

// Route should return the name of the module
func (msg MsgSwapEthClaim) Route() string { return RouterKey }

const (
TypeMsgSwapEth = "swap_eth"
)

// Hash implements WithdrawBatch.Hash
func (msg *MsgSwapEthClaim) ClaimHash() []byte {
path := fmt.Sprintf("%d", msg.EventNonce)
return tmhash.Sum([]byte(path))
}

// ------------------------------------------------
Loading