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: 21 additions & 0 deletions cmd/livepeer_cli/wizard.go
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,27 @@ func httpPostWithParamsHeaders(url string, val url.Values, headers map[string]st
return "", false
}

func (w *wizard) confirm(prompt string) bool {
fmt.Printf("%s [Y/n] ", prompt)
text := w.read()
if text != "Y" {
fmt.Println("Aborting.")
return false
}
return true
}

func (w *wizard) printGasInfo(gasLimit *big.Int, gasPrice *big.Int) {
var cost *big.Float
if gasPrice != nil {
cost = new(big.Float).SetInt(new(big.Int).Mul(gasLimit, gasPrice))
} else {
cost = new(big.Float).SetInt(new(big.Int).Mul(gasLimit, w.eth.GasPrice()))
}
fmt.Printf("Estimated TX cost: %v ETH\n", eth.ToETH(cost, big.NewInt(1)))
}


defer resp.Body.Close()
result, err := ioutil.ReadAll(resp.Body)
if err != nil {
Expand Down
30 changes: 30 additions & 0 deletions cmd/livepeer_cli/wizard_bond.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,12 @@ func (w *wizard) rebond() {
}

if dInfo.Status == "Unbonded" {
w.printGasInfo(big.NewInt(eth.BondGas), nil)
if !w.confirm(fmt.Sprintf("Are you sure you want to bond %v LPT to \"%s\"?", eth.FormatUnits(amount, "lpt"), tAddr.Hex())) {
return
}


fmt.Printf("You are unbonded - you will need to choose an address to rebond to.\n")

var toAddr common.Address
Expand Down Expand Up @@ -260,6 +266,12 @@ func (w *wizard) unbond() {

fmt.Printf("Current Bonded Amount: %v\n", eth.FormatUnits(dInfo.BondedAmount, "LPT"))
fmt.Printf("Current Delegate: %v\n", dInfo.DelegateAddress.Hex())
w.printGasInfo(big.NewInt(eth.RebondGas), nil)
if !w.confirm(fmt.Sprintf("Are you sure you want to rebond from unbonding lock %v?", unbondingLockID)) {
return
}



fmt.Printf("Would you like to fully unbond? (y/n) - ")

Expand Down Expand Up @@ -298,6 +310,12 @@ func (w *wizard) withdrawStake() {
if err != nil {
glog.Errorf("Error getting delegator info: %v", err)
return
w.printGasInfo(big.NewInt(eth.UnbondGas), nil)
if !w.confirm(fmt.Sprintf("Are you sure you want to unbond %v LPT?", eth.FormatUnits(amount, "lpt"))) {
return
}


}

fmt.Printf("Current Bonded Amount: %v\n", eth.FormatUnits(dInfo.BondedAmount, "LPT"))
Expand All @@ -324,6 +342,12 @@ func (w *wizard) withdrawStake() {
}

val := url.Values{
w.printGasInfo(big.NewInt(eth.WithdrawStakeGas), nil)
if !w.confirm(fmt.Sprintf("Are you sure you want to withdraw stake from unbonding lock %v?", unbondingLockID)) {
return
}


"unbondingLockId": {fmt.Sprintf("%v", strconv.FormatInt(unbondingLockID, 10))},
}

Expand All @@ -336,6 +360,12 @@ func (w *wizard) withdrawFees() {
glog.Errorf("Error getting delegator info: %v", err)
return
}
w.printGasInfo(big.NewInt(eth.WithdrawFeesGas), nil)
if !w.confirm(fmt.Sprintf("Are you sure you want to withdraw %v ETH in fees?", eth.FormatUnits(dInfo.PendingFees, "eth"))) {
return
}



val := url.Values{
"amount": {fmt.Sprintf("%v", dInfo.PendingFees.String())},
Expand Down
8 changes: 8 additions & 0 deletions cmd/livepeer_cli/wizard_rounds.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"io/ioutil"
"math/big"
"net/http"

"github.com/livepeer/go-livepeer/eth"
)

func (w *wizard) currentRound() (*big.Int, error) {
Expand All @@ -30,6 +32,12 @@ func (w *wizard) currentRound() (*big.Int, error) {

return cr, nil
}
w.printGasInfo(big.NewInt(eth.InitializeRoundGas), nil)
if !w.confirm("Are you sure you want to initialize the round?") {
return
}



func (w *wizard) initializeRound() {
httpPost(fmt.Sprintf("http://%v:%v/initializeRound", w.host, w.httpPort))
Expand Down
8 changes: 8 additions & 0 deletions cmd/livepeer_cli/wizard_token.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@ package main

import (
"fmt"
"math/big"
"net/url"
"strings"

"github.com/livepeer/go-livepeer/eth"
)

func (w *wizard) transferTokens() {
Expand All @@ -14,6 +17,11 @@ func (w *wizard) transferTokens() {

amount := w.readBigInt("Enter amount")

w.printGasInfo(big.NewInt(eth.TransferTokensGas), nil)
if !w.confirm(fmt.Sprintf("Are you sure you want to send %v LPTU to \"%s\"?", eth.FormatUnits(amount, "lpt"), to)) {
return
}

val := url.Values{
"to": {fmt.Sprintf("%v", to)},
"amount": {fmt.Sprintf("%v", amount.String())},
Expand Down
18 changes: 18 additions & 0 deletions cmd/livepeer_cli/wizard_transcoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,12 @@ func (w *wizard) getOrchestratorConfigFormValues() url.Values {
"currency": {fmt.Sprintf("%v", currency)},
"pixelsPerUnit": {fmt.Sprintf("%v", pixelsPerUnit)},
"serviceURI": {fmt.Sprintf("%v", serviceURI)},
w.printGasInfo(big.NewInt(eth.BondGas), nil)
if !w.confirm("Are you sure you want to activate an orchestrator?") {
return
}


}
}

Expand All @@ -221,6 +227,12 @@ func (w *wizard) callReward() {

if c.Cmp(t.LastRewardRound) == 0 {
fmt.Printf("Reward for current round %v already called\n", c)
w.printGasInfo(big.NewInt(eth.SetOrchestratorConfigGas), nil)
if !w.confirm("Are you sure you want to set the orchestrator config?") {
return
}


return
}

Expand All @@ -241,6 +253,12 @@ func (w *wizard) vote() {
}
return in, nil
})
w.printGasInfo(big.NewInt(eth.RewardGas), nil)
if !w.confirm("Are you sure you want to call reward?") {
return
}



var (
confirm = "n"
Expand Down
Loading