Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: replace with MustAccAddressFromBech32 #108

Merged
merged 4 commits into from
Oct 31, 2023
Merged
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
2 changes: 1 addition & 1 deletion x/crosschain/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,7 @@ func CmdGetPendingSendToExternal(chainName string) *cobra.Command {

addr, err := sdk.AccAddressFromBech32(args[0])
if err != nil {
return nil
return err
}
res, err := queryClient.GetPendingSendToExternal(cmd.Context(), &types.QueryPendingSendToExternalRequest{
ChainName: chainName,
Expand Down
7 changes: 2 additions & 5 deletions x/crosschain/keeper/attestation.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,7 @@ func (k Keeper) TryAttestation(ctx sdk.Context, att *types.Attestation, claim ty
attestationPower := sdkmath.NewInt(0)

for _, oracleStr := range att.Votes {
oracleAddr, err := sdk.AccAddressFromBech32(oracleStr)
if err != nil {
panic(fmt.Errorf("invalid oracle address %s", err.Error()))
}
oracleAddr := sdk.MustAccAddressFromBech32(oracleStr)
oracle, found := k.GetOracle(ctx, oracleAddr)
if !found {
k.Logger(ctx).Error("TryAttestation", "not found oracle", oracleAddr.String(), "claimEventNonce",
Expand All @@ -99,7 +96,7 @@ func (k Keeper) TryAttestation(ctx sdk.Context, att *types.Attestation, claim ty
att.Observed = true
k.SetAttestation(ctx, claim.GetEventNonce(), claim.ClaimHash(), att)

err = k.processAttestation(ctx, claim)
err := k.processAttestation(ctx, claim)
ctx.EventManager().EmitEvent(sdk.NewEvent(
types.EventTypeContractEvent,
sdk.NewAttribute(sdk.AttributeKeyModule, k.moduleName),
Expand Down
5 changes: 1 addition & 4 deletions x/crosschain/keeper/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,7 @@ func InitGenesis(ctx sdk.Context, k Keeper, state *types.GenesisState) {
// while all attestations have already been cleaned up we can do this instead and
// not carry around every validators event nonce counter forever.
for _, vote := range att.Votes {
oracle, err := sdk.AccAddressFromBech32(vote)
if err != nil {
panic(err)
}
oracle := sdk.MustAccAddressFromBech32(vote)
last := k.GetLastEventNonceByOracle(ctx, oracle)
if claim.GetEventNonce() > last {
// 0x23
Expand Down
5 changes: 1 addition & 4 deletions x/crosschain/keeper/oracle.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,10 +183,7 @@ func (k Keeper) GetAllOracles(ctx sdk.Context, isOnline bool) (oracles types.Ora
}

func (k Keeper) SlashOracle(ctx sdk.Context, oracleAddrStr string) {
oracleAddr, err := sdk.AccAddressFromBech32(oracleAddrStr)
if err != nil {
panic(err)
}
oracleAddr := sdk.MustAccAddressFromBech32(oracleAddrStr)
oracle, found := k.GetOracle(ctx, oracleAddr)
if !found {
panic(types.ErrNoFoundOracle)
Expand Down
132 changes: 22 additions & 110 deletions x/crosschain/types/msgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,11 +166,7 @@ func (m *MsgBondedOracle) GetSignBytes() []byte {
}

func (m *MsgBondedOracle) GetSigners() []sdk.AccAddress {
acc, err := sdk.AccAddressFromBech32(m.OracleAddress)
if err != nil {
panic(err)
}
return []sdk.AccAddress{acc}
return []sdk.AccAddress{sdk.MustAccAddressFromBech32(m.OracleAddress)}
}

// MsgAddDelegate
Expand All @@ -197,11 +193,7 @@ func (m *MsgAddDelegate) GetSignBytes() []byte {
}

func (m *MsgAddDelegate) GetSigners() []sdk.AccAddress {
acc, err := sdk.AccAddressFromBech32(m.OracleAddress)
if err != nil {
panic(err)
}
return []sdk.AccAddress{acc}
return []sdk.AccAddress{sdk.MustAccAddressFromBech32(m.OracleAddress)}
}

// MsgReDelegate
Expand All @@ -228,11 +220,7 @@ func (m *MsgReDelegate) GetSignBytes() []byte {
}

func (m *MsgReDelegate) GetSigners() []sdk.AccAddress {
acc, err := sdk.AccAddressFromBech32(m.OracleAddress)
if err != nil {
panic(err)
}
return []sdk.AccAddress{acc}
return []sdk.AccAddress{sdk.MustAccAddressFromBech32(m.OracleAddress)}
}

// MsgEditBridger
Expand All @@ -257,11 +245,7 @@ func (m *MsgEditBridger) GetSignBytes() []byte {
}

func (m *MsgEditBridger) GetSigners() []sdk.AccAddress {
acc, err := sdk.AccAddressFromBech32(m.OracleAddress)
if err != nil {
panic(err)
}
return []sdk.AccAddress{acc}
return []sdk.AccAddress{sdk.MustAccAddressFromBech32(m.OracleAddress)}
}

// MsgWithdrawReward
Expand All @@ -286,11 +270,7 @@ func (m *MsgWithdrawReward) GetSignBytes() []byte {
}

func (m *MsgWithdrawReward) GetSigners() []sdk.AccAddress {
acc, err := sdk.AccAddressFromBech32(m.OracleAddress)
if err != nil {
panic(err)
}
return []sdk.AccAddress{acc}
return []sdk.AccAddress{sdk.MustAccAddressFromBech32(m.OracleAddress)}
}

// MsgUnbondedOracle
Expand All @@ -315,11 +295,7 @@ func (m *MsgUnbondedOracle) GetSignBytes() []byte {
}

func (m *MsgUnbondedOracle) GetSigners() []sdk.AccAddress {
acc, err := sdk.AccAddressFromBech32(m.OracleAddress)
if err != nil {
panic(err)
}
return []sdk.AccAddress{acc}
return []sdk.AccAddress{sdk.MustAccAddressFromBech32(m.OracleAddress)}
}

// MsgOracleSetConfirm
Expand Down Expand Up @@ -349,11 +325,7 @@ func (m *MsgOracleSetConfirm) GetSignBytes() []byte {

// GetSigners defines whose signature is required
func (m *MsgOracleSetConfirm) GetSigners() []sdk.AccAddress {
acc, err := sdk.AccAddressFromBech32(m.BridgerAddress)
if err != nil {
panic(err)
}
return []sdk.AccAddress{acc}
return []sdk.AccAddress{sdk.MustAccAddressFromBech32(m.BridgerAddress)}
}

// MsgSendToExternal
Expand Down Expand Up @@ -384,11 +356,7 @@ func (m *MsgSendToExternal) GetSignBytes() []byte {

// GetSigners defines whose signature is required
func (m *MsgSendToExternal) GetSigners() []sdk.AccAddress {
acc, err := sdk.AccAddressFromBech32(m.Sender)
if err != nil {
panic(err)
}
return []sdk.AccAddress{acc}
return []sdk.AccAddress{sdk.MustAccAddressFromBech32(m.Sender)}
}

// MsgRequestBatch
Expand Down Expand Up @@ -418,11 +386,7 @@ func (m *MsgRequestBatch) GetSignBytes() []byte {

// GetSigners defines whose signature is required
func (m *MsgRequestBatch) GetSigners() []sdk.AccAddress {
acc, err := sdk.AccAddressFromBech32(m.Sender)
if err != nil {
panic(err)
}
return []sdk.AccAddress{acc}
return []sdk.AccAddress{sdk.MustAccAddressFromBech32(m.Sender)}
}

// MsgConfirmBatch
Expand Down Expand Up @@ -452,11 +416,7 @@ func (m *MsgConfirmBatch) GetSignBytes() []byte {

// GetSigners defines whose signature is required
func (m *MsgConfirmBatch) GetSigners() []sdk.AccAddress {
acc, err := sdk.AccAddressFromBech32(m.BridgerAddress)
if err != nil {
panic(err)
}
return []sdk.AccAddress{acc}
return []sdk.AccAddress{sdk.MustAccAddressFromBech32(m.BridgerAddress)}
}

// MsgCancelSendToExternal
Expand Down Expand Up @@ -486,11 +446,7 @@ func (m *MsgCancelSendToExternal) GetSignBytes() []byte {

// GetSigners defines whose signature is required
func (m *MsgCancelSendToExternal) GetSigners() []sdk.AccAddress {
acc, err := sdk.AccAddressFromBech32(m.Sender)
if err != nil {
panic(err)
}
return []sdk.AccAddress{acc}
return []sdk.AccAddress{sdk.MustAccAddressFromBech32(m.Sender)}
}

// MsgIncreaseBridgeFee
Expand Down Expand Up @@ -520,11 +476,7 @@ func (m *MsgIncreaseBridgeFee) GetSignBytes() []byte {

// GetSigners defines whose signature is required
func (m *MsgIncreaseBridgeFee) GetSigners() []sdk.AccAddress {
acc, err := sdk.AccAddressFromBech32(m.Sender)
if err != nil {
panic(err)
}
return []sdk.AccAddress{acc}
return []sdk.AccAddress{sdk.MustAccAddressFromBech32(m.Sender)}
}

// ExternalClaim represents a claim on ethereum state
Expand Down Expand Up @@ -588,20 +540,12 @@ func (m *MsgSendToFxClaim) GetSignBytes() []byte {
}

func (m *MsgSendToFxClaim) GetClaimer() sdk.AccAddress {
val, err := sdk.AccAddressFromBech32(m.BridgerAddress)
if err != nil {
panic(err)
}
return val
return sdk.MustAccAddressFromBech32(m.BridgerAddress)
}

// GetSigners defines whose signature is required
func (m *MsgSendToFxClaim) GetSigners() []sdk.AccAddress {
acc, err := sdk.AccAddressFromBech32(m.BridgerAddress)
if err != nil {
panic(err)
}
return []sdk.AccAddress{acc}
return []sdk.AccAddress{sdk.MustAccAddressFromBech32(m.BridgerAddress)}
}

// Type should return the action
Expand Down Expand Up @@ -647,20 +591,12 @@ func (m *MsgSendToExternalClaim) GetSignBytes() []byte {
}

func (m *MsgSendToExternalClaim) GetClaimer() sdk.AccAddress {
val, err := sdk.AccAddressFromBech32(m.BridgerAddress)
if err != nil {
panic(fmt.Sprintf("invalid address %s", m.BridgerAddress))
}
return val
return sdk.MustAccAddressFromBech32(m.BridgerAddress)
}

// GetSigners defines whose signature is required
func (m *MsgSendToExternalClaim) GetSigners() []sdk.AccAddress {
acc, err := sdk.AccAddressFromBech32(m.BridgerAddress)
if err != nil {
panic(err)
}
return []sdk.AccAddress{acc}
return []sdk.AccAddress{sdk.MustAccAddressFromBech32(m.BridgerAddress)}
}

// Route should return the name of the module
Expand Down Expand Up @@ -691,19 +627,11 @@ func (m *MsgBridgeTokenClaim) GetSignBytes() []byte {
}

func (m *MsgBridgeTokenClaim) GetSigners() []sdk.AccAddress {
acc, err := sdk.AccAddressFromBech32(m.BridgerAddress)
if err != nil {
panic(err)
}
return []sdk.AccAddress{acc}
return []sdk.AccAddress{sdk.MustAccAddressFromBech32(m.BridgerAddress)}
}

func (m *MsgBridgeTokenClaim) GetClaimer() sdk.AccAddress {
val, err := sdk.AccAddressFromBech32(m.BridgerAddress)
if err != nil {
panic(fmt.Sprintf("invalid address %s", m.BridgerAddress))
}
return val
return sdk.MustAccAddressFromBech32(m.BridgerAddress)
}

func (m *MsgBridgeTokenClaim) GetType() ClaimType {
Expand Down Expand Up @@ -740,20 +668,12 @@ func (m *MsgOracleSetUpdatedClaim) GetSignBytes() []byte {
}

func (m *MsgOracleSetUpdatedClaim) GetClaimer() sdk.AccAddress {
val, err := sdk.AccAddressFromBech32(m.BridgerAddress)
if err != nil {
panic(fmt.Sprintf("invalid address %s", m.BridgerAddress))
}
return val
return sdk.MustAccAddressFromBech32(m.BridgerAddress)
}

// GetSigners defines whose signature is required
func (m *MsgOracleSetUpdatedClaim) GetSigners() []sdk.AccAddress {
acc, err := sdk.AccAddressFromBech32(m.BridgerAddress)
if err != nil {
panic(err)
}
return []sdk.AccAddress{acc}
return []sdk.AccAddress{sdk.MustAccAddressFromBech32(m.BridgerAddress)}
}

// Type should return the action
Expand All @@ -773,23 +693,15 @@ func (m *MsgSetOrchestratorAddress) ValidateBasic() (err error) {
}

func (m *MsgSetOrchestratorAddress) GetSigners() []sdk.AccAddress {
acc, err := sdk.AccAddressFromBech32(m.BridgerAddress)
if err != nil {
panic(err)
}
return []sdk.AccAddress{acc}
return []sdk.AccAddress{sdk.MustAccAddressFromBech32(m.BridgerAddress)}
}

func (m *MsgAddOracleDeposit) ValidateBasic() (err error) {
return nil
}

func (m *MsgAddOracleDeposit) GetSigners() []sdk.AccAddress {
acc, err := sdk.AccAddressFromBech32(m.OracleAddress)
if err != nil {
panic(err)
}
return []sdk.AccAddress{acc}
return []sdk.AccAddress{sdk.MustAccAddressFromBech32(m.OracleAddress)}
}

// Route returns the MsgUpdateParams message route.
Expand Down
13 changes: 2 additions & 11 deletions x/crosschain/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -321,20 +321,11 @@ func (m *OutgoingTxBatch) GetCheckpoint(gravityIDString string) ([]byte, error)
// --- Oracle(S) --- //

func (m *Oracle) GetOracle() sdk.AccAddress {
// oracle address can't be empty
addr, err := sdk.AccAddressFromBech32(m.OracleAddress)
if err != nil {
panic(err)
}
return addr
return sdk.MustAccAddressFromBech32(m.OracleAddress)
}

func (m *Oracle) GetBridger() sdk.AccAddress {
addr, err := sdk.AccAddressFromBech32(m.BridgerAddress)
if err != nil {
panic(err)
}
return addr
return sdk.MustAccAddressFromBech32(m.BridgerAddress)
}

func (m *Oracle) GetValidator() sdk.ValAddress {
Expand Down
9 changes: 3 additions & 6 deletions x/erc20/types/msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,7 @@ func (m *MsgConvertCoin) GetSignBytes() []byte {

// GetSigners defines whose signature is required
func (m *MsgConvertCoin) GetSigners() []sdk.AccAddress {
addr := sdk.MustAccAddressFromBech32(m.Sender)
return []sdk.AccAddress{addr}
return []sdk.AccAddress{sdk.MustAccAddressFromBech32(m.Sender)}
}

// NewMsgConvertERC20 creates a new instance of MsgConvertERC20
Expand Down Expand Up @@ -121,8 +120,7 @@ func (m *MsgConvertERC20) GetSignBytes() []byte {

// GetSigners defines whose signature is required
func (m *MsgConvertERC20) GetSigners() []sdk.AccAddress {
addr := common.HexToAddress(m.Sender)
return []sdk.AccAddress{addr.Bytes()}
return []sdk.AccAddress{common.HexToAddress(m.Sender).Bytes()}
}

func NewMsgConvertDenom(sender, receiver sdk.AccAddress, coin sdk.Coin, target string) *MsgConvertDenom {
Expand Down Expand Up @@ -161,8 +159,7 @@ func (m *MsgConvertDenom) GetSignBytes() []byte {

// GetSigners defines whose signature is required
func (m *MsgConvertDenom) GetSigners() []sdk.AccAddress {
addr := sdk.MustAccAddressFromBech32(m.Sender)
return []sdk.AccAddress{addr}
return []sdk.AccAddress{sdk.MustAccAddressFromBech32(m.Sender)}
}

// Route returns the MsgUpdateParams message route.
Expand Down
Loading
Loading