Skip to content

Commit bb1a57c

Browse files
authored
Merge pull request #403 from oasisprotocol/matevz/cmd/more-ux-hints
Add hint for the Testnet faucet, no account, no ParaTime and failed deposit
2 parents 954cd3f + 4bd699c commit bb1a57c

File tree

22 files changed

+130
-172
lines changed

22 files changed

+130
-172
lines changed

cmd/account/allow.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,7 @@ var allowCmd = &cobra.Command{
2323
txCfg := common.GetTransactionConfig()
2424
beneficiary, amount := args[0], args[1]
2525

26-
if npa.Account == nil {
27-
cobra.CheckErr("no accounts configured in your wallet")
28-
}
26+
npa.MustHaveAccount()
2927

3028
// When not in offline mode, connect to the given network endpoint.
3129
ctx := context.Background()
@@ -60,7 +58,7 @@ var allowCmd = &cobra.Command{
6058
sigTx, err := common.SignConsensusTransaction(ctx, npa, acc, conn, tx)
6159
cobra.CheckErr(err)
6260

63-
common.BroadcastOrExportTransaction(ctx, npa.ParaTime, conn, sigTx, nil, nil)
61+
common.BroadcastOrExportTransaction(ctx, npa, conn, sigTx, nil, nil)
6462
},
6563
}
6664

cmd/account/amend_commission_schedule.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,7 @@ var (
2828
npa := common.GetNPASelection(cfg)
2929
txCfg := common.GetTransactionConfig()
3030

31-
if npa.Account == nil {
32-
cobra.CheckErr("no accounts configured in your wallet")
33-
}
31+
npa.MustHaveAccount()
3432
acc := common.LoadAccount(cfg, npa.AccountName)
3533

3634
// When not in offline mode, connect to the given network endpoint.
@@ -115,7 +113,7 @@ var (
115113
sigTx, err := common.SignConsensusTransaction(ctx, npa, acc, conn, tx)
116114
cobra.CheckErr(err)
117115

118-
common.BroadcastOrExportTransaction(ctx, npa.ParaTime, conn, sigTx, nil, nil)
116+
common.BroadcastOrExportTransaction(ctx, npa, conn, sigTx, nil, nil)
119117
},
120118
}
121119
)

cmd/account/burn.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,7 @@ var burnCmd = &cobra.Command{
2323
txCfg := common.GetTransactionConfig()
2424
amountStr := args[0]
2525

26-
if npa.Account == nil {
27-
cobra.CheckErr("no accounts configured in your wallet")
28-
}
26+
npa.MustHaveAccount()
2927

3028
// When not in offline mode, connect to the given network endpoint.
3129
ctx := context.Background()
@@ -50,7 +48,7 @@ var burnCmd = &cobra.Command{
5048
sigTx, err := common.SignConsensusTransaction(ctx, npa, acc, conn, tx)
5149
cobra.CheckErr(err)
5250

53-
common.BroadcastOrExportTransaction(ctx, npa.ParaTime, conn, sigTx, nil, nil)
51+
common.BroadcastOrExportTransaction(ctx, npa, conn, sigTx, nil, nil)
5452
},
5553
}
5654

cmd/account/delegate.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,7 @@ var delegateCmd = &cobra.Command{
2727
txCfg := common.GetTransactionConfig()
2828
amount, to := args[0], args[1]
2929

30-
if npa.Account == nil {
31-
cobra.CheckErr("no accounts configured in your wallet")
32-
}
30+
npa.MustHaveAccount()
3331

3432
// When not in offline mode, connect to the given network endpoint.
3533
ctx := context.Background()
@@ -94,7 +92,7 @@ var delegateCmd = &cobra.Command{
9492
}
9593
}
9694

97-
if !common.BroadcastOrExportTransaction(ctx, npa.ParaTime, conn, sigTx, meta, nil) {
95+
if !common.BroadcastOrExportTransaction(ctx, npa, conn, sigTx, meta, nil) {
9896
return
9997
}
10098

cmd/account/deposit.go

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
ethCommon "github.com/ethereum/go-ethereum/common"
88
"github.com/spf13/cobra"
99

10+
"github.com/oasisprotocol/oasis-core/go/common/errors"
1011
"github.com/oasisprotocol/oasis-sdk/client-sdk/go/client"
1112
"github.com/oasisprotocol/oasis-sdk/client-sdk/go/connection"
1213
sdkSignature "github.com/oasisprotocol/oasis-sdk/client-sdk/go/crypto/signature"
@@ -32,12 +33,8 @@ var depositCmd = &cobra.Command{
3233
to = args[1]
3334
}
3435

35-
if npa.Account == nil {
36-
cobra.CheckErr("no accounts configured in your wallet")
37-
}
38-
if npa.ParaTime == nil {
39-
cobra.CheckErr("no ParaTimes to deposit into")
40-
}
36+
npa.MustHaveAccount()
37+
npa.MustHaveParaTime()
4138

4239
// When not in offline mode, connect to the given network endpoint.
4340
ctx := context.Background()
@@ -94,7 +91,7 @@ var depositCmd = &cobra.Command{
9491
return ce.Deposit
9592
})
9693

97-
common.BroadcastTransaction(ctx, npa.ParaTime, conn, sigTx, meta, nil)
94+
common.BroadcastTransaction(ctx, npa, conn, sigTx, meta, nil)
9895

9996
fmt.Printf("Waiting for deposit result...\n")
10097

@@ -108,10 +105,12 @@ var depositCmd = &cobra.Command{
108105
case true:
109106
fmt.Printf("Deposit succeeded.\n")
110107
case false:
111-
cobra.CheckErr(fmt.Errorf("deposit failed with error code %d from module %s",
112-
we.Error.Code,
113-
we.Error.Module,
114-
))
108+
cobra.CheckErr(fmt.Sprintf("Deposit failed with error: %s",
109+
common.PrettyErrorHints(ctx, npa, conn, tx, meta, &types.FailedCallResult{
110+
Module: we.Error.Module,
111+
Code: we.Error.Code,
112+
Message: errors.FromCode(we.Error.Module, we.Error.Code, "").Error(),
113+
})))
115114
}
116115
},
117116
}

cmd/account/entity.go

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,7 @@ var (
3434
cfg := cliConfig.Global()
3535
npa := common.GetNPASelection(cfg)
3636

37-
if npa.Account == nil {
38-
cobra.CheckErr("no accounts configured in your wallet")
39-
}
37+
npa.MustHaveAccount()
4038

4139
// Load the account and ensure it corresponds to the entity.
4240
acc := common.LoadAccount(cfg, npa.AccountName)
@@ -81,9 +79,7 @@ var (
8179
txCfg := common.GetTransactionConfig()
8280
filename := args[0]
8381

84-
if npa.Account == nil {
85-
cobra.CheckErr("no accounts configured in your wallet")
86-
}
82+
npa.MustHaveAccount()
8783

8884
// When not in offline mode, connect to the given network endpoint.
8985
ctx := context.Background()
@@ -127,7 +123,7 @@ var (
127123
sigTx, err := common.SignConsensusTransaction(ctx, npa, acc, conn, tx)
128124
cobra.CheckErr(err)
129125

130-
common.BroadcastOrExportTransaction(ctx, npa.ParaTime, conn, sigTx, nil, nil)
126+
common.BroadcastOrExportTransaction(ctx, npa, conn, sigTx, nil, nil)
131127
},
132128
}
133129

@@ -140,9 +136,7 @@ var (
140136
npa := common.GetNPASelection(cfg)
141137
txCfg := common.GetTransactionConfig()
142138

143-
if npa.Account == nil {
144-
cobra.CheckErr("no accounts configured in your wallet")
145-
}
139+
npa.MustHaveAccount()
146140

147141
// When not in offline mode, connect to the given network endpoint.
148142
ctx := context.Background()
@@ -160,7 +154,7 @@ var (
160154
sigTx, err := common.SignConsensusTransaction(ctx, npa, acc, conn, tx)
161155
cobra.CheckErr(err)
162156

163-
common.BroadcastOrExportTransaction(ctx, npa.ParaTime, conn, sigTx, nil, nil)
157+
common.BroadcastOrExportTransaction(ctx, npa, conn, sigTx, nil, nil)
164158
},
165159
}
166160

@@ -174,9 +168,7 @@ var (
174168
cfg := cliConfig.Global()
175169
npa := common.GetNPASelection(cfg)
176170

177-
if npa.Account == nil {
178-
cobra.CheckErr("no accounts configured in your wallet")
179-
}
171+
npa.MustHaveAccount()
180172

181173
var fsRegistry metadataRegistry.MutableProvider
182174
switch registryPath {

cmd/account/node_unfreeze.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,7 @@ var nodeUnfreezeCmd = &cobra.Command{
2323
txCfg := common.GetTransactionConfig()
2424
rawNodeID := args[0]
2525

26-
if npa.Account == nil {
27-
cobra.CheckErr("no accounts configured in your wallet")
28-
}
26+
npa.MustHaveAccount()
2927

3028
// When not in offline mode, connect to the given network endpoint.
3129
ctx := context.Background()
@@ -50,7 +48,7 @@ var nodeUnfreezeCmd = &cobra.Command{
5048
sigTx, err := common.SignConsensusTransaction(ctx, npa, acc, conn, tx)
5149
cobra.CheckErr(err)
5250

53-
common.BroadcastOrExportTransaction(ctx, npa.ParaTime, conn, sigTx, nil, nil)
51+
common.BroadcastOrExportTransaction(ctx, npa, conn, sigTx, nil, nil)
5452
},
5553
}
5654

cmd/account/transfer.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,7 @@ var transferCmd = &cobra.Command{
3636
cobra.CheckErr("unexpected number of arguments") // Should never happen.
3737
}
3838

39-
if npa.Account == nil {
40-
cobra.CheckErr("no accounts configured in your wallet")
41-
}
39+
npa.MustHaveAccount()
4240

4341
// When not in offline mode, connect to the given network endpoint.
4442
ctx := context.Background()
@@ -116,7 +114,7 @@ var transferCmd = &cobra.Command{
116114
cobra.CheckErr(err)
117115
}
118116

119-
common.BroadcastOrExportTransaction(ctx, npa.ParaTime, conn, sigTx, meta, nil)
117+
common.BroadcastOrExportTransaction(ctx, npa, conn, sigTx, meta, nil)
120118
},
121119
}
122120

cmd/account/undelegate.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,7 @@ var undelegateCmd = &cobra.Command{
2727
txCfg := common.GetTransactionConfig()
2828
amount, from := args[0], args[1]
2929

30-
if npa.Account == nil {
31-
cobra.CheckErr("no accounts configured in your wallet")
32-
}
30+
npa.MustHaveAccount()
3331

3432
// When not in offline mode, connect to the given network endpoint.
3533
ctx := context.Background()
@@ -90,7 +88,7 @@ var undelegateCmd = &cobra.Command{
9088
}
9189
}
9290

93-
if !common.BroadcastOrExportTransaction(ctx, npa.ParaTime, conn, sigTx, meta, nil) {
91+
if !common.BroadcastOrExportTransaction(ctx, npa, conn, sigTx, meta, nil) {
9492
return
9593
}
9694

cmd/account/withdraw.go

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,8 @@ var withdrawCmd = &cobra.Command{
3232
to = args[1]
3333
}
3434

35-
if npa.Account == nil {
36-
cobra.CheckErr("no accounts configured in your wallet")
37-
}
38-
if npa.ParaTime == nil {
39-
cobra.CheckErr("no ParaTimes to withdraw from")
40-
}
35+
npa.MustHaveAccount()
36+
npa.MustHaveParaTime()
4137

4238
// When not in offline mode, connect to the given network endpoint.
4339
ctx := context.Background()
@@ -112,7 +108,7 @@ var withdrawCmd = &cobra.Command{
112108
return ce.Withdraw
113109
})
114110

115-
common.BroadcastTransaction(ctx, npa.ParaTime, conn, sigTx, meta, nil)
111+
common.BroadcastTransaction(ctx, npa, conn, sigTx, meta, nil)
116112

117113
fmt.Printf("Waiting for withdraw result...\n")
118114

0 commit comments

Comments
 (0)