From 77bd30901db638833feca646fdb34f9434171462 Mon Sep 17 00:00:00 2001 From: Ian Norden Date: Wed, 17 Jun 2020 11:33:19 -0500 Subject: [PATCH] golint, add go report card --- README.md | 9 ++++++++- batch.go | 2 ++ database.go | 5 ++++- iterator.go | 6 +++++- 4 files changed, 19 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index d0d9d9a..7a9dcf3 100644 --- a/README.md +++ b/README.md @@ -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 } ``` diff --git a/batch.go b/batch.go index f90f52a..de7f14d 100644 --- a/batch.go +++ b/batch.go @@ -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, diff --git a/database.go b/database.go index e8d9028..4ee318a 100644 --- a/database.go +++ b/database.go @@ -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 diff --git a/iterator.go b/iterator.go index 3336eeb..a1e45dd 100644 --- a/iterator.go +++ b/iterator.go @@ -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,