mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-22 04:36:42 +00:00
Update api.go
This commit is contained in:
parent
5d51208334
commit
a4bb43b5e2
1 changed files with 38 additions and 32 deletions
|
|
@ -97,6 +97,15 @@ type feeHistoryResult struct {
|
||||||
BlobGasUsedRatio []float64 `json:"blobGasUsedRatio,omitempty"`
|
BlobGasUsedRatio []float64 `json:"blobGasUsedRatio,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// convertBigIntSlice converts a slice of *big.Int to a slice of *hexutil.Big.
|
||||||
|
func convertBigIntSlice(values []*big.Int) []*hexutil.Big {
|
||||||
|
result := make([]*hexutil.Big, len(values))
|
||||||
|
for i, v := range values {
|
||||||
|
result[i] = (*hexutil.Big)(v)
|
||||||
|
}
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
// FeeHistory returns the fee market history.
|
// FeeHistory returns the fee market history.
|
||||||
func (api *EthereumAPI) FeeHistory(ctx context.Context, blockCount math.HexOrDecimal64, lastBlock rpc.BlockNumber, rewardPercentiles []float64) (*feeHistoryResult, error) {
|
func (api *EthereumAPI) FeeHistory(ctx context.Context, blockCount math.HexOrDecimal64, lastBlock rpc.BlockNumber, rewardPercentiles []float64) (*feeHistoryResult, error) {
|
||||||
oldest, reward, baseFee, gasUsed, blobBaseFee, blobGasUsed, err := api.b.FeeHistory(ctx, uint64(blockCount), lastBlock, rewardPercentiles)
|
oldest, reward, baseFee, gasUsed, blobBaseFee, blobGasUsed, err := api.b.FeeHistory(ctx, uint64(blockCount), lastBlock, rewardPercentiles)
|
||||||
|
|
@ -110,23 +119,14 @@ func (api *EthereumAPI) FeeHistory(ctx context.Context, blockCount math.HexOrDec
|
||||||
if reward != nil {
|
if reward != nil {
|
||||||
results.Reward = make([][]*hexutil.Big, len(reward))
|
results.Reward = make([][]*hexutil.Big, len(reward))
|
||||||
for i, w := range reward {
|
for i, w := range reward {
|
||||||
results.Reward[i] = make([]*hexutil.Big, len(w))
|
results.Reward[i] = convertBigIntSlice(w)
|
||||||
for j, v := range w {
|
|
||||||
results.Reward[i][j] = (*hexutil.Big)(v)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if baseFee != nil {
|
if baseFee != nil {
|
||||||
results.BaseFee = make([]*hexutil.Big, len(baseFee))
|
results.BaseFee = convertBigIntSlice(baseFee)
|
||||||
for i, v := range baseFee {
|
|
||||||
results.BaseFee[i] = (*hexutil.Big)(v)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if blobBaseFee != nil {
|
if blobBaseFee != nil {
|
||||||
results.BlobBaseFee = make([]*hexutil.Big, len(blobBaseFee))
|
results.BlobBaseFee = convertBigIntSlice(blobBaseFee)
|
||||||
for i, v := range blobBaseFee {
|
|
||||||
results.BlobBaseFee[i] = (*hexutil.Big)(v)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if blobGasUsed != nil {
|
if blobGasUsed != nil {
|
||||||
results.BlobGasUsedRatio = blobGasUsed
|
results.BlobGasUsedRatio = blobGasUsed
|
||||||
|
|
@ -1645,6 +1645,24 @@ func (api *TransactionAPI) currentBlobSidecarVersion() byte {
|
||||||
return types.BlobSidecarVersion0
|
return types.BlobSidecarVersion0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// convertLegacyBlobTxSidecar converts legacy blob transaction proofs to the
|
||||||
|
// current version if necessary.
|
||||||
|
// TODO: remove in go-ethereum v1.17.x
|
||||||
|
func (api *TransactionAPI) convertLegacyBlobTxSidecar(tx *types.Transaction) (*types.Transaction, error) {
|
||||||
|
sc := tx.BlobTxSidecar()
|
||||||
|
if sc == nil {
|
||||||
|
return tx, nil
|
||||||
|
}
|
||||||
|
exp := api.currentBlobSidecarVersion()
|
||||||
|
if sc.Version == types.BlobSidecarVersion0 && exp == types.BlobSidecarVersion1 {
|
||||||
|
if err := sc.ToV1(); err != nil {
|
||||||
|
return nil, fmt.Errorf("blob sidecar conversion failed: %v", err)
|
||||||
|
}
|
||||||
|
tx = tx.WithBlobTxSidecar(sc)
|
||||||
|
}
|
||||||
|
return tx, nil
|
||||||
|
}
|
||||||
|
|
||||||
// SendRawTransaction will add the signed transaction to the transaction pool.
|
// SendRawTransaction will add the signed transaction to the transaction pool.
|
||||||
// The sender is responsible for signing the transaction and using the correct nonce.
|
// The sender is responsible for signing the transaction and using the correct nonce.
|
||||||
func (api *TransactionAPI) SendRawTransaction(ctx context.Context, input hexutil.Bytes) (common.Hash, error) {
|
func (api *TransactionAPI) SendRawTransaction(ctx context.Context, input hexutil.Bytes) (common.Hash, error) {
|
||||||
|
|
@ -1653,16 +1671,10 @@ func (api *TransactionAPI) SendRawTransaction(ctx context.Context, input hexutil
|
||||||
return common.Hash{}, err
|
return common.Hash{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Convert legacy blob transaction proofs.
|
var err error
|
||||||
// TODO: remove in go-ethereum v1.17.x
|
tx, err = api.convertLegacyBlobTxSidecar(tx)
|
||||||
if sc := tx.BlobTxSidecar(); sc != nil {
|
if err != nil {
|
||||||
exp := api.currentBlobSidecarVersion()
|
return common.Hash{}, err
|
||||||
if sc.Version == types.BlobSidecarVersion0 && exp == types.BlobSidecarVersion1 {
|
|
||||||
if err := sc.ToV1(); err != nil {
|
|
||||||
return common.Hash{}, fmt.Errorf("blob sidecar conversion failed: %v", err)
|
|
||||||
}
|
|
||||||
tx = tx.WithBlobTxSidecar(sc)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return SubmitTransaction(ctx, api.b, tx)
|
return SubmitTransaction(ctx, api.b, tx)
|
||||||
|
|
@ -1676,16 +1688,10 @@ func (api *TransactionAPI) SendRawTransactionSync(ctx context.Context, input hex
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Convert legacy blob transaction proofs.
|
var err error
|
||||||
// TODO: remove in go-ethereum v1.17.x
|
tx, err = api.convertLegacyBlobTxSidecar(tx)
|
||||||
if sc := tx.BlobTxSidecar(); sc != nil {
|
if err != nil {
|
||||||
exp := api.currentBlobSidecarVersion()
|
return nil, err
|
||||||
if sc.Version == types.BlobSidecarVersion0 && exp == types.BlobSidecarVersion1 {
|
|
||||||
if err := sc.ToV1(); err != nil {
|
|
||||||
return nil, fmt.Errorf("blob sidecar conversion failed: %v", err)
|
|
||||||
}
|
|
||||||
tx = tx.WithBlobTxSidecar(sc)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ch := make(chan core.ChainEvent, 128)
|
ch := make(chan core.ChainEvent, 128)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue