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
/
batch.go
109 lines (92 loc) · 2.69 KB
/
batch.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
package eth
import (
"github.com/Worldcoin/hubble-commander/encoder"
"github.com/Worldcoin/hubble-commander/models"
"github.com/Worldcoin/hubble-commander/models/enums/batchtype"
"github.com/ethereum/go-ethereum/common"
)
type DecodedBatch interface {
GetID() models.Uint256
GetBase() *DecodedBatchBase
ToDecodedTxBatch() *DecodedTxBatch
ToDecodedDepositBatch() *DecodedDepositBatch
ToBatch(prevStateRoot common.Hash) *models.Batch
GetCommitmentsLength() int
}
type DecodedBatchBase struct {
ID models.Uint256
Type batchtype.BatchType
TransactionHash common.Hash
Hash common.Hash
FinalisationBlock uint32
AccountTreeRoot common.Hash
MinedTime models.Timestamp
Committer common.Address
}
func NewDecodedBatchBase(
batch *ContractBatch,
transactionHash, accountRoot common.Hash,
minedTime *models.Timestamp,
) *DecodedBatchBase {
return &DecodedBatchBase{
ID: batch.ID,
Type: batch.BatchType,
TransactionHash: transactionHash,
Hash: batch.Hash,
FinalisationBlock: batch.FinaliseOn,
AccountTreeRoot: accountRoot,
MinedTime: *minedTime,
Committer: batch.Committer,
}
}
func (b *DecodedBatchBase) ToBatch(prevStateRoot common.Hash) *models.Batch {
return &models.Batch{
ID: b.ID,
Type: b.Type,
TransactionHash: b.TransactionHash,
Hash: &b.Hash,
FinalisationBlock: &b.FinalisationBlock,
AccountTreeRoot: &b.AccountTreeRoot,
MinedTime: &b.MinedTime,
PrevStateRoot: &prevStateRoot,
}
}
type DecodedTxBatch struct {
DecodedBatchBase
Commitments []encoder.Commitment
}
func (b *DecodedTxBatch) GetID() models.Uint256 {
return b.DecodedBatchBase.ID
}
func (b *DecodedTxBatch) GetBase() *DecodedBatchBase {
return &b.DecodedBatchBase
}
func (b *DecodedTxBatch) ToDecodedTxBatch() *DecodedTxBatch {
return b
}
func (b *DecodedTxBatch) ToDecodedDepositBatch() *DecodedDepositBatch {
panic("ToDecodedDepositBatch cannot be invoked on DecodedTxBatch")
}
func (b *DecodedTxBatch) GetCommitmentsLength() int {
return len(b.Commitments)
}
type DecodedDepositBatch struct {
DecodedBatchBase
SubtreeID models.Uint256
PathAtDepth uint32
}
func (b *DecodedDepositBatch) GetID() models.Uint256 {
return b.DecodedBatchBase.ID
}
func (b *DecodedDepositBatch) GetBase() *DecodedBatchBase {
return &b.DecodedBatchBase
}
func (b *DecodedDepositBatch) ToDecodedTxBatch() *DecodedTxBatch {
panic("ToDecodedTxBatch cannot be invoked on DecodedDepositBatch")
}
func (b *DecodedDepositBatch) ToDecodedDepositBatch() *DecodedDepositBatch {
return b
}
func (b *DecodedDepositBatch) GetCommitmentsLength() int {
return 1
}