mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-14 16:03:45 +00:00
Initial Setup
This commit is contained in:
parent
65875c629d
commit
85cdd9d281
1 changed files with 12 additions and 8 deletions
|
|
@ -1332,7 +1332,7 @@ func RPCMarshalHeader(head *types.Header) map[string]interface{} {
|
||||||
// RPCMarshalBlock converts the given block to the RPC output which depends on fullTx. If inclTx is true transactions are
|
// RPCMarshalBlock converts the given block to the RPC output which depends on fullTx. If inclTx is true transactions are
|
||||||
// returned. When fullTx is true the returned block contains full transaction details, otherwise it will only contain
|
// returned. When fullTx is true the returned block contains full transaction details, otherwise it will only contain
|
||||||
// transaction hashes.
|
// transaction hashes.
|
||||||
func RPCMarshalBlock(block *types.Block, inclTx bool, fullTx bool, config *params.ChainConfig) (map[string]interface{}, error) {
|
func RPCMarshalBlock(block *types.Block, inclTx bool, fullTx bool, config *params.ChainConfig, backend *Backend) (map[string]interface{}, error) {
|
||||||
fields := RPCMarshalHeader(block.Header())
|
fields := RPCMarshalHeader(block.Header())
|
||||||
fields["size"] = hexutil.Uint64(block.Size())
|
fields["size"] = hexutil.Uint64(block.Size())
|
||||||
|
|
||||||
|
|
@ -1342,7 +1342,7 @@ func RPCMarshalBlock(block *types.Block, inclTx bool, fullTx bool, config *param
|
||||||
}
|
}
|
||||||
if fullTx {
|
if fullTx {
|
||||||
formatTx = func(tx *types.Transaction) (interface{}, error) {
|
formatTx = func(tx *types.Transaction) (interface{}, error) {
|
||||||
return newRPCTransactionFromBlockHash(block, tx.Hash(), config), nil
|
return newRPCTransactionFromBlockHash(block, tx.Hash(), config, backend), nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
txs := block.Transactions()
|
txs := block.Transactions()
|
||||||
|
|
@ -1376,7 +1376,7 @@ func (s *PublicBlockChainAPI) rpcMarshalHeader(ctx context.Context, header *type
|
||||||
// rpcMarshalBlock uses the generalized output filler, then adds the total difficulty field, which requires
|
// rpcMarshalBlock uses the generalized output filler, then adds the total difficulty field, which requires
|
||||||
// a `PublicBlockchainAPI`.
|
// a `PublicBlockchainAPI`.
|
||||||
func (s *PublicBlockChainAPI) rpcMarshalBlock(ctx context.Context, b *types.Block, inclTx bool, fullTx bool) (map[string]interface{}, error) {
|
func (s *PublicBlockChainAPI) rpcMarshalBlock(ctx context.Context, b *types.Block, inclTx bool, fullTx bool) (map[string]interface{}, error) {
|
||||||
fields, err := RPCMarshalBlock(b, inclTx, fullTx, s.b.ChainConfig())
|
fields, err := RPCMarshalBlock(b, inclTx, fullTx, s.b.ChainConfig(), &s.b)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
@ -1469,8 +1469,12 @@ func newRPCPendingTransaction(tx *types.Transaction, current *types.Header, conf
|
||||||
}
|
}
|
||||||
|
|
||||||
// newRPCTransactionFromBlockIndex returns a transaction that will serialize to the RPC representation.
|
// newRPCTransactionFromBlockIndex returns a transaction that will serialize to the RPC representation.
|
||||||
func newRPCTransactionFromBlockIndex(b *types.Block, index uint64, config *params.ChainConfig) *RPCTransaction {
|
func newRPCTransactionFromBlockIndex(b *types.Block, index uint64, config *params.ChainConfig, backend Backend) *RPCTransaction {
|
||||||
txs := b.Transactions()
|
txs := b.Transactions()
|
||||||
|
tx, _, _, _ := rawdb.ReadBorTransaction(backend.ChainDb(), b.Hash())
|
||||||
|
if tx != nil {
|
||||||
|
txs = append(txs, tx)
|
||||||
|
}
|
||||||
if index >= uint64(len(txs)) {
|
if index >= uint64(len(txs)) {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
@ -1488,10 +1492,10 @@ func newRPCRawTransactionFromBlockIndex(b *types.Block, index uint64) hexutil.By
|
||||||
}
|
}
|
||||||
|
|
||||||
// newRPCTransactionFromBlockHash returns a transaction that will serialize to the RPC representation.
|
// newRPCTransactionFromBlockHash returns a transaction that will serialize to the RPC representation.
|
||||||
func newRPCTransactionFromBlockHash(b *types.Block, hash common.Hash, config *params.ChainConfig) *RPCTransaction {
|
func newRPCTransactionFromBlockHash(b *types.Block, hash common.Hash, config *params.ChainConfig, backend *Backend) *RPCTransaction {
|
||||||
for idx, tx := range b.Transactions() {
|
for idx, tx := range b.Transactions() {
|
||||||
if tx.Hash() == hash {
|
if tx.Hash() == hash {
|
||||||
return newRPCTransactionFromBlockIndex(b, uint64(idx), config)
|
return newRPCTransactionFromBlockIndex(b, uint64(idx), config, *backend)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
|
@ -1633,7 +1637,7 @@ func (s *PublicTransactionPoolAPI) GetBlockTransactionCountByHash(ctx context.Co
|
||||||
// GetTransactionByBlockNumberAndIndex returns the transaction for the given block number and index.
|
// GetTransactionByBlockNumberAndIndex returns the transaction for the given block number and index.
|
||||||
func (s *PublicTransactionPoolAPI) GetTransactionByBlockNumberAndIndex(ctx context.Context, blockNr rpc.BlockNumber, index hexutil.Uint) *RPCTransaction {
|
func (s *PublicTransactionPoolAPI) GetTransactionByBlockNumberAndIndex(ctx context.Context, blockNr rpc.BlockNumber, index hexutil.Uint) *RPCTransaction {
|
||||||
if block, _ := s.b.BlockByNumber(ctx, blockNr); block != nil {
|
if block, _ := s.b.BlockByNumber(ctx, blockNr); block != nil {
|
||||||
return newRPCTransactionFromBlockIndex(block, uint64(index), s.b.ChainConfig())
|
return newRPCTransactionFromBlockIndex(block, uint64(index), s.b.ChainConfig(), s.b)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
@ -1641,7 +1645,7 @@ func (s *PublicTransactionPoolAPI) GetTransactionByBlockNumberAndIndex(ctx conte
|
||||||
// GetTransactionByBlockHashAndIndex returns the transaction for the given block hash and index.
|
// GetTransactionByBlockHashAndIndex returns the transaction for the given block hash and index.
|
||||||
func (s *PublicTransactionPoolAPI) GetTransactionByBlockHashAndIndex(ctx context.Context, blockHash common.Hash, index hexutil.Uint) *RPCTransaction {
|
func (s *PublicTransactionPoolAPI) GetTransactionByBlockHashAndIndex(ctx context.Context, blockHash common.Hash, index hexutil.Uint) *RPCTransaction {
|
||||||
if block, _ := s.b.BlockByHash(ctx, blockHash); block != nil {
|
if block, _ := s.b.BlockByHash(ctx, blockHash); block != nil {
|
||||||
return newRPCTransactionFromBlockIndex(block, uint64(index), s.b.ChainConfig())
|
return newRPCTransactionFromBlockIndex(block, uint64(index), s.b.ChainConfig(), s.b)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue