backfiller refactoring; explicity errs; golint
This commit is contained in:
+18
-18
@@ -45,14 +45,14 @@ func NewPayloadConverter(chainConfig *params.ChainConfig) *Converter {
|
||||
func (pc *Converter) Convert(payload statediff.Payload) (*IPLDPayload, error) {
|
||||
// Unpack block rlp to access fields
|
||||
block := new(types.Block)
|
||||
err := rlp.DecodeBytes(payload.BlockRlp, block)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
decodeErr := rlp.DecodeBytes(payload.BlockRlp, block)
|
||||
if decodeErr != nil {
|
||||
return nil, decodeErr
|
||||
}
|
||||
header := block.Header()
|
||||
headerRlp, err := rlp.EncodeToBytes(header)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
headerRlp, encodeErr := rlp.EncodeToBytes(header)
|
||||
if encodeErr != nil {
|
||||
return nil, encodeErr
|
||||
}
|
||||
trxLen := len(block.Transactions())
|
||||
convertedPayload := &IPLDPayload{
|
||||
@@ -70,9 +70,9 @@ func (pc *Converter) Convert(payload statediff.Payload) (*IPLDPayload, error) {
|
||||
transactions := block.Transactions()
|
||||
for _, trx := range transactions {
|
||||
// Extract to and from data from the the transactions for indexing
|
||||
from, err := types.Sender(signer, trx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
from, senderErr := types.Sender(signer, trx)
|
||||
if senderErr != nil {
|
||||
return nil, senderErr
|
||||
}
|
||||
txMeta := &TrxMetaData{
|
||||
Dst: handleNullAddr(trx.To()),
|
||||
@@ -84,14 +84,14 @@ func (pc *Converter) Convert(payload statediff.Payload) (*IPLDPayload, error) {
|
||||
|
||||
// Decode receipts for this block
|
||||
receipts := make(types.Receipts, 0)
|
||||
err = rlp.DecodeBytes(payload.ReceiptsRlp, &receipts)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
decodeErr = rlp.DecodeBytes(payload.ReceiptsRlp, &receipts)
|
||||
if decodeErr != nil {
|
||||
return nil, decodeErr
|
||||
}
|
||||
// Derive any missing fields
|
||||
err = receipts.DeriveFields(pc.chainConfig, block.Hash(), block.NumberU64(), block.Transactions())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
deriveErr := receipts.DeriveFields(pc.chainConfig, block.Hash(), block.NumberU64(), block.Transactions())
|
||||
if deriveErr != nil {
|
||||
return nil, deriveErr
|
||||
}
|
||||
for i, receipt := range receipts {
|
||||
// If the transaction for this receipt has a "to" address, the above DeriveFields() fails to assign it to the receipt's ContractAddress
|
||||
@@ -118,9 +118,9 @@ func (pc *Converter) Convert(payload statediff.Payload) (*IPLDPayload, error) {
|
||||
|
||||
// Unpack state diff rlp to access fields
|
||||
stateDiff := new(statediff.StateDiff)
|
||||
err = rlp.DecodeBytes(payload.StateDiffRlp, stateDiff)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
decodeErr = rlp.DecodeBytes(payload.StateDiffRlp, stateDiff)
|
||||
if decodeErr != nil {
|
||||
return nil, decodeErr
|
||||
}
|
||||
for _, createdAccount := range stateDiff.CreatedAccounts {
|
||||
hashKey := common.BytesToHash(createdAccount.Key)
|
||||
|
||||
+33
-33
@@ -28,7 +28,7 @@ import (
|
||||
|
||||
// IPLDFetcher is an interface for fetching IPLDs
|
||||
type IPLDFetcher interface {
|
||||
FetchCIDs(cids CIDWrapper) (*IPLDWrapper, error)
|
||||
FetchIPLDs(cids CIDWrapper) (*IPLDWrapper, error)
|
||||
}
|
||||
|
||||
// EthIPLDFetcher is used to fetch ETH IPLD objects from IPFS
|
||||
@@ -47,8 +47,8 @@ func NewIPLDFetcher(ipfsPath string) (*EthIPLDFetcher, error) {
|
||||
}, nil
|
||||
}
|
||||
|
||||
// FetchCIDs is the exported method for fetching and returning all the cids passed in a CIDWrapper
|
||||
func (f *EthIPLDFetcher) FetchCIDs(cids CIDWrapper) (*IPLDWrapper, error) {
|
||||
// FetchIPLDs is the exported method for fetching and returning all the IPLDS specified in the CIDWrapper
|
||||
func (f *EthIPLDFetcher) FetchIPLDs(cids CIDWrapper) (*IPLDWrapper, error) {
|
||||
|
||||
log.Debug("fetching iplds")
|
||||
blocks := &IPLDWrapper{
|
||||
@@ -61,29 +61,29 @@ func (f *EthIPLDFetcher) FetchCIDs(cids CIDWrapper) (*IPLDWrapper, error) {
|
||||
StorageNodes: make(map[common.Hash]map[common.Hash]blocks.Block),
|
||||
}
|
||||
|
||||
err := f.fetchHeaders(cids, blocks)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
headersErr := f.fetchHeaders(cids, blocks)
|
||||
if headersErr != nil {
|
||||
return nil, headersErr
|
||||
}
|
||||
err = f.fetchUncles(cids, blocks)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
unclesErr := f.fetchUncles(cids, blocks)
|
||||
if unclesErr != nil {
|
||||
return nil, unclesErr
|
||||
}
|
||||
err = f.fetchTrxs(cids, blocks)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
trxsErr := f.fetchTrxs(cids, blocks)
|
||||
if trxsErr != nil {
|
||||
return nil, trxsErr
|
||||
}
|
||||
err = f.fetchRcts(cids, blocks)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
rctsErr := f.fetchRcts(cids, blocks)
|
||||
if rctsErr != nil {
|
||||
return nil, rctsErr
|
||||
}
|
||||
err = f.fetchStorage(cids, blocks)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
storageErr := f.fetchStorage(cids, blocks)
|
||||
if storageErr != nil {
|
||||
return nil, storageErr
|
||||
}
|
||||
err = f.fetchState(cids, blocks)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
stateErr := f.fetchState(cids, blocks)
|
||||
if stateErr != nil {
|
||||
return nil, stateErr
|
||||
}
|
||||
|
||||
return blocks, nil
|
||||
@@ -174,13 +174,13 @@ func (f *EthIPLDFetcher) fetchState(cids CIDWrapper, blocks *IPLDWrapper) error
|
||||
if stateNode.CID == "" || stateNode.Key == "" {
|
||||
continue
|
||||
}
|
||||
dc, err := cid.Decode(stateNode.CID)
|
||||
if err != nil {
|
||||
return err
|
||||
dc, decodeErr := cid.Decode(stateNode.CID)
|
||||
if decodeErr != nil {
|
||||
return decodeErr
|
||||
}
|
||||
block, err := f.fetch(dc)
|
||||
if err != nil {
|
||||
return err
|
||||
block, fetchErr := f.fetch(dc)
|
||||
if fetchErr != nil {
|
||||
return fetchErr
|
||||
}
|
||||
blocks.StateNodes[common.HexToHash(stateNode.Key)] = block
|
||||
}
|
||||
@@ -196,13 +196,13 @@ func (f *EthIPLDFetcher) fetchStorage(cids CIDWrapper, blks *IPLDWrapper) error
|
||||
if storageNode.CID == "" || storageNode.Key == "" || storageNode.StateKey == "" {
|
||||
continue
|
||||
}
|
||||
dc, err := cid.Decode(storageNode.CID)
|
||||
if err != nil {
|
||||
return err
|
||||
dc, decodeErr := cid.Decode(storageNode.CID)
|
||||
if decodeErr != nil {
|
||||
return decodeErr
|
||||
}
|
||||
blk, err := f.fetch(dc)
|
||||
if err != nil {
|
||||
return err
|
||||
blk, fetchErr := f.fetch(dc)
|
||||
if fetchErr != nil {
|
||||
return fetchErr
|
||||
}
|
||||
if blks.StorageNodes[common.HexToHash(storageNode.StateKey)] == nil {
|
||||
blks.StorageNodes[common.HexToHash(storageNode.StateKey)] = make(map[common.Hash]blocks.Block)
|
||||
|
||||
@@ -83,7 +83,7 @@ var _ = Describe("Fetcher", func() {
|
||||
It("Fetches and returns IPLDs for the CIDs provided in the CIDWrapper", func() {
|
||||
fetcher := new(ipfs.EthIPLDFetcher)
|
||||
fetcher.BlockService = mockBlockService
|
||||
iplds, err := fetcher.FetchCIDs(mockCIDWrapper)
|
||||
iplds, err := fetcher.FetchIPLDs(mockCIDWrapper)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(iplds.BlockNumber).To(Equal(mockCIDWrapper.BlockNumber))
|
||||
Expect(len(iplds.Headers)).To(Equal(1))
|
||||
|
||||
+21
-6
@@ -23,23 +23,38 @@ import (
|
||||
"github.com/ethereum/go-ethereum/crypto"
|
||||
"github.com/ipfs/go-blockservice"
|
||||
"github.com/ipfs/go-ipfs/core"
|
||||
"github.com/ipfs/go-ipfs/plugin/loader"
|
||||
"github.com/ipfs/go-ipfs/repo/fsrepo"
|
||||
)
|
||||
|
||||
// InitIPFSPlugins is used to initialized IPFS plugins before creating a new IPFS node
|
||||
// This should only be called once
|
||||
func InitIPFSPlugins() error {
|
||||
l, err := loader.NewPluginLoader("")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = l.Initialize()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return l.Inject()
|
||||
}
|
||||
|
||||
// InitIPFSBlockService is used to configure and return a BlockService using an ipfs repo path (e.g. ~/.ipfs)
|
||||
func InitIPFSBlockService(ipfsPath string) (blockservice.BlockService, error) {
|
||||
r, err := fsrepo.Open(ipfsPath)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
r, openErr := fsrepo.Open(ipfsPath)
|
||||
if openErr != nil {
|
||||
return nil, openErr
|
||||
}
|
||||
ctx := context.Background()
|
||||
cfg := &core.BuildCfg{
|
||||
Online: false,
|
||||
Repo: r,
|
||||
}
|
||||
ipfsNode, err := core.NewNode(ctx, cfg)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
ipfsNode, newNodeErr := core.NewNode(ctx, cfg)
|
||||
if newNodeErr != nil {
|
||||
return nil, newNodeErr
|
||||
}
|
||||
return ipfsNode.Blocks, nil
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ package mocks
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/vulcanize/vulcanizedb/pkg/ipfs"
|
||||
)
|
||||
|
||||
|
||||
+21
-35
@@ -22,8 +22,6 @@ import (
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/core/types"
|
||||
"github.com/ethereum/go-ethereum/rlp"
|
||||
"github.com/ipfs/go-ipfs/plugin/loader"
|
||||
|
||||
"github.com/vulcanize/eth-block-extractor/pkg/ipfs"
|
||||
"github.com/vulcanize/eth-block-extractor/pkg/ipfs/eth_block_header"
|
||||
"github.com/vulcanize/eth-block-extractor/pkg/ipfs/eth_block_receipts"
|
||||
@@ -49,18 +47,6 @@ type Publisher struct {
|
||||
|
||||
// NewIPLDPublisher creates a pointer to a new Publisher which satisfies the IPLDPublisher interface
|
||||
func NewIPLDPublisher(ipfsPath string) (*Publisher, error) {
|
||||
l, err := loader.NewPluginLoader("")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
err = l.Initialize()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
err = l.Inject()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
node, err := ipfs.InitIPFSNode(ipfsPath)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -77,47 +63,47 @@ func NewIPLDPublisher(ipfsPath string) (*Publisher, error) {
|
||||
// Publish publishes an IPLDPayload to IPFS and returns the corresponding CIDPayload
|
||||
func (pub *Publisher) Publish(payload *IPLDPayload) (*CIDPayload, error) {
|
||||
// Process and publish headers
|
||||
headerCid, err := pub.publishHeaders(payload.HeaderRLP)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
headerCid, headersErr := pub.publishHeaders(payload.HeaderRLP)
|
||||
if headersErr != nil {
|
||||
return nil, headersErr
|
||||
}
|
||||
|
||||
// Process and publish uncles
|
||||
uncleCids := make(map[common.Hash]string)
|
||||
for _, uncle := range payload.BlockBody.Uncles {
|
||||
uncleRlp, err := rlp.EncodeToBytes(uncle)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
uncleRlp, encodeErr := rlp.EncodeToBytes(uncle)
|
||||
if encodeErr != nil {
|
||||
return nil, encodeErr
|
||||
}
|
||||
cid, err := pub.publishHeaders(uncleRlp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
cid, unclesErr := pub.publishHeaders(uncleRlp)
|
||||
if unclesErr != nil {
|
||||
return nil, unclesErr
|
||||
}
|
||||
uncleCids[uncle.Hash()] = cid
|
||||
}
|
||||
|
||||
// Process and publish transactions
|
||||
transactionCids, err := pub.publishTransactions(payload.BlockBody, payload.TrxMetaData)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
transactionCids, trxsErr := pub.publishTransactions(payload.BlockBody, payload.TrxMetaData)
|
||||
if trxsErr != nil {
|
||||
return nil, trxsErr
|
||||
}
|
||||
|
||||
// Process and publish receipts
|
||||
receiptsCids, err := pub.publishReceipts(payload.Receipts, payload.ReceiptMetaData)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
receiptsCids, rctsErr := pub.publishReceipts(payload.Receipts, payload.ReceiptMetaData)
|
||||
if rctsErr != nil {
|
||||
return nil, rctsErr
|
||||
}
|
||||
|
||||
// Process and publish state leafs
|
||||
stateNodeCids, err := pub.publishStateNodes(payload.StateNodes)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
stateNodeCids, stateErr := pub.publishStateNodes(payload.StateNodes)
|
||||
if stateErr != nil {
|
||||
return nil, stateErr
|
||||
}
|
||||
|
||||
// Process and publish storage leafs
|
||||
storageNodeCids, err := pub.publishStorageNodes(payload.StorageNodes)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
storageNodeCids, storageErr := pub.publishStorageNodes(payload.StorageNodes)
|
||||
if storageErr != nil {
|
||||
return nil, storageErr
|
||||
}
|
||||
|
||||
// Package CIDs and their metadata into a single struct
|
||||
|
||||
@@ -24,7 +24,7 @@ import (
|
||||
|
||||
// IPLDResolver is the interface to resolving IPLDs
|
||||
type IPLDResolver interface {
|
||||
ResolveIPLDs(ipfsBlocks IPLDWrapper) (streamer.SuperNodePayload, error)
|
||||
ResolveIPLDs(ipfsBlocks IPLDWrapper) streamer.SuperNodePayload
|
||||
}
|
||||
|
||||
// EthIPLDResolver is the underlying struct to support the IPLDResolver interface
|
||||
@@ -36,7 +36,7 @@ func NewIPLDResolver() *EthIPLDResolver {
|
||||
}
|
||||
|
||||
// ResolveIPLDs is the exported method for resolving all of the ETH IPLDs packaged in an IpfsBlockWrapper
|
||||
func (eir *EthIPLDResolver) ResolveIPLDs(ipfsBlocks IPLDWrapper) (streamer.SuperNodePayload, error) {
|
||||
func (eir *EthIPLDResolver) ResolveIPLDs(ipfsBlocks IPLDWrapper) streamer.SuperNodePayload {
|
||||
response := &streamer.SuperNodePayload{
|
||||
BlockNumber: ipfsBlocks.BlockNumber,
|
||||
StateNodesRlp: make(map[common.Hash][]byte),
|
||||
@@ -48,7 +48,7 @@ func (eir *EthIPLDResolver) ResolveIPLDs(ipfsBlocks IPLDWrapper) (streamer.Super
|
||||
eir.resolveReceipts(ipfsBlocks.Receipts, response)
|
||||
eir.resolveState(ipfsBlocks.StateNodes, response)
|
||||
eir.resolveStorage(ipfsBlocks.StorageNodes, response)
|
||||
return *response, nil
|
||||
return *response
|
||||
}
|
||||
|
||||
func (eir *EthIPLDResolver) resolveHeaders(blocks []blocks.Block, response *streamer.SuperNodePayload) {
|
||||
|
||||
Reference in New Issue
Block a user