Add Send and SendXLM methods to wallet interface
This commit is contained in:
10
types.go
10
types.go
@ -339,8 +339,12 @@ type WalletAPI struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type wOptions struct {
|
type wOptions struct {
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Txid string `json:"txid"`
|
Txid string `json:"txid"`
|
||||||
|
Recipient string `json:"recipient"`
|
||||||
|
Amount string `json:"amount"`
|
||||||
|
Currency string `json:"currency"`
|
||||||
|
Message string `json:"message"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type wParams struct {
|
type wParams struct {
|
||||||
@ -562,6 +566,8 @@ type Wallet struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type wallet interface {
|
type wallet interface {
|
||||||
|
Send(recipient string, amount string, currency string, message ...string) (WalletAPI, error)
|
||||||
|
SendXLM(recipient string, amount string, message ...string) (WalletAPI, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
type keybase interface {
|
type keybase interface {
|
||||||
|
|||||||
27
wallet.go
27
wallet.go
@ -4,6 +4,7 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
// walletAPIOut sends JSON requests to the wallet API and returns its response.
|
// walletAPIOut sends JSON requests to the wallet API and returns its response.
|
||||||
@ -65,3 +66,29 @@ func (k *Keybase) CancelRequest(requestID string) error {
|
|||||||
_, err := k.Exec("wallet", "cancel-request", requestID)
|
_, err := k.Exec("wallet", "cancel-request", requestID)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Send sends the specified amount of the specified currency to a user
|
||||||
|
func (w Wallet) Send(recipient string, amount string, currency string, message ...string) (WalletAPI, error) {
|
||||||
|
m := WalletAPI{
|
||||||
|
Params: &wParams{},
|
||||||
|
}
|
||||||
|
m.Method = "send"
|
||||||
|
m.Params.Options.Recipient = recipient
|
||||||
|
m.Params.Options.Amount = amount
|
||||||
|
m.Params.Options.Currency = currency
|
||||||
|
if len(message) > 0 {
|
||||||
|
m.Params.Options.Message = strings.Join(message, " ")
|
||||||
|
}
|
||||||
|
|
||||||
|
r, err := walletAPIOut(w.keybase, m)
|
||||||
|
if err != nil {
|
||||||
|
return WalletAPI{}, err
|
||||||
|
}
|
||||||
|
return r, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// SendXLM sends the specified amount of XLM to a user
|
||||||
|
func (w Wallet) SendXLM(recipient string, amount string, message ...string) (WalletAPI, error) {
|
||||||
|
result, err := w.Send(recipient, amount, "XLM", message...)
|
||||||
|
return result, err
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user