Skip to content

Commit 3e1d7b2

Browse files
committed
Add job command as POC
1 parent 6028d4b commit 3e1d7b2

File tree

1 file changed

+51
-3
lines changed

1 file changed

+51
-3
lines changed

cmd/job.go

+51-3
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,24 @@ limitations under the License.
1616
package cmd
1717

1818
import (
19+
"context"
1920
"fmt"
21+
"log"
22+
"math/big"
23+
"strings"
2024

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"
2129
"github.com/spf13/cobra"
30+
31+
jobManager "razor/pkg/bindings"
2232
)
2333

2434
// jobCmd represents the job command
2535
var jobCmd = &cobra.Command{
26-
Use: "job",
36+
Use: "jobs",
2737
Short: "A brief description of your command",
2838
Long: `A longer description that spans multiple lines and likely contains examples
2939
and usage of using your command. For example:
@@ -32,8 +42,46 @@ Cobra is a CLI library for Go that empowers applications.
3242
This application is a tool to generate the needed files
3343
to quickly create a Cobra application.`,
3444
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+
}
3785
},
3886
}
3987

0 commit comments

Comments
 (0)