Move appropriate methods to wallet interface

This commit is contained in:
Sam
2019-09-23 00:59:44 -04:00
parent d2bdf62100
commit 9c4b5cf202
2 changed files with 12 additions and 8 deletions

View File

@ -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 {

View File

@ -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
}