Remove unused functions

This commit is contained in:
Prathamesh Musale 2022-05-18 17:48:17 +05:30
parent 36e590c092
commit 9676690a2d
5 changed files with 93 additions and 103 deletions

View File

@ -82,8 +82,9 @@ func (s *ResponseFilterer) filterHeaders(headerFilter HeaderFilter, response *IP
return err return err
} }
response.Header = models.IPLDModel{ response.Header = models.IPLDModel{
Data: headerRLP, BlockNumber: payload.Block.Number().String(),
Key: cid.String(), Data: headerRLP,
Key: cid.String(),
} }
if headerFilter.Uncles { if headerFilter.Uncles {
response.Uncles = make([]models.IPLDModel, len(payload.Block.Body().Uncles)) response.Uncles = make([]models.IPLDModel, len(payload.Block.Body().Uncles))
@ -97,8 +98,9 @@ func (s *ResponseFilterer) filterHeaders(headerFilter HeaderFilter, response *IP
return err return err
} }
response.Uncles[i] = models.IPLDModel{ response.Uncles[i] = models.IPLDModel{
Data: uncleRlp, BlockNumber: uncle.Number.String(),
Key: cid.String(), Data: uncleRlp,
Key: cid.String(),
} }
} }
} }
@ -183,8 +185,9 @@ func (s *ResponseFilterer) filerReceipts(receiptFilter ReceiptFilter, response *
// TODO: Verify this filter logic. // TODO: Verify this filter logic.
if checkReceipts(receipt, receiptFilter.Topics, topics, receiptFilter.LogAddresses, contracts, trxHashes) { if checkReceipts(receipt, receiptFilter.Topics, topics, receiptFilter.LogAddresses, contracts, trxHashes) {
response.Receipts = append(response.Receipts, models.IPLDModel{ response.Receipts = append(response.Receipts, models.IPLDModel{
Data: rctIPLDData[idx], BlockNumber: payload.Block.Number().String(),
Key: rctLeafCID[idx].String(), Data: rctIPLDData[idx],
Key: rctLeafCID[idx].String(),
}) })
} }
} }
@ -282,8 +285,9 @@ func (s *ResponseFilterer) filterStateAndStorage(stateFilter StateFilter, storag
StateLeafKey: common.BytesToHash(stateNode.LeafKey), StateLeafKey: common.BytesToHash(stateNode.LeafKey),
Path: stateNode.Path, Path: stateNode.Path,
IPLD: models.IPLDModel{ IPLD: models.IPLDModel{
Data: stateNode.NodeValue, BlockNumber: payload.Block.Number().String(),
Key: cid.String(), Data: stateNode.NodeValue,
Key: cid.String(),
}, },
Type: stateNode.NodeType, Type: stateNode.NodeType,
}) })
@ -300,8 +304,9 @@ func (s *ResponseFilterer) filterStateAndStorage(stateFilter StateFilter, storag
StateLeafKey: common.BytesToHash(stateNode.LeafKey), StateLeafKey: common.BytesToHash(stateNode.LeafKey),
StorageLeafKey: common.BytesToHash(storageNode.LeafKey), StorageLeafKey: common.BytesToHash(storageNode.LeafKey),
IPLD: models.IPLDModel{ IPLD: models.IPLDModel{
Data: storageNode.NodeValue, BlockNumber: payload.Block.Number().String(),
Key: cid.String(), Data: storageNode.NodeValue,
Key: cid.String(),
}, },
Type: storageNode.NodeType, Type: storageNode.NodeType,
Path: storageNode.Path, Path: storageNode.Path,

View File

@ -61,14 +61,16 @@ var _ = Describe("Filterer", func() {
Expect(stateNode.Type).To(Equal(sdtypes.Leaf)) Expect(stateNode.Type).To(Equal(sdtypes.Leaf))
if bytes.Equal(stateNode.StateLeafKey.Bytes(), test_helpers.AccountLeafKey) { if bytes.Equal(stateNode.StateLeafKey.Bytes(), test_helpers.AccountLeafKey) {
Expect(stateNode.IPLD).To(Equal(models.IPLDModel{ Expect(stateNode.IPLD).To(Equal(models.IPLDModel{
Data: test_helpers.State2IPLD.RawData(), BlockNumber: test_helpers.BlockNumber.String(),
Key: test_helpers.State2IPLD.Cid().String(), Data: test_helpers.State2IPLD.RawData(),
Key: test_helpers.State2IPLD.Cid().String(),
})) }))
} }
if bytes.Equal(stateNode.StateLeafKey.Bytes(), test_helpers.ContractLeafKey) { if bytes.Equal(stateNode.StateLeafKey.Bytes(), test_helpers.ContractLeafKey) {
Expect(stateNode.IPLD).To(Equal(models.IPLDModel{ Expect(stateNode.IPLD).To(Equal(models.IPLDModel{
Data: test_helpers.State1IPLD.RawData(), BlockNumber: test_helpers.BlockNumber.String(),
Key: test_helpers.State1IPLD.Cid().String(), Data: test_helpers.State1IPLD.RawData(),
Key: test_helpers.State1IPLD.Cid().String(),
})) }))
} }
} }
@ -87,8 +89,9 @@ var _ = Describe("Filterer", func() {
Expect(len(iplds1.StateNodes)).To(Equal(0)) Expect(len(iplds1.StateNodes)).To(Equal(0))
Expect(len(iplds1.Receipts)).To(Equal(1)) Expect(len(iplds1.Receipts)).To(Equal(1))
Expect(iplds1.Receipts[0]).To(Equal(models.IPLDModel{ Expect(iplds1.Receipts[0]).To(Equal(models.IPLDModel{
Data: test_helpers.Rct1IPLD, BlockNumber: test_helpers.BlockNumber.String(),
Key: test_helpers.Rct1CID.String(), Data: test_helpers.Rct1IPLD,
Key: test_helpers.Rct1CID.String(),
})) }))
iplds2, err := filterer.Filter(rctTopicsFilter, test_helpers.MockConvertedPayload) iplds2, err := filterer.Filter(rctTopicsFilter, test_helpers.MockConvertedPayload)
@ -102,8 +105,9 @@ var _ = Describe("Filterer", func() {
Expect(len(iplds2.StateNodes)).To(Equal(0)) Expect(len(iplds2.StateNodes)).To(Equal(0))
Expect(len(iplds2.Receipts)).To(Equal(1)) Expect(len(iplds2.Receipts)).To(Equal(1))
Expect(iplds2.Receipts[0]).To(Equal(models.IPLDModel{ Expect(iplds2.Receipts[0]).To(Equal(models.IPLDModel{
Data: test_helpers.Rct1IPLD, BlockNumber: test_helpers.BlockNumber.String(),
Key: test_helpers.Rct1CID.String(), Data: test_helpers.Rct1IPLD,
Key: test_helpers.Rct1CID.String(),
})) }))
iplds3, err := filterer.Filter(rctTopicsAndAddressFilter, test_helpers.MockConvertedPayload) iplds3, err := filterer.Filter(rctTopicsAndAddressFilter, test_helpers.MockConvertedPayload)
@ -117,8 +121,9 @@ var _ = Describe("Filterer", func() {
Expect(len(iplds3.StateNodes)).To(Equal(0)) Expect(len(iplds3.StateNodes)).To(Equal(0))
Expect(len(iplds3.Receipts)).To(Equal(1)) Expect(len(iplds3.Receipts)).To(Equal(1))
Expect(iplds3.Receipts[0]).To(Equal(models.IPLDModel{ Expect(iplds3.Receipts[0]).To(Equal(models.IPLDModel{
Data: test_helpers.Rct1IPLD, BlockNumber: test_helpers.BlockNumber.String(),
Key: test_helpers.Rct1CID.String(), Data: test_helpers.Rct1IPLD,
Key: test_helpers.Rct1CID.String(),
})) }))
iplds4, err := filterer.Filter(rctAddressesAndTopicFilter, test_helpers.MockConvertedPayload) iplds4, err := filterer.Filter(rctAddressesAndTopicFilter, test_helpers.MockConvertedPayload)
@ -132,8 +137,9 @@ var _ = Describe("Filterer", func() {
Expect(len(iplds4.StateNodes)).To(Equal(0)) Expect(len(iplds4.StateNodes)).To(Equal(0))
Expect(len(iplds4.Receipts)).To(Equal(1)) Expect(len(iplds4.Receipts)).To(Equal(1))
Expect(iplds4.Receipts[0]).To(Equal(models.IPLDModel{ Expect(iplds4.Receipts[0]).To(Equal(models.IPLDModel{
Data: test_helpers.Rct2IPLD, BlockNumber: test_helpers.BlockNumber.String(),
Key: test_helpers.Rct2CID.String(), Data: test_helpers.Rct2IPLD,
Key: test_helpers.Rct2CID.String(),
})) }))
iplds5, err := filterer.Filter(rctsForAllCollectedTrxs, test_helpers.MockConvertedPayload) iplds5, err := filterer.Filter(rctsForAllCollectedTrxs, test_helpers.MockConvertedPayload)
@ -165,8 +171,9 @@ var _ = Describe("Filterer", func() {
Expect(len(iplds6.StateNodes)).To(Equal(0)) Expect(len(iplds6.StateNodes)).To(Equal(0))
Expect(len(iplds6.Receipts)).To(Equal(1)) Expect(len(iplds6.Receipts)).To(Equal(1))
Expect(iplds4.Receipts[0]).To(Equal(models.IPLDModel{ Expect(iplds4.Receipts[0]).To(Equal(models.IPLDModel{
Data: test_helpers.Rct2IPLD, BlockNumber: test_helpers.BlockNumber.String(),
Key: test_helpers.Rct2CID.String(), Data: test_helpers.Rct2IPLD,
Key: test_helpers.Rct2CID.String(),
})) }))
iplds7, err := filterer.Filter(stateFilter, test_helpers.MockConvertedPayload) iplds7, err := filterer.Filter(stateFilter, test_helpers.MockConvertedPayload)
@ -181,8 +188,9 @@ var _ = Describe("Filterer", func() {
Expect(len(iplds7.StateNodes)).To(Equal(1)) Expect(len(iplds7.StateNodes)).To(Equal(1))
Expect(iplds7.StateNodes[0].StateLeafKey.Bytes()).To(Equal(test_helpers.AccountLeafKey)) Expect(iplds7.StateNodes[0].StateLeafKey.Bytes()).To(Equal(test_helpers.AccountLeafKey))
Expect(iplds7.StateNodes[0].IPLD).To(Equal(models.IPLDModel{ Expect(iplds7.StateNodes[0].IPLD).To(Equal(models.IPLDModel{
Data: test_helpers.State2IPLD.RawData(), BlockNumber: test_helpers.BlockNumber.String(),
Key: test_helpers.State2IPLD.Cid().String(), Data: test_helpers.State2IPLD.RawData(),
Key: test_helpers.State2IPLD.Cid().String(),
})) }))
iplds8, err := filterer.Filter(rctTopicsAndAddressFilterFail, test_helpers.MockConvertedPayload) iplds8, err := filterer.Filter(rctTopicsAndAddressFilterFail, test_helpers.MockConvertedPayload)

View File

@ -113,8 +113,9 @@ func (f *IPLDFetcher) FetchHeader(tx *sqlx.Tx, c models.HeaderModel) (models.IPL
return models.IPLDModel{}, err return models.IPLDModel{}, err
} }
return models.IPLDModel{ return models.IPLDModel{
Data: headerBytes, BlockNumber: c.BlockNumber,
Key: c.CID, Data: headerBytes,
Key: c.CID,
}, nil }, nil
} }
@ -132,8 +133,9 @@ func (f *IPLDFetcher) FetchUncles(tx *sqlx.Tx, cids []models.UncleModel) ([]mode
return nil, err return nil, err
} }
uncleIPLDs[i] = models.IPLDModel{ uncleIPLDs[i] = models.IPLDModel{
Data: uncleBytes, BlockNumber: c.BlockNumber,
Key: c.CID, Data: uncleBytes,
Key: c.CID,
} }
} }
return uncleIPLDs, nil return uncleIPLDs, nil
@ -153,8 +155,9 @@ func (f *IPLDFetcher) FetchTrxs(tx *sqlx.Tx, cids []models.TxModel) ([]models.IP
return nil, err return nil, err
} }
trxIPLDs[i] = models.IPLDModel{ trxIPLDs[i] = models.IPLDModel{
Data: txBytes, BlockNumber: c.BlockNumber,
Key: c.CID, Data: txBytes,
Key: c.CID,
} }
} }
return trxIPLDs, nil return trxIPLDs, nil
@ -175,8 +178,9 @@ func (f *IPLDFetcher) FetchRcts(tx *sqlx.Tx, cids []models.ReceiptModel) ([]mode
} }
//nodeVal, err := DecodeLeafNode(rctBytes) //nodeVal, err := DecodeLeafNode(rctBytes)
rctIPLDs[i] = models.IPLDModel{ rctIPLDs[i] = models.IPLDModel{
Data: rctBytes, BlockNumber: c.BlockNumber,
Key: c.LeafCID, Data: rctBytes,
Key: c.LeafCID,
} }
} }
return rctIPLDs, nil return rctIPLDs, nil
@ -200,8 +204,9 @@ func (f *IPLDFetcher) FetchState(tx *sqlx.Tx, cids []models.StateNodeModel) ([]S
} }
stateNodes = append(stateNodes, StateNode{ stateNodes = append(stateNodes, StateNode{
IPLD: models.IPLDModel{ IPLD: models.IPLDModel{
Data: stateBytes, BlockNumber: stateNode.BlockNumber,
Key: stateNode.CID, Data: stateBytes,
Key: stateNode.CID,
}, },
StateLeafKey: common.HexToHash(stateNode.StateKey), StateLeafKey: common.HexToHash(stateNode.StateKey),
Type: ResolveToNodeType(stateNode.NodeType), Type: ResolveToNodeType(stateNode.NodeType),
@ -229,8 +234,9 @@ func (f *IPLDFetcher) FetchStorage(tx *sqlx.Tx, cids []models.StorageNodeWithSta
} }
storageNodes = append(storageNodes, StorageNode{ storageNodes = append(storageNodes, StorageNode{
IPLD: models.IPLDModel{ IPLD: models.IPLDModel{
Data: storageBytes, BlockNumber: storageNode.BlockNumber,
Key: storageNode.CID, Data: storageBytes,
Key: storageNode.CID,
}, },
StateLeafKey: common.HexToHash(storageNode.StateKey), StateLeafKey: common.HexToHash(storageNode.StateKey),
StorageLeafKey: common.HexToHash(storageNode.StorageKey), StorageLeafKey: common.HexToHash(storageNode.StorageKey),

View File

@ -494,43 +494,52 @@ var (
MockIPLDs = eth.IPLDs{ MockIPLDs = eth.IPLDs{
BlockNumber: new(big.Int).Set(BlockNumber), BlockNumber: new(big.Int).Set(BlockNumber),
Header: models.IPLDModel{ Header: models.IPLDModel{
Data: HeaderIPLD.RawData(), BlockNumber: BlockNumber.String(),
Key: HeaderIPLD.Cid().String(), Data: HeaderIPLD.RawData(),
Key: HeaderIPLD.Cid().String(),
}, },
Transactions: []models.IPLDModel{ Transactions: []models.IPLDModel{
{ {
Data: Trx1IPLD.RawData(), BlockNumber: BlockNumber.String(),
Key: Trx1IPLD.Cid().String(), Data: Trx1IPLD.RawData(),
Key: Trx1IPLD.Cid().String(),
}, },
{ {
Data: Trx2IPLD.RawData(), BlockNumber: BlockNumber.String(),
Key: Trx2IPLD.Cid().String(), Data: Trx2IPLD.RawData(),
Key: Trx2IPLD.Cid().String(),
}, },
{ {
Data: Trx3IPLD.RawData(), BlockNumber: BlockNumber.String(),
Key: Trx3IPLD.Cid().String(), Data: Trx3IPLD.RawData(),
Key: Trx3IPLD.Cid().String(),
}, },
{ {
Data: Trx4IPLD.RawData(), BlockNumber: BlockNumber.String(),
Key: Trx4IPLD.Cid().String(), Data: Trx4IPLD.RawData(),
Key: Trx4IPLD.Cid().String(),
}, },
}, },
Receipts: []models.IPLDModel{ Receipts: []models.IPLDModel{
{ {
Data: Rct1IPLD, BlockNumber: BlockNumber.String(),
Key: Rct1CID.String(), Data: Rct1IPLD,
Key: Rct1CID.String(),
}, },
{ {
Data: Rct2IPLD, BlockNumber: BlockNumber.String(),
Key: Rct2CID.String(), Data: Rct2IPLD,
Key: Rct2CID.String(),
}, },
{ {
Data: Rct3IPLD, BlockNumber: BlockNumber.String(),
Key: Rct3CID.String(), Data: Rct3IPLD,
Key: Rct3CID.String(),
}, },
{ {
Data: Rct4IPLD, BlockNumber: BlockNumber.String(),
Key: Rct4CID.String(), Data: Rct4IPLD,
Key: Rct4CID.String(),
}, },
}, },
StateNodes: []eth.StateNode{ StateNodes: []eth.StateNode{
@ -538,8 +547,9 @@ var (
StateLeafKey: common.BytesToHash(ContractLeafKey), StateLeafKey: common.BytesToHash(ContractLeafKey),
Type: sdtypes.Leaf, Type: sdtypes.Leaf,
IPLD: models.IPLDModel{ IPLD: models.IPLDModel{
Data: State1IPLD.RawData(), BlockNumber: BlockNumber.String(),
Key: State1IPLD.Cid().String(), Data: State1IPLD.RawData(),
Key: State1IPLD.Cid().String(),
}, },
Path: []byte{'\x06'}, Path: []byte{'\x06'},
}, },
@ -547,8 +557,9 @@ var (
StateLeafKey: common.BytesToHash(AccountLeafKey), StateLeafKey: common.BytesToHash(AccountLeafKey),
Type: sdtypes.Leaf, Type: sdtypes.Leaf,
IPLD: models.IPLDModel{ IPLD: models.IPLDModel{
Data: State2IPLD.RawData(), BlockNumber: BlockNumber.String(),
Key: State2IPLD.Cid().String(), Data: State2IPLD.RawData(),
Key: State2IPLD.Cid().String(),
}, },
Path: []byte{'\x0c'}, Path: []byte{'\x0c'},
}, },
@ -559,8 +570,9 @@ var (
StorageLeafKey: common.BytesToHash(StorageLeafKey), StorageLeafKey: common.BytesToHash(StorageLeafKey),
Type: sdtypes.Leaf, Type: sdtypes.Leaf,
IPLD: models.IPLDModel{ IPLD: models.IPLDModel{
Data: StorageIPLD.RawData(), BlockNumber: BlockNumber.String(),
Key: StorageIPLD.Cid().String(), Data: StorageIPLD.RawData(),
Key: StorageIPLD.Cid().String(),
}, },
Path: []byte{}, Path: []byte{},
}, },

View File

@ -18,11 +18,9 @@ package shared
import ( import (
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/statediff/indexer/ipld"
"github.com/ipfs/go-cid" "github.com/ipfs/go-cid"
blockstore "github.com/ipfs/go-ipfs-blockstore" blockstore "github.com/ipfs/go-ipfs-blockstore"
dshelp "github.com/ipfs/go-ipfs-ds-help" dshelp "github.com/ipfs/go-ipfs-ds-help"
node "github.com/ipfs/go-ipld-format"
"github.com/jmoiron/sqlx" "github.com/jmoiron/sqlx"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
) )
@ -50,33 +48,6 @@ func Rollback(tx *sqlx.Tx) {
} }
} }
// PublishIPLD is used to insert an ipld into Postgres blockstore with the provided tx
func PublishIPLD(tx *sqlx.Tx, i node.Node) error {
dbKey := dshelp.MultihashToDsKey(i.Cid().Hash())
prefixedKey := blockstore.BlockPrefix.String() + dbKey.String()
raw := i.RawData()
_, err := tx.Exec(`INSERT INTO public.blocks (key, data) VALUES ($1, $2) ON CONFLICT (key) DO NOTHING`, prefixedKey, raw)
return err
}
// FetchIPLD is used to retrieve an ipld from Postgres blockstore with the provided tx and cid string
func FetchIPLD(tx *sqlx.Tx, cid string) ([]byte, error) {
mhKey, err := MultihashKeyFromCIDString(cid)
if err != nil {
return nil, err
}
pgStr := `SELECT data FROM public.blocks WHERE key = $1`
var block []byte
return block, tx.Get(&block, pgStr, mhKey)
}
// FetchIPLDByMhKey is used to retrieve an ipld from Postgres blockstore with the provided tx and mhkey string
func FetchIPLDByMhKey(tx *sqlx.Tx, mhKey string) ([]byte, error) {
pgStr := `SELECT data FROM public.blocks WHERE key = $1`
var block []byte
return block, tx.Get(&block, pgStr, mhKey)
}
// FetchIPLDByMhKeyAndBlockNumber is used to retrieve an ipld from Postgres blockstore with the provided tx, mhkey string and blockNumber // FetchIPLDByMhKeyAndBlockNumber is used to retrieve an ipld from Postgres blockstore with the provided tx, mhkey string and blockNumber
func FetchIPLDByMhKeyAndBlockNumber(tx *sqlx.Tx, mhKey string, blockNumber uint64) ([]byte, error) { func FetchIPLDByMhKeyAndBlockNumber(tx *sqlx.Tx, mhKey string, blockNumber uint64) ([]byte, error) {
pgStr := `SELECT data FROM public.blocks WHERE key = $1 AND block_number = $2` pgStr := `SELECT data FROM public.blocks WHERE key = $1 AND block_number = $2`
@ -99,15 +70,3 @@ func MultihashKeyFromCIDString(c string) (string, error) {
dbKey := dshelp.MultihashToDsKey(dc.Hash()) dbKey := dshelp.MultihashToDsKey(dc.Hash())
return blockstore.BlockPrefix.String() + dbKey.String(), nil return blockstore.BlockPrefix.String() + dbKey.String(), nil
} }
// PublishRaw derives a cid from raw bytes and provided codec and multihash type, and writes it to the db tx
func PublishRaw(tx *sqlx.Tx, codec, mh uint64, raw []byte) (string, error) {
c, err := ipld.RawdataToCid(codec, raw, mh)
if err != nil {
return "", err
}
dbKey := dshelp.MultihashToDsKey(c.Hash())
prefixedKey := blockstore.BlockPrefix.String() + dbKey.String()
_, err = tx.Exec(`INSERT INTO public.blocks (key, data) VALUES ($1, $2) ON CONFLICT (key) DO NOTHING`, prefixedKey, raw)
return c.String(), err
}