2020-01-17 23:16:01 +00:00
|
|
|
// VulcanizeDB
|
|
|
|
// Copyright © 2019 Vulcanize
|
|
|
|
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU Affero General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU Affero General Public License for more details.
|
|
|
|
|
|
|
|
// You should have received a copy of the GNU Affero General Public License
|
|
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
2020-02-03 18:22:29 +00:00
|
|
|
package eth
|
2020-01-17 23:16:01 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"math/big"
|
|
|
|
|
|
|
|
"github.com/spf13/viper"
|
2020-02-03 18:22:29 +00:00
|
|
|
|
2020-06-22 18:12:32 +00:00
|
|
|
"github.com/vulcanize/ipfs-blockchain-watcher/pkg/shared"
|
2020-01-17 23:16:01 +00:00
|
|
|
)
|
|
|
|
|
2020-02-03 18:22:29 +00:00
|
|
|
// SubscriptionSettings config is used by a subscriber to specify what eth data to stream from the super node
|
|
|
|
type SubscriptionSettings struct {
|
2020-01-17 23:16:01 +00:00
|
|
|
BackFill bool
|
|
|
|
BackFillOnly bool
|
|
|
|
Start *big.Int
|
|
|
|
End *big.Int // set to 0 or a negative value to have no ending block
|
|
|
|
HeaderFilter HeaderFilter
|
|
|
|
TxFilter TxFilter
|
|
|
|
ReceiptFilter ReceiptFilter
|
|
|
|
StateFilter StateFilter
|
|
|
|
StorageFilter StorageFilter
|
|
|
|
}
|
|
|
|
|
|
|
|
// HeaderFilter contains filter settings for headers
|
|
|
|
type HeaderFilter struct {
|
|
|
|
Off bool
|
|
|
|
Uncles bool
|
|
|
|
}
|
|
|
|
|
|
|
|
// TxFilter contains filter settings for txs
|
|
|
|
type TxFilter struct {
|
|
|
|
Off bool
|
|
|
|
Src []string
|
|
|
|
Dst []string
|
|
|
|
}
|
|
|
|
|
|
|
|
// ReceiptFilter contains filter settings for receipts
|
|
|
|
type ReceiptFilter struct {
|
2020-02-23 23:14:29 +00:00
|
|
|
Off bool
|
|
|
|
// TODO: change this so that we filter for receipts first and we always return the corresponding transaction
|
2020-04-02 03:34:06 +00:00
|
|
|
MatchTxs bool // turn on to retrieve receipts that pair with retrieved transactions
|
|
|
|
LogAddresses []string // receipt contains logs from the provided addresses
|
|
|
|
Topics [][]string
|
2020-01-17 23:16:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// StateFilter contains filter settings for state
|
|
|
|
type StateFilter struct {
|
|
|
|
Off bool
|
|
|
|
Addresses []string // is converted to state key by taking its keccak256 hash
|
|
|
|
IntermediateNodes bool
|
|
|
|
}
|
|
|
|
|
|
|
|
// StorageFilter contains filter settings for storage
|
|
|
|
type StorageFilter struct {
|
|
|
|
Off bool
|
|
|
|
Addresses []string
|
2020-02-23 23:14:29 +00:00
|
|
|
StorageKeys []string // need to be the hashs key themselves not slot position
|
2020-01-17 23:16:01 +00:00
|
|
|
IntermediateNodes bool
|
|
|
|
}
|
|
|
|
|
|
|
|
// Init is used to initialize a EthSubscription struct with env variables
|
2020-02-03 18:22:29 +00:00
|
|
|
func NewEthSubscriptionConfig() (*SubscriptionSettings, error) {
|
|
|
|
sc := new(SubscriptionSettings)
|
2020-01-17 23:16:01 +00:00
|
|
|
// Below default to false, which means we do not backfill by default
|
|
|
|
sc.BackFill = viper.GetBool("superNode.ethSubscription.historicalData")
|
|
|
|
sc.BackFillOnly = viper.GetBool("superNode.ethSubscription.historicalDataOnly")
|
|
|
|
// Below default to 0
|
|
|
|
// 0 start means we start at the beginning and 0 end means we continue indefinitely
|
|
|
|
sc.Start = big.NewInt(viper.GetInt64("superNode.ethSubscription.startingBlock"))
|
|
|
|
sc.End = big.NewInt(viper.GetInt64("superNode.ethSubscription.endingBlock"))
|
|
|
|
// Below default to false, which means we get all headers and no uncles by default
|
|
|
|
sc.HeaderFilter = HeaderFilter{
|
2020-02-05 01:02:01 +00:00
|
|
|
Off: viper.GetBool("superNode.ethSubscription.headerFilter.off"),
|
|
|
|
Uncles: viper.GetBool("superNode.ethSubscription.headerFilter.uncles"),
|
2020-01-17 23:16:01 +00:00
|
|
|
}
|
|
|
|
// Below defaults to false and two slices of length 0
|
|
|
|
// Which means we get all transactions by default
|
|
|
|
sc.TxFilter = TxFilter{
|
2020-01-21 19:12:35 +00:00
|
|
|
Off: viper.GetBool("superNode.ethSubscription.txFilter.off"),
|
|
|
|
Src: viper.GetStringSlice("superNode.ethSubscription.txFilter.src"),
|
|
|
|
Dst: viper.GetStringSlice("superNode.ethSubscription.txFilter.dst"),
|
2020-01-17 23:16:01 +00:00
|
|
|
}
|
2020-02-23 23:14:29 +00:00
|
|
|
// By default all of the topic slices will be empty => match on any/all topics
|
|
|
|
topics := make([][]string, 4)
|
|
|
|
topics[0] = viper.GetStringSlice("superNode.ethSubscription.receiptFilter.topic0s")
|
|
|
|
topics[1] = viper.GetStringSlice("superNode.ethSubscription.receiptFilter.topic1s")
|
|
|
|
topics[2] = viper.GetStringSlice("superNode.ethSubscription.receiptFilter.topic2s")
|
|
|
|
topics[3] = viper.GetStringSlice("superNode.ethSubscription.receiptFilter.topic3s")
|
2020-01-17 23:16:01 +00:00
|
|
|
sc.ReceiptFilter = ReceiptFilter{
|
2020-04-02 03:34:06 +00:00
|
|
|
Off: viper.GetBool("superNode.ethSubscription.receiptFilter.off"),
|
|
|
|
MatchTxs: viper.GetBool("superNode.ethSubscription.receiptFilter.matchTxs"),
|
|
|
|
LogAddresses: viper.GetStringSlice("superNode.ethSubscription.receiptFilter.contracts"),
|
|
|
|
Topics: topics,
|
2020-01-17 23:16:01 +00:00
|
|
|
}
|
|
|
|
// Below defaults to two false, and a slice of length 0
|
|
|
|
// Which means we get all state leafs by default, but no intermediate nodes
|
|
|
|
sc.StateFilter = StateFilter{
|
|
|
|
Off: viper.GetBool("superNode.ethSubscription.stateFilter.off"),
|
|
|
|
IntermediateNodes: viper.GetBool("superNode.ethSubscription.stateFilter.intermediateNodes"),
|
|
|
|
Addresses: viper.GetStringSlice("superNode.ethSubscription.stateFilter.addresses"),
|
|
|
|
}
|
|
|
|
// Below defaults to two false, and two slices of length 0
|
|
|
|
// Which means we get all storage leafs by default, but no intermediate nodes
|
|
|
|
sc.StorageFilter = StorageFilter{
|
|
|
|
Off: viper.GetBool("superNode.ethSubscription.storageFilter.off"),
|
|
|
|
IntermediateNodes: viper.GetBool("superNode.ethSubscription.storageFilter.intermediateNodes"),
|
|
|
|
Addresses: viper.GetStringSlice("superNode.ethSubscription.storageFilter.addresses"),
|
|
|
|
StorageKeys: viper.GetStringSlice("superNode.ethSubscription.storageFilter.storageKeys"),
|
|
|
|
}
|
2020-01-21 19:12:35 +00:00
|
|
|
return sc, nil
|
2020-01-17 23:16:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// StartingBlock satisfies the SubscriptionSettings() interface
|
2020-02-03 18:22:29 +00:00
|
|
|
func (sc *SubscriptionSettings) StartingBlock() *big.Int {
|
2020-01-17 23:16:01 +00:00
|
|
|
return sc.Start
|
|
|
|
}
|
|
|
|
|
|
|
|
// EndingBlock satisfies the SubscriptionSettings() interface
|
2020-02-03 18:22:29 +00:00
|
|
|
func (sc *SubscriptionSettings) EndingBlock() *big.Int {
|
2020-01-17 23:16:01 +00:00
|
|
|
return sc.End
|
|
|
|
}
|
|
|
|
|
|
|
|
// HistoricalData satisfies the SubscriptionSettings() interface
|
2020-02-03 18:22:29 +00:00
|
|
|
func (sc *SubscriptionSettings) HistoricalData() bool {
|
2020-01-17 23:16:01 +00:00
|
|
|
return sc.BackFill
|
|
|
|
}
|
|
|
|
|
|
|
|
// HistoricalDataOnly satisfies the SubscriptionSettings() interface
|
2020-02-03 18:22:29 +00:00
|
|
|
func (sc *SubscriptionSettings) HistoricalDataOnly() bool {
|
2020-01-17 23:16:01 +00:00
|
|
|
return sc.BackFillOnly
|
|
|
|
}
|
|
|
|
|
|
|
|
// ChainType satisfies the SubscriptionSettings() interface
|
2020-02-03 18:22:29 +00:00
|
|
|
func (sc *SubscriptionSettings) ChainType() shared.ChainType {
|
|
|
|
return shared.Ethereum
|
2020-01-17 23:16:01 +00:00
|
|
|
}
|