-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* module/eth: added `Syncing()` * added doc --------- Co-authored-by: lmittmann <lmittmann@users.noreply.github.com>
- Loading branch information
Showing
6 changed files
with
67 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package eth | ||
|
||
import ( | ||
"github.com/lmittmann/w3/internal/module" | ||
"github.com/lmittmann/w3/w3types" | ||
) | ||
|
||
// Syncing requests the syncing status of the node. | ||
func Syncing() w3types.RPCCallerFactory[bool] { | ||
return module.NewFactory( | ||
"eth_syncing", | ||
[]any{}, | ||
module.WithRetWrapper(syncingRetWrapper), | ||
) | ||
} | ||
|
||
func syncingRetWrapper(ret *bool) any { | ||
return (*syncingBool)(ret) | ||
} | ||
|
||
type syncingBool bool | ||
|
||
func (s *syncingBool) UnmarshalJSON(b []byte) error { | ||
if string(b) == "false" { | ||
*s = false | ||
} else { | ||
*s = true | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package eth_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/lmittmann/w3/module/eth" | ||
"github.com/lmittmann/w3/rpctest" | ||
) | ||
|
||
func TestSyncing(t *testing.T) { | ||
rpctest.RunTestCases(t, []rpctest.TestCase[bool]{ | ||
{ | ||
Golden: "syncing__false", | ||
Call: eth.Syncing(), | ||
WantRet: false, | ||
}, | ||
{ | ||
Golden: "syncing__true", | ||
Call: eth.Syncing(), | ||
WantRet: true, | ||
}, | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
> {"jsonrpc":"2.0","id":1,"method":"eth_syncing","params":[]} | ||
< {"jsonrpc":"2.0","id":1,"result":false} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
> {"jsonrpc":"2.0","id":1,"method":"eth_syncing","params":[]} | ||
< {"jsonrpc":"2.0","id":1,"result":{"currentBlock":"0x3cf522","healedBytecodeBytes":"0x0","healedBytecodes":"0x0","healedTrienodes":"0x0","healingBytecode":"0x0","healingTrienodes":"0x0","highestBlock":"0x3e0e41","startingBlock":"0x3cbed5","syncedAccountBytes":"0x0","syncedAccounts":"0x0","syncedBytecodeBytes":"0x0","syncedBytecodes":"0x0","syncedStorage":"0x0","syncedStorageBytes":"0x0"}} |