mirror of
https://gitlab.com/pulsechaincom/erigon-pulse.git
synced 2024-12-26 05:27:19 +00:00
11f4978ed4
Following our previous discussion on erigon's discord, this PR requests to upstream all Otterscan modifications to erigon's repo. That decision comes after getting feedback from lots of users at events this year, and although it may introduce some friction for development, it will make integrators life easier by having all our modifications available out of box, e.g., dappnode users will get our RPCs since their official packages are built from erigon repo. I'm submitting the source-code as-is, please let me know if you think there is a better code organization. The current set of modifications comprises only new RPCs. There are some proposals for extra-stages that would add new tables, but they are still WIP and will be submitted separately in future after more testing.
98 lines
2.4 KiB
Go
98 lines
2.4 KiB
Go
package commands
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"github.com/ledgerwatch/erigon/common"
|
|
"github.com/ledgerwatch/erigon/common/hexutil"
|
|
"github.com/ledgerwatch/erigon/core/rawdb"
|
|
"github.com/ledgerwatch/erigon/rpc"
|
|
)
|
|
|
|
func (api *OtterscanAPIImpl) GetBlockDetails(ctx context.Context, number rpc.BlockNumber) (map[string]interface{}, error) {
|
|
tx, err := api.db.BeginRo(ctx)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer tx.Rollback()
|
|
|
|
b, senders, err := api.getBlockWithSenders(ctx, number, tx)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if b == nil {
|
|
return nil, nil
|
|
}
|
|
|
|
chainConfig, err := api.chainConfig(tx)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
getBlockRes, err := api.delegateGetBlockByNumber(tx, b, number, false)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
getIssuanceRes, err := api.delegateIssuance(tx, b, chainConfig)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
feesRes, err := api.delegateBlockFees(ctx, tx, b, senders, chainConfig)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
response := map[string]interface{}{}
|
|
response["block"] = getBlockRes
|
|
response["issuance"] = getIssuanceRes
|
|
response["totalFees"] = hexutil.Uint64(feesRes)
|
|
return response, nil
|
|
}
|
|
|
|
// TODO: remove duplication with GetBlockDetails
|
|
func (api *OtterscanAPIImpl) GetBlockDetailsByHash(ctx context.Context, hash common.Hash) (map[string]interface{}, error) {
|
|
tx, err := api.db.BeginRo(ctx)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer tx.Rollback()
|
|
|
|
// b, senders, err := rawdb.ReadBlockByHashWithSenders(tx, hash)
|
|
blockNumber := rawdb.ReadHeaderNumber(tx, hash)
|
|
if blockNumber == nil {
|
|
return nil, fmt.Errorf("couldn't find block number for hash %v", hash.Bytes())
|
|
}
|
|
b, senders, err := api._blockReader.BlockWithSenders(ctx, tx, hash, *blockNumber)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if b == nil {
|
|
return nil, nil
|
|
}
|
|
|
|
chainConfig, err := api.chainConfig(tx)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
getBlockRes, err := api.delegateGetBlockByNumber(tx, b, rpc.BlockNumber(b.Number().Int64()), false)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
getIssuanceRes, err := api.delegateIssuance(tx, b, chainConfig)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
feesRes, err := api.delegateBlockFees(ctx, tx, b, senders, chainConfig)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
response := map[string]interface{}{}
|
|
response["block"] = getBlockRes
|
|
response["issuance"] = getIssuanceRes
|
|
response["totalFees"] = hexutil.Uint64(feesRes)
|
|
return response, nil
|
|
}
|