forked from cerc-io/ipfs-ethdb
Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0e24a9f543 |
@@ -0,0 +1,29 @@
|
|||||||
|
name: Notion Sync
|
||||||
|
|
||||||
|
on:
|
||||||
|
workflow_dispatch:
|
||||||
|
issues:
|
||||||
|
types:
|
||||||
|
[
|
||||||
|
opened,
|
||||||
|
edited,
|
||||||
|
labeled,
|
||||||
|
unlabeled,
|
||||||
|
assigned,
|
||||||
|
unassigned,
|
||||||
|
milestoned,
|
||||||
|
demilestoned,
|
||||||
|
reopened,
|
||||||
|
closed,
|
||||||
|
]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
notion_job:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
name: Add GitHub Issues to Notion
|
||||||
|
steps:
|
||||||
|
- name: Add GitHub Issues to Notion
|
||||||
|
uses: vulcanize/notion-github-action@v1.2.4-issueid
|
||||||
|
with:
|
||||||
|
notion-token: ${{ secrets.NOTION_TOKEN }}
|
||||||
|
notion-db: ${{ secrets.NOTION_DATABASE }}
|
||||||
@@ -50,7 +50,7 @@ import (
|
|||||||
"github.com/ipfs/go-ipfs/core"
|
"github.com/ipfs/go-ipfs/core"
|
||||||
"github.com/ipfs/go-ipfs/repo/fsrepo"
|
"github.com/ipfs/go-ipfs/repo/fsrepo"
|
||||||
"github.com/jmoiron/sqlx"
|
"github.com/jmoiron/sqlx"
|
||||||
"github.com/vulcanize/ipfs-ethdb/v4"
|
"github.com/vulcanize/ipfs-ethdb"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|||||||
+1
-1
@@ -25,7 +25,7 @@ import (
|
|||||||
. "github.com/onsi/ginkgo"
|
. "github.com/onsi/ginkgo"
|
||||||
. "github.com/onsi/gomega"
|
. "github.com/onsi/gomega"
|
||||||
|
|
||||||
ipfsethdb "github.com/vulcanize/ipfs-ethdb/v4"
|
ipfsethdb "github.com/vulcanize/ipfs-ethdb/v3"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
|||||||
+1
-1
@@ -26,7 +26,7 @@ import (
|
|||||||
. "github.com/onsi/ginkgo"
|
. "github.com/onsi/ginkgo"
|
||||||
. "github.com/onsi/gomega"
|
. "github.com/onsi/gomega"
|
||||||
|
|
||||||
ipfsethdb "github.com/vulcanize/ipfs-ethdb/v4"
|
ipfsethdb "github.com/vulcanize/ipfs-ethdb/v3"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
module github.com/vulcanize/ipfs-ethdb/v4
|
module github.com/vulcanize/ipfs-ethdb/v3
|
||||||
|
|
||||||
go 1.18
|
go 1.18
|
||||||
|
|
||||||
|
|||||||
+4
-9
@@ -17,8 +17,6 @@
|
|||||||
package pgipfsethdb
|
package pgipfsethdb
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"math/big"
|
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/ethdb"
|
"github.com/ethereum/go-ethereum/ethdb"
|
||||||
"github.com/jmoiron/sqlx"
|
"github.com/jmoiron/sqlx"
|
||||||
)
|
)
|
||||||
@@ -30,16 +28,13 @@ type Batch struct {
|
|||||||
db *sqlx.DB
|
db *sqlx.DB
|
||||||
tx *sqlx.Tx
|
tx *sqlx.Tx
|
||||||
valueSize int
|
valueSize int
|
||||||
|
|
||||||
blockNumber *big.Int
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewBatch returns a ethdb.Batch interface for PG-IPFS
|
// NewBatch returns a ethdb.Batch interface for PG-IPFS
|
||||||
func NewBatch(db *sqlx.DB, tx *sqlx.Tx, blockNumber *big.Int) ethdb.Batch {
|
func NewBatch(db *sqlx.DB, tx *sqlx.Tx) ethdb.Batch {
|
||||||
b := &Batch{
|
b := &Batch{
|
||||||
db: db,
|
db: db,
|
||||||
tx: tx,
|
tx: tx,
|
||||||
blockNumber: blockNumber,
|
|
||||||
}
|
}
|
||||||
if tx == nil {
|
if tx == nil {
|
||||||
b.Reset()
|
b.Reset()
|
||||||
@@ -55,7 +50,7 @@ func (b *Batch) Put(key []byte, value []byte) (err error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if _, err = b.tx.Exec(putPgStr, mhKey, value, b.blockNumber.Uint64()); err != nil {
|
if _, err = b.tx.Exec(putPgStr, mhKey, value); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
b.valueSize += len(value)
|
b.valueSize += len(value)
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ import (
|
|||||||
. "github.com/onsi/ginkgo"
|
. "github.com/onsi/ginkgo"
|
||||||
. "github.com/onsi/gomega"
|
. "github.com/onsi/gomega"
|
||||||
|
|
||||||
pgipfsethdb "github.com/vulcanize/ipfs-ethdb/v4/postgres"
|
pgipfsethdb "github.com/vulcanize/ipfs-ethdb/v3/postgres"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@@ -49,11 +49,6 @@ var _ = Describe("Batch", func() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
database = pgipfsethdb.NewDatabase(db, cacheConfig)
|
database = pgipfsethdb.NewDatabase(db, cacheConfig)
|
||||||
|
|
||||||
databaseWithBlock, ok := database.(*pgipfsethdb.Database)
|
|
||||||
Expect(ok).To(BeTrue())
|
|
||||||
(*databaseWithBlock).BlockNumber = testBlockNumber
|
|
||||||
|
|
||||||
batch = database.NewBatch()
|
batch = database.NewBatch()
|
||||||
})
|
})
|
||||||
AfterEach(func() {
|
AfterEach(func() {
|
||||||
|
|||||||
@@ -20,7 +20,6 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"math/big"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
@@ -33,9 +32,9 @@ import (
|
|||||||
var errNotSupported = errors.New("this operation is not supported")
|
var errNotSupported = errors.New("this operation is not supported")
|
||||||
|
|
||||||
var (
|
var (
|
||||||
hasPgStr = "SELECT exists(select 1 from public.blocks WHERE key = $1 LIMIT 1)"
|
hasPgStr = "SELECT exists(select 1 from public.blocks WHERE key = $1)"
|
||||||
getPgStr = "SELECT data FROM public.blocks WHERE key = $1 LIMIT 1"
|
getPgStr = "SELECT data FROM public.blocks WHERE key = $1"
|
||||||
putPgStr = "INSERT INTO public.blocks (key, data, block_number) VALUES ($1, $2, $3) ON CONFLICT DO NOTHING"
|
putPgStr = "INSERT INTO public.blocks (key, data) VALUES ($1, $2) ON CONFLICT (key) DO NOTHING"
|
||||||
deletePgStr = "DELETE FROM public.blocks WHERE key = $1"
|
deletePgStr = "DELETE FROM public.blocks WHERE key = $1"
|
||||||
dbSizePgStr = "SELECT pg_database_size(current_database())"
|
dbSizePgStr = "SELECT pg_database_size(current_database())"
|
||||||
)
|
)
|
||||||
@@ -46,8 +45,6 @@ var _ ethdb.Database = &Database{}
|
|||||||
type Database struct {
|
type Database struct {
|
||||||
db *sqlx.DB
|
db *sqlx.DB
|
||||||
cache *groupcache.Group
|
cache *groupcache.Group
|
||||||
|
|
||||||
BlockNumber *big.Int
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *Database) ModifyAncients(f func(ethdb.AncientWriteOp) error) (int64, error) {
|
func (d *Database) ModifyAncients(f func(ethdb.AncientWriteOp) error) (int64, error) {
|
||||||
@@ -139,7 +136,7 @@ func (d *Database) Put(key []byte, value []byte) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
_, err = d.db.Exec(putPgStr, mhKey, value, d.BlockNumber.Uint64())
|
_, err = d.db.Exec(putPgStr, mhKey, value)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -248,13 +245,13 @@ func (d *Database) Compact(start []byte, limit []byte) error {
|
|||||||
// NewBatch creates a write-only database that buffers changes to its host db
|
// NewBatch creates a write-only database that buffers changes to its host db
|
||||||
// until a final write is called
|
// until a final write is called
|
||||||
func (d *Database) NewBatch() ethdb.Batch {
|
func (d *Database) NewBatch() ethdb.Batch {
|
||||||
return NewBatch(d.db, nil, d.BlockNumber)
|
return NewBatch(d.db, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewBatchWithSize satisfies the ethdb.Batcher interface.
|
// NewBatchWithSize satisfies the ethdb.Batcher interface.
|
||||||
// NewBatchWithSize creates a write-only database batch with pre-allocated buffer.
|
// NewBatchWithSize creates a write-only database batch with pre-allocated buffer.
|
||||||
func (d *Database) NewBatchWithSize(size int) ethdb.Batch {
|
func (d *Database) NewBatchWithSize(size int) ethdb.Batch {
|
||||||
return NewBatch(d.db, nil, d.BlockNumber)
|
return NewBatch(d.db, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewIterator satisfies the ethdb.Iteratee interface
|
// NewIterator satisfies the ethdb.Iteratee interface
|
||||||
|
|||||||
+10
-15
@@ -28,18 +28,17 @@ import (
|
|||||||
. "github.com/onsi/ginkgo"
|
. "github.com/onsi/ginkgo"
|
||||||
. "github.com/onsi/gomega"
|
. "github.com/onsi/gomega"
|
||||||
|
|
||||||
pgipfsethdb "github.com/vulcanize/ipfs-ethdb/v4/postgres"
|
pgipfsethdb "github.com/vulcanize/ipfs-ethdb/v3/postgres"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
database ethdb.Database
|
database ethdb.Database
|
||||||
db *sqlx.DB
|
db *sqlx.DB
|
||||||
err error
|
err error
|
||||||
testBlockNumber = big.NewInt(1337)
|
testHeader = types.Header{Number: big.NewInt(1337)}
|
||||||
testHeader = types.Header{Number: testBlockNumber}
|
testValue, _ = rlp.EncodeToBytes(testHeader)
|
||||||
testValue, _ = rlp.EncodeToBytes(testHeader)
|
testEthKey = testHeader.Hash().Bytes()
|
||||||
testEthKey = testHeader.Hash().Bytes()
|
testMhKey, _ = pgipfsethdb.MultihashKeyFromKeccak256(testEthKey)
|
||||||
testMhKey, _ = pgipfsethdb.MultihashKeyFromKeccak256(testEthKey)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var _ = Describe("Database", func() {
|
var _ = Describe("Database", func() {
|
||||||
@@ -54,10 +53,6 @@ var _ = Describe("Database", func() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
database = pgipfsethdb.NewDatabase(db, cacheConfig)
|
database = pgipfsethdb.NewDatabase(db, cacheConfig)
|
||||||
|
|
||||||
databaseWithBlock, ok := database.(*pgipfsethdb.Database)
|
|
||||||
Expect(ok).To(BeTrue())
|
|
||||||
(*databaseWithBlock).BlockNumber = testBlockNumber
|
|
||||||
})
|
})
|
||||||
AfterEach(func() {
|
AfterEach(func() {
|
||||||
groupcache.DeregisterGroup("db")
|
groupcache.DeregisterGroup("db")
|
||||||
@@ -72,7 +67,7 @@ var _ = Describe("Database", func() {
|
|||||||
Expect(has).ToNot(BeTrue())
|
Expect(has).ToNot(BeTrue())
|
||||||
})
|
})
|
||||||
It("returns true if a key-pair exists in the db", func() {
|
It("returns true if a key-pair exists in the db", func() {
|
||||||
_, err = db.Exec("INSERT into public.blocks (key, data, block_number) VALUES ($1, $2, $3)", testMhKey, testValue, testBlockNumber.Uint64())
|
_, err = db.Exec("INSERT into public.blocks (key, data) VALUES ($1, $2)", testMhKey, testValue)
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
has, err := database.Has(testEthKey)
|
has, err := database.Has(testEthKey)
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
@@ -87,7 +82,7 @@ var _ = Describe("Database", func() {
|
|||||||
Expect(err.Error()).To(ContainSubstring("sql: no rows in result set"))
|
Expect(err.Error()).To(ContainSubstring("sql: no rows in result set"))
|
||||||
})
|
})
|
||||||
It("returns the value associated with the key, if the pair exists", func() {
|
It("returns the value associated with the key, if the pair exists", func() {
|
||||||
_, err = db.Exec("INSERT into public.blocks (key, data, block_number) VALUES ($1, $2, $3)", testMhKey, testValue, testBlockNumber.Uint64())
|
_, err = db.Exec("INSERT into public.blocks (key, data) VALUES ($1, $2)", testMhKey, testValue)
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
val, err := database.Get(testEthKey)
|
val, err := database.Get(testEthKey)
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
|
|||||||
+1
-1
@@ -18,7 +18,7 @@ import (
|
|||||||
"github.com/ethereum/go-ethereum/core/state"
|
"github.com/ethereum/go-ethereum/core/state"
|
||||||
"github.com/ethereum/go-ethereum/trie"
|
"github.com/ethereum/go-ethereum/trie"
|
||||||
"github.com/jmoiron/sqlx"
|
"github.com/jmoiron/sqlx"
|
||||||
"github.com/vulcanize/ipfs-ethdb/v4/postgres"
|
"github.com/vulcanize/ipfs-ethdb/v3/postgres"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|||||||
Reference in New Issue
Block a user