Skip to content

Commit 28d22df

Browse files
authored
Display "advanced" txs in the CLI (keybase#17717)
* Add isAdvanced, summaryAdvanced, operations to protocol * Add includeAdvanced * Display advanced txs in the CLI * Fix mock * Something
1 parent 5a9d54c commit 28d22df

16 files changed

Lines changed: 259 additions & 60 deletions

File tree

‎go/client/stellar_common.go‎

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,20 @@ func printPayment(g *libkb.GlobalContext, p stellar1.PaymentCLILocal, verbose bo
2525
if p.Unread {
2626
timeStr += " *"
2727
}
28-
lineUnescaped("%v", ColorString(g, "bold", timeStr))
28+
lineUnescaped(ColorString(g, "bold", timeStr))
29+
30+
if p.IsAdvanced {
31+
line("Account: %s", p.FromStellar.String())
32+
line("Transaction ID: %v", p.TxID)
33+
line(p.SummaryAdvanced)
34+
if verbose {
35+
line("Operations: %d", len(p.Operations))
36+
for _, op := range p.Operations {
37+
line("\t%s", op)
38+
}
39+
}
40+
return
41+
}
2942

3043
// if path payment, show the source asset amount
3144
if p.SourceAmountActual != "" {
@@ -103,7 +116,7 @@ func printPayment(g *libkb.GlobalContext, p stellar1.PaymentCLILocal, verbose bo
103116
}
104117
}
105118
if verbose {
106-
line("Transaction Hash: %v", p.TxID)
119+
line("Transaction ID: %v", p.TxID)
107120
}
108121
switch {
109122
case p.Status == "":

‎go/protocol/stellar1/local.go‎

Lines changed: 59 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎go/protocol/stellar1/remote.go‎

Lines changed: 27 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎go/stellar/remote/interface.go‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,14 @@ import (
77
"github.com/keybase/client/go/protocol/stellar1"
88
)
99

10+
type RecentPaymentsArg struct {
11+
AccountID stellar1.AccountID
12+
Cursor *stellar1.PageCursor
13+
Limit int
14+
SkipPending bool
15+
IncludeAdvanced bool
16+
}
17+
1018
type Remoter interface {
1119
AccountSeqno(ctx context.Context, accountID stellar1.AccountID) (uint64, error)
1220
Balances(ctx context.Context, accountID stellar1.AccountID) ([]stellar1.Balance, error)
@@ -19,7 +27,7 @@ type Remoter interface {
1927
AcquireAutoClaimLock(context.Context) (string, error)
2028
ReleaseAutoClaimLock(context.Context, string) error
2129
NextAutoClaim(context.Context) (*stellar1.AutoClaim, error)
22-
RecentPayments(ctx context.Context, accountID stellar1.AccountID, cursor *stellar1.PageCursor, limit int, skipPending bool) (stellar1.PaymentsPage, error)
30+
RecentPayments(ctx context.Context, arg RecentPaymentsArg) (stellar1.PaymentsPage, error)
2331
PendingPayments(ctx context.Context, accountID stellar1.AccountID, limit int) ([]stellar1.PaymentSummary, error)
2432
PaymentDetails(ctx context.Context, accountID stellar1.AccountID, txID string) (res stellar1.PaymentDetails, err error)
2533
PaymentDetailsGeneric(ctx context.Context, txID string) (res stellar1.PaymentDetails, err error)

‎go/stellar/remote/remote.go‎

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -504,27 +504,27 @@ type recentPaymentsResult struct {
504504
Result stellar1.PaymentsPage `json:"res"`
505505
}
506506

507-
func RecentPayments(ctx context.Context, g *libkb.GlobalContext,
508-
accountID stellar1.AccountID, cursor *stellar1.PageCursor, limit int, skipPending bool) (stellar1.PaymentsPage, error) {
507+
func RecentPayments(ctx context.Context, g *libkb.GlobalContext, arg RecentPaymentsArg) (stellar1.PaymentsPage, error) {
509508
mctx := libkb.NewMetaContext(ctx, g)
510509
apiArg := libkb.APIArg{
511510
Endpoint: "stellar/recentpayments",
512511
SessionType: libkb.APISessionTypeREQUIRED,
513512
Args: libkb.HTTPArgs{
514-
"account_id": libkb.S{Val: accountID.String()},
515-
"limit": libkb.I{Val: limit},
516-
"skip_pending": libkb.B{Val: skipPending},
517-
"include_multi": libkb.B{Val: true},
513+
"account_id": libkb.S{Val: arg.AccountID.String()},
514+
"limit": libkb.I{Val: arg.Limit},
515+
"skip_pending": libkb.B{Val: arg.SkipPending},
516+
"include_multi": libkb.B{Val: true},
517+
"include_advanced": libkb.B{Val: arg.IncludeAdvanced},
518518
},
519519
RetryCount: 3,
520520
RetryMultiplier: 1.5,
521521
InitialTimeout: 10 * time.Second,
522522
}
523523

524-
if cursor != nil {
525-
apiArg.Args["horizon_cursor"] = libkb.S{Val: cursor.HorizonCursor}
526-
apiArg.Args["direct_cursor"] = libkb.S{Val: cursor.DirectCursor}
527-
apiArg.Args["relay_cursor"] = libkb.S{Val: cursor.RelayCursor}
524+
if arg.Cursor != nil {
525+
apiArg.Args["horizon_cursor"] = libkb.S{Val: arg.Cursor.HorizonCursor}
526+
apiArg.Args["direct_cursor"] = libkb.S{Val: arg.Cursor.DirectCursor}
527+
apiArg.Args["relay_cursor"] = libkb.S{Val: arg.Cursor.RelayCursor}
528528
}
529529

530530
var apiRes recentPaymentsResult

‎go/stellar/remote/remote_net.go‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ func (r *RemoteNet) NextAutoClaim(ctx context.Context) (*stellar1.AutoClaim, err
6262
return NextAutoClaim(ctx, r.G())
6363
}
6464

65-
func (r *RemoteNet) RecentPayments(ctx context.Context, accountID stellar1.AccountID, cursor *stellar1.PageCursor, limit int, skipPending bool) (stellar1.PaymentsPage, error) {
66-
return RecentPayments(ctx, r.G(), accountID, cursor, limit, skipPending)
65+
func (r *RemoteNet) RecentPayments(ctx context.Context, arg RecentPaymentsArg) (stellar1.PaymentsPage, error) {
66+
return RecentPayments(ctx, r.G(), arg)
6767
}
6868

6969
func (r *RemoteNet) PendingPayments(ctx context.Context, accountID stellar1.AccountID, limit int) ([]stellar1.PaymentSummary, error) {

‎go/stellar/stellar.go‎

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,12 @@ func ImportSecretKey(mctx libkb.MetaContext, secretKey stellar1.SecretKey, makeP
223223
mctx.Debug("ImportSecretKey, failed to parse secret key after import: %s", err)
224224
return nil
225225
}
226-
page, err := remote.RecentPayments(mctx.Ctx(), mctx.G(), accountID, nil, 0, true)
226+
arg := remote.RecentPaymentsArg{
227+
AccountID: accountID,
228+
SkipPending: true,
229+
IncludeAdvanced: true,
230+
}
231+
page, err := remote.RecentPayments(mctx.Ctx(), mctx.G(), arg)
227232
if err != nil {
228233
mctx.Debug("ImportSecretKey, RecentPayments error: %s", err)
229234
return nil
@@ -1390,7 +1395,11 @@ func GetOwnPrimaryAccountID(mctx libkb.MetaContext) (res stellar1.AccountID, err
13901395

13911396
func RecentPaymentsCLILocal(mctx libkb.MetaContext, remoter remote.Remoter, accountID stellar1.AccountID) (res []stellar1.PaymentOrErrorCLILocal, err error) {
13921397
defer mctx.TraceTimed("Stellar.RecentPaymentsCLILocal", func() error { return err })()
1393-
page, err := remoter.RecentPayments(mctx.Ctx(), accountID, nil, 0, false)
1398+
arg := remote.RecentPaymentsArg{
1399+
AccountID: accountID,
1400+
IncludeAdvanced: true,
1401+
}
1402+
page, err := remoter.RecentPayments(mctx.Ctx(), arg)
13941403
if err != nil {
13951404
return nil, err
13961405
}
@@ -1437,14 +1446,17 @@ func localizePayment(mctx libkb.MetaContext, p stellar1.PaymentSummary) (res ste
14371446
case stellar1.PaymentSummaryType_STELLAR:
14381447
p := p.Stellar()
14391448
return stellar1.PaymentCLILocal{
1440-
TxID: p.TxID,
1441-
Time: p.Ctime,
1442-
Status: "Completed",
1443-
Amount: p.Amount,
1444-
Asset: p.Asset,
1445-
FromStellar: p.From,
1446-
ToStellar: &p.To,
1447-
Unread: p.Unread,
1449+
TxID: p.TxID,
1450+
Time: p.Ctime,
1451+
Status: "Completed",
1452+
Amount: p.Amount,
1453+
Asset: p.Asset,
1454+
FromStellar: p.From,
1455+
ToStellar: &p.To,
1456+
Unread: p.Unread,
1457+
IsAdvanced: p.IsAdvanced,
1458+
SummaryAdvanced: p.SummaryAdvanced,
1459+
Operations: p.Operations,
14481460
}, nil
14491461
case stellar1.PaymentSummaryType_DIRECT:
14501462
p := p.Direct()

‎go/stellar/stellarsvc/frontend.go‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,13 @@ func (s *Server) GetPaymentsLocal(ctx context.Context, arg stellar1.GetPaymentsL
309309
return page, ErrAccountIDMissing
310310
}
311311

312-
srvPayments, err := s.remoter.RecentPayments(ctx, arg.AccountID, arg.Cursor, 0, true)
312+
rpArg := remote.RecentPaymentsArg{
313+
AccountID: arg.AccountID,
314+
Cursor: arg.Cursor,
315+
SkipPending: true,
316+
IncludeAdvanced: false, // TODO: make this true when the frontend is ready for it
317+
}
318+
srvPayments, err := s.remoter.RecentPayments(ctx, rpArg)
313319
if err != nil {
314320
return page, err
315321
}
@@ -400,6 +406,9 @@ func (s *Server) GetPaymentDetailsLocal(ctx context.Context, arg stellar1.GetPay
400406
SourceAsset: summary.SourceAsset,
401407
SourceAmountMax: summary.SourceAmountMax,
402408
SourceAmountActual: summary.SourceAmountActual,
409+
IsAdvanced: summary.IsAdvanced,
410+
SummaryAdvanced: summary.SummaryAdvanced,
411+
Operations: summary.Operations,
403412
}
404413

405414
return payment, nil

‎go/stellar/stellarsvc/remote_mock_test.go‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -459,8 +459,8 @@ func (r *RemoteClientMock) NextAutoClaim(ctx context.Context) (*stellar1.AutoCla
459459
return r.Backend.NextAutoClaim(ctx, r.Tc)
460460
}
461461

462-
func (r *RemoteClientMock) RecentPayments(ctx context.Context, accountID stellar1.AccountID, cursor *stellar1.PageCursor, limit int, skipPending bool) (stellar1.PaymentsPage, error) {
463-
return r.Backend.RecentPayments(ctx, r.Tc, accountID, cursor, limit, skipPending)
462+
func (r *RemoteClientMock) RecentPayments(ctx context.Context, arg remote.RecentPaymentsArg) (stellar1.PaymentsPage, error) {
463+
return r.Backend.RecentPayments(ctx, r.Tc, arg.AccountID, arg.Cursor, arg.Limit, arg.SkipPending)
464464
}
465465

466466
func (r *RemoteClientMock) PendingPayments(ctx context.Context, accountID stellar1.AccountID, limit int) ([]stellar1.PaymentSummary, error) {

‎go/stellar/transform.go‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,10 @@ func transformPaymentStellar(mctx libkb.MetaContext, acctID stellar1.AccountID,
137137
loc.SourceAmountMax = p.SourceAmountMax
138138
loc.SourceAmountActual = p.SourceAmountActual
139139

140+
loc.IsAdvanced = p.IsAdvanced
141+
loc.SummaryAdvanced = p.SummaryAdvanced
142+
loc.Operations = p.Operations
143+
140144
return loc, nil
141145
}
142146

0 commit comments

Comments
 (0)