combined/directp publish and indexing for btc; tests

This commit is contained in:
Ian Norden
2020-04-30 17:22:22 -05:00
parent 65da8cafe7
commit 059664ffc9
11 changed files with 306 additions and 133 deletions
+13 -2
View File
@@ -19,11 +19,13 @@ package shared
import (
"bytes"
"github.com/ethereum/go-ethereum/common"
"github.com/ipfs/go-ipfs-blockstore"
"github.com/ipfs/go-ipfs-ds-help"
node "github.com/ipfs/go-ipld-format"
"github.com/jmoiron/sqlx"
"github.com/sirupsen/logrus"
"github.com/ethereum/go-ethereum/common"
"github.com/vulcanize/vulcanizedb/pkg/ipfs"
)
@@ -79,3 +81,12 @@ func Rollback(tx *sqlx.Tx) {
logrus.Error(err)
}
}
// 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.CidToDsKey(i.Cid())
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
}