golint, add go report card

This commit is contained in:
Ian Norden 2020-06-17 11:33:19 -05:00
parent 750fa6bbd5
commit 77bd30901d
4 changed files with 19 additions and 3 deletions

View File

@ -1,5 +1,6 @@
## pg-ipfs-ethdb
[![Go Report Card](https://goreportcard.com/badge/github.com/vulcanize/pg-ipfs-ethdb)](https://goreportcard.com/report/github.com/vulcanize/pg-ipfs-ethdb)
> go-ethereum ethdb interfaces for Ethereum state data stored in Postgres-backed IPFS
@ -29,6 +30,8 @@ with a few exceptions:
package main
import (
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/state"
"github.com/ethereum/go-ethereum/trie"
"github.com/jmoiron/sqlx"
"github.com/vulcanize/pg-ipfs-ethdb"
@ -40,8 +43,12 @@ func main() {
kvs := ipfsethdb.NewKeyValueStore(db)
trieDB := trie.NewDatabase(kvs)
trie, _ := trie.New(common.Hash{}, trieDB)
// do stuff with trie or trieDB
// do stuff
database := ipfsethdb.NewDatabase(db)
statedb := state.NewDatabase(database)
// do stuff with the state database
}
```

View File

@ -21,12 +21,14 @@ import (
"github.com/jmoiron/sqlx"
)
// Batch is the type that satisfies the ethdb.Batch interface for PG-IPFS Ethereum data
type Batch struct {
db *sqlx.DB
tx *sqlx.Tx
size int
}
// NewBatch returns a ethdb.Batch interface for PG-IPFS
func NewBatch(db *sqlx.DB) ethdb.Batch {
return &Batch{
db: db,

View File

@ -35,16 +35,19 @@ var (
dbSizePgStr = "SELECT pg_database_size(current_database())"
)
// Database is the type that satisfies the ethdb.Database and ethdb.KeyValueStore interfaces for PG-IPFS Ethereum data
type Database struct {
db *sqlx.DB
}
// NewKeyValueStore returns a ethdb.KeyValueStore interface for PG-IPFS
func NewKeyValueStore(db *sqlx.DB) ethdb.KeyValueStore {
return &Database{
db: db,
}
}
// NewDatabase returns a ethdb.Database interface for PG-IPFS
func NewDatabase(db *sqlx.DB) ethdb.Database {
return &Database{
db: db,
@ -190,7 +193,7 @@ func (d *Database) NewBatch() ethdb.Batch {
// Note: This method assumes that the prefix is NOT part of the start, so there's
// no need for the caller to prepend the prefix to the start
func (d *Database) NewIterator(prefix []byte, start []byte) ethdb.Iterator {
return NewIterator([]byte{}, []byte{}, d.db)
return NewIterator(start, prefix, d.db)
}
// Close satisfies the io.Closer interface

View File

@ -21,14 +21,18 @@ import (
"github.com/jmoiron/sqlx"
)
// We don't need these iterator interfaces right now
// Iterator is the type that satisfies the ethdb.Iterator interface for PG-IPFS Ethereum data
// Iteratee interface is only used in Geth for various tests, trie/sync_bloom.go (for fast sync), and rawdb.InspectDatabase
// Don't need this interface for the majority of state operations
// This should not be confused with trie.NodeIterator or state.NodeIteraor (which can be constructed from the ethdb.KeyValueStore and ethdb.Database interfaces)
// ethdb.KeyValueStore => trie.Database => trie.Trie => trie.NodeIterator
type Iterator struct {
db *sqlx.DB
currentKey, prefix []byte
err error
}
// NewIterator returns a ethdb.Iterator interface for PG-IPFS
func NewIterator(start, prefix []byte, db *sqlx.DB) ethdb.Iterator {
return &Iterator{
db: db,