From 9c4b5cf2027744bb0fe4fbffe087e1978737b046 Mon Sep 17 00:00:00 2001 From: Sam Date: Mon, 23 Sep 2019 00:59:44 -0400 Subject: [PATCH] Move appropriate methods to wallet interface --- types.go | 6 ++++-- wallet.go | 14 ++++++++------ 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/types.go b/types.go index d479924..0ee3d07 100644 --- a/types.go +++ b/types.go @@ -566,8 +566,12 @@ type Wallet struct { } type wallet interface { + CancelRequest(requestID string) error + RequestPayment(user string, amount float64, memo ...string) Send(recipient string, amount string, currency string, message ...string) (WalletAPI, error) SendXLM(recipient string, amount string, message ...string) (WalletAPI, error) + StellarAddress(user string) (string, error) + TxDetail(txid string) (WalletAPI, error) } type keybase interface { @@ -580,8 +584,6 @@ type keybase interface { loggedIn() bool username() string version() string - RequestPayment(user string, amount float64, memo ...string) - CancelRequest(requestID string) error } type status struct { diff --git a/wallet.go b/wallet.go index ed9e6c4..a367883 100644 --- a/wallet.go +++ b/wallet.go @@ -25,26 +25,26 @@ func walletAPIOut(k *Keybase, w WalletAPI) (WalletAPI, error) { } // TxDetail returns details of a stellar transaction -func (k *Keybase) TxDetail(txid string) (WalletAPI, error) { +func (w Wallet) TxDetail(txid string) (WalletAPI, error) { m := WalletAPI{ Params: &wParams{}, } m.Method = "details" m.Params.Options.Txid = txid - r, err := walletAPIOut(k, m) + r, err := walletAPIOut(w.keybase, m) return r, err } // StellarAddress returns the primary stellar address of a given user -func (k *Keybase) StellarAddress(user string) (string, error) { +func (w Wallet) StellarAddress(user string) (string, error) { m := WalletAPI{ Params: &wParams{}, } m.Method = "lookup" m.Params.Options.Name = user - r, err := walletAPIOut(k, m) + r, err := walletAPIOut(w.keybase, m) if err != nil { return "", err } @@ -52,7 +52,8 @@ func (k *Keybase) StellarAddress(user string) (string, error) { } // RequestPayment sends a request for payment to a user -func (k *Keybase) RequestPayment(user string, amount float64, memo ...string) error { +func (w Wallet) RequestPayment(user string, amount float64, memo ...string) error { + k := w.keybase if len(memo) > 0 { _, err := k.Exec("wallet", "request", user, fmt.Sprintf("%f", amount), "-m", memo[0]) return err @@ -62,7 +63,8 @@ func (k *Keybase) RequestPayment(user string, amount float64, memo ...string) er } // CancelRequest cancels a request for payment previously sent to a user -func (k *Keybase) CancelRequest(requestID string) error { +func (w Wallet) CancelRequest(requestID string) error { + k := w.keybase _, err := k.Exec("wallet", "cancel-request", requestID) return err }