-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e3d6f5e
commit 3c7ec15
Showing
5 changed files
with
176 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package aggsenderrpc | ||
|
||
import ( | ||
"fmt" | ||
|
||
zkevm "github.com/0xPolygon/cdk" | ||
"github.com/0xPolygon/cdk-rpc/rpc" | ||
"github.com/0xPolygon/cdk/aggsender/types" | ||
"github.com/0xPolygon/cdk/log" | ||
) | ||
|
||
const ( | ||
base10 = 10 | ||
) | ||
|
||
type aggsenderStorer interface { | ||
GetCertificateByHeight(height uint64) (*types.CertificateInfo, error) | ||
GetLastSentCertificate() (*types.CertificateInfo, error) | ||
} | ||
|
||
type aggsenderStatuser interface { | ||
Status() types.AggsenderStatus | ||
} | ||
|
||
type AggsenderRPC struct { | ||
logger *log.Logger | ||
storage aggsenderStorer | ||
aggsender aggsenderStatuser | ||
} | ||
|
||
func NewAggsenderRPC( | ||
logger *log.Logger, | ||
storage aggsenderStorer, | ||
aggsender aggsenderStatuser, | ||
) *AggsenderRPC { | ||
return &AggsenderRPC{ | ||
logger: logger, | ||
storage: storage, | ||
aggsender: aggsender, | ||
} | ||
} | ||
|
||
// curl -X POST http://localhost:5576/ -H "Con -application/json" \ | ||
// -d '{"method":"aggsender_status", "params":[], "id":1}' | ||
func (b *AggsenderRPC) Status() (interface{}, rpc.Error) { | ||
status := b.aggsender.Status() | ||
res := struct { | ||
Version zkevm.FullVersion `json:"version"` | ||
Status types.AggsenderStatus `json:"status"` | ||
EpochNotifier string `json:"epoch_notifier"` | ||
}{ | ||
Version: zkevm.GetVersion(), | ||
Status: status, | ||
} | ||
return res, nil | ||
} | ||
|
||
// latest: curl -X POST http://localhost:5576/ -H "Con -application/json" \ | ||
// -d '{"method":"aggsender_getCertificateHeaderPerHeight", "params":[], "id":1}' | ||
func (b *AggsenderRPC) GetCertificateHeaderPerHeight(height *uint64) (interface{}, rpc.Error) { | ||
var certInfo *types.CertificateInfo | ||
var err error | ||
if height == nil { | ||
certInfo, err = b.storage.GetLastSentCertificate() | ||
} else { | ||
certInfo, err = b.storage.GetCertificateByHeight(*height) | ||
} | ||
if err != nil { | ||
return nil, rpc.NewRPCError(rpc.DefaultErrorCode, fmt.Sprintf("error getting certificate by height: %v", err)) | ||
} | ||
return certInfo, 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,39 @@ | ||
package rpcclient | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
|
||
"github.com/0xPolygon/cdk-rpc/rpc" | ||
"github.com/0xPolygon/cdk/aggsender/types" | ||
) | ||
|
||
// Client wraps all the available endpoints of the data abailability committee node server | ||
type Client struct { | ||
url string | ||
} | ||
|
||
func NewClient(url string) *Client { | ||
return &Client{ | ||
url: url, | ||
} | ||
} | ||
|
||
func (c *Client) GetCertificateHeaderPerHeight(height *uint64) (*types.CertificateInfo, error) { | ||
response, err := rpc.JSONRPCCall(c.url, "aggsender_getCertificateHeaderPerHeight", height) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
// Check if the response is an error | ||
if response.Error != nil { | ||
return nil, fmt.Errorf("error in the response calling aggsender_getCertificateHeaderPerHeight: %v", response.Error) | ||
} | ||
cert := types.CertificateInfo{} | ||
// Get the batch number from the response hex string | ||
err = json.Unmarshal(response.Result, &cert) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return &cert, 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,26 @@ | ||
package types | ||
|
||
import "time" | ||
|
||
type AggsenderStatusType string | ||
|
||
const ( | ||
StatusNone AggsenderStatusType = "none" | ||
StatusCheckingInitialStage AggsenderStatusType = "checking_initial_stage" | ||
StatusCertificateStage AggsenderStatusType = "certificate_stage" | ||
) | ||
|
||
type AggsenderStatus struct { | ||
Running bool `json:"running"` | ||
StartTime time.Time `json:"start_time"` | ||
Status AggsenderStatusType `json:"status"` | ||
LastError string `json:"last_error"` | ||
} | ||
|
||
func (a *AggsenderStatus) SetLastError(err error) { | ||
if err == nil { | ||
a.LastError = "" | ||
} else { | ||
a.LastError = err.Error() | ||
} | ||
} |
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