2018-11-07 21:50:43 +00:00
|
|
|
// VulcanizeDB
|
|
|
|
// Copyright © 2018 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/>.
|
2018-05-05 20:25:54 +00:00
|
|
|
|
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
2018-07-20 16:37:46 +00:00
|
|
|
"log"
|
|
|
|
"time"
|
|
|
|
|
2018-05-05 20:25:54 +00:00
|
|
|
"github.com/spf13/cobra"
|
2018-07-20 16:37:46 +00:00
|
|
|
|
2018-09-19 17:22:05 +00:00
|
|
|
"github.com/vulcanize/vulcanizedb/examples/erc20_watcher/event_triggered/dai"
|
2018-05-05 20:25:54 +00:00
|
|
|
"github.com/vulcanize/vulcanizedb/examples/erc20_watcher/every_block"
|
2018-09-19 17:22:05 +00:00
|
|
|
"github.com/vulcanize/vulcanizedb/examples/generic"
|
2018-05-05 20:25:54 +00:00
|
|
|
"github.com/vulcanize/vulcanizedb/libraries/shared"
|
2018-11-23 18:12:24 +00:00
|
|
|
"github.com/vulcanize/vulcanizedb/pkg/omni/shared/constants"
|
2018-11-15 18:53:08 +00:00
|
|
|
"github.com/vulcanize/vulcanizedb/utils"
|
2018-05-05 20:25:54 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// erc20Cmd represents the erc20 command
|
|
|
|
var erc20Cmd = &cobra.Command{
|
|
|
|
Use: "erc20",
|
|
|
|
Short: "Fetches and persists token supply",
|
2018-09-19 17:22:05 +00:00
|
|
|
Long: `Fetches transfer and approval events, totalSupply, allowances, and
|
|
|
|
balances for the configured token from each block and persists it in Vulcanize DB.
|
2018-05-05 20:25:54 +00:00
|
|
|
vulcanizedb erc20 --config environments/public
|
|
|
|
|
|
|
|
Expects an ethereum node to be running and requires a .toml config file:
|
|
|
|
|
|
|
|
[database]
|
|
|
|
name = "vulcanize_public"
|
|
|
|
hostname = "localhost"
|
|
|
|
port = 5432
|
|
|
|
|
|
|
|
[client]
|
|
|
|
ipcPath = "/Users/user/Library/Ethereum/geth.ipc"
|
|
|
|
`,
|
|
|
|
Run: func(cmd *cobra.Command, args []string) {
|
|
|
|
watchERC20s()
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
func watchERC20s() {
|
|
|
|
ticker := time.NewTicker(5 * time.Second)
|
|
|
|
defer ticker.Stop()
|
2018-11-15 18:53:08 +00:00
|
|
|
|
|
|
|
blockChain := getBlockChain()
|
|
|
|
db := utils.LoadPostgres(databaseConfig, blockChain.Node())
|
2018-09-19 17:22:05 +00:00
|
|
|
|
|
|
|
con := generic.DaiConfig
|
|
|
|
con.Filters = constants.DaiERC20Filters
|
2018-05-05 20:25:54 +00:00
|
|
|
watcher := shared.Watcher{
|
2018-11-15 18:53:08 +00:00
|
|
|
DB: db,
|
2018-07-18 20:59:40 +00:00
|
|
|
Blockchain: blockChain,
|
2018-05-05 20:25:54 +00:00
|
|
|
}
|
|
|
|
|
2018-09-19 17:22:05 +00:00
|
|
|
// It is important that the event transformer is executed before the every_block transformer
|
|
|
|
// because the events are used to generate the token holder address list that is used to
|
|
|
|
// collect balances and allowances at every block
|
|
|
|
transformers := append(dai.DaiEventTriggeredTransformerInitializer(), every_block.ERC20EveryBlockTransformerInitializer()...)
|
|
|
|
|
2018-11-15 18:53:08 +00:00
|
|
|
err := watcher.AddTransformers(transformers, con)
|
2018-09-19 17:22:05 +00:00
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2018-05-05 20:25:54 +00:00
|
|
|
for range ticker.C {
|
|
|
|
watcher.Execute()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
rootCmd.AddCommand(erc20Cmd)
|
|
|
|
}
|