This repository has been archived by the owner on Mar 31, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
chain_events.go
92 lines (79 loc) · 2.26 KB
/
chain_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
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 vega
import (
"errors"
"fmt"
)
var (
ErrUnsupportedChainEvent = errors.New("unsupported chain event")
)
func (c *BuiltinAssetEvent) PrepareToSign() ([]byte, error) {
switch act := c.Action.(type) {
case *BuiltinAssetEvent_Deposit:
return act.Deposit.PrepareToSign()
case *BuiltinAssetEvent_Withdrawal:
return act.Withdrawal.PrepareToSign()
default:
return nil, ErrUnsupportedChainEvent
}
}
func (c *BuiltinAssetDeposit) PrepareToSign() ([]byte, error) {
out := []byte{}
out = append(out, []byte(c.VegaAssetId)...)
out = append(out, []byte(c.PartyId)...)
out = append(out, []byte(fmt.Sprintf("%v", c.Amount))...)
return out, nil
}
func (c *BuiltinAssetWithdrawal) PrepareToSign() ([]byte, error) {
out := []byte{}
out = append(out, []byte(c.VegaAssetId)...)
out = append(out, []byte(c.PartyId)...)
out = append(out, []byte(fmt.Sprintf("%v", c.Amount))...)
return out, nil
}
func (c *ERC20Event) PrepareToSign() ([]byte, error) {
out := []byte{}
out = append(out, []byte(fmt.Sprintf("%v", c.Block))...)
out = append(out, []byte(fmt.Sprintf("%v", c.Index))...)
var (
next []byte
err error
)
switch act := c.Action.(type) {
case *ERC20Event_AssetList:
next, err = act.AssetList.PrepareToSign()
case *ERC20Event_AssetDelist:
next, err = act.AssetDelist.PrepareToSign()
case *ERC20Event_Deposit:
next, err = act.Deposit.PrepareToSign()
case *ERC20Event_Withdrawal:
next, err = act.Withdrawal.PrepareToSign()
default:
err = ErrUnsupportedChainEvent
}
if err != nil {
return nil, err
}
out = append(out, next...)
return out, nil
}
func (c *ERC20AssetList) PrepareToSign() ([]byte, error) {
return []byte(c.VegaAssetId), nil
}
func (c *ERC20AssetDelist) PrepareToSign() ([]byte, error) {
return []byte(c.VegaAssetId), nil
}
func (c *ERC20Deposit) PrepareToSign() ([]byte, error) {
out := []byte{}
out = append(out, []byte(c.VegaAssetId)...)
out = append(out, []byte(c.SourceEthereumAddress)...)
out = append(out, []byte(c.TargetPartyId)...)
out = append(out, []byte(c.Amount)...)
return out, nil
}
func (c *ERC20Withdrawal) PrepareToSign() ([]byte, error) {
out := []byte{}
out = append(out, []byte(c.VegaAssetId)...)
out = append(out, []byte(c.TargetEthereumAddress)...)
out = append(out, []byte(c.ReferenceNonce)...)
return out, nil
}