-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathsyncing.go
44 lines (36 loc) · 1.1 KB
/
syncing.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package api
import (
"context"
"github.com/goccy/go-json"
)
// Syncing -
type Syncing struct {
Synced bool `json:"-"`
StartingBlockNum string `json:"starting_block_num"`
CurrentBlockNum string `json:"current_block_num"`
HighestBlockNum string `json:"highest_block_num"`
StartingBlockHash string `json:"starting_block_hash"`
CurrentBlockHash string `json:"current_block_hash"`
HighestBlockHash string `json:"highest_block_hash"`
}
// UnmarshalJSON -
func (s *Syncing) UnmarshalJSON(data []byte) error {
type buf Syncing
if err := json.Unmarshal(data, (*buf)(s)); err == nil {
s.Synced = true
return nil
}
var synced bool
if err := json.Unmarshal(data, &synced); err != nil {
return err
}
s.Synced = synced
return nil
}
// Syncing - Returns an object about the sync status, or false if the node is not synching
func (api API) Syncing(ctx context.Context, opts ...RequestOption) (*Response[Syncing], error) {
request := api.prepareRequest("starknet_syncing", []any{}, opts...)
var response Response[Syncing]
err := post(ctx, api, *request, &response)
return &response, err
}