-
Notifications
You must be signed in to change notification settings - Fork 0
/
send_to_ibc_v2.go
101 lines (87 loc) · 2.73 KB
/
send_to_ibc_v2.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
package evmhandler
import (
"fmt"
"math/big"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/ethereum/go-ethereum/accounts/abi"
"github.com/ethereum/go-ethereum/common"
elysiumkeeper "github.com/furyaxyz/elysium/v2/x/elysium/keeper"
"github.com/furyaxyz/elysium/v2/x/elysium/types"
)
var _ types.EvmLogHandler = SendToIbcV2Handler{}
// SendToIbcEventV2 represent the signature of
// `event __ElysiumSendToIbc(address indexed sender, string indexed recipient, string indexed channel_id, uint256 amount, bytes extraData)`
var SendToIbcEventV2 abi.Event
func init() {
addressType, _ := abi.NewType("address", "", nil)
uint256Type, _ := abi.NewType("uint256", "", nil)
stringType, _ := abi.NewType("string", "", nil)
bytesType, _ := abi.NewType("bytes", "", nil)
SendToIbcEventV2 = abi.NewEvent(
SendToIbcEventName,
SendToIbcEventName,
false,
abi.Arguments{abi.Argument{
Name: "sender",
Type: addressType,
Indexed: true,
}, abi.Argument{
Name: "channel_id",
Type: uint256Type,
Indexed: true,
}, abi.Argument{
Name: "recipient",
Type: stringType,
Indexed: false,
}, abi.Argument{
Name: "amount",
Type: uint256Type,
Indexed: false,
}, abi.Argument{
Name: "extraData",
Type: bytesType,
Indexed: false,
}},
)
}
// SendToIbcV2Handler handles `__ElysiumSendToIbc` log
type SendToIbcV2Handler struct {
*SendToIbcHandler
}
func NewSendToIbcV2Handler(bankKeeper types.BankKeeper, elysiumKeeper elysiumkeeper.Keeper) *SendToIbcV2Handler {
return &SendToIbcV2Handler{
SendToIbcHandler: NewSendToIbcHandler(bankKeeper, elysiumKeeper),
}
}
func (h SendToIbcV2Handler) EventID() common.Hash {
return SendToIbcEventV2.ID
}
func (h SendToIbcV2Handler) Handle(
ctx sdk.Context,
contract common.Address,
topics []common.Hash,
data []byte,
_ func(contractAddress common.Address, logSig common.Hash, logData []byte),
) error {
if len(topics) != 3 {
// log and ignore
h.elysiumKeeper.Logger(ctx).Info("log signature matches but wrong number of indexed events")
for i, topic := range topics {
h.elysiumKeeper.Logger(ctx).Debug(fmt.Sprintf("topic index: %d value: %s", i, topic.TerminalString()))
}
return nil
}
unpacked, err := SendToIbcEventV2.Inputs.Unpack(data)
if err != nil {
// log and ignore
h.elysiumKeeper.Logger(ctx).Error("log signature matches but failed to decode", "error", err)
return nil
}
// needs to crope the extra bytes in the topic by using BytesToAddress
sender := common.BytesToAddress(topics[1].Bytes())
channelId := new(big.Int).SetBytes(topics[2].Bytes())
recipient := unpacked[0].(string)
amount := unpacked[1].(*big.Int)
// extraData := unpacked[2].([]byte)
return h.handle(ctx, contract, sender, recipient, amount, channelId)
}