Skip to content

Commit

Permalink
feat(x/crosschain): recover execute claimEvent (#811)
Browse files Browse the repository at this point in the history
Co-authored-by: fx0x55 <[email protected]>
  • Loading branch information
zakir-code and fx0x55 authored Nov 18, 2024
1 parent 509f4cd commit ea214d9
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 27 deletions.
2 changes: 1 addition & 1 deletion contract/bridge_fee_oracle.sol.go

Large diffs are not rendered by default.

15 changes: 8 additions & 7 deletions contract/icrosschain.sol.go

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

15 changes: 10 additions & 5 deletions precompiles/crosschain/execute_claim.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,11 @@ func (m *ExecuteClaimMethod) Run(evm *vm.EVM, contract *vm.Contract) ([]byte, er
}
stateDB := evm.StateDB.(evmtypes.ExtStateDB)
if err = stateDB.ExecuteNativeAction(contract.Address(), nil, func(ctx sdk.Context) error {
if err = crosschainKeeper.ExecuteClaim(ctx, args.EventNonce.Uint64()); err != nil {
return err
preExecuteErr, executeErr := crosschainKeeper.ExecuteClaim(ctx, args.EventNonce.Uint64())
if preExecuteErr != nil {
return preExecuteErr
}
data, topic, err := m.NewExecuteClaimEvent(contract.Caller(), args.EventNonce, args.Chain)
data, topic, err := m.NewExecuteClaimEvent(contract.Caller(), args.EventNonce, args.Chain, executeErr)
if err != nil {
return err
}
Expand All @@ -83,8 +84,12 @@ func NewExecuteClaimABI() ExecuteClaimABI {
}
}

func (m ExecuteClaimABI) NewExecuteClaimEvent(sender common.Address, eventNonce *big.Int, dstChain string) (data []byte, topic []common.Hash, err error) {
return evmtypes.PackTopicData(m.Event, []common.Hash{sender.Hash()}, eventNonce, dstChain)
func (m ExecuteClaimABI) NewExecuteClaimEvent(sender common.Address, eventNonce *big.Int, dstChain string, executeErr error) (data []byte, topic []common.Hash, err error) {
errReason := ""
if executeErr != nil {
errReason = executeErr.Error()
}
return evmtypes.PackTopicData(m.Event, []common.Hash{sender.Hash()}, eventNonce, dstChain, errReason)
}

func (m ExecuteClaimABI) PackInput(args fxcontract.ExecuteClaimArgs) ([]byte, error) {
Expand Down
2 changes: 1 addition & 1 deletion precompiles/crosschain/execute_claim_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func TestExecuteClaimMethod_ABI(t *testing.T) {
methodStr := `function executeClaim(string _chain, uint256 _eventNonce) returns(bool _result)`
assert.Equal(t, methodStr, executeClaimABI.Method.String())

eventStr := `event ExecuteClaimEvent(address indexed _sender, uint256 _eventNonce, string _chain)`
eventStr := `event ExecuteClaimEvent(address indexed _sender, uint256 _eventNonce, string _chain, string _errReason)`
assert.Equal(t, eventStr, executeClaimABI.Event.String())
}

Expand Down
2 changes: 1 addition & 1 deletion precompiles/types/expected_keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ type BankKeeper interface {
}

type CrosschainKeeper interface {
ExecuteClaim(ctx sdk.Context, eventNonce uint64) error
ExecuteClaim(ctx sdk.Context, eventNonce uint64) (error, error)
BridgeCoinSupply(ctx context.Context, token, target string) (sdk.Coin, error)
CrosschainBaseCoin(ctx sdk.Context, from sdk.AccAddress, receipt string, amount, fee sdk.Coin, fxTarget *crosschaintypes.FxTarget, memo string, originToken bool) error
BridgeCallBaseCoin(ctx sdk.Context, from, refund, to common.Address, coins sdk.Coins, data, memo []byte, quoteId *big.Int, fxTarget *crosschaintypes.FxTarget, originTokenAmount sdkmath.Int) (uint64, error)
Expand Down
3 changes: 2 additions & 1 deletion solidity/contracts/bridge/ICrosschain.sol
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ interface ICrosschain is IBridgeCall {
event ExecuteClaimEvent(
address indexed _sender,
uint256 _eventNonce,
string _chain
string _chain,
string _errReason
);
}
Loading

0 comments on commit ea214d9

Please sign in to comment.