-
Notifications
You must be signed in to change notification settings - Fork 808
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add native associate tx type (#1694)
- Loading branch information
Showing
13 changed files
with
614 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package types | ||
|
||
import ( | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" | ||
) | ||
|
||
const TypeMsgAssociate = "evm_associate" | ||
|
||
var ( | ||
_ sdk.Msg = &MsgAssociate{} | ||
) | ||
|
||
func NewMsgAssociate(sender sdk.AccAddress, customMsg string) *MsgAssociate { | ||
return &MsgAssociate{Sender: sender.String(), CustomMessage: customMsg} | ||
} | ||
|
||
func (msg *MsgAssociate) Route() string { | ||
return RouterKey | ||
} | ||
|
||
func (msg *MsgAssociate) Type() string { | ||
return TypeMsgAssociate | ||
} | ||
|
||
func (msg *MsgAssociate) GetSigners() []sdk.AccAddress { | ||
from, err := sdk.AccAddressFromBech32(msg.Sender) | ||
if err != nil { | ||
panic(err) | ||
} | ||
return []sdk.AccAddress{from} | ||
} | ||
|
||
func (msg *MsgAssociate) GetSignBytes() []byte { | ||
return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(msg)) | ||
} | ||
|
||
func (msg *MsgAssociate) ValidateBasic() error { | ||
_, err := sdk.AccAddressFromBech32(msg.Sender) | ||
if err != nil { | ||
return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "Invalid sender address (%s)", err) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func IsTxMsgAssociate(tx sdk.Tx) bool { | ||
msgs := tx.GetMsgs() | ||
if len(msgs) != 1 { | ||
return false | ||
} | ||
_, ok := msgs[0].(*MsgAssociate) | ||
return ok | ||
} |
Oops, something went wrong.