-
Notifications
You must be signed in to change notification settings - Fork 109
/
ethereumEvent.go
85 lines (73 loc) · 2.62 KB
/
ethereumEvent.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
package events
// -----------------------------------------------------
// ethereumEvent : Creates LockEvents from new events on the
// Ethereum blockchain.
// -----------------------------------------------------
import (
"math/big"
ebrelayerTypes "github.com/33cn/plugin/plugin/dapp/x2ethereum/ebrelayer/types"
"github.com/ethereum/go-ethereum/accounts/abi"
"github.com/ethereum/go-ethereum/common"
)
// LockEvent : struct which represents a LogLock event
type LockEvent struct {
From common.Address
To []byte
Token common.Address
Symbol string
Value *big.Int
Nonce *big.Int
}
// BurnEvent : struct which represents a BurnEvent event
type BurnEvent struct {
Token common.Address
Symbol string
Amount *big.Int
OwnerFrom common.Address
Chain33Receiver []byte
Nonce *big.Int
}
// NewProphecyClaimEvent : struct which represents a LogNewProphecyClaim event
type NewProphecyClaimEvent struct {
ProphecyID *big.Int
ClaimType uint8
Chain33Sender []byte
EthereumReceiver common.Address
ValidatorAddress common.Address
TokenAddress common.Address
Symbol string
Amount *big.Int
}
//LogNewBridgeToken ...
type LogNewBridgeToken struct {
Token common.Address
Symbol string
}
// UnpackLogLock : Handles new LogLock events
func UnpackLogLock(contractAbi abi.ABI, eventName string, eventData []byte) (lockEvent *LockEvent, err error) {
event := &LockEvent{}
// Parse the event's attributes as Ethereum network variables
err = contractAbi.UnpackIntoInterface(event, eventName, eventData)
if err != nil {
eventsLog.Error("UnpackLogLock", "Failed to unpack abi due to:", err.Error())
return nil, ebrelayerTypes.ErrUnpack
}
eventsLog.Info("UnpackLogLock", "value", event.Value.String(), "symbol", event.Symbol,
"token addr", event.Token.Hex(), "sender", event.From.Hex(),
"recipient", string(event.To), "nonce", event.Nonce.String())
return event, nil
}
//UnpackLogBurn ...
func UnpackLogBurn(contractAbi abi.ABI, eventName string, eventData []byte) (burnEvent *BurnEvent, err error) {
event := &BurnEvent{}
// Parse the event's attributes as Ethereum network variables
err = contractAbi.UnpackIntoInterface(event, eventName, eventData)
if err != nil {
eventsLog.Error("UnpackLogBurn", "Failed to unpack abi due to:", err.Error())
return nil, ebrelayerTypes.ErrUnpack
}
eventsLog.Info("UnpackLogBurn", "token addr", event.Token.Hex(), "symbol", event.Symbol,
"Amount", event.Amount.String(), "OwnerFrom", event.OwnerFrom.String(),
"Chain33Receiver", string(event.Chain33Receiver), "nonce", event.Nonce.String())
return event, nil
}