-
Notifications
You must be signed in to change notification settings - Fork 0
/
events.go
66 lines (55 loc) · 1.87 KB
/
events.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
// Copyright 2020 ChainSafe Systems
// SPDX-License-Identifier: LGPL-3.0-only
package platdot
import (
"github.com/rjman-self/platdot-utils/msg"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
)
func (l *listener) handleErc20DepositedEvent(destId msg.ChainId, nonce msg.Nonce) (msg.Message, error) {
l.log.Info("Handling fungible deposit event", "dest", destId, "nonce", nonce)
record, err := l.erc20HandlerContract.GetDepositRecord(&bind.CallOpts{From: l.conn.Keypair().CommonAddress()}, uint64(nonce), uint8(destId))
if err != nil {
l.log.Error("Error Unpacking ERC20 Deposit Record", "err", err)
return msg.Message{}, err
}
return msg.NewFungibleTransfer(
l.cfg.id,
destId,
nonce,
record.Amount,
record.ResourceID,
record.DestinationRecipientAddress,
), nil
}
func (l *listener) handleErc721DepositedEvent(destId msg.ChainId, nonce msg.Nonce) (msg.Message, error) {
l.log.Info("Handling nonfungible deposit event")
record, err := l.erc721HandlerContract.GetDepositRecord(&bind.CallOpts{From: l.conn.Keypair().CommonAddress()}, uint64(nonce), uint8(destId))
if err != nil {
l.log.Error("Error Unpacking ERC721 Deposit Record", "err", err)
return msg.Message{}, err
}
return msg.NewNonFungibleTransfer(
l.cfg.id,
destId,
nonce,
record.ResourceID,
record.TokenID,
record.DestinationRecipientAddress,
record.MetaData,
), nil
}
func (l *listener) handleGenericDepositedEvent(destId msg.ChainId, nonce msg.Nonce) (msg.Message, error) {
l.log.Info("Handling generic deposit event")
record, err := l.genericHandlerContract.GetDepositRecord(&bind.CallOpts{From: l.conn.Keypair().CommonAddress()}, uint64(nonce), uint8(destId))
if err != nil {
l.log.Error("Error Unpacking Generic Deposit Record", "err", err)
return msg.Message{}, nil
}
return msg.NewGenericTransfer(
l.cfg.id,
destId,
nonce,
record.ResourceID,
record.MetaData[:],
), nil
}