forked from okx/xlayer-node
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Sync Trusted State via jRPC instead of Broadcast (0xPolygonHermez#1840)
* break down jrpc package to share objects * sync trusted state via jRPC instead of broadcast --------- Co-authored-by: ToniRamirezM <[email protected]>
- Loading branch information
1 parent
13dc968
commit 743b904
Showing
44 changed files
with
2,360 additions
and
1,999 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
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,57 @@ | ||
package client | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
"fmt" | ||
"math/big" | ||
|
||
"github.com/0xPolygonHermez/zkevm-node/hex" | ||
"github.com/0xPolygonHermez/zkevm-node/jsonrpc/types" | ||
"github.com/0xPolygonHermez/zkevm-node/log" | ||
) | ||
|
||
// BatchNumber returns the latest batch number | ||
func (c *Client) BatchNumber(ctx context.Context) (uint64, error) { | ||
response, err := JSONRPCCall(c.url, "zkevm_batchNumber") | ||
if err != nil { | ||
return 0, err | ||
} | ||
|
||
if response.Error != nil { | ||
return 0, fmt.Errorf("%v %v", response.Error.Code, response.Error.Message) | ||
} | ||
|
||
var result string | ||
err = json.Unmarshal(response.Result, &result) | ||
if err != nil { | ||
return 0, err | ||
} | ||
|
||
bigBatchNumber := hex.DecodeBig(result) | ||
batchNumber := bigBatchNumber.Uint64() | ||
|
||
return batchNumber, nil | ||
} | ||
|
||
// BatchByNumber returns a batch from the current canonical chain. If number is nil, the | ||
// latest known batch is returned. | ||
func (c *Client) BatchByNumber(ctx context.Context, number *big.Int) (*types.Batch, error) { | ||
response, err := JSONRPCCall(c.url, "zkevm_getBatchByNumber", types.ToBatchNumArg(number), true) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
if response.Error != nil { | ||
return nil, fmt.Errorf("%v %v", response.Error.Code, response.Error.Message) | ||
} | ||
|
||
var result *types.Batch | ||
log.Debugf(string(response.Result)) | ||
err = json.Unmarshal(response.Result, &result) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return result, 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
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
Oops, something went wrong.