-
Notifications
You must be signed in to change notification settings - Fork 39
/
Copy pathbatches.go
52 lines (45 loc) · 1.55 KB
/
batches.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
package common
import (
"fmt"
"math/big"
"sync/atomic"
"github.com/ethereum/go-ethereum/rlp"
)
// ExtBatch is an encrypted form of batch used when passing the batch around outside of an enclave.
// todo (#718) - expand this structure to contain the required fields.
type ExtBatch struct {
Header *BatchHeader
// todo - remove and replace with enclave API
TxHashes []TxHash // The hashes of the transactions included in the batch.
EncryptedTxBlob EncryptedTransactions
hash atomic.Value
}
// Hash returns the keccak256 hash of the batch's header.
// The hash is computed on the first call and cached thereafter.
func (b *ExtBatch) Hash() L2BatchHash {
if hash := b.hash.Load(); hash != nil {
return hash.(L2BatchHash)
}
v := b.Header.Hash()
b.hash.Store(v)
return v
}
func (b *ExtBatch) Encoded() ([]byte, error) {
return rlp.EncodeToBytes(b)
}
func (b *ExtBatch) SeqNo() *big.Int { return new(big.Int).Set(b.Header.SequencerOrderNo) }
func DecodeExtBatch(encoded []byte) (*ExtBatch, error) {
var batch ExtBatch
if err := rlp.DecodeBytes(encoded, &batch); err != nil {
return nil, err
}
return &batch, nil
}
func (b *ExtBatch) SDump() string {
return fmt.Sprintf("Tx_Len=%d, encrypted_blob_len=%d", len(b.TxHashes), len(b.EncryptedTxBlob))
}
// BatchRequest is used when requesting a range of batches from a peer.
type BatchRequest struct {
Requester string // The address of the requester, used to direct the response
FromSeqNo *big.Int // The requester's view of the current head seq no, or nil if they haven't stored any batches.
}