Skip to content

Commit

Permalink
can specify qtum sender address for deploy
Browse files Browse the repository at this point in the history
  • Loading branch information
hayeah committed Jan 11, 2018
1 parent 83e590a commit b6561c3
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 7 deletions.
3 changes: 2 additions & 1 deletion cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
var (
app = kingpin.New("solar", "Solidity smart contract deployment management.")
qtumRPC = app.Flag("qtum_rpc", "RPC provider url").Envar("QTUM_RPC").String()
qtumSenderAddress = app.Flag("qtum_sender", "(qtum) Sender UXTO Address").Envar("QTUM_SENDER").String()

// geth --rpc --rpcapi="eth,personal,miner"
ethRPC = app.Flag("eth_rpc", "RPC provider url").Envar("ETH_RPC").String()
Expand Down Expand Up @@ -133,7 +134,7 @@ func (c *solarCLI) Deployer() (deployer deployer.Deployer) {
if err != nil {
log.Fatalf("Invalid RPC url: %#v", rawurl)
}
deployer, err = qtum.NewDeployer(rpcURL, c.ContractsRepository())
deployer, err = qtum.NewDeployer(rpcURL, c.ContractsRepository(), *qtumSenderAddress)
} else if rawurl = *ethRPC; rawurl != "" {
rpcURL, err = url.ParseRequestURI(rawurl)
if err != nil {
Expand Down
5 changes: 5 additions & 0 deletions contract/contractsRepo.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ func (r *ContractsRepository) Get(name string) (*DeployedContract, bool) {
return contract, ok
}

func (r *ContractsRepository) GetLib(name string) (*DeployedContract, bool) {
contract, ok := r.Libraries[name]
return contract, ok
}

func (r *ContractsRepository) Len() int {
return len(r.Contracts)
}
Expand Down
19 changes: 15 additions & 4 deletions deploy.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package solar

import (
"github.com/qtumproject/solar/contract"
"fmt"
"log"
"strings"
Expand Down Expand Up @@ -59,7 +60,7 @@ func init() {
Repo: repo,
}

contract, err := compiler.Compile()
compiledContract, err := compiler.Compile()
if err != nil {
return errors.Wrap(err, "compile")
}
Expand All @@ -73,7 +74,7 @@ func init() {
params = []byte(jsonParams)
}

err = deployer.CreateContract(contract, params, target.name, *force, *aslib)
err = deployer.CreateContract(compiledContract, params, target.name, *force, *aslib)
if err != nil {
fmt.Println("\u2757\ufe0f \033[36mdeploy\033[0m", err)
return
Expand All @@ -96,8 +97,18 @@ func init() {
return err
}

c, _ := repo.Get(target.name)
fmt.Printf(" \033[36mdeployed\033[0m %s => %s\n", target.name, c.Address)
var deployedContract *contract.DeployedContract
if *aslib {
deployedContract, _ = repo.GetLib(target.name)
} else {
deployedContract, _ = repo.Get(target.name)
}

if deployedContract == nil {
return errors.New("failed to deploy contract")
}

fmt.Printf(" \033[36mdeployed\033[0m %s => %s\n", target.name, deployedContract.Address)
}

return
Expand Down
16 changes: 14 additions & 2 deletions deployer/qtum/qtumDeployer.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,18 @@ import (
type Deployer struct {
rpc *RPC
*contract.ContractsRepository

// qtum base58 sender address used to create a contract.
senderAddress string
}

func NewDeployer(rpcURL *url.URL, repo *contract.ContractsRepository) (*Deployer, error) {
func NewDeployer(rpcURL *url.URL, repo *contract.ContractsRepository, senderAddress string) (*Deployer, error) {
return &Deployer{
rpc: &RPC{
BaseURL: rpcURL,
},
ContractsRepository: repo,
senderAddress: senderAddress,
}, nil
}

Expand Down Expand Up @@ -68,7 +72,15 @@ func (d *Deployer) CreateContract(c *contract.CompiledContract, jsonParams []byt

var tx TransactionReceipt

err = d.rpc.Call(&tx, "createcontract", bin, gasLimit)
args := []interface{}{
bin, gasLimit, 0.0000004,
}

if d.senderAddress != "" {
args = append(args, d.senderAddress)
}

err = d.rpc.Call(&tx,"createcontract", args...)

if err != nil {
return errors.Wrap(err, "createcontract")
Expand Down

0 comments on commit b6561c3

Please sign in to comment.