Merge remote-tracking branch 'origin/master' into endpoints
This commit is contained in:
commit
969da82f6e
@ -42,6 +42,7 @@ import (
|
||||
"github.com/ethereum/go-ethereum/trie"
|
||||
|
||||
"github.com/vulcanize/ipfs-ethdb"
|
||||
"github.com/vulcanize/ipld-eth-indexer/pkg/ipfs"
|
||||
"github.com/vulcanize/ipld-eth-indexer/pkg/postgres"
|
||||
shared2 "github.com/vulcanize/ipld-eth-indexer/pkg/shared"
|
||||
|
||||
@ -298,7 +299,8 @@ func (b *Backend) BlockByNumber(ctx context.Context, blockNumber rpc.BlockNumber
|
||||
}()
|
||||
|
||||
// Fetch and decode the header IPLD
|
||||
headerIPLD, err := b.Fetcher.FetchHeader(tx, headerCID)
|
||||
var headerIPLD ipfs.BlockModel
|
||||
headerIPLD, err = b.Fetcher.FetchHeader(tx, headerCID)
|
||||
if err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
return nil, nil
|
||||
@ -306,44 +308,51 @@ func (b *Backend) BlockByNumber(ctx context.Context, blockNumber rpc.BlockNumber
|
||||
return nil, err
|
||||
}
|
||||
var header types.Header
|
||||
if err := rlp.DecodeBytes(headerIPLD.Data, &header); err != nil {
|
||||
err = rlp.DecodeBytes(headerIPLD.Data, &header)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// Fetch and decode the uncle IPLDs
|
||||
uncleIPLDs, err := b.Fetcher.FetchUncles(tx, uncleCIDs)
|
||||
var uncleIPLDs []ipfs.BlockModel
|
||||
uncleIPLDs, err = b.Fetcher.FetchUncles(tx, uncleCIDs)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var uncles []*types.Header
|
||||
for _, uncleIPLD := range uncleIPLDs {
|
||||
var uncle types.Header
|
||||
if err := rlp.DecodeBytes(uncleIPLD.Data, &uncle); err != nil {
|
||||
err = rlp.DecodeBytes(uncleIPLD.Data, &uncle)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
uncles = append(uncles, &uncle)
|
||||
}
|
||||
// Fetch and decode the transaction IPLDs
|
||||
txIPLDs, err := b.Fetcher.FetchTrxs(tx, txCIDs)
|
||||
var txIPLDs []ipfs.BlockModel
|
||||
txIPLDs, err = b.Fetcher.FetchTrxs(tx, txCIDs)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var transactions []*types.Transaction
|
||||
for _, txIPLD := range txIPLDs {
|
||||
var transaction types.Transaction
|
||||
if err := rlp.DecodeBytes(txIPLD.Data, &transaction); err != nil {
|
||||
err = rlp.DecodeBytes(txIPLD.Data, &transaction)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
transactions = append(transactions, &transaction)
|
||||
}
|
||||
// Fetch and decode the receipt IPLDs
|
||||
rctIPLDs, err := b.Fetcher.FetchRcts(tx, rctCIDs)
|
||||
var rctIPLDs []ipfs.BlockModel
|
||||
rctIPLDs, err = b.Fetcher.FetchRcts(tx, rctCIDs)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var receipts []*types.Receipt
|
||||
for _, rctIPLD := range rctIPLDs {
|
||||
var receipt types.Receipt
|
||||
if err := rlp.DecodeBytes(rctIPLD.Data, &receipt); err != nil {
|
||||
err = rlp.DecodeBytes(rctIPLD.Data, &receipt)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
receipts = append(receipts, &receipt)
|
||||
@ -381,7 +390,8 @@ func (b *Backend) BlockByHash(ctx context.Context, hash common.Hash) (*types.Blo
|
||||
}()
|
||||
|
||||
// Fetch and decode the header IPLD
|
||||
headerIPLD, err := b.Fetcher.FetchHeader(tx, headerCID)
|
||||
var headerIPLD ipfs.BlockModel
|
||||
headerIPLD, err = b.Fetcher.FetchHeader(tx, headerCID)
|
||||
if err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
return nil, nil
|
||||
@ -389,11 +399,13 @@ func (b *Backend) BlockByHash(ctx context.Context, hash common.Hash) (*types.Blo
|
||||
return nil, err
|
||||
}
|
||||
var header types.Header
|
||||
if err := rlp.DecodeBytes(headerIPLD.Data, &header); err != nil {
|
||||
err = rlp.DecodeBytes(headerIPLD.Data, &header)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// Fetch and decode the uncle IPLDs
|
||||
uncleIPLDs, err := b.Fetcher.FetchUncles(tx, uncleCIDs)
|
||||
var uncleIPLDs []ipfs.BlockModel
|
||||
uncleIPLDs, err = b.Fetcher.FetchUncles(tx, uncleCIDs)
|
||||
if err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
return nil, nil
|
||||
@ -403,13 +415,15 @@ func (b *Backend) BlockByHash(ctx context.Context, hash common.Hash) (*types.Blo
|
||||
var uncles []*types.Header
|
||||
for _, uncleIPLD := range uncleIPLDs {
|
||||
var uncle types.Header
|
||||
if err := rlp.DecodeBytes(uncleIPLD.Data, &uncle); err != nil {
|
||||
err = rlp.DecodeBytes(uncleIPLD.Data, &uncle)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
uncles = append(uncles, &uncle)
|
||||
}
|
||||
// Fetch and decode the transaction IPLDs
|
||||
txIPLDs, err := b.Fetcher.FetchTrxs(tx, txCIDs)
|
||||
var txIPLDs []ipfs.BlockModel
|
||||
txIPLDs, err = b.Fetcher.FetchTrxs(tx, txCIDs)
|
||||
if err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
return nil, nil
|
||||
@ -419,13 +433,15 @@ func (b *Backend) BlockByHash(ctx context.Context, hash common.Hash) (*types.Blo
|
||||
var transactions []*types.Transaction
|
||||
for _, txIPLD := range txIPLDs {
|
||||
var transaction types.Transaction
|
||||
if err := rlp.DecodeBytes(txIPLD.Data, &transaction); err != nil {
|
||||
err = rlp.DecodeBytes(txIPLD.Data, &transaction)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
transactions = append(transactions, &transaction)
|
||||
}
|
||||
// Fetch and decode the receipt IPLDs
|
||||
rctIPLDs, err := b.Fetcher.FetchRcts(tx, rctCIDs)
|
||||
var rctIPLDs []ipfs.BlockModel
|
||||
rctIPLDs, err = b.Fetcher.FetchRcts(tx, rctCIDs)
|
||||
if err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
return nil, nil
|
||||
@ -435,7 +451,8 @@ func (b *Backend) BlockByHash(ctx context.Context, hash common.Hash) (*types.Blo
|
||||
var receipts []*types.Receipt
|
||||
for _, rctIPLD := range rctIPLDs {
|
||||
var receipt types.Receipt
|
||||
if err := rlp.DecodeBytes(rctIPLD.Data, &receipt); err != nil {
|
||||
err = rlp.DecodeBytes(rctIPLD.Data, &receipt)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
receipts = append(receipts, &receipt)
|
||||
@ -686,10 +703,12 @@ func (b *Backend) GetCodeByHash(ctx context.Context, address common.Address, has
|
||||
err = tx.Commit()
|
||||
}
|
||||
}()
|
||||
if err := tx.Get(&codeHash, RetrieveCodeHashByLeafKeyAndBlockHash, leafKey.Hex(), hash.Hex()); err != nil {
|
||||
err = tx.Get(&codeHash, RetrieveCodeHashByLeafKeyAndBlockHash, leafKey.Hex(), hash.Hex())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
mhKey, err := shared2.MultihashKeyFromKeccak256(common.BytesToHash(codeHash))
|
||||
var mhKey string
|
||||
mhKey, err = shared2.MultihashKeyFromKeccak256(common.BytesToHash(codeHash))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -86,7 +86,8 @@ func (ecr *CIDRetriever) Retrieve(filter SubscriptionSettings, blockNumber int64
|
||||
}()
|
||||
|
||||
// Retrieve cached header CIDs at this block height
|
||||
headers, err := ecr.RetrieveHeaderCIDs(tx, blockNumber)
|
||||
var headers []eth.HeaderModel
|
||||
headers, err = ecr.RetrieveHeaderCIDs(tx, blockNumber)
|
||||
if err != nil {
|
||||
log.Error("header cid retrieval error")
|
||||
return nil, true, err
|
||||
@ -101,7 +102,8 @@ func (ecr *CIDRetriever) Retrieve(filter SubscriptionSettings, blockNumber int64
|
||||
empty = false
|
||||
if filter.HeaderFilter.Uncles {
|
||||
// Retrieve uncle cids for this header id
|
||||
uncleCIDs, err := ecr.RetrieveUncleCIDsByHeaderID(tx, header.ID)
|
||||
var uncleCIDs []eth.UncleModel
|
||||
uncleCIDs, err = ecr.RetrieveUncleCIDsByHeaderID(tx, header.ID)
|
||||
if err != nil {
|
||||
log.Error("uncle cid retrieval error")
|
||||
return nil, true, err
|
||||
@ -472,17 +474,20 @@ func (ecr *CIDRetriever) RetrieveBlockByHash(blockHash common.Hash) (eth.HeaderM
|
||||
}
|
||||
}()
|
||||
|
||||
headerCID, err := ecr.RetrieveHeaderCIDByHash(tx, blockHash)
|
||||
var headerCID eth.HeaderModel
|
||||
headerCID, err = ecr.RetrieveHeaderCIDByHash(tx, blockHash)
|
||||
if err != nil {
|
||||
log.Error("header cid retrieval error")
|
||||
return eth.HeaderModel{}, nil, nil, nil, err
|
||||
}
|
||||
uncleCIDs, err := ecr.RetrieveUncleCIDsByHeaderID(tx, headerCID.ID)
|
||||
var uncleCIDs []eth.UncleModel
|
||||
uncleCIDs, err = ecr.RetrieveUncleCIDsByHeaderID(tx, headerCID.ID)
|
||||
if err != nil {
|
||||
log.Error("uncle cid retrieval error")
|
||||
return eth.HeaderModel{}, nil, nil, nil, err
|
||||
}
|
||||
txCIDs, err := ecr.RetrieveTxCIDsByHeaderID(tx, headerCID.ID)
|
||||
var txCIDs []eth.TxModel
|
||||
txCIDs, err = ecr.RetrieveTxCIDsByHeaderID(tx, headerCID.ID)
|
||||
if err != nil {
|
||||
log.Error("tx cid retrieval error")
|
||||
return eth.HeaderModel{}, nil, nil, nil, err
|
||||
@ -491,7 +496,8 @@ func (ecr *CIDRetriever) RetrieveBlockByHash(blockHash common.Hash) (eth.HeaderM
|
||||
for i, txCID := range txCIDs {
|
||||
txIDs[i] = txCID.ID
|
||||
}
|
||||
rctCIDs, err := ecr.RetrieveReceiptCIDsByTxIDs(tx, txIDs)
|
||||
var rctCIDs []eth.ReceiptModel
|
||||
rctCIDs, err = ecr.RetrieveReceiptCIDsByTxIDs(tx, txIDs)
|
||||
if err != nil {
|
||||
log.Error("rct cid retrieval error")
|
||||
}
|
||||
@ -518,7 +524,8 @@ func (ecr *CIDRetriever) RetrieveBlockByNumber(blockNumber int64) (eth.HeaderMod
|
||||
}
|
||||
}()
|
||||
|
||||
headerCID, err := ecr.RetrieveHeaderCIDs(tx, blockNumber)
|
||||
var headerCID []eth.HeaderModel
|
||||
headerCID, err = ecr.RetrieveHeaderCIDs(tx, blockNumber)
|
||||
if err != nil {
|
||||
log.Error("header cid retrieval error")
|
||||
return eth.HeaderModel{}, nil, nil, nil, err
|
||||
@ -526,12 +533,14 @@ func (ecr *CIDRetriever) RetrieveBlockByNumber(blockNumber int64) (eth.HeaderMod
|
||||
if len(headerCID) < 1 {
|
||||
return eth.HeaderModel{}, nil, nil, nil, fmt.Errorf("header cid retrieval error, no header CIDs found at block %d", blockNumber)
|
||||
}
|
||||
uncleCIDs, err := ecr.RetrieveUncleCIDsByHeaderID(tx, headerCID[0].ID)
|
||||
var uncleCIDs []eth.UncleModel
|
||||
uncleCIDs, err = ecr.RetrieveUncleCIDsByHeaderID(tx, headerCID[0].ID)
|
||||
if err != nil {
|
||||
log.Error("uncle cid retrieval error")
|
||||
return eth.HeaderModel{}, nil, nil, nil, err
|
||||
}
|
||||
txCIDs, err := ecr.RetrieveTxCIDsByHeaderID(tx, headerCID[0].ID)
|
||||
var txCIDs []eth.TxModel
|
||||
txCIDs, err = ecr.RetrieveTxCIDsByHeaderID(tx, headerCID[0].ID)
|
||||
if err != nil {
|
||||
log.Error("tx cid retrieval error")
|
||||
return eth.HeaderModel{}, nil, nil, nil, err
|
||||
@ -540,7 +549,8 @@ func (ecr *CIDRetriever) RetrieveBlockByNumber(blockNumber int64) (eth.HeaderMod
|
||||
for i, txCID := range txCIDs {
|
||||
txIDs[i] = txCID.ID
|
||||
}
|
||||
rctCIDs, err := ecr.RetrieveReceiptCIDsByTxIDs(tx, txIDs)
|
||||
var rctCIDs []eth.ReceiptModel
|
||||
rctCIDs, err = ecr.RetrieveReceiptCIDsByTxIDs(tx, txIDs)
|
||||
if err != nil {
|
||||
log.Error("rct cid retrieval error")
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user