Skip to content
This repository was archived by the owner on Aug 31, 2021. It is now read-only.

Commit 6580899

Browse files
committed
goimports -w; golinting, remove some unused code
1 parent 11b5efb commit 6580899

34 files changed

+175
-170
lines changed

integration_test/contract_watcher_full_transformer_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ package integration
1818

1919
import (
2020
"fmt"
21-
"github.com/vulcanize/vulcanizedb/pkg/config"
2221
"math/rand"
2322
"strings"
2423
"time"
@@ -27,6 +26,7 @@ import (
2726
. "github.com/onsi/ginkgo"
2827
. "github.com/onsi/gomega"
2928

29+
"github.com/vulcanize/vulcanizedb/pkg/config"
3030
"github.com/vulcanize/vulcanizedb/pkg/contract_watcher/full/transformer"
3131
"github.com/vulcanize/vulcanizedb/pkg/contract_watcher/shared/constants"
3232
"github.com/vulcanize/vulcanizedb/pkg/contract_watcher/shared/helpers/test_helpers"

pkg/contract_watcher/full/converter/converter.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
package converter
1818

1919
import (
20-
"errors"
2120
"fmt"
2221
"math/big"
2322
"strconv"
@@ -32,22 +31,24 @@ import (
3231
"github.com/vulcanize/vulcanizedb/pkg/core"
3332
)
3433

35-
// Converter is used to convert watched event logs to
34+
// ConverterInterface is used to convert watched event logs to
3635
// custom logs containing event input name => value maps
3736
type ConverterInterface interface {
3837
Convert(watchedEvent core.WatchedEvent, event types.Event) (*types.Log, error)
3938
Update(info *contract.Contract)
4039
}
4140

41+
// Converter is the underlying struct for the ConverterInterface
4242
type Converter struct {
4343
ContractInfo *contract.Contract
4444
}
4545

46+
// Update configures the converter for a specific contract
4647
func (c *Converter) Update(info *contract.Contract) {
4748
c.ContractInfo = info
4849
}
4950

50-
// Convert the given watched event log into a types.Log for the given event
51+
// Convert converts the given watched event log into a types.Log for the given event
5152
func (c *Converter) Convert(watchedEvent core.WatchedEvent, event types.Event) (*types.Log, error) {
5253
boundContract := bind.NewBoundContract(common.HexToAddress(c.ContractInfo.Address), c.ContractInfo.ParsedAbi, nil, nil, nil)
5354
values := make(map[string]interface{})
@@ -88,14 +89,14 @@ func (c *Converter) Convert(watchedEvent core.WatchedEvent, event types.Event) (
8889
b := input.(byte)
8990
strValues[fieldName] = string(b)
9091
default:
91-
return nil, errors.New(fmt.Sprintf("error: unhandled abi type %T", input))
92+
return nil, fmt.Errorf("error: unhandled abi type %T", input)
9293
}
9394
}
9495

9596
// Only hold onto logs that pass our address filter, if any
9697
if c.ContractInfo.PassesEventFilter(strValues) {
9798
eventLog := &types.Log{
98-
Id: watchedEvent.LogID,
99+
ID: watchedEvent.LogID,
99100
Values: strValues,
100101
Block: watchedEvent.BlockNumber,
101102
Tx: watchedEvent.TxHash,

pkg/contract_watcher/full/retriever/block_retriever.go

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,12 @@ package retriever
1818

1919
import (
2020
"database/sql"
21+
2122
"github.com/vulcanize/vulcanizedb/libraries/shared/repository"
2223
"github.com/vulcanize/vulcanizedb/pkg/datastore/postgres"
2324
)
2425

25-
// Block retriever is used to retrieve the first block for a given contract and the most recent block
26+
// BlockRetriever is used to retrieve the first block for a given contract and the most recent block
2627
// It requires a vDB synced database with blocks, transactions, receipts, and logs
2728
type BlockRetriever interface {
2829
RetrieveFirstBlock(contractAddr string) (int64, error)
@@ -33,13 +34,15 @@ type blockRetriever struct {
3334
db *postgres.DB
3435
}
3536

36-
func NewBlockRetriever(db *postgres.DB) (r *blockRetriever) {
37+
// NewBlockRetriever returns a new BlockRetriever
38+
func NewBlockRetriever(db *postgres.DB) BlockRetriever {
3739
return &blockRetriever{
3840
db: db,
3941
}
4042
}
4143

42-
// Try both methods of finding the first block, with the receipt method taking precedence
44+
// RetrieveFirstBlock fetches the block number for the earliest block in the db
45+
// Tries both methods of finding the first block, with the receipt method taking precedence
4346
func (r *blockRetriever) RetrieveFirstBlock(contractAddr string) (int64, error) {
4447
i, err := r.retrieveFirstBlockFromReceipts(contractAddr)
4548
if err != nil {
@@ -55,7 +58,7 @@ func (r *blockRetriever) RetrieveFirstBlock(contractAddr string) (int64, error)
5558
// For some contracts the contract creation transaction receipt doesn't have the contract address so this doesn't work (e.g. Sai)
5659
func (r *blockRetriever) retrieveFirstBlockFromReceipts(contractAddr string) (int64, error) {
5760
var firstBlock int64
58-
addressId, getAddressErr := repository.GetOrCreateAddress(r.db, contractAddr)
61+
addressID, getAddressErr := repository.GetOrCreateAddress(r.db, contractAddr)
5962
if getAddressErr != nil {
6063
return firstBlock, getAddressErr
6164
}
@@ -66,7 +69,7 @@ func (r *blockRetriever) retrieveFirstBlockFromReceipts(contractAddr string) (in
6669
WHERE contract_address_id = $1
6770
ORDER BY block_id ASC
6871
LIMIT 1)`,
69-
addressId,
72+
addressID,
7073
)
7174

7275
return firstBlock, err
@@ -84,7 +87,7 @@ func (r *blockRetriever) retrieveFirstBlockFromLogs(contractAddr string) (int64,
8487
return int64(firstBlock), err
8588
}
8689

87-
// Method to retrieve the most recent block in vDB
90+
// RetrieveMostRecentBlock retrieves the most recent block number in vDB
8891
func (r *blockRetriever) RetrieveMostRecentBlock() (int64, error) {
8992
var lastBlock int64
9093
err := r.db.Get(

pkg/contract_watcher/full/retriever/block_retriever_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,11 @@
1717
package retriever_test
1818

1919
import (
20+
"strings"
21+
2022
"github.com/ethereum/go-ethereum/core/types"
2123
. "github.com/onsi/ginkgo"
2224
. "github.com/onsi/gomega"
23-
"strings"
2425

2526
"github.com/vulcanize/vulcanizedb/pkg/contract_watcher/full/retriever"
2627
"github.com/vulcanize/vulcanizedb/pkg/contract_watcher/shared/constants"

pkg/contract_watcher/full/retriever/retriever_suite_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@
1717
package retriever_test
1818

1919
import (
20-
"github.com/sirupsen/logrus"
2120
"io/ioutil"
2221
"testing"
2322

2423
. "github.com/onsi/ginkgo"
2524
. "github.com/onsi/gomega"
25+
"github.com/sirupsen/logrus"
2626
)
2727

2828
func TestRetriever(t *testing.T) {

pkg/contract_watcher/full/transformer/transformer.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import (
3535
"github.com/vulcanize/vulcanizedb/pkg/datastore/postgres/repositories"
3636
)
3737

38+
// Transformer is the top level struct for transforming watched contract data
3839
// Requires a fully synced vDB and a running eth node (or infura)
3940
type Transformer struct {
4041
// Database interfaces
@@ -60,7 +61,7 @@ type Transformer struct {
6061
LastBlock int64
6162
}
6263

63-
// Transformer takes in config for blockchain, database, and network id
64+
// NewTransformer takes in contract config, blockchain, and database, and returns a new Transformer
6465
func NewTransformer(con config.ContractConfig, BC core.BlockChain, DB *postgres.DB) *Transformer {
6566
return &Transformer{
6667
Poller: poller.NewPoller(BC, DB, types.FullSync),
@@ -75,6 +76,7 @@ func NewTransformer(con config.ContractConfig, BC core.BlockChain, DB *postgres.
7576
}
7677
}
7778

79+
// Init initializes the transformer
7880
// Use after creating and setting transformer
7981
// Loops over all of the addr => filter sets
8082
// Uses parser to pull event info from abi
@@ -167,6 +169,7 @@ func (tr *Transformer) Init() error {
167169
return nil
168170
}
169171

172+
// Execute runs the transformation processes
170173
// Iterates through stored, initialized contract objects
171174
// Iterates through contract's event filters, grabbing watched event logs
172175
// Uses converter to convert logs into custom log type
@@ -227,6 +230,7 @@ func (tr *Transformer) Execute() error {
227230
return nil
228231
}
229232

233+
// GetConfig returns the transformers config; satisfies the transformer interface
230234
func (tr *Transformer) GetConfig() config.ContractConfig {
231235
return tr.Config
232236
}

pkg/contract_watcher/full/transformer/transformer_suite_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@
1717
package transformer_test
1818

1919
import (
20-
"github.com/sirupsen/logrus"
2120
"io/ioutil"
2221
"testing"
2322

2423
. "github.com/onsi/ginkgo"
2524
. "github.com/onsi/gomega"
25+
"github.com/sirupsen/logrus"
2626
)
2727

2828
func TestTransformer(t *testing.T) {

pkg/contract_watcher/header/converter/converter.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ package converter
1818

1919
import (
2020
"encoding/json"
21-
"errors"
2221
"fmt"
2322
"math/big"
2423
"strconv"
@@ -32,16 +31,19 @@ import (
3231
"github.com/vulcanize/vulcanizedb/pkg/contract_watcher/shared/types"
3332
)
3433

34+
// ConverterInterface is the interface for converting geth logs to our custom log type
3535
type ConverterInterface interface {
3636
Convert(logs []gethTypes.Log, event types.Event, headerID int64) ([]types.Log, error)
3737
ConvertBatch(logs []gethTypes.Log, events map[string]types.Event, headerID int64) (map[string][]types.Log, error)
3838
Update(info *contract.Contract)
3939
}
4040

41+
// Converter is the underlying struct for the ConverterInterface
4142
type Converter struct {
4243
ContractInfo *contract.Contract
4344
}
4445

46+
// Update is used to configure the converter with a specific contract
4547
func (c *Converter) Update(info *contract.Contract) {
4648
c.ContractInfo = info
4749
}
@@ -98,7 +100,7 @@ func (c *Converter) Convert(logs []gethTypes.Log, event types.Event, headerID in
98100
strValues[fieldName] = converted.String()
99101
seenHashes = append(seenHashes, converted)
100102
default:
101-
return nil, errors.New(fmt.Sprintf("error: unhandled abi type %T", input))
103+
return nil, fmt.Errorf("error: unhandled abi type %T", input)
102104
}
103105
}
104106

@@ -114,7 +116,7 @@ func (c *Converter) Convert(logs []gethTypes.Log, event types.Event, headerID in
114116
Values: strValues,
115117
Raw: raw,
116118
TransactionIndex: log.TxIndex,
117-
Id: headerID,
119+
ID: headerID,
118120
})
119121

120122
// Cache emitted values if their caching is turned on
@@ -130,7 +132,7 @@ func (c *Converter) Convert(logs []gethTypes.Log, event types.Event, headerID in
130132
return returnLogs, nil
131133
}
132134

133-
// Convert the given watched event logs into types.Logs; returns a map of event names to a slice of their converted logs
135+
// ConvertBatch converts the given watched event logs into types.Logs; returns a map of event names to a slice of their converted logs
134136
func (c *Converter) ConvertBatch(logs []gethTypes.Log, events map[string]types.Event, headerID int64) (map[string][]types.Log, error) {
135137
boundContract := bind.NewBoundContract(common.HexToAddress(c.ContractInfo.Address), c.ContractInfo.ParsedAbi, nil, nil, nil)
136138
eventsToLogs := make(map[string][]types.Log)
@@ -182,7 +184,7 @@ func (c *Converter) ConvertBatch(logs []gethTypes.Log, events map[string]types.E
182184
strValues[fieldName] = converted.String()
183185
seenHashes = append(seenHashes, converted)
184186
default:
185-
return nil, errors.New(fmt.Sprintf("error: unhandled abi type %T", input))
187+
return nil, fmt.Errorf("error: unhandled abi type %T", input)
186188
}
187189
}
188190

@@ -198,7 +200,7 @@ func (c *Converter) ConvertBatch(logs []gethTypes.Log, events map[string]types.E
198200
Values: strValues,
199201
Raw: raw,
200202
TransactionIndex: log.TxIndex,
201-
Id: headerID,
203+
ID: headerID,
202204
})
203205

204206
// Cache emitted values that pass the argument filter if their caching is turned on

pkg/contract_watcher/header/converter/converter_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,11 @@ var _ = Describe("Converter", func() {
7272
Expect(logs[0].Values["to"]).To(Equal(sender1.String()))
7373
Expect(logs[0].Values["from"]).To(Equal(sender2.String()))
7474
Expect(logs[0].Values["value"]).To(Equal(value.String()))
75-
Expect(logs[0].Id).To(Equal(int64(232)))
75+
Expect(logs[0].ID).To(Equal(int64(232)))
7676
Expect(logs[1].Values["to"]).To(Equal(sender2.String()))
7777
Expect(logs[1].Values["from"]).To(Equal(sender1.String()))
7878
Expect(logs[1].Values["value"]).To(Equal(value.String()))
79-
Expect(logs[1].Id).To(Equal(int64(232)))
79+
Expect(logs[1].ID).To(Equal(int64(232)))
8080
})
8181

8282
It("Keeps track of addresses it sees if they will be used for method polling", func() {

pkg/contract_watcher/header/fetcher/fetcher.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
"github.com/vulcanize/vulcanizedb/pkg/core"
2525
)
2626

27+
// Fetcher is the fetching interface
2728
type Fetcher interface {
2829
FetchLogs(contractAddresses []string, topics []common.Hash, missingHeader core.Header) ([]types.Log, error)
2930
}
@@ -32,13 +33,14 @@ type fetcher struct {
3233
blockChain core.BlockChain
3334
}
3435

35-
func NewFetcher(blockchain core.BlockChain) *fetcher {
36+
// NewFetcher returns a new Fetcher
37+
func NewFetcher(blockchain core.BlockChain) Fetcher {
3638
return &fetcher{
3739
blockChain: blockchain,
3840
}
3941
}
4042

41-
// Checks all topic0s, on all addresses, fetching matching logs for the given header
43+
// FetchLogs checks all topic0s, on all addresses, fetching matching logs for the given header
4244
func (fetcher *fetcher) FetchLogs(contractAddresses []string, topic0s []common.Hash, header core.Header) ([]types.Log, error) {
4345
addresses := hexStringsToAddresses(contractAddresses)
4446
blockHash := common.HexToHash(header.Hash)

0 commit comments

Comments
 (0)