Skip to content

Commit

Permalink
replace NewGeneralMessage
Browse files Browse the repository at this point in the history
  • Loading branch information
fish-sammy committed Nov 1, 2023
1 parent 3a409f9 commit 72c282c
Show file tree
Hide file tree
Showing 9 changed files with 20 additions and 29 deletions.
2 changes: 1 addition & 1 deletion x/axelarnet/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func NewProposalHandler(k keeper.Keeper, nexusK types.Nexus, accountK types.Acco
payloadHash := crypto.Keccak256(contractCall.Payload)

msgID, txID, nonce := nexusK.GenerateMessageID(ctx)
msg := nexus.NewGeneralMessage_(msgID, sender, recipient, payloadHash, txID, nonce, nil)
msg := nexus.NewGeneralMessage(msgID, sender, recipient, payloadHash, txID, nonce, nil)

events.Emit(ctx, &types.ContractCallSubmitted{
MessageID: msg.ID,
Expand Down
2 changes: 1 addition & 1 deletion x/axelarnet/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func (s msgServer) CallContract(c context.Context, req *types.CallContractReques
payloadHash := crypto.Keccak256(req.Payload)

msgID, txID, nonce := s.nexus.GenerateMessageID(ctx)
msg := nexus.NewGeneralMessage_(msgID, sender, recipient, payloadHash, txID, nonce, nil)
msg := nexus.NewGeneralMessage(msgID, sender, recipient, payloadHash, txID, nonce, nil)

events.Emit(ctx, &types.ContractCallSubmitted{
MessageID: msg.ID,
Expand Down
4 changes: 2 additions & 2 deletions x/axelarnet/message_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ func handleMessage(ctx sdk.Context, n types.Nexus, b types.BankKeeper, sourceAdd

destChain := funcs.MustOk(n.GetChain(ctx, nexus.ChainName(msg.DestinationChain)))
recipient := nexus.CrossChainAddress{Chain: destChain, Address: msg.DestinationAddress}
m := nexus.NewGeneralMessage_(
m := nexus.NewGeneralMessage(
id,
sourceAddress,
recipient,
Expand Down Expand Up @@ -283,7 +283,7 @@ func handleMessageWithToken(ctx sdk.Context, n types.Nexus, b types.BankKeeper,

destChain := funcs.MustOk(n.GetChain(ctx, nexus.ChainName(msg.DestinationChain)))
recipient := nexus.CrossChainAddress{Chain: destChain, Address: msg.DestinationAddress}
m := nexus.NewGeneralMessage_(
m := nexus.NewGeneralMessage(
id,
sourceAddress,
recipient,
Expand Down
4 changes: 2 additions & 2 deletions x/evm/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ func setMessageToNexus(ctx sdk.Context, n types.Nexus, event types.Event, asset
Address: e.ContractCall.ContractAddress,
}

message = nexus.NewGeneralMessage_(
message = nexus.NewGeneralMessage(
string(event.GetID()),
sender,
recipient,
Expand All @@ -239,7 +239,7 @@ func setMessageToNexus(ctx sdk.Context, n types.Nexus, event types.Event, asset
Address: e.ContractCallWithToken.ContractAddress,
}

message = nexus.NewGeneralMessage_(
message = nexus.NewGeneralMessage(
string(event.GetID()),
sender,
recipient,
Expand Down
7 changes: 5 additions & 2 deletions x/evm/abci_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func TestHandleGeneralMessage(t *testing.T) {
asset := rand.Coin()

givenMessage := Given("a message", func() {
msg = nexus.NewGeneralMessage(evmTestUtils.RandomHash().Hex(), sender, receiver, evmCrypto.Keccak256(payload), nexus.Approved, evmTestUtils.RandomHash().Bytes()[:], uint64(rand.I64Between(0, 10000)), nil)
msg = nexus.NewGeneralMessage(evmTestUtils.RandomHash().Hex(), sender, receiver, evmCrypto.Keccak256(payload), evmTestUtils.RandomHash().Bytes()[:], uint64(rand.I64Between(0, 10000)), nil)

ctx, _, n, multisigKeeper, _, destinationCk = setup()
n.SetMessageFailedFunc = func(ctx sdk.Context, id string) error {
Expand Down Expand Up @@ -280,7 +280,10 @@ func TestHandleGeneralMessages(t *testing.T) {
destChain.Module = types.ModuleName
sender := nexus.CrossChainAddress{Chain: srcChain, Address: evmTestUtils.RandomAddress().Hex()}
receiver := nexus.CrossChainAddress{Chain: destChain, Address: evmTestUtils.RandomAddress().Hex()}
msg := nexus.NewGeneralMessage(evmTestUtils.RandomHash().Hex(), sender, receiver, evmTestUtils.RandomHash().Bytes(), nexus.Processing, evmTestUtils.RandomHash().Bytes()[:], uint64(rand.I64Between(0, 10000)), nil)

msg := nexus.NewGeneralMessage(evmTestUtils.RandomHash().Hex(), sender, receiver, evmTestUtils.RandomHash().Bytes(), evmTestUtils.RandomHash().Bytes()[:], uint64(rand.I64Between(0, 10000)), nil)
msg.Status = nexus.Processing

msgs = append(msgs, msg)
}
return msgs
Expand Down
2 changes: 1 addition & 1 deletion x/evm/types/command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func TestNewApproveContractCallCommandFromGeneralMessage(t *testing.T) {
destChain := nexus.Chain{Name: nexus.ChainName(rand.StrBetween(8, 64)), Module: types.ModuleName}
sender := nexus.CrossChainAddress{Chain: srcChain, Address: rand.AccAddr().String()}
receiver := nexus.CrossChainAddress{Chain: destChain, Address: testutils.RandomAddress().Hex()}
msg := nexus.NewGeneralMessage(txID.Hex(), sender, receiver, payloadHash, nexus.Approved, txID[:], eventIndex, nil)
msg := nexus.NewGeneralMessage(txID.Hex(), sender, receiver, payloadHash, txID[:], eventIndex, nil)

actual := types.NewApproveContractCallCommandGeneric(chainID, keyID,
common.HexToAddress(msg.GetDestinationAddress()), common.BytesToHash(msg.PayloadHash), common.BytesToHash(msg.SourceTxID), msg.GetSourceChain(), msg.GetSourceAddress(), msg.SourceTxIndex, msg.ID)
Expand Down
7 changes: 5 additions & 2 deletions x/nexus/exported/testutils/rand.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,17 @@ func RandomMessage(statuses ...exported.GeneralMessage_Status) exported.GeneralM
statuses = []exported.GeneralMessage_Status{exported.Approved, exported.Processing, exported.Executed, exported.Failed}
}
coin := rand.Coin()
return exported.NewGeneralMessage(

msg := exported.NewGeneralMessage(
rand.StrBetween(10, 20),
RandomCrossChainAddress(),
RandomCrossChainAddress(),
rand.Bytes(32),
rand.Of(statuses...),
rand.Bytes(32),
uint64(rand.I64Between(0, 10000)),
&coin,
)
msg.Status = rand.Of(statuses...)

return msg
}
19 changes: 2 additions & 17 deletions x/nexus/exported/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,23 +240,8 @@ func (m TransferDirection) ValidateBasic() error {
}
}

// NewGeneralMessage returns a GeneralMessage struct
// Deprecated: use NewGeneralMessage_ instead
func NewGeneralMessage(id string, sender CrossChainAddress, recipient CrossChainAddress, payloadHash []byte, status GeneralMessage_Status, sourceTxID []byte, sourceTxIndex uint64, asset *sdk.Coin) GeneralMessage {
return GeneralMessage{
ID: id,
Sender: sender,
Recipient: recipient,
PayloadHash: payloadHash,
Status: status,
Asset: asset,
SourceTxID: sourceTxID,
SourceTxIndex: sourceTxIndex,
}
}

// NewGeneralMessage_ returns a GeneralMessage struct with status set to approved
func NewGeneralMessage_(id string, sender CrossChainAddress, recipient CrossChainAddress, payloadHash []byte, sourceTxID []byte, sourceTxIndex uint64, asset *sdk.Coin) GeneralMessage {
// NewGeneralMessage returns a GeneralMessage struct with status set to approved
func NewGeneralMessage(id string, sender CrossChainAddress, recipient CrossChainAddress, payloadHash []byte, sourceTxID []byte, sourceTxIndex uint64, asset *sdk.Coin) GeneralMessage {
return GeneralMessage{
ID: id,
Sender: sender,
Expand Down
2 changes: 1 addition & 1 deletion x/nexus/keeper/msg_dispatcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func (m Messenger) routeMsg(ctx sdk.Context, msg exported.WasmMessage) error {
sender := exported.CrossChainAddress{Chain: sourceChain, Address: msg.SourceAddress}
recipient := exported.CrossChainAddress{Chain: destinationChain, Address: msg.DestinationAddress}

nexusMsg := exported.NewGeneralMessage_(id, sender, recipient, msg.PayloadHash, msg.SourceTxID, msg.SourceTxIndex, nil)
nexusMsg := exported.NewGeneralMessage(id, sender, recipient, msg.PayloadHash, msg.SourceTxID, msg.SourceTxIndex, nil)
if err := m.Nexus.SetNewMessage(ctx, nexusMsg); err != nil {
return err
}
Expand Down

0 comments on commit 72c282c

Please sign in to comment.