Commit 9f9cf618 authored by protolambda's avatar protolambda

op-node: reduce batch inner type encode/decode methods to just one way

Signed-off-by: default avatarprotolambda <proto@protolambda.com>
parent 72cd6482
...@@ -53,8 +53,6 @@ type InnerBatchData interface { ...@@ -53,8 +53,6 @@ type InnerBatchData interface {
GetBatchType() int GetBatchType() int
encode(w io.Writer) error encode(w io.Writer) error
decode(r *bytes.Reader) error decode(r *bytes.Reader) error
encodeBytes() ([]byte, error)
decodeBytes(data []byte) error
} }
// EncodeRLP implements rlp.Encoder // EncodeRLP implements rlp.Encoder
...@@ -121,7 +119,7 @@ func (b *BatchData) decodeTyped(data []byte) error { ...@@ -121,7 +119,7 @@ func (b *BatchData) decodeTyped(data []byte) error {
default: default:
return fmt.Errorf("unrecognized batch type: %d", data[0]) return fmt.Errorf("unrecognized batch type: %d", data[0])
} }
if err := inner.decodeBytes(data[1:]); err != nil { if err := inner.decode(bytes.NewReader(data[1:])); err != nil {
return err return err
} }
b.inner = inner b.inner = inner
......
...@@ -65,13 +65,3 @@ func (b *SingularBatch) encode(w io.Writer) error { ...@@ -65,13 +65,3 @@ func (b *SingularBatch) encode(w io.Writer) error {
func (b *SingularBatch) decode(r *bytes.Reader) error { func (b *SingularBatch) decode(r *bytes.Reader) error {
return rlp.Decode(r, b) return rlp.Decode(r, b)
} }
// encodeBytes returns the byte encoding of SingularBatch
func (b *SingularBatch) encodeBytes() ([]byte, error) {
return rlp.EncodeToBytes(b)
}
// decodeBytes parses data into b from data
func (b *SingularBatch) decodeBytes(data []byte) error {
return rlp.DecodeBytes(data, b)
}
...@@ -224,12 +224,6 @@ func (bp *spanBatchPayload) decodePayload(r *bytes.Reader) error { ...@@ -224,12 +224,6 @@ func (bp *spanBatchPayload) decodePayload(r *bytes.Reader) error {
return nil return nil
} }
// decodeBytes parses data into b from data
func (b *RawSpanBatch) decodeBytes(data []byte) error {
r := bytes.NewReader(data)
return b.decode(r)
}
// decode reads the byte encoding of SpanBatch from Reader stream // decode reads the byte encoding of SpanBatch from Reader stream
func (b *RawSpanBatch) decode(r *bytes.Reader) error { func (b *RawSpanBatch) decode(r *bytes.Reader) error {
if r.Len() > MaxSpanBatchSize { if r.Len() > MaxSpanBatchSize {
...@@ -383,17 +377,6 @@ func (b *RawSpanBatch) encode(w io.Writer) error { ...@@ -383,17 +377,6 @@ func (b *RawSpanBatch) encode(w io.Writer) error {
return nil return nil
} }
// encodeBytes returns the byte encoding of SpanBatch
func (b *RawSpanBatch) encodeBytes() ([]byte, error) {
buf := encodeBufferPool.Get().(*bytes.Buffer)
defer encodeBufferPool.Put(buf)
buf.Reset()
if err := b.encode(buf); err != nil {
return []byte{}, err
}
return buf.Bytes(), nil
}
// derive converts RawSpanBatch into SpanBatch, which has a list of spanBatchElement. // derive converts RawSpanBatch into SpanBatch, which has a list of spanBatchElement.
// We need chain config constants to derive values for making payload attributes. // We need chain config constants to derive values for making payload attributes.
func (b *RawSpanBatch) derive(blockTime, genesisTimestamp uint64, chainID *big.Int) (*SpanBatch, error) { func (b *RawSpanBatch) derive(blockTime, genesisTimestamp uint64, chainID *big.Int) (*SpanBatch, error) {
......
...@@ -294,11 +294,12 @@ func TestSpanBatchRoundTrip(t *testing.T) { ...@@ -294,11 +294,12 @@ func TestSpanBatchRoundTrip(t *testing.T) {
rawSpanBatch := RandomRawSpanBatch(rng, chainID) rawSpanBatch := RandomRawSpanBatch(rng, chainID)
result, err := rawSpanBatch.encodeBytes() var result bytes.Buffer
err := rawSpanBatch.encode(&result)
require.NoError(t, err) require.NoError(t, err)
var sb RawSpanBatch var sb RawSpanBatch
err = sb.decodeBytes(result) err = sb.decode(bytes.NewReader(result.Bytes()))
require.NoError(t, err) require.NoError(t, err)
sb.txs.recoverV(chainID) sb.txs.recoverV(chainID)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment