@@ -16,14 +16,24 @@ limitations under the License.
16
16
package cmd
17
17
18
18
import (
19
+ "context"
19
20
"fmt"
21
+ "log"
22
+ "math/big"
23
+ "strings"
20
24
25
+ "github.com/ethereum/go-ethereum"
26
+ "github.com/ethereum/go-ethereum/accounts/abi"
27
+ "github.com/ethereum/go-ethereum/common"
28
+ "github.com/ethereum/go-ethereum/ethclient"
21
29
"github.com/spf13/cobra"
30
+
31
+ jobManager "razor/pkg/bindings"
22
32
)
23
33
24
34
// jobCmd represents the job command
25
35
var jobCmd = & cobra.Command {
26
- Use : "job " ,
36
+ Use : "jobs " ,
27
37
Short : "A brief description of your command" ,
28
38
Long : `A longer description that spans multiple lines and likely contains examples
29
39
and usage of using your command. For example:
@@ -32,8 +42,46 @@ Cobra is a CLI library for Go that empowers applications.
32
42
This application is a tool to generate the needed files
33
43
to quickly create a Cobra application.` ,
34
44
Run : func (cmd * cobra.Command , args []string ) {
35
- fmt .Println ("job called" )
36
- fmt .Println (args )
45
+ fmt .Println ("Job command called" )
46
+
47
+ client , err := ethclient .Dial ("wss://goerli.infura.io/ws/v3/0d8f675eedad42cb82600b8e208b3465" )
48
+ if err != nil {
49
+ log .Fatal (err )
50
+ }
51
+
52
+ header , err := client .HeaderByNumber (context .Background (), nil )
53
+ if err != nil {
54
+ log .Fatal (err )
55
+ }
56
+
57
+ contractAddress := common .HexToAddress ("0x264F48268dCEA2E264333B40dfe7d82fB8837E23" )
58
+ query := ethereum.FilterQuery {
59
+ FromBlock : big .NewInt (0 ).Sub (header .Number , big .NewInt (1000 )),
60
+ ToBlock : header .Number ,
61
+ Addresses : []common.Address {
62
+ contractAddress ,
63
+ },
64
+ }
65
+
66
+ logs , err := client .FilterLogs (context .Background (), query )
67
+ if err != nil {
68
+ log .Fatal (err )
69
+ }
70
+
71
+ contractAbi , err := abi .JSON (strings .NewReader (string (jobManager .JobManagerABI )))
72
+ if err != nil {
73
+ log .Fatal (err )
74
+ }
75
+
76
+ for _ , vLog := range logs {
77
+ data , abc := contractAbi .Unpack ("JobReported" , vLog .Data )
78
+ if abc != nil {
79
+ log .Fatal (abc )
80
+ }
81
+
82
+ fmt .Println (data )
83
+
84
+ }
37
85
},
38
86
}
39
87
0 commit comments