forked from cerc-io/ipld-eth-server
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
|
return err
|
||||||
}
|
}
|
||||||
response.Header = models.IPLDModel{
|
response.Header = models.IPLDModel{
|
||||||
|
BlockNumber: payload.Block.Number().String(),
|
||||||
Data: headerRLP,
|
Data: headerRLP,
|
||||||
Key: cid.String(),
|
Key: cid.String(),
|
||||||
}
|
}
|
||||||
@ -97,6 +98,7 @@ func (s *ResponseFilterer) filterHeaders(headerFilter HeaderFilter, response *IP
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
response.Uncles[i] = models.IPLDModel{
|
response.Uncles[i] = models.IPLDModel{
|
||||||
|
BlockNumber: uncle.Number.String(),
|
||||||
Data: uncleRlp,
|
Data: uncleRlp,
|
||||||
Key: cid.String(),
|
Key: cid.String(),
|
||||||
}
|
}
|
||||||
@ -183,6 +185,7 @@ 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{
|
||||||
|
BlockNumber: payload.Block.Number().String(),
|
||||||
Data: rctIPLDData[idx],
|
Data: rctIPLDData[idx],
|
||||||
Key: rctLeafCID[idx].String(),
|
Key: rctLeafCID[idx].String(),
|
||||||
})
|
})
|
||||||
@ -282,6 +285,7 @@ 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{
|
||||||
|
BlockNumber: payload.Block.Number().String(),
|
||||||
Data: stateNode.NodeValue,
|
Data: stateNode.NodeValue,
|
||||||
Key: cid.String(),
|
Key: cid.String(),
|
||||||
},
|
},
|
||||||
@ -300,6 +304,7 @@ 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{
|
||||||
|
BlockNumber: payload.Block.Number().String(),
|
||||||
Data: storageNode.NodeValue,
|
Data: storageNode.NodeValue,
|
||||||
Key: cid.String(),
|
Key: cid.String(),
|
||||||
},
|
},
|
||||||
|
@ -61,12 +61,14 @@ 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{
|
||||||
|
BlockNumber: test_helpers.BlockNumber.String(),
|
||||||
Data: test_helpers.State2IPLD.RawData(),
|
Data: test_helpers.State2IPLD.RawData(),
|
||||||
Key: test_helpers.State2IPLD.Cid().String(),
|
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{
|
||||||
|
BlockNumber: test_helpers.BlockNumber.String(),
|
||||||
Data: test_helpers.State1IPLD.RawData(),
|
Data: test_helpers.State1IPLD.RawData(),
|
||||||
Key: test_helpers.State1IPLD.Cid().String(),
|
Key: test_helpers.State1IPLD.Cid().String(),
|
||||||
}))
|
}))
|
||||||
@ -87,6 +89,7 @@ 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{
|
||||||
|
BlockNumber: test_helpers.BlockNumber.String(),
|
||||||
Data: test_helpers.Rct1IPLD,
|
Data: test_helpers.Rct1IPLD,
|
||||||
Key: test_helpers.Rct1CID.String(),
|
Key: test_helpers.Rct1CID.String(),
|
||||||
}))
|
}))
|
||||||
@ -102,6 +105,7 @@ 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{
|
||||||
|
BlockNumber: test_helpers.BlockNumber.String(),
|
||||||
Data: test_helpers.Rct1IPLD,
|
Data: test_helpers.Rct1IPLD,
|
||||||
Key: test_helpers.Rct1CID.String(),
|
Key: test_helpers.Rct1CID.String(),
|
||||||
}))
|
}))
|
||||||
@ -117,6 +121,7 @@ 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{
|
||||||
|
BlockNumber: test_helpers.BlockNumber.String(),
|
||||||
Data: test_helpers.Rct1IPLD,
|
Data: test_helpers.Rct1IPLD,
|
||||||
Key: test_helpers.Rct1CID.String(),
|
Key: test_helpers.Rct1CID.String(),
|
||||||
}))
|
}))
|
||||||
@ -132,6 +137,7 @@ 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{
|
||||||
|
BlockNumber: test_helpers.BlockNumber.String(),
|
||||||
Data: test_helpers.Rct2IPLD,
|
Data: test_helpers.Rct2IPLD,
|
||||||
Key: test_helpers.Rct2CID.String(),
|
Key: test_helpers.Rct2CID.String(),
|
||||||
}))
|
}))
|
||||||
@ -165,6 +171,7 @@ 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{
|
||||||
|
BlockNumber: test_helpers.BlockNumber.String(),
|
||||||
Data: test_helpers.Rct2IPLD,
|
Data: test_helpers.Rct2IPLD,
|
||||||
Key: test_helpers.Rct2CID.String(),
|
Key: test_helpers.Rct2CID.String(),
|
||||||
}))
|
}))
|
||||||
@ -181,6 +188,7 @@ 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{
|
||||||
|
BlockNumber: test_helpers.BlockNumber.String(),
|
||||||
Data: test_helpers.State2IPLD.RawData(),
|
Data: test_helpers.State2IPLD.RawData(),
|
||||||
Key: test_helpers.State2IPLD.Cid().String(),
|
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{}, err
|
||||||
}
|
}
|
||||||
return models.IPLDModel{
|
return models.IPLDModel{
|
||||||
|
BlockNumber: c.BlockNumber,
|
||||||
Data: headerBytes,
|
Data: headerBytes,
|
||||||
Key: c.CID,
|
Key: c.CID,
|
||||||
}, nil
|
}, nil
|
||||||
@ -132,6 +133,7 @@ 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{
|
||||||
|
BlockNumber: c.BlockNumber,
|
||||||
Data: uncleBytes,
|
Data: uncleBytes,
|
||||||
Key: c.CID,
|
Key: c.CID,
|
||||||
}
|
}
|
||||||
@ -153,6 +155,7 @@ 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{
|
||||||
|
BlockNumber: c.BlockNumber,
|
||||||
Data: txBytes,
|
Data: txBytes,
|
||||||
Key: c.CID,
|
Key: c.CID,
|
||||||
}
|
}
|
||||||
@ -175,6 +178,7 @@ 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{
|
||||||
|
BlockNumber: c.BlockNumber,
|
||||||
Data: rctBytes,
|
Data: rctBytes,
|
||||||
Key: c.LeafCID,
|
Key: c.LeafCID,
|
||||||
}
|
}
|
||||||
@ -200,6 +204,7 @@ 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{
|
||||||
|
BlockNumber: stateNode.BlockNumber,
|
||||||
Data: stateBytes,
|
Data: stateBytes,
|
||||||
Key: stateNode.CID,
|
Key: stateNode.CID,
|
||||||
},
|
},
|
||||||
@ -229,6 +234,7 @@ func (f *IPLDFetcher) FetchStorage(tx *sqlx.Tx, cids []models.StorageNodeWithSta
|
|||||||
}
|
}
|
||||||
storageNodes = append(storageNodes, StorageNode{
|
storageNodes = append(storageNodes, StorageNode{
|
||||||
IPLD: models.IPLDModel{
|
IPLD: models.IPLDModel{
|
||||||
|
BlockNumber: storageNode.BlockNumber,
|
||||||
Data: storageBytes,
|
Data: storageBytes,
|
||||||
Key: storageNode.CID,
|
Key: storageNode.CID,
|
||||||
},
|
},
|
||||||
|
@ -494,41 +494,50 @@ 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{
|
||||||
|
BlockNumber: BlockNumber.String(),
|
||||||
Data: HeaderIPLD.RawData(),
|
Data: HeaderIPLD.RawData(),
|
||||||
Key: HeaderIPLD.Cid().String(),
|
Key: HeaderIPLD.Cid().String(),
|
||||||
},
|
},
|
||||||
Transactions: []models.IPLDModel{
|
Transactions: []models.IPLDModel{
|
||||||
{
|
{
|
||||||
|
BlockNumber: BlockNumber.String(),
|
||||||
Data: Trx1IPLD.RawData(),
|
Data: Trx1IPLD.RawData(),
|
||||||
Key: Trx1IPLD.Cid().String(),
|
Key: Trx1IPLD.Cid().String(),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
BlockNumber: BlockNumber.String(),
|
||||||
Data: Trx2IPLD.RawData(),
|
Data: Trx2IPLD.RawData(),
|
||||||
Key: Trx2IPLD.Cid().String(),
|
Key: Trx2IPLD.Cid().String(),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
BlockNumber: BlockNumber.String(),
|
||||||
Data: Trx3IPLD.RawData(),
|
Data: Trx3IPLD.RawData(),
|
||||||
Key: Trx3IPLD.Cid().String(),
|
Key: Trx3IPLD.Cid().String(),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
BlockNumber: BlockNumber.String(),
|
||||||
Data: Trx4IPLD.RawData(),
|
Data: Trx4IPLD.RawData(),
|
||||||
Key: Trx4IPLD.Cid().String(),
|
Key: Trx4IPLD.Cid().String(),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Receipts: []models.IPLDModel{
|
Receipts: []models.IPLDModel{
|
||||||
{
|
{
|
||||||
|
BlockNumber: BlockNumber.String(),
|
||||||
Data: Rct1IPLD,
|
Data: Rct1IPLD,
|
||||||
Key: Rct1CID.String(),
|
Key: Rct1CID.String(),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
BlockNumber: BlockNumber.String(),
|
||||||
Data: Rct2IPLD,
|
Data: Rct2IPLD,
|
||||||
Key: Rct2CID.String(),
|
Key: Rct2CID.String(),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
BlockNumber: BlockNumber.String(),
|
||||||
Data: Rct3IPLD,
|
Data: Rct3IPLD,
|
||||||
Key: Rct3CID.String(),
|
Key: Rct3CID.String(),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
BlockNumber: BlockNumber.String(),
|
||||||
Data: Rct4IPLD,
|
Data: Rct4IPLD,
|
||||||
Key: Rct4CID.String(),
|
Key: Rct4CID.String(),
|
||||||
},
|
},
|
||||||
@ -538,6 +547,7 @@ var (
|
|||||||
StateLeafKey: common.BytesToHash(ContractLeafKey),
|
StateLeafKey: common.BytesToHash(ContractLeafKey),
|
||||||
Type: sdtypes.Leaf,
|
Type: sdtypes.Leaf,
|
||||||
IPLD: models.IPLDModel{
|
IPLD: models.IPLDModel{
|
||||||
|
BlockNumber: BlockNumber.String(),
|
||||||
Data: State1IPLD.RawData(),
|
Data: State1IPLD.RawData(),
|
||||||
Key: State1IPLD.Cid().String(),
|
Key: State1IPLD.Cid().String(),
|
||||||
},
|
},
|
||||||
@ -547,6 +557,7 @@ var (
|
|||||||
StateLeafKey: common.BytesToHash(AccountLeafKey),
|
StateLeafKey: common.BytesToHash(AccountLeafKey),
|
||||||
Type: sdtypes.Leaf,
|
Type: sdtypes.Leaf,
|
||||||
IPLD: models.IPLDModel{
|
IPLD: models.IPLDModel{
|
||||||
|
BlockNumber: BlockNumber.String(),
|
||||||
Data: State2IPLD.RawData(),
|
Data: State2IPLD.RawData(),
|
||||||
Key: State2IPLD.Cid().String(),
|
Key: State2IPLD.Cid().String(),
|
||||||
},
|
},
|
||||||
@ -559,6 +570,7 @@ var (
|
|||||||
StorageLeafKey: common.BytesToHash(StorageLeafKey),
|
StorageLeafKey: common.BytesToHash(StorageLeafKey),
|
||||||
Type: sdtypes.Leaf,
|
Type: sdtypes.Leaf,
|
||||||
IPLD: models.IPLDModel{
|
IPLD: models.IPLDModel{
|
||||||
|
BlockNumber: BlockNumber.String(),
|
||||||
Data: StorageIPLD.RawData(),
|
Data: StorageIPLD.RawData(),
|
||||||
Key: StorageIPLD.Cid().String(),
|
Key: StorageIPLD.Cid().String(),
|
||||||
},
|
},
|
||||||
|
@ -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
|
|
||||||
}
|
|
||||||
|
Loading…
Reference in New Issue
Block a user