github.com/0xsequence/ethkit@v1.25.0/cmd/ethkit/_receipts.go (about) 1 package main 2 3 import ( 4 "context" 5 "fmt" 6 "time" 7 8 "github.com/0xsequence/ethkit/ethmonitor" 9 "github.com/0xsequence/ethkit/ethreceipts" 10 "github.com/0xsequence/ethkit/ethrpc" 11 "github.com/goware/logger" 12 "github.com/spf13/cobra" 13 ) 14 15 func init() { 16 watch := &watch{} 17 cmd := &cobra.Command{ 18 Use: "receipts", 19 Short: "Receipts ... etc..", 20 Run: watch.Run, 21 } 22 23 // cmd.Flags().String("file", "", "path to truffle contract artifacts file (required)") 24 // cmd.Flags().Bool("abi", false, "abi") 25 // cmd.Flags().Bool("bytecode", false, "bytecode") 26 27 rootCmd.AddCommand(cmd) 28 } 29 30 type watch struct { 31 } 32 33 func (c *watch) Run(cmd *cobra.Command, args []string) { 34 fmt.Println("xx") 35 36 log := logger.NewLogger(logger.LogLevel_DEBUG) 37 38 provider, err := ethrpc.NewProvider("https://xxx") 39 if err != nil { 40 panic(err) 41 } 42 43 monitorOptions := ethmonitor.DefaultOptions 44 monitorOptions.Logger = log 45 monitorOptions.WithLogs = true 46 monitorOptions.BlockRetentionLimit = 1000 47 48 monitor, err := ethmonitor.NewMonitor(provider, monitorOptions) 49 if err != nil { 50 panic(err) 51 } 52 53 receipts, err := ethreceipts.NewReceiptsListener(log, provider, monitor) 54 if err != nil { 55 panic(err) 56 } 57 58 go func() { 59 err := monitor.Run(context.Background()) 60 if err != nil { 61 panic(err) 62 } 63 }() 64 65 go func() { 66 err := receipts.Run(context.Background()) 67 if err != nil { 68 panic(err) 69 } 70 }() 71 72 time.Sleep(10 * time.Minute) 73 74 // fFile, _ := cmd.Flags().GetString("file") 75 // fAbi, _ := cmd.Flags().GetBool("abi") 76 // fBytecode, _ := cmd.Flags().GetBool("bytecode") 77 78 // if fFile == "" { 79 // fmt.Println("error: please pass --file") 80 // help(cmd) 81 // return 82 // } 83 // if !fAbi && !fBytecode { 84 // fmt.Println("error: please pass either --abi or --bytecode") 85 // help(cmd) 86 // return 87 // } 88 // if fAbi && fBytecode { 89 // fmt.Println("error: please pass either --abi or --bytecode, not both") 90 // help(cmd) 91 // return 92 // } 93 94 // artifacts, err := ethartifact.ParseArtifactFile(fFile) 95 // if err != nil { 96 // log.Fatal(err) 97 // return 98 // } 99 100 // if fAbi { 101 // fmt.Println(string(artifacts.ABI)) 102 // } 103 104 // if fBytecode { 105 // fmt.Println(artifacts.Bytecode) 106 // } 107 }