diff --git a/types.go b/types.go index a944613..b6f2224 100644 --- a/types.go +++ b/types.go @@ -339,8 +339,12 @@ type WalletAPI struct { } type wOptions struct { - Name string `json:"name"` - Txid string `json:"txid"` + Name string `json:"name"` + Txid string `json:"txid"` + Recipient string `json:"recipient"` + Amount string `json:"amount"` + Currency string `json:"currency"` + Message string `json:"message"` } type wParams struct { @@ -562,6 +566,8 @@ type Wallet struct { } 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 { diff --git a/wallet.go b/wallet.go index cfc11a6..ed9e6c4 100644 --- a/wallet.go +++ b/wallet.go @@ -4,6 +4,7 @@ import ( "encoding/json" "errors" "fmt" + "strings" ) // 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) 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 +}