Browse Source

Add Send and SendXLM methods to wallet interface

main
Sam 5 years ago
parent
commit
e64220b071
  1. 10
      types.go
  2. 27
      wallet.go

10
types.go

@ -339,8 +339,12 @@ type WalletAPI struct { @@ -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 { @@ -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 {

27
wallet.go

@ -4,6 +4,7 @@ import ( @@ -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 { @@ -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
}

Loading…
Cancel
Save