forked from NethermindEth/starknet.go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
chain.go
51 lines (46 loc) · 1.51 KB
/
chain.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
45
46
47
48
49
50
51
package rpc
import (
"context"
"github.com/icicd/starknet.go/utils"
)
// ChainID returns the chain ID for transaction replay protection.
//
// Parameters:
// - ctx: The context.Context object for the function
// Returns:
// - string: The chain ID
// - error: An error if any occurred during the execution
func (provider *Provider) ChainID(ctx context.Context) (string, error) {
if provider.chainID != "" {
return provider.chainID, nil
}
var result string
// Note: []interface{}{}...force an empty `params[]` in the jsonrpc request
if err := provider.c.CallContext(ctx, &result, "starknet_chainId", []interface{}{}...); err != nil {
return "", Err(InternalError, err)
}
provider.chainID = utils.HexToShortStr(result)
return provider.chainID, nil
}
// Syncing retrieves the synchronization status of the provider.
//
// Parameters:
// - ctx: The context.Context object for the function
// Returns:
// - *SyncStatus: The synchronization status
// - error: An error if any occurred during the execution
func (provider *Provider) Syncing(ctx context.Context) (*SyncStatus, error) {
var result interface{}
// Note: []interface{}{}...force an empty `params[]` in the jsonrpc request
if err := provider.c.CallContext(ctx, &result, "starknet_syncing", []interface{}{}...); err != nil {
return nil, Err(InternalError, err)
}
switch res := result.(type) {
case bool:
return &SyncStatus{SyncStatus: res}, nil
case SyncStatus:
return &res, nil
default:
return nil, Err(InternalError, "internal error with starknet_syncing")
}
}