Skip to content

Commit

Permalink
Merge pull request #7 from MysteriumNetwork/improvement/v0.0.3-feedback
Browse files Browse the repository at this point in the history
Improvement/v0.0.3 feedback
  • Loading branch information
tadovas authored Aug 7, 2018
2 parents 4e93719 + 67b967b commit fd8d61b
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 33 deletions.
22 changes: 14 additions & 8 deletions cli/deployer/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ var registrationFee = flag.Int64("payments.registrationFee", 100, "Registration
var erc20address = flag.String("payments.erc20address", "", "ERC20 token address for payments. In hex (0x...) format")
var contractPath = flag.String("contract.binPath", "", "Path to bin file of payments contract")
var abiPath = flag.String("contract.abiPath", "", "Path to ABI file of payments contract")
var gethUrl = flag.String("geth.url", "", "URL value of started geth to connect")
var keystoreDir = flag.String("keystore.directory", "testnet", "specify runtime dir for keystore keys")
var passphrase = flag.String("keystore.passphrase", "", "Pashprase to unlock specified key from keystore")
var etherAddress = flag.String("ether.address", "", "Ethereum acc to use for deployment")

func main() {
flag.Parse()
Expand All @@ -35,23 +39,25 @@ func executeCommand(cmd string) error {
case "deploy":
return deployContract()
case "newAccount":
return helpers.NewAccount()
ks := helpers.GetKeystore(*keystoreDir)
return helpers.NewAccount(*passphrase, ks)
case "listAccounts":
return helpers.ListAccounts()
ks := helpers.GetKeystore(*keystoreDir)
return helpers.ListAccounts(ks)
case "clientStatus":
_, completed, err := helpers.LookupBackend()
_, completed, err := helpers.LookupBackend(*gethUrl)
<-completed
return err
case "ethBalance":
return getBalanceOf(*helpers.Address)
return getBalanceOf(*etherAddress)
case "help":
flag.Usage()
return nil
}
return errors.New("unknown command: " + cmd)
}
func getBalanceOf(address string) error {
backend, syncCompleted, err := helpers.LookupBackend()
backend, syncCompleted, err := helpers.LookupBackend(*gethUrl)
if err != nil {
return err
}
Expand All @@ -65,15 +71,15 @@ func getBalanceOf(address string) error {
}

func deployContract() (err error) {
ks := helpers.GetKeystore()
acc, err := helpers.GetUnlockedAcc(ks)
ks := helpers.GetKeystore(*keystoreDir)
acc, err := helpers.GetUnlockedAcc(*etherAddress, *passphrase, ks)
if err != nil {
return
}
fmt.Println("Lookedup acc: ", acc.Address.String())
transactor := helpers.CreateNewKeystoreTransactor(ks, acc)

client, _, err := helpers.LookupBackend()
client, _, err := helpers.LookupBackend(*gethUrl)
if err != nil {
return err
}
Expand Down
7 changes: 2 additions & 5 deletions cli/helpers/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package helpers

import (
"context"
"flag"
"fmt"
"time"

Expand All @@ -11,10 +10,8 @@ import (
"github.com/ethereum/go-ethereum/ethclient"
)

var GethUrl = flag.String("geth.url", "", "URL value of started geth to connect")

func LookupBackend() (*ethclient.Client, chan bool, error) {
ethClient, err := ethclient.Dial(*GethUrl)
func LookupBackend(rpcUrl string) (*ethclient.Client, chan bool, error) {
ethClient, err := ethclient.Dial(rpcUrl)
if err != nil {
return nil, nil, err
}
Expand Down
23 changes: 8 additions & 15 deletions cli/helpers/keystore.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package helpers

import (
"errors"
"flag"
"fmt"

"github.com/ethereum/go-ethereum/accounts"
Expand All @@ -12,35 +11,29 @@ import (
"github.com/ethereum/go-ethereum/core/types"
)

var KeyStoreDir = flag.String("keystore.directory", "testnet", "specify runtime dir for keystore keys")
var Passphrase = flag.String("keystore.passphrase", "", "Pashprase to unlock specified key from keystore")
var Address = flag.String("ether.address", "", "Ethereum acc to use for deployment")

func GetKeystore() *keystore.KeyStore {
return keystore.NewKeyStore(*KeyStoreDir, keystore.StandardScryptN, keystore.StandardScryptP)
func GetKeystore(keystoreDir string) *keystore.KeyStore {
return keystore.NewKeyStore(keystoreDir, keystore.StandardScryptN, keystore.StandardScryptP)
}

func ListAccounts() error {
ks := GetKeystore()
func ListAccounts(ks *keystore.KeyStore) error {
for i, acc := range ks.Accounts() {
fmt.Printf("%d: Address: %s\n", i, acc.Address.String())
}
return nil
}

func NewAccount() (err error) {
ks := GetKeystore()
_, err = ks.NewAccount(*Passphrase)
func NewAccount(passphrase string, ks *keystore.KeyStore) (err error) {
_, err = ks.NewAccount(passphrase)
return
}

func GetUnlockedAcc(ks *keystore.KeyStore) (*accounts.Account, error) {
searchAcc := accounts.Account{Address: common.HexToAddress(*Address)}
func GetUnlockedAcc(address, passphrase string, ks *keystore.KeyStore) (*accounts.Account, error) {
searchAcc := accounts.Account{Address: common.HexToAddress(address)}
foundAcc, err := ks.Find(searchAcc)
if err != nil {
return nil, err
}
err = ks.Unlock(foundAcc, *Passphrase)
err = ks.Unlock(foundAcc, passphrase)
if err != nil {
return nil, err
}
Expand Down
10 changes: 7 additions & 3 deletions cli/minter/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ import (
var erc20contract = flag.String("erc20.address", "", "Address of ERC20 mintable token")
var whom = flag.String("forAddress", "", "Address for which tokens to mint")
var amount = flag.Int64("amount", 1000000, "Amount of tokens to mint")
var gethUrl = flag.String("geth.url", "", "URL value of started geth to connect")
var keystoreDir = flag.String("keystore.directory", "testnet", "specify runtime dir for keystore keys")
var passphrase = flag.String("keystore.passphrase", "", "Pashprase to unlock specified key from keystore")
var etherAddress = flag.String("ether.address", "", "Ethereum acc to use for deployment")

func main() {
flag.Parse()
Expand All @@ -28,15 +32,15 @@ func main() {
}

func mintToken() (err error) {
ks := helpers.GetKeystore()
acc, err := helpers.GetUnlockedAcc(ks)
ks := helpers.GetKeystore(*keystoreDir)
acc, err := helpers.GetUnlockedAcc(*etherAddress, *passphrase, ks)
if err != nil {
return
}
fmt.Println("Lookedup acc: ", acc.Address.String())
transactor := helpers.CreateNewKeystoreTransactor(ks, acc)

client, _, err := helpers.LookupBackend()
client, _, err := helpers.LookupBackend(*gethUrl)
if err != nil {
return err
}
Expand Down
3 changes: 2 additions & 1 deletion test_utils/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ import (

type TransactionalBackend interface {
bind.ContractBackend
Commit() //taken from Simulated backend
Commit() //taken from Simulated backend
TransactionReceipt(ctx context.Context, txHash common.Hash) (*types.Receipt, error) //taken from Simulated backend
}

// Keep in mind that initial amount is actually in Gwei - you need really HUGE
Expand Down
5 changes: 4 additions & 1 deletion test_utils/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,14 @@ type EthAccount struct {

func NewAccountFromKey(privateKey *ecdsa.PrivateKey) *EthAccount {

transactor := bind.NewKeyedTransactor(privateKey)
transactor.GasLimit = 0

return &EthAccount{
PrivateKey: privateKey,
PublicKey: privateKey.PublicKey,
Address: crypto.PubkeyToAddress(privateKey.PublicKey),
Transactor: bind.NewKeyedTransactor(privateKey),
Transactor: transactor,
}
}

Expand Down

0 comments on commit fd8d61b

Please sign in to comment.