-
Notifications
You must be signed in to change notification settings - Fork 612
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
feat: #258 Register Counterparty Address #376
Changes from 11 commits
ef53ea1
1f6271b
325ff94
019baeb
b658d02
353fb97
9bfd299
89affa4
9e8a8d8
c1bf0a5
0b63aaf
acae9d6
7552b79
4e22511
0603eee
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
package cli | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
|
||
// external library imports | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we can exclude these comments? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You mentioned here splitting up the imports -> #337 (comment) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yea, splitting the imports is good 👍 I'm just not sure we need the comments (I mostly added those to explain it in the pseudocode) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My programmer's brain took that literally 😆 Please stamp for removal -> #385 |
||
"github.com/cosmos/cosmos-sdk/client" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
// GetQueryCmd returns the query commands for 29-fee | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,33 @@ | ||
package keeper | ||
|
||
// TODO | ||
//var _ types.MsgServer = Keeper{} | ||
import ( | ||
"context" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
|
||
"github.com/cosmos/ibc-go/modules/apps/29-fee/types" | ||
) | ||
|
||
var _ types.MsgServer = Keeper{} | ||
|
||
// RegisterCounterpartyAddress is called by the relayer on each channelEnd and allows them to specify their counterparty address before relaying | ||
// This ensures they will be properly compensated for forward relaying since destination chain must send back relayer's source address (counterparty address) in acknowledgement | ||
// This function may be called more than once by relayer, in which case, latest counterparty address is always used. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @AdityaSripal I took this to mean that the address can be overwritten by calling There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Correct |
||
func (k Keeper) RegisterCounterpartyAddress(goCtx context.Context, msg *types.MsgRegisterCounterpartyAddress) (*types.MsgRegisterCounterpartyAddressResponse, error) { | ||
ctx := sdk.UnwrapSDKContext(goCtx) | ||
|
||
k.SetCounterpartyAddress( | ||
ctx, msg.Address, msg.CounterpartyAddress, | ||
) | ||
|
||
k.Logger(ctx).Info("Registering counterparty address for relayer with", "Source address:", msg.Address, "With counterparty address:", msg.CounterpartyAddress) | ||
seantking marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
return &types.MsgRegisterCounterpartyAddressResponse{}, nil | ||
} | ||
|
||
// EscrowPacketFee defines a rpc handler method for MsgEscrowPacketFee | ||
// EscrowPacketFee is an open callback that may be called by any module/user that wishes to escrow funds in order to | ||
// incentivize the relaying of the given packet. | ||
func (k Keeper) EscrowPacketFee(goCtx context.Context, msg *types.MsgEscrowPacketFee) (*types.MsgEscrowPacketFeeResponse, error) { | ||
return &types.MsgEscrowPacketFeeResponse{}, nil | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,29 @@ | ||
package types | ||
|
||
// standard library imports | ||
import "fmt" | ||
|
||
const ( | ||
// ModuleName defines the 29-fee name | ||
ModuleName = "ibcfee" | ||
|
||
// StoreKey is the store key string for IBC transfer | ||
StoreKey = ModuleName | ||
|
||
// PortKey is the port id that is wrapped by fee middleware | ||
PortKey = "feetransfer" | ||
|
||
// RouterKey is the message route for IBC transfer | ||
RouterKey = ModuleName | ||
|
||
// QuerierRoute is the querier route for IBC transfer | ||
QuerierRoute = ModuleName | ||
|
||
// Key prefix for relayer address mapping | ||
RelayerAddressKeyPrefix = "relayerAddress" | ||
colin-axner marked this conversation as resolved.
Show resolved
Hide resolved
|
||
) | ||
|
||
// Key for relayer source address -> counteryparty address mapping | ||
func KeyRelayerAddress(address string) []byte { | ||
colin-axner marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return []byte(fmt.Sprintf("%s/%s", RelayerAddressKeyPrefix, address)) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package types_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/cosmos/ibc-go/modules/apps/29-fee/types" | ||
) | ||
|
||
func TestKeyRelayerAddress(t *testing.T) { | ||
var ( | ||
relayerAddress = "relayer_address" | ||
) | ||
|
||
key := types.KeyRelayerAddress(relayerAddress) | ||
require.Equal(t, string(key), "relayerAddress/relayer_address") | ||
colin-axner marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,44 @@ | ||
package types | ||
|
||
/* | ||
import ( | ||
"strings" | ||
|
||
// external library imports | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" | ||
clienttypes "github.com/cosmos/ibc-go/modules/core/02-client/types" | ||
host "github.com/cosmos/ibc-go/modules/core/24-host" | ||
) | ||
|
||
// NewMsg | ||
func NewMsg() *Msg { | ||
return &Msg{ | ||
// msg types | ||
const ( | ||
TypeMsgRegisterCounterpartyAddress = "registerCounterpartyAddress" | ||
) | ||
|
||
// NewMsgRegisterCounterpartyAddress creates a new instance of MsgRegisterCounterpartyAddress | ||
func NewMsgRegisterCounterpartyAddress(sourceAddress, counterpartyAddress string) *MsgRegisterCounterpartyAddress { | ||
colin-axner marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return &MsgRegisterCounterpartyAddress{ | ||
Address: sourceAddress, | ||
CounterpartyAddress: counterpartyAddress, | ||
} | ||
} | ||
|
||
// ValidateBasic performs a basic check of the Msg fields. | ||
func (msg Msg) ValidateBasic() error { | ||
// ValidateBasic performs a basic check of the MsgRegisterCounterpartyAddress fields | ||
func (msg MsgRegisterCounterpartyAddress) ValidateBasic() error { | ||
_, err := sdk.AccAddressFromBech32(msg.Address) | ||
if err != nil { | ||
return sdkerrors.Wrap(err, "failed to convert msg.Address into sdk.AccAddress") | ||
} | ||
|
||
_, err = sdk.AccAddressFromBech32(msg.CounterpartyAddress) | ||
if err != nil { | ||
return sdkerrors.Wrap(err, "failed to convert msg.Address into sdk.AccAddress") | ||
colin-axner marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
return nil | ||
} | ||
|
||
// GetSigners implements sdk.Msg | ||
func (msg MsgTransfer) GetSigners() []sdk.AccAddress { | ||
signer, err := sdk.AccAddressFromBech32(msg.Sender) | ||
func (msg MsgRegisterCounterpartyAddress) GetSigners() []sdk.AccAddress { | ||
signer, err := sdk.AccAddressFromBech32(msg.Address) | ||
if err != nil { | ||
panic(err) | ||
} | ||
return []sdk.AccAddress{signer} | ||
} | ||
*/ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,36 @@ | ||
package types | ||
|
||
/* | ||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/stretchr/testify/require" | ||
"github.com/tendermint/tendermint/crypto/secp256k1" | ||
) | ||
|
||
"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
var ( | ||
validAddr = sdk.AccAddress(secp256k1.GenPrivKey().PubKey().Address()).String() | ||
invalidAddr = "invalid_address" | ||
) | ||
|
||
func (suite *TypesTestSuite) TestMsgValidateBasic() { | ||
// TestMsgTransferValidation tests ValidateBasic for MsgTransfer | ||
func TestMsgRegisterCountepartyAddressValidation(t *testing.T) { | ||
testCases := []struct { | ||
name string | ||
msg *types.Msg | ||
msg *MsgRegisterCounterpartyAddress | ||
expPass bool | ||
}{ | ||
{"", types.NewMsg(), true}, | ||
{"validate with correct sdk.AccAddress", NewMsgRegisterCounterpartyAddress(validAddr, validAddr), true}, | ||
{"validate with incorrect destination relayer address", NewMsgRegisterCounterpartyAddress(invalidAddr, validAddr), false}, | ||
{"validate with incorrect counterparty relayer address", NewMsgRegisterCounterpartyAddress(validAddr, invalidAddr), false}, | ||
} | ||
|
||
for _, tc := range testCases { | ||
tc := tc | ||
|
||
suite.Run(tc.name, func() { | ||
err := tc.msg.ValidateBasic() | ||
if tc.expPass { | ||
suite.Require().NoError(err) | ||
} else { | ||
suite.Require().Error(err) | ||
} | ||
}) | ||
for i, tc := range testCases { | ||
err := tc.msg.ValidateBasic() | ||
if tc.expPass { | ||
require.NoError(t, err, "valid test case %d failed: %s", i, tc.name) | ||
} else { | ||
require.Error(t, err, "invalid test case %d passed: %s", i, tc.name) | ||
} | ||
} | ||
} | ||
*/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for clarity?