Skip to content

Commit

Permalink
Feature/banana (#95)
Browse files Browse the repository at this point in the history
* import contract bindings from cdk-contracts-tooling

* import contract bindings from cdk-contracts-tooling

* Implementation done

* Add E2E test for banana

* Remove integration testing

* fix: lint

* fix: go version

* fix: exclude mocks dir for lint

* fix: yml

* fix: lint

---------

Co-authored-by: Goran Rojovic <[email protected]>
  • Loading branch information
arnaubennassar and goran-ethernal authored Jul 12, 2024
1 parent 2319d3c commit 72ae676
Show file tree
Hide file tree
Showing 54 changed files with 625 additions and 12,986 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v3

- name: Install Go
uses: actions/setup-go@v3
with:
go-version: '1.21.x'

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v2
Expand Down
9 changes: 5 additions & 4 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@ jobs:
- name: Install Go
uses: actions/setup-go@v3
with:
go-version: 1.19.x
go-version: 1.21.x
cache: false
- name: Checkout code
uses: actions/checkout@v3
- name: Lint
run: |
make install-linter
make lint
uses: golangci/[email protected]
with:
args: --timeout 10m --verbose
2 changes: 1 addition & 1 deletion .github/workflows/test-e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
strategy:
fail-fast: false
matrix:
go-version: [ 1.19.x ]
go-version: [ 1.21.x ]
goarch: [ "amd64" ]
runs-on: ubuntu-latest
steps:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test-unit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
strategy:
fail-fast: false
matrix:
go-version: [ 1.19.x ]
go-version: [ 1.21.x ]
goarch: [ "amd64" ]
runs-on: ubuntu-latest
steps:
Expand Down
1 change: 1 addition & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ run:
- state/runtime/instrumentation
- test
- ci
- mocks

linters:
enable:
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# CONTAINER FOR BUILDING BINARY
FROM golang:1.19 AS build
FROM golang:1.21 AS build

# INSTALL DEPENDENCIES
RUN go install github.com/gobuffalo/packr/v2/[email protected]
Expand Down
21 changes: 21 additions & 0 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ type Client interface {
GetOffChainData(ctx context.Context, hash common.Hash) ([]byte, error)
ListOffChainData(ctx context.Context, hashes []common.Hash) (map[common.Hash][]byte, error)
SignSequence(ctx context.Context, signedSequence types.SignedSequence) ([]byte, error)
SignSequenceBanana(ctx context.Context, signedSequence types.SignedSequenceBanana) ([]byte, error)
}

// factory is the implementation of the data committee client factory
Expand Down Expand Up @@ -87,6 +88,26 @@ func (c *client) SignSequence(ctx context.Context, signedSequence types.SignedSe
return result, nil
}

// SignSequenceBanana sends a request to sign the given sequence by the data committee member
// if successful returns the signature. The signature should be validated after using this method!
func (c *client) SignSequenceBanana(ctx context.Context, signedSequence types.SignedSequenceBanana) ([]byte, error) {
response, err := rpc.JSONRPCCallWithContext(ctx, c.url, "datacom_signSequenceBanana", signedSequence)
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.ArgBytes
if err = json.Unmarshal(response.Result, &result); err != nil {
return nil, err
}

return result, nil
}

// GetOffChainData returns data based on it's hash
func (c *client) GetOffChainData(ctx context.Context, hash common.Hash) ([]byte, error) {
response, err := rpc.JSONRPCCallWithContext(ctx, c.url, "sync_getOffChainData", hash)
Expand Down
20 changes: 10 additions & 10 deletions etherman/etherman.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import (
"fmt"
"math/big"

"github.com/0xPolygon/cdk-contracts-tooling/contracts/etrog/polygondatacommittee"
"github.com/0xPolygon/cdk-contracts-tooling/contracts/etrog/polygonvalidiumetrog"
"github.com/0xPolygon/cdk-data-availability/config"
"github.com/0xPolygon/cdk-data-availability/etherman/smartcontracts/etrog/polygondatacommittee"
"github.com/0xPolygon/cdk-data-availability/etherman/smartcontracts/etrog/polygonvalidium"
"github.com/0xPolygon/cdk-data-availability/log"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common"
Expand Down Expand Up @@ -41,23 +41,23 @@ type Etherman interface {
TrustedSequencer(ctx context.Context) (common.Address, error)
WatchSetTrustedSequencer(
ctx context.Context,
events chan *polygonvalidium.PolygonvalidiumSetTrustedSequencer,
events chan *polygonvalidiumetrog.PolygonvalidiumetrogSetTrustedSequencer,
) (event.Subscription, error)
TrustedSequencerURL(ctx context.Context) (string, error)
WatchSetTrustedSequencerURL(
ctx context.Context,
events chan *polygonvalidium.PolygonvalidiumSetTrustedSequencerURL,
events chan *polygonvalidiumetrog.PolygonvalidiumetrogSetTrustedSequencerURL,
) (event.Subscription, error)
FilterSequenceBatches(
opts *bind.FilterOpts,
numBatch []uint64,
) (*polygonvalidium.PolygonvalidiumSequenceBatchesIterator, error)
) (*polygonvalidiumetrog.PolygonvalidiumetrogSequenceBatchesIterator, error)
}

// etherman is the implementation of EtherMan.
type etherman struct {
EthClient *ethclient.Client
CDKValidium *polygonvalidium.Polygonvalidium
CDKValidium *polygonvalidiumetrog.Polygonvalidiumetrog
DataCommittee *polygondatacommittee.Polygondatacommittee
}

Expand All @@ -72,7 +72,7 @@ func New(ctx context.Context, cfg config.L1Config) (Etherman, error) {
return nil, err
}

cdkValidium, err := polygonvalidium.NewPolygonvalidium(
cdkValidium, err := polygonvalidiumetrog.NewPolygonvalidiumetrog(
common.HexToAddress(cfg.PolygonValidiumAddress),
ethClient,
)
Expand Down Expand Up @@ -126,7 +126,7 @@ func (e *etherman) TrustedSequencer(ctx context.Context) (common.Address, error)
// WatchSetTrustedSequencer watches trusted sequencer address
func (e *etherman) WatchSetTrustedSequencer(
ctx context.Context,
events chan *polygonvalidium.PolygonvalidiumSetTrustedSequencer,
events chan *polygonvalidiumetrog.PolygonvalidiumetrogSetTrustedSequencer,
) (event.Subscription, error) {
return e.CDKValidium.WatchSetTrustedSequencer(&bind.WatchOpts{Context: ctx}, events)
}
Expand All @@ -142,14 +142,14 @@ func (e *etherman) TrustedSequencerURL(ctx context.Context) (string, error) {
// WatchSetTrustedSequencerURL watches trusted sequencer's RPC url
func (e *etherman) WatchSetTrustedSequencerURL(
ctx context.Context,
events chan *polygonvalidium.PolygonvalidiumSetTrustedSequencerURL,
events chan *polygonvalidiumetrog.PolygonvalidiumetrogSetTrustedSequencerURL,
) (event.Subscription, error) {
return e.CDKValidium.WatchSetTrustedSequencerURL(&bind.WatchOpts{Context: ctx}, events)
}

// FilterSequenceBatches retrieves filtered batches on CDK validium
func (e *etherman) FilterSequenceBatches(opts *bind.FilterOpts,
numBatch []uint64) (*polygonvalidium.PolygonvalidiumSequenceBatchesIterator, error) {
numBatch []uint64) (*polygonvalidiumetrog.PolygonvalidiumetrogSequenceBatchesIterator, error) {
return e.CDKValidium.FilterSequenceBatches(opts, numBatch)
}

Expand Down
16 changes: 0 additions & 16 deletions etherman/smartcontracts/abigen.sh

This file was deleted.

Loading

0 comments on commit 72ae676

Please sign in to comment.