-
Notifications
You must be signed in to change notification settings - Fork 13
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
5ec3939
commit 9f1919f
Showing
9 changed files
with
184 additions
and
60 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,52 @@ | ||
package etherman2 | ||
|
||
import ( | ||
"log" | ||
|
||
internal_contracts "github.com/0xPolygon/cdk/etherman2/internal/contracts" | ||
"github.com/ethereum/go-ethereum/common" | ||
"github.com/ethereum/go-ethereum/ethclient" | ||
) | ||
|
||
type Etherman2ContractBuilder struct { | ||
build struct { | ||
result *Contracts | ||
} | ||
params struct { | ||
rpcURL string | ||
RollupElderberry *common.Address | ||
} | ||
} | ||
|
||
func NewEtherman2ContractBuilder(rpcURL string) *Etherman2ContractBuilder { | ||
res := &Etherman2ContractBuilder{} | ||
res.params.rpcURL = rpcURL | ||
return res | ||
} | ||
|
||
func (e *Etherman2ContractBuilder) AddRollupElderberry(address common.Address) *Etherman2ContractBuilder { | ||
if e.build.result != nil { | ||
log.Fatal("Cannot add contracts after build") | ||
} | ||
e.params.RollupElderberry = &address | ||
return e | ||
} | ||
|
||
func (e *Etherman2ContractBuilder) Build() (*Contracts, error) { | ||
if e.build.result != nil { | ||
return e.build.result, nil | ||
} | ||
l1Client, err := ethclient.Dial(e.params.rpcURL) | ||
if err != nil { | ||
return nil, err | ||
} | ||
e.build.result = &Contracts{} | ||
if e.params.RollupElderberry != nil { | ||
rollupElderberry, err := internal_contracts.NewContractRollupElderberry(*e.params.RollupElderberry, l1Client) | ||
if err != nil { | ||
return nil, err | ||
} | ||
e.build.result.RollupElderberry = rollupElderberry | ||
} | ||
return e.build.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
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,24 @@ | ||
package etherman2 | ||
|
||
import ( | ||
"github.com/0xPolygon/cdk-contracts-tooling/contracts/elderberry/polygonvalidiumetrog" | ||
"github.com/ethereum/go-ethereum/common" | ||
) | ||
|
||
type Etherman2Contract[T any] interface { | ||
GetContract() *T | ||
GetAddress() common.Address | ||
} | ||
|
||
type Etherman2ContractRollupCommon interface { | ||
TrustedSequencer() (common.Address, error) | ||
} | ||
|
||
type Etherman2ContractRollupElderberry interface { | ||
Etherman2Contract[polygonvalidiumetrog.Polygonvalidiumetrog] | ||
Etherman2ContractRollupCommon | ||
} | ||
|
||
type Contracts struct { | ||
RollupElderberry Etherman2ContractRollupElderberry | ||
} |
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,33 @@ | ||
package internal_contracts | ||
|
||
import ( | ||
"github.com/ethereum/go-ethereum/accounts/abi/bind" | ||
"github.com/ethereum/go-ethereum/common" | ||
) | ||
|
||
type ContractBase[T any] struct { | ||
contractBind *T | ||
address common.Address | ||
} | ||
|
||
type contractConstructorFunc[T any] func(address common.Address, backend bind.ContractBackend) (*T, error) | ||
|
||
func NewContractBase[T any](constructor contractConstructorFunc[T], address common.Address, backend bind.ContractBackend) (*ContractBase[T], error) { | ||
contractBind, err := constructor(address, backend) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return &ContractBase[T]{ | ||
contractBind: contractBind, | ||
address: address, | ||
}, nil | ||
} | ||
|
||
func (e *ContractBase[T]) GetContract() *T { | ||
return e.contractBind | ||
} | ||
|
||
func (e *ContractBase[T]) GetAddress() common.Address { | ||
return e.address | ||
} |
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 internal_contracts | ||
|
||
import ( | ||
"github.com/0xPolygon/cdk-contracts-tooling/contracts/elderberry/polygonvalidiumetrog" | ||
"github.com/ethereum/go-ethereum/accounts/abi/bind" | ||
"github.com/ethereum/go-ethereum/common" | ||
) | ||
|
||
type ContractRollupElderberry struct { | ||
*ContractBase[polygonvalidiumetrog.Polygonvalidiumetrog] | ||
} | ||
|
||
func NewContractRollupElderberry(address common.Address, backend bind.ContractBackend) (*ContractRollupElderberry, error) { | ||
//ZkEVM, err := polygonvalidiumetrog.NewPolygonvalidiumetrog(address, backend) | ||
base, err := NewContractBase(polygonvalidiumetrog.NewPolygonvalidiumetrog, address, backend) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return &ContractRollupElderberry{ | ||
ContractBase: base, | ||
}, nil | ||
} | ||
|
||
func (e *ContractRollupElderberry) TrustedSequencer() (common.Address, error) { | ||
return e.GetContract().TrustedSequencer(&bind.CallOpts{Pending: 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
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