diff --git a/sequencing.go b/sequencing.go index 44c0567..6f2e69a 100644 --- a/sequencing.go +++ b/sequencing.go @@ -40,24 +40,15 @@ type BatchVerifier interface { VerifyBatch(ctx context.Context, req VerifyBatchRequest) (*VerifyBatchResponse, error) } -// RollupId is a unique identifier for a rollup chain -type RollupId = []byte - -// Tx is a rollup transaction -type Tx = []byte - -// Hash is a cryptographic hash of the Batch -type Hash = []byte - // Batch is a collection of transactions type Batch struct { - Transactions []Tx + Transactions [][]byte } // SubmitRollupTransactionRequest is a request to submit a transaction from rollup to sequencer type SubmitRollupTransactionRequest struct { - RollupId RollupId - Tx Tx + RollupId []byte + Tx []byte } // SubmitRollupTransactionResponse is a response to submitting a transaction from rollup to sequencer @@ -66,8 +57,8 @@ type SubmitRollupTransactionResponse struct { // GetNextBatchRequest is a request to get the next batch of transactions from sequencer to rollup type GetNextBatchRequest struct { - RollupId RollupId - LastBatchHash Hash + RollupId []byte + LastBatchHash []byte MaxBytes uint64 } @@ -79,8 +70,8 @@ type GetNextBatchResponse struct { // VerifyBatchRequest is a request to verify a batch of transactions received from the sequencer type VerifyBatchRequest struct { - RollupId RollupId - BatchHash Hash + RollupId []byte + BatchHash []byte } // VerifyBatchResponse is a response to verifying a batch of transactions received from the sequencer diff --git a/serialization.go b/serialization.go index 936bf65..063b257 100644 --- a/serialization.go +++ b/serialization.go @@ -8,30 +8,12 @@ import ( // ToProto serializes a batch to a protobuf message. func (batch *Batch) ToProto() *pbseq.Batch { - return &pbseq.Batch{Transactions: txsToByteSlices(batch.Transactions)} + return &pbseq.Batch{Transactions: batch.Transactions} } // FromProto deserializes a batch from a protobuf message. func (batch *Batch) FromProto(pb *pbseq.Batch) { - batch.Transactions = byteSlicesToTxs(pb.Transactions) -} - -func txsToByteSlices(txs []Tx) [][]byte { - if txs == nil { - return nil - } - bytes := make([][]byte, len(txs)) - copy(bytes, txs) - return bytes -} - -func byteSlicesToTxs(bytes [][]byte) []Tx { - if len(bytes) == 0 { - return nil - } - txs := make([]Tx, len(bytes)) - copy(txs, bytes) - return txs + batch.Transactions = pb.Transactions } // Marshal serializes a batch to a byte slice. diff --git a/test/dummy.go b/test/dummy.go index f064cb2..3632350 100644 --- a/test/dummy.go +++ b/test/dummy.go @@ -19,19 +19,19 @@ var ErrInvalidRollupId = errors.New("invalid rollup id") // TransactionQueue is a queue of transactions type TransactionQueue struct { - queue []sequencing.Tx + queue [][]byte mu sync.Mutex } // NewTransactionQueue creates a new TransactionQueue func NewTransactionQueue() *TransactionQueue { return &TransactionQueue{ - queue: make([]sequencing.Tx, 0), + queue: make([][]byte, 0), } } // AddTransaction adds a new transaction to the queue -func (tq *TransactionQueue) AddTransaction(tx sequencing.Tx) { +func (tq *TransactionQueue) AddTransaction(tx []byte) { tq.mu.Lock() defer tq.mu.Unlock() tq.queue = append(tq.queue, tx)