/
parser.go
92 lines (78 loc) · 3.17 KB
/
parser.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
package ethtxs
// --------------------------------------------------------
// Parser
//
// Parses structs containing event information into
// unsigned transactions for validators to sign, then
// relays the data packets as transactions on the
// chain33 Bridge.
// --------------------------------------------------------
import (
"github.com/33cn/chain33/common/address"
"github.com/33cn/plugin/plugin/dapp/cross2eth/ebrelayer/relayer/events"
ebrelayerTypes "github.com/33cn/plugin/plugin/dapp/cross2eth/ebrelayer/types"
)
// LogLockToEthBridgeClaim : parses and packages a LockEvent struct with a validator address in an EthBridgeClaim msg
func LogLockToEthBridgeClaim(event *events.LockEvent, ethereumChainID int64, bridgeBrankAddr, ethTxHash string, decimal int64) (*ebrelayerTypes.EthBridgeClaim, error) {
recipient := event.To
if 0 == len(recipient) {
return nil, ebrelayerTypes.ErrEmptyAddress
}
chain33Receiver := new(address.Address)
chain33Receiver.SetBytes(recipient)
witnessClaim := &ebrelayerTypes.EthBridgeClaim{}
witnessClaim.EthereumChainID = ethereumChainID
witnessClaim.BridgeBrankAddr = bridgeBrankAddr
witnessClaim.Nonce = event.Nonce.Int64()
witnessClaim.TokenAddr = event.Token.String()
witnessClaim.Symbol = event.Symbol
witnessClaim.EthereumSender = event.From.String()
witnessClaim.Chain33Receiver = chain33Receiver.String()
witnessClaim.Amount = event.Value.String()
witnessClaim.ClaimType = int32(events.ClaimTypeLock)
witnessClaim.ChainName = ""
witnessClaim.Decimal = decimal
witnessClaim.EthTxHash = ethTxHash
return witnessClaim, nil
}
//LogBurnToEthBridgeClaim ...
func LogBurnToEthBridgeClaim(event *events.BurnEvent, ethereumChainID int64, bridgeBrankAddr, ethTxHash string, decimal int64) (*ebrelayerTypes.EthBridgeClaim, error) {
recipient := event.Chain33Receiver
if 0 == len(recipient) {
return nil, ebrelayerTypes.ErrEmptyAddress
}
chain33Receiver := new(address.Address)
chain33Receiver.SetBytes(recipient)
witnessClaim := &ebrelayerTypes.EthBridgeClaim{}
witnessClaim.EthereumChainID = ethereumChainID
witnessClaim.BridgeBrankAddr = bridgeBrankAddr
witnessClaim.Nonce = event.Nonce.Int64()
witnessClaim.TokenAddr = event.Token.String()
witnessClaim.Symbol = event.Symbol
witnessClaim.EthereumSender = event.OwnerFrom.String()
witnessClaim.Chain33Receiver = chain33Receiver.String()
witnessClaim.Amount = event.Amount.String()
witnessClaim.ClaimType = int32(events.ClaimTypeBurn)
witnessClaim.ChainName = ""
witnessClaim.Decimal = decimal
witnessClaim.EthTxHash = ethTxHash
return witnessClaim, nil
}
// Chain33MsgToProphecyClaim : parses event data from a Chain33Msg, packaging it as a ProphecyClaim
func Chain33MsgToProphecyClaim(msg events.Chain33Msg) ProphecyClaim {
claimType := msg.ClaimType
chain33Sender := msg.Chain33Sender
ethereumReceiver := msg.EthereumReceiver
symbol := msg.Symbol
amount := msg.Amount
prophecyClaim := ProphecyClaim{
ClaimType: claimType,
Chain33Sender: chain33Sender.Bytes(),
EthereumReceiver: ethereumReceiver,
//TokenContractAddress: tokenContractAddress,
Symbol: symbol,
Amount: amount,
chain33TxHash: msg.TxHash,
}
return prophecyClaim
}