Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 17 additions & 4 deletions chain/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,23 @@ var (

// Chain is the blockchain chain configuration
type Chain struct {
Name string `json:"name"`
Genesis *Genesis `json:"genesis"`
Params *Params `json:"params"`
Bootnodes []string `json:"bootnodes,omitempty"`
Name string `json:"name" yaml:"name"`
Genesis *Genesis `json:"genesis" yaml:"genesis"`
Params *Params `json:"params" yaml:"params"`
Bootnodes []string `json:"bootnodes,omitempty" yaml:"bootnodes,omitempty"`
Node *Node `json:"node,omitempty" yaml:"node,omitempty"`
}

// Node represents the node configuration
type Node struct {
P2P struct {
StaticNodes []string `json:"staticNodes,omitempty" yaml:"staticNodes,omitempty"`
} `json:"p2p,omitempty" yaml:"p2p,omitempty"`
}

// Bootnode is the blockchain bootnodes configuration
type Bootnode struct {
Bootnodes []string `json:"bootnodes" yaml:"bootnodes"`
}

// Genesis specifies the header fields, state of a genesis block
Expand Down
1 change: 1 addition & 0 deletions chain/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ type Params struct {
ChainID int64 `json:"chainID"`
Engine map[string]interface{} `json:"engine"`
BlockGasTarget uint64 `json:"blockGasTarget"`
Bootnodes []string `json:"bootnodes"`

// Access control configuration
ContractDeployerAllowList *AddressListConfig `json:"contractDeployerAllowList,omitempty"`
Expand Down
54 changes: 51 additions & 3 deletions command/bridge/deposit/erc1155/deposit_erc1155.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package erc1155

import (
"errors"
"fmt"
"math/big"
"strings"
Expand All @@ -18,13 +19,20 @@ import (
)

type depositERC1155Params struct {
*common.ERC1155BridgeParams
minterKey string
SenderKey string
JSONRPCAddr string
TokenAddr string
PredicateAddr string
Amounts []string
TokenIDs []string
Receivers []string
ChildChainMintable bool
minterKey string // Keep this for backward compatibility
}

var (
// depositParams is abstraction for provided bridge parameter values
dp *depositERC1155Params = &depositERC1155Params{ERC1155BridgeParams: common.NewERC1155BridgeParams()}
dp *depositERC1155Params = &depositERC1155Params{}
)

// GetCommand returns the bridge deposit command
Expand Down Expand Up @@ -303,3 +311,43 @@ func createApproveERC1155PredicateTxn(rootERC1155Predicate,
return helper.CreateTransaction(ethgo.ZeroAddress, &addr,
input, nil, !dp.ChildChainMintable), nil
}

func (dp *depositERC1155Params) RegisterCommonFlags(cmd *cobra.Command) {
cmd.Flags().StringVar(
&dp.SenderKey,
"sender-key",
"",
"the sender's private key",
)
cmd.Flags().StringVar(
&dp.JSONRPCAddr,
"json-rpc",
"",
"the JSON RPC address",
)
}

func (dp *depositERC1155Params) Validate() error {
if dp.SenderKey == "" {
return errors.New("sender key is required")
}
if dp.JSONRPCAddr == "" {
return errors.New("JSON RPC address is required")
}
if dp.TokenAddr == "" {
return errors.New("token address is required")
}
if dp.PredicateAddr == "" {
return errors.New("predicate address is required")
}
if len(dp.Amounts) == 0 {
return errors.New("amounts are required")
}
if len(dp.TokenIDs) == 0 {
return errors.New("token IDs are required")
}
if len(dp.Receivers) == 0 {
return errors.New("receivers are required")
}
return nil
}
57 changes: 47 additions & 10 deletions command/bridge/deposit/erc20/deposit_erc20.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package erc20

import (
"errors"
"fmt"
"math/big"

Expand All @@ -18,13 +19,19 @@ import (
)

type depositERC20Params struct {
*common.ERC20BridgeParams
minterKey string
SenderKey string
JSONRPCAddr string
TokenAddr string
PredicateAddr string
Amounts []string
Receivers []string
ChildChainMintable bool
minterKey string // Keep this for backward compatibility
}

var (
// depositParams is abstraction for provided bridge parameter values
dp *depositERC20Params = &depositERC20Params{ERC20BridgeParams: common.NewERC20BridgeParams()}
dp *depositERC20Params = &depositERC20Params{}
)

// GetCommand returns the bridge deposit command
Expand Down Expand Up @@ -59,13 +66,6 @@ func GetCommand() *cobra.Command {
"root ERC 20 token predicate address",
)

depositCmd.Flags().StringVar(
&dp.minterKey,
common.MinterKeyFlag,
"",
common.MinterKeyFlagDesc,
)

_ = depositCmd.MarkFlagRequired(common.ReceiversFlag)
_ = depositCmd.MarkFlagRequired(common.AmountsFlag)
_ = depositCmd.MarkFlagRequired(common.RootTokenFlag)
Expand Down Expand Up @@ -284,3 +284,40 @@ func createDepositTxn(sender, receiver types.Address, amount *big.Int) (*ethgo.T
return helper.CreateTransaction(ethgo.Address(sender), &addr,
input, nil, !dp.ChildChainMintable), nil
}

func (dp *depositERC20Params) RegisterCommonFlags(cmd *cobra.Command) {
cmd.Flags().StringVar(
&dp.SenderKey,
"sender-key",
"",
"the sender's private key",
)
cmd.Flags().StringVar(
&dp.JSONRPCAddr,
"json-rpc",
"",
"the JSON RPC address",
)
}

func (dp *depositERC20Params) Validate() error {
if dp.SenderKey == "" {
return errors.New("sender key is required")
}
if dp.JSONRPCAddr == "" {
return errors.New("JSON RPC address is required")
}
if dp.TokenAddr == "" {
return errors.New("token address is required")
}
if dp.PredicateAddr == "" {
return errors.New("predicate address is required")
}
if len(dp.Amounts) == 0 {
return errors.New("amounts are required")
}
if len(dp.Receivers) == 0 {
return errors.New("receivers are required")
}
return nil
}
67 changes: 48 additions & 19 deletions command/bridge/deposit/erc721/deposit_erc721.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package deposit

import (
"errors"
"fmt"
"math/big"
"strings"
Expand All @@ -17,12 +18,17 @@ import (
)

type depositERC721Params struct {
*common.ERC721BridgeParams
minterKey string
SenderKey string
JSONRPCAddr string
TokenAddr string
PredicateAddr string
TokenIDs []string
Receivers []string
ChildChainMintable bool
}

var (
dp *depositERC721Params = &depositERC721Params{ERC721BridgeParams: common.NewERC721BridgeParams()}
dp *depositERC721Params = &depositERC721Params{}
)

func GetCommand() *cobra.Command {
Expand Down Expand Up @@ -56,13 +62,6 @@ func GetCommand() *cobra.Command {
"root ERC 721 token predicate address",
)

depositCmd.Flags().StringVar(
&dp.minterKey,
common.MinterKeyFlag,
"",
common.MinterKeyFlagDesc,
)

_ = depositCmd.MarkFlagRequired(common.ReceiversFlag)
_ = depositCmd.MarkFlagRequired(common.TokenIDsFlag)
_ = depositCmd.MarkFlagRequired(common.RootTokenFlag)
Expand Down Expand Up @@ -110,14 +109,7 @@ func runCommand(cmd *cobra.Command, _ []string) {
tokenIDs[i] = tokenID
}

if dp.minterKey != "" {
minterKey, err := helper.DecodePrivateKey(dp.minterKey)
if err != nil {
outputter.SetError(fmt.Errorf("invalid minter key provided: %w", err))

return
}

if dp.ChildChainMintable {
for i := 0; i < len(tokenIDs); i++ {
mintTxn, err := createMintTxn(types.Address(depositorAddr), types.Address(depositorAddr))
if err != nil {
Expand All @@ -126,7 +118,7 @@ func runCommand(cmd *cobra.Command, _ []string) {
return
}

receipt, err := txRelayer.SendTransaction(mintTxn, minterKey)
receipt, err := txRelayer.SendTransaction(mintTxn, depositorKey)
if err != nil {
outputter.SetError(fmt.Errorf("failed to send mint transaction to depositor %s: %w",
depositorAddr, err))
Expand Down Expand Up @@ -271,3 +263,40 @@ func createApproveERC721PredicateTxn(rootERC721Predicate, rootERC721Token types.
return helper.CreateTransaction(ethgo.ZeroAddress, &addr, input,
nil, !dp.ChildChainMintable), nil
}

func (dp *depositERC721Params) RegisterCommonFlags(cmd *cobra.Command) {
cmd.Flags().StringVar(
&dp.SenderKey,
"sender-key",
"",
"the sender's private key",
)
cmd.Flags().StringVar(
&dp.JSONRPCAddr,
"json-rpc",
"",
"the JSON RPC address",
)
}

func (dp *depositERC721Params) Validate() error {
if dp.SenderKey == "" {
return errors.New("sender key is required")
}
if dp.JSONRPCAddr == "" {
return errors.New("JSON RPC address is required")
}
if dp.TokenAddr == "" {
return errors.New("token address is required")
}
if dp.PredicateAddr == "" {
return errors.New("predicate address is required")
}
if len(dp.TokenIDs) == 0 {
return errors.New("token IDs are required")
}
if len(dp.Receivers) == 0 {
return errors.New("receivers are required")
}
return nil
}
Loading
Loading