Skip to content

Commit

Permalink
feat: agg-sender (#22)
Browse files Browse the repository at this point in the history
Co-authored-by: Goran Rojovic <[email protected]>
Co-authored-by: Victor Castell <[email protected]>
Co-authored-by: joanestebanr <[email protected]>
Co-authored-by: Arnau Bennassar <[email protected]>
  • Loading branch information
5 people authored Oct 31, 2024
1 parent b43c062 commit 2a76deb
Show file tree
Hide file tree
Showing 51 changed files with 6,741 additions and 183 deletions.
42 changes: 42 additions & 0 deletions aggregator/agglayer/agglayer_client.go → agglayer/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ var ErrAgglayerRateLimitExceeded = fmt.Errorf("agglayer rate limit exceeded")
type AgglayerClientInterface interface {
SendTx(signedTx SignedTx) (common.Hash, error)
WaitTxToBeMined(hash common.Hash, ctx context.Context) error
SendCertificate(certificate *SignedCertificate) (common.Hash, error)
GetCertificateHeader(certificateHash common.Hash) (*CertificateHeader, error)
}

// AggLayerClient is the client that will be used to interact with the AggLayer
Expand Down Expand Up @@ -86,3 +88,43 @@ func (c *AggLayerClient) WaitTxToBeMined(hash common.Hash, ctx context.Context)
}
}
}

// SendCertificate sends a certificate to the AggLayer
func (c *AggLayerClient) SendCertificate(certificate *SignedCertificate) (common.Hash, error) {
response, err := rpc.JSONRPCCall(c.url, "interop_sendCertificate", certificate)
if err != nil {
return common.Hash{}, err
}

if response.Error != nil {
return common.Hash{}, fmt.Errorf("%d %s", response.Error.Code, response.Error.Message)
}

var result types.ArgHash
err = json.Unmarshal(response.Result, &result)
if err != nil {
return common.Hash{}, err
}

return result.Hash(), nil
}

// GetCertificateHeader returns the certificate header associated to the hash
func (c *AggLayerClient) GetCertificateHeader(certificateHash common.Hash) (*CertificateHeader, error) {
response, err := rpc.JSONRPCCall(c.url, "interop_getCertificateHeader", certificateHash)
if err != nil {
return nil, err
}

if response.Error != nil {
return nil, fmt.Errorf("%d %s", response.Error.Code, response.Error.Message)
}

var result *CertificateHeader
err = json.Unmarshal(response.Result, &result)
if err != nil {
return nil, err
}

return result, nil
}
138 changes: 138 additions & 0 deletions agglayer/mock_agglayer_client.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

File renamed without changes.
Loading

0 comments on commit 2a76deb

Please sign in to comment.