This repository has been archived by the owner on Oct 6, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
meta.go
67 lines (54 loc) · 1.45 KB
/
meta.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
package models
import (
"encoding/binary"
"math/big"
"github.com/Worldcoin/hubble-commander/models/enums/batchtype"
"github.com/ethereum/go-ethereum/common"
)
const mmMetaLength = 72 // 4 + 32 + 32 + 4
type BatchMeta struct {
BatchType batchtype.BatchType
Size uint8
Committer common.Address
FinaliseOn uint32
}
type MassMigrationMeta struct {
SpokeID uint32
TokenID Uint256
Amount Uint256
FeeReceiver uint32
}
func NewMassMigrationMetaFromBigInts(meta [4]*big.Int) *MassMigrationMeta {
return &MassMigrationMeta{
SpokeID: uint32(meta[0].Uint64()),
TokenID: MakeUint256FromBig(*meta[1]),
Amount: MakeUint256FromBig(*meta[2]),
FeeReceiver: uint32(meta[3].Uint64()),
}
}
func (m *MassMigrationMeta) BigInts() [4]*big.Int {
return [4]*big.Int{
big.NewInt(int64(m.SpokeID)),
m.TokenID.ToBig(),
m.Amount.ToBig(),
big.NewInt(int64(m.FeeReceiver)),
}
}
func (m *MassMigrationMeta) Bytes() []byte {
b := make([]byte, mmMetaLength)
binary.BigEndian.PutUint32(b[0:4], m.SpokeID)
copy(b[4:36], m.TokenID.Bytes())
copy(b[36:68], m.Amount.Bytes())
binary.BigEndian.PutUint32(b[68:72], m.FeeReceiver)
return b
}
func (m *MassMigrationMeta) SetBytes(data []byte) error {
if len(data) != mmMetaLength {
return ErrInvalidLength
}
m.SpokeID = binary.BigEndian.Uint32(data[0:4])
m.TokenID.SetBytes(data[4:36])
m.Amount.SetBytes(data[36:68])
m.FeeReceiver = binary.BigEndian.Uint32(data[68:72])
return nil
}