mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
core/types: simplify blob tx sidecar encoding
This commit is contained in:
parent
51cdfd184e
commit
34afde7bf2
1 changed files with 9 additions and 17 deletions
|
|
@ -23,6 +23,7 @@ import (
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/common"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
"github.com/ethereum/go-ethereum/common/hexutil"
|
"github.com/ethereum/go-ethereum/common/hexutil"
|
||||||
|
"github.com/ethereum/go-ethereum/crypto/kzg4844"
|
||||||
"github.com/holiman/uint256"
|
"github.com/holiman/uint256"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -47,14 +48,13 @@ type txJSON struct {
|
||||||
S *hexutil.Big `json:"s"`
|
S *hexutil.Big `json:"s"`
|
||||||
YParity *hexutil.Uint64 `json:"yParity,omitempty"`
|
YParity *hexutil.Uint64 `json:"yParity,omitempty"`
|
||||||
|
|
||||||
|
// Blob transaction sidecar encoding:
|
||||||
|
Blobs []kzg4844.Blob `json:"blobs,omitempty"`
|
||||||
|
Commitments []kzg4844.Commitment `json:"commitments,omitempty"`
|
||||||
|
Proofs []kzg4844.Proof `json:"proofs,omitempty"`
|
||||||
|
|
||||||
// Only used for encoding:
|
// Only used for encoding:
|
||||||
Hash common.Hash `json:"hash"`
|
Hash common.Hash `json:"hash"`
|
||||||
|
|
||||||
// Only used for eth_fillTransaction ing a
|
|
||||||
// blob transaction.
|
|
||||||
Blobs []hexutil.Bytes `json:"blobs,omitempty"`
|
|
||||||
Commitments []hexutil.Bytes `json:"commitments,omitempty"`
|
|
||||||
Proofs []hexutil.Bytes `json:"proofs,omitempty"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// yParityValue returns the YParity value from JSON. For backwards-compatibility reasons,
|
// yParityValue returns the YParity value from JSON. For backwards-compatibility reasons,
|
||||||
|
|
@ -149,17 +149,9 @@ func (tx *Transaction) MarshalJSON() ([]byte, error) {
|
||||||
yparity := itx.V.Uint64()
|
yparity := itx.V.Uint64()
|
||||||
enc.YParity = (*hexutil.Uint64)(&yparity)
|
enc.YParity = (*hexutil.Uint64)(&yparity)
|
||||||
if sidecar := itx.Sidecar; sidecar != nil {
|
if sidecar := itx.Sidecar; sidecar != nil {
|
||||||
if len(sidecar.Blobs) != len(sidecar.Commitments) && len(sidecar.Blobs) != len(sidecar.Proofs) {
|
enc.Blobs = itx.Sidecar.Blobs
|
||||||
return nil, errors.New("blob fields count mismatch")
|
enc.Commitments = itx.Sidecar.Commitments
|
||||||
}
|
enc.Proofs = itx.Sidecar.Proofs
|
||||||
enc.Blobs = make([]hexutil.Bytes, len(sidecar.Blobs))
|
|
||||||
enc.Commitments = make([]hexutil.Bytes, len(sidecar.Commitments))
|
|
||||||
enc.Proofs = make([]hexutil.Bytes, len(sidecar.Proofs))
|
|
||||||
for i, b := range sidecar.Blobs {
|
|
||||||
enc.Blobs[i] = b[:]
|
|
||||||
enc.Commitments[i] = sidecar.Commitments[i][:]
|
|
||||||
enc.Proofs[i] = sidecar.Proofs[i][:]
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return json.Marshal(&enc)
|
return json.Marshal(&enc)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue