Remove unused functions
This commit is contained in:
parent
36e590c092
commit
9676690a2d
@ -82,6 +82,7 @@ func (s *ResponseFilterer) filterHeaders(headerFilter HeaderFilter, response *IP
|
||||
return err
|
||||
}
|
||||
response.Header = models.IPLDModel{
|
||||
BlockNumber: payload.Block.Number().String(),
|
||||
Data: headerRLP,
|
||||
Key: cid.String(),
|
||||
}
|
||||
@ -97,6 +98,7 @@ func (s *ResponseFilterer) filterHeaders(headerFilter HeaderFilter, response *IP
|
||||
return err
|
||||
}
|
||||
response.Uncles[i] = models.IPLDModel{
|
||||
BlockNumber: uncle.Number.String(),
|
||||
Data: uncleRlp,
|
||||
Key: cid.String(),
|
||||
}
|
||||
@ -183,6 +185,7 @@ func (s *ResponseFilterer) filerReceipts(receiptFilter ReceiptFilter, response *
|
||||
// TODO: Verify this filter logic.
|
||||
if checkReceipts(receipt, receiptFilter.Topics, topics, receiptFilter.LogAddresses, contracts, trxHashes) {
|
||||
response.Receipts = append(response.Receipts, models.IPLDModel{
|
||||
BlockNumber: payload.Block.Number().String(),
|
||||
Data: rctIPLDData[idx],
|
||||
Key: rctLeafCID[idx].String(),
|
||||
})
|
||||
@ -282,6 +285,7 @@ func (s *ResponseFilterer) filterStateAndStorage(stateFilter StateFilter, storag
|
||||
StateLeafKey: common.BytesToHash(stateNode.LeafKey),
|
||||
Path: stateNode.Path,
|
||||
IPLD: models.IPLDModel{
|
||||
BlockNumber: payload.Block.Number().String(),
|
||||
Data: stateNode.NodeValue,
|
||||
Key: cid.String(),
|
||||
},
|
||||
@ -300,6 +304,7 @@ func (s *ResponseFilterer) filterStateAndStorage(stateFilter StateFilter, storag
|
||||
StateLeafKey: common.BytesToHash(stateNode.LeafKey),
|
||||
StorageLeafKey: common.BytesToHash(storageNode.LeafKey),
|
||||
IPLD: models.IPLDModel{
|
||||
BlockNumber: payload.Block.Number().String(),
|
||||
Data: storageNode.NodeValue,
|
||||
Key: cid.String(),
|
||||
},
|
||||
|
@ -61,12 +61,14 @@ var _ = Describe("Filterer", func() {
|
||||
Expect(stateNode.Type).To(Equal(sdtypes.Leaf))
|
||||
if bytes.Equal(stateNode.StateLeafKey.Bytes(), test_helpers.AccountLeafKey) {
|
||||
Expect(stateNode.IPLD).To(Equal(models.IPLDModel{
|
||||
BlockNumber: test_helpers.BlockNumber.String(),
|
||||
Data: test_helpers.State2IPLD.RawData(),
|
||||
Key: test_helpers.State2IPLD.Cid().String(),
|
||||
}))
|
||||
}
|
||||
if bytes.Equal(stateNode.StateLeafKey.Bytes(), test_helpers.ContractLeafKey) {
|
||||
Expect(stateNode.IPLD).To(Equal(models.IPLDModel{
|
||||
BlockNumber: test_helpers.BlockNumber.String(),
|
||||
Data: test_helpers.State1IPLD.RawData(),
|
||||
Key: test_helpers.State1IPLD.Cid().String(),
|
||||
}))
|
||||
@ -87,6 +89,7 @@ var _ = Describe("Filterer", func() {
|
||||
Expect(len(iplds1.StateNodes)).To(Equal(0))
|
||||
Expect(len(iplds1.Receipts)).To(Equal(1))
|
||||
Expect(iplds1.Receipts[0]).To(Equal(models.IPLDModel{
|
||||
BlockNumber: test_helpers.BlockNumber.String(),
|
||||
Data: test_helpers.Rct1IPLD,
|
||||
Key: test_helpers.Rct1CID.String(),
|
||||
}))
|
||||
@ -102,6 +105,7 @@ var _ = Describe("Filterer", func() {
|
||||
Expect(len(iplds2.StateNodes)).To(Equal(0))
|
||||
Expect(len(iplds2.Receipts)).To(Equal(1))
|
||||
Expect(iplds2.Receipts[0]).To(Equal(models.IPLDModel{
|
||||
BlockNumber: test_helpers.BlockNumber.String(),
|
||||
Data: test_helpers.Rct1IPLD,
|
||||
Key: test_helpers.Rct1CID.String(),
|
||||
}))
|
||||
@ -117,6 +121,7 @@ var _ = Describe("Filterer", func() {
|
||||
Expect(len(iplds3.StateNodes)).To(Equal(0))
|
||||
Expect(len(iplds3.Receipts)).To(Equal(1))
|
||||
Expect(iplds3.Receipts[0]).To(Equal(models.IPLDModel{
|
||||
BlockNumber: test_helpers.BlockNumber.String(),
|
||||
Data: test_helpers.Rct1IPLD,
|
||||
Key: test_helpers.Rct1CID.String(),
|
||||
}))
|
||||
@ -132,6 +137,7 @@ var _ = Describe("Filterer", func() {
|
||||
Expect(len(iplds4.StateNodes)).To(Equal(0))
|
||||
Expect(len(iplds4.Receipts)).To(Equal(1))
|
||||
Expect(iplds4.Receipts[0]).To(Equal(models.IPLDModel{
|
||||
BlockNumber: test_helpers.BlockNumber.String(),
|
||||
Data: test_helpers.Rct2IPLD,
|
||||
Key: test_helpers.Rct2CID.String(),
|
||||
}))
|
||||
@ -165,6 +171,7 @@ var _ = Describe("Filterer", func() {
|
||||
Expect(len(iplds6.StateNodes)).To(Equal(0))
|
||||
Expect(len(iplds6.Receipts)).To(Equal(1))
|
||||
Expect(iplds4.Receipts[0]).To(Equal(models.IPLDModel{
|
||||
BlockNumber: test_helpers.BlockNumber.String(),
|
||||
Data: test_helpers.Rct2IPLD,
|
||||
Key: test_helpers.Rct2CID.String(),
|
||||
}))
|
||||
@ -181,6 +188,7 @@ var _ = Describe("Filterer", func() {
|
||||
Expect(len(iplds7.StateNodes)).To(Equal(1))
|
||||
Expect(iplds7.StateNodes[0].StateLeafKey.Bytes()).To(Equal(test_helpers.AccountLeafKey))
|
||||
Expect(iplds7.StateNodes[0].IPLD).To(Equal(models.IPLDModel{
|
||||
BlockNumber: test_helpers.BlockNumber.String(),
|
||||
Data: test_helpers.State2IPLD.RawData(),
|
||||
Key: test_helpers.State2IPLD.Cid().String(),
|
||||
}))
|
||||
|
@ -113,6 +113,7 @@ func (f *IPLDFetcher) FetchHeader(tx *sqlx.Tx, c models.HeaderModel) (models.IPL
|
||||
return models.IPLDModel{}, err
|
||||
}
|
||||
return models.IPLDModel{
|
||||
BlockNumber: c.BlockNumber,
|
||||
Data: headerBytes,
|
||||
Key: c.CID,
|
||||
}, nil
|
||||
@ -132,6 +133,7 @@ func (f *IPLDFetcher) FetchUncles(tx *sqlx.Tx, cids []models.UncleModel) ([]mode
|
||||
return nil, err
|
||||
}
|
||||
uncleIPLDs[i] = models.IPLDModel{
|
||||
BlockNumber: c.BlockNumber,
|
||||
Data: uncleBytes,
|
||||
Key: c.CID,
|
||||
}
|
||||
@ -153,6 +155,7 @@ func (f *IPLDFetcher) FetchTrxs(tx *sqlx.Tx, cids []models.TxModel) ([]models.IP
|
||||
return nil, err
|
||||
}
|
||||
trxIPLDs[i] = models.IPLDModel{
|
||||
BlockNumber: c.BlockNumber,
|
||||
Data: txBytes,
|
||||
Key: c.CID,
|
||||
}
|
||||
@ -175,6 +178,7 @@ func (f *IPLDFetcher) FetchRcts(tx *sqlx.Tx, cids []models.ReceiptModel) ([]mode
|
||||
}
|
||||
//nodeVal, err := DecodeLeafNode(rctBytes)
|
||||
rctIPLDs[i] = models.IPLDModel{
|
||||
BlockNumber: c.BlockNumber,
|
||||
Data: rctBytes,
|
||||
Key: c.LeafCID,
|
||||
}
|
||||
@ -200,6 +204,7 @@ func (f *IPLDFetcher) FetchState(tx *sqlx.Tx, cids []models.StateNodeModel) ([]S
|
||||
}
|
||||
stateNodes = append(stateNodes, StateNode{
|
||||
IPLD: models.IPLDModel{
|
||||
BlockNumber: stateNode.BlockNumber,
|
||||
Data: stateBytes,
|
||||
Key: stateNode.CID,
|
||||
},
|
||||
@ -229,6 +234,7 @@ func (f *IPLDFetcher) FetchStorage(tx *sqlx.Tx, cids []models.StorageNodeWithSta
|
||||
}
|
||||
storageNodes = append(storageNodes, StorageNode{
|
||||
IPLD: models.IPLDModel{
|
||||
BlockNumber: storageNode.BlockNumber,
|
||||
Data: storageBytes,
|
||||
Key: storageNode.CID,
|
||||
},
|
||||
|
@ -494,41 +494,50 @@ var (
|
||||
MockIPLDs = eth.IPLDs{
|
||||
BlockNumber: new(big.Int).Set(BlockNumber),
|
||||
Header: models.IPLDModel{
|
||||
BlockNumber: BlockNumber.String(),
|
||||
Data: HeaderIPLD.RawData(),
|
||||
Key: HeaderIPLD.Cid().String(),
|
||||
},
|
||||
Transactions: []models.IPLDModel{
|
||||
{
|
||||
BlockNumber: BlockNumber.String(),
|
||||
Data: Trx1IPLD.RawData(),
|
||||
Key: Trx1IPLD.Cid().String(),
|
||||
},
|
||||
{
|
||||
BlockNumber: BlockNumber.String(),
|
||||
Data: Trx2IPLD.RawData(),
|
||||
Key: Trx2IPLD.Cid().String(),
|
||||
},
|
||||
{
|
||||
BlockNumber: BlockNumber.String(),
|
||||
Data: Trx3IPLD.RawData(),
|
||||
Key: Trx3IPLD.Cid().String(),
|
||||
},
|
||||
{
|
||||
BlockNumber: BlockNumber.String(),
|
||||
Data: Trx4IPLD.RawData(),
|
||||
Key: Trx4IPLD.Cid().String(),
|
||||
},
|
||||
},
|
||||
Receipts: []models.IPLDModel{
|
||||
{
|
||||
BlockNumber: BlockNumber.String(),
|
||||
Data: Rct1IPLD,
|
||||
Key: Rct1CID.String(),
|
||||
},
|
||||
{
|
||||
BlockNumber: BlockNumber.String(),
|
||||
Data: Rct2IPLD,
|
||||
Key: Rct2CID.String(),
|
||||
},
|
||||
{
|
||||
BlockNumber: BlockNumber.String(),
|
||||
Data: Rct3IPLD,
|
||||
Key: Rct3CID.String(),
|
||||
},
|
||||
{
|
||||
BlockNumber: BlockNumber.String(),
|
||||
Data: Rct4IPLD,
|
||||
Key: Rct4CID.String(),
|
||||
},
|
||||
@ -538,6 +547,7 @@ var (
|
||||
StateLeafKey: common.BytesToHash(ContractLeafKey),
|
||||
Type: sdtypes.Leaf,
|
||||
IPLD: models.IPLDModel{
|
||||
BlockNumber: BlockNumber.String(),
|
||||
Data: State1IPLD.RawData(),
|
||||
Key: State1IPLD.Cid().String(),
|
||||
},
|
||||
@ -547,6 +557,7 @@ var (
|
||||
StateLeafKey: common.BytesToHash(AccountLeafKey),
|
||||
Type: sdtypes.Leaf,
|
||||
IPLD: models.IPLDModel{
|
||||
BlockNumber: BlockNumber.String(),
|
||||
Data: State2IPLD.RawData(),
|
||||
Key: State2IPLD.Cid().String(),
|
||||
},
|
||||
@ -559,6 +570,7 @@ var (
|
||||
StorageLeafKey: common.BytesToHash(StorageLeafKey),
|
||||
Type: sdtypes.Leaf,
|
||||
IPLD: models.IPLDModel{
|
||||
BlockNumber: BlockNumber.String(),
|
||||
Data: StorageIPLD.RawData(),
|
||||
Key: StorageIPLD.Cid().String(),
|
||||
},
|
||||
|
@ -18,11 +18,9 @@ package shared
|
||||
|
||||
import (
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/statediff/indexer/ipld"
|
||||
"github.com/ipfs/go-cid"
|
||||
blockstore "github.com/ipfs/go-ipfs-blockstore"
|
||||
dshelp "github.com/ipfs/go-ipfs-ds-help"
|
||||
node "github.com/ipfs/go-ipld-format"
|
||||
"github.com/jmoiron/sqlx"
|
||||
"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
|
||||
func FetchIPLDByMhKeyAndBlockNumber(tx *sqlx.Tx, mhKey string, blockNumber uint64) ([]byte, error) {
|
||||
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())
|
||||
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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user