From becb8cd41e2ace3845bf50d21d69fab861f9712f Mon Sep 17 00:00:00 2001 From: Howard Yeh Date: Wed, 31 Jan 2018 21:52:43 +0800 Subject: [PATCH] add gasLimit option to deploy command --- deploy.go | 3 ++- deployer/deployer.go | 3 ++- deployer/eth/ethDeployer.go | 2 +- deployer/qtum/qtumDeployer.go | 6 +++--- 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/deploy.go b/deploy.go index d03307e..122e7cd 100644 --- a/deploy.go +++ b/deploy.go @@ -39,6 +39,7 @@ func init() { aslib := cmd.Flag("lib", "Deploy the contract as a library").Bool() noconfirm := cmd.Flag("no-confirm", "Don't wait for network to confirm deploy").Bool() noFastConfirm := cmd.Flag("no-fast-confirm", "(dev) Don't generate block to confirm deploy immediately").Bool() + gasLimit := cmd.Flag("gasLimit", "gas limit for creating a contract").Default("3000000").Int() target := cmd.Arg("target", "Solidity contracts to deploy.").Required().String() jsonParams := cmd.Arg("jsonParams", "Constructor params as a json array").Default("").String() @@ -75,7 +76,7 @@ func init() { params = []byte(jsonParams) } - err = deployer.CreateContract(compiledContract, params, target.name, *force, *aslib) + err = deployer.CreateContract(compiledContract, params, target.name, *force, *aslib, *gasLimit) if err != nil { fmt.Println("\u2757\ufe0f \033[36mdeploy\033[0m", err) return diff --git a/deployer/deployer.go b/deployer/deployer.go index 0c998f7..2ac9b25 100644 --- a/deployer/deployer.go +++ b/deployer/deployer.go @@ -5,7 +5,8 @@ import ( ) type Deployer interface { - CreateContract(contract *contract.CompiledContract, jsonParams []byte, name string, overwrite bool, asLib bool) error + // FIXME better interface for call options + CreateContract(contract *contract.CompiledContract, jsonParams []byte, name string, overwrite bool, asLib bool, gasLimit int) error ConfirmContract(contract *contract.DeployedContract) error Mine() error } diff --git a/deployer/eth/ethDeployer.go b/deployer/eth/ethDeployer.go index b10bb4b..a80e3a2 100644 --- a/deployer/eth/ethDeployer.go +++ b/deployer/eth/ethDeployer.go @@ -41,7 +41,7 @@ func NewDeployer(rpcURL *url.URL, repo *contract.ContractsRepository) (*Deployer }, nil } -func (d *Deployer) CreateContract(c *contract.CompiledContract, jsonParams []byte, name string, overwrite bool, aslib bool) (err error) { +func (d *Deployer) CreateContract(c *contract.CompiledContract, jsonParams []byte, name string, overwrite bool, aslib bool, gasLimit int) (err error) { if overwrite { if aslib && d.LibExists(name) { return errors.Errorf("library name already used: %s", name) diff --git a/deployer/qtum/qtumDeployer.go b/deployer/qtum/qtumDeployer.go index 8a4a3ec..b2e488f 100644 --- a/deployer/qtum/qtumDeployer.go +++ b/deployer/qtum/qtumDeployer.go @@ -54,7 +54,7 @@ func (d *Deployer) ConfirmContract(c *contract.DeployedContract) (err error) { } } -func (d *Deployer) CreateContract(c *contract.CompiledContract, jsonParams []byte, name string, overwrite bool, aslib bool) (err error) { +func (d *Deployer) CreateContract(c *contract.CompiledContract, jsonParams []byte, name string, overwrite bool, aslib bool, gasLimit int) (err error) { if !overwrite { if aslib && d.LibExists(name) { return errors.Errorf("library name already used: %s", name) @@ -63,8 +63,6 @@ func (d *Deployer) CreateContract(c *contract.CompiledContract, jsonParams []byt } } - gasLimit := 3000000 - bin, err := c.ToBytes(jsonParams) if err != nil { return @@ -76,6 +74,8 @@ func (d *Deployer) CreateContract(c *contract.CompiledContract, jsonParams []byt bin, gasLimit, 0.0000004, } + // fmt.Println("create contract args", args) + if d.senderAddress != "" { args = append(args, d.senderAddress) }