aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--callback_handler_test.go3
-rw-r--r--xmrpayclnt.go35
2 files changed, 21 insertions, 17 deletions
diff --git a/callback_handler_test.go b/callback_handler_test.go
index e303a70..d1ed083 100644
--- a/callback_handler_test.go
+++ b/callback_handler_test.go
@@ -2,7 +2,6 @@ package xmrpayclnt_test
import (
"bytes"
- "context"
"encoding/json"
"fmt"
"log"
@@ -43,7 +42,7 @@ func ExampleCallbackHandler() {
// Request a transfer and register a callback for it
clnt := xmrpay.New(xmrPaySrvUrl)
- resp, cb, err := clnt.NewTxWithCallback(context.Background(), 123, "lorem ipsum", cbHlr)
+ resp, cb, err := clnt.NewTxWithCallback(123, "lorem ipsum", cbHlr)
if err != nil {
log.Fatal(err)
}
diff --git a/xmrpayclnt.go b/xmrpayclnt.go
index 2ecd183..fc2470c 100644
--- a/xmrpayclnt.go
+++ b/xmrpayclnt.go
@@ -5,7 +5,6 @@ package xmrpayclnt
import (
"bytes"
- "context"
"encoding/json"
"log"
"net/http"
@@ -30,16 +29,22 @@ type Client struct {
endpoint *url.URL
}
-// New creates a client that will connect to the moneropay server at
+// New creates a client that will connect to the MoneroPay server at
// endpoint.
func New(endpoint *url.URL) *Client {
- return &Client{jttp.NewClient(&http.Client{}), endpoint}
+ return WithClient(&http.Client{}, endpoint)
+}
+
+// WithClient creates a MoneroPay client that will use the given HTTP
+// client to connect to the MoneroPay server at endpoint.
+func WithClient(c *http.Client, endpoint *url.URL) *Client {
+ return &Client{jttp.NewClient(c), endpoint}
}
// Balance returns the entire wallet balance.
-func (c *Client) Balance(ctx context.Context) (model.BalanceResponse, error) {
+func (c *Client) Balance() (model.BalanceResponse, error) {
url := c.endpoint.JoinPath(balancePath)
- req, err := http.NewRequestWithContext(ctx, http.MethodGet, url.String(), nil)
+ req, err := http.NewRequest(http.MethodGet, url.String(), nil)
if err != nil {
return model.BalanceResponse{}, err
}
@@ -49,9 +54,9 @@ func (c *Client) Balance(ctx context.Context) (model.BalanceResponse, error) {
}
// Health returns true if all required services are up.
-func (c *Client) Health(ctx context.Context) (bool, error) {
+func (c *Client) Health() (bool, error) {
url := c.endpoint.JoinPath(healthPath)
- req, err := http.NewRequestWithContext(ctx, http.MethodGet, url.String(), nil)
+ req, err := http.NewRequest(http.MethodGet, url.String(), nil)
if err != nil {
return false, err
}
@@ -61,14 +66,14 @@ func (c *Client) Health(ctx context.Context) (bool, error) {
}
// NewTx creates a subaddress for incoming transfers.
-func (c *Client) NewTx(ctx context.Context, amount uint64, description string) (model.ReceivePostResponse, error) {
- return c.postReceive(ctx, amount, description, "")
+func (c *Client) NewTx(amount uint64, description string) (model.ReceivePostResponse, error) {
+ return c.postReceive(amount, description, "")
}
// NewTxWithCallback creates a subaddress and a callback to monitor it.
-func (c *Client) NewTxWithCallback(ctx context.Context, amount uint64, description string, ch *CallbackHandler) (model.ReceivePostResponse, Callback, error) {
+func (c *Client) NewTxWithCallback(amount uint64, description string, ch *CallbackHandler) (model.ReceivePostResponse, Callback, error) {
cb := ch.listen()
- if resp, err := c.postReceive(ctx, amount, description, cb.url.String()); err == nil {
+ if resp, err := c.postReceive(amount, description, cb.url.String()); err == nil {
return resp, cb, nil
} else {
cb.Close()
@@ -77,10 +82,10 @@ func (c *Client) NewTxWithCallback(ctx context.Context, amount uint64, descripti
}
// GetTxStatus retrieves information about a transfer on a subaddress.
-func (c *Client) GetTxStatus(ctx context.Context, address string) (model.ReceiveGetResponse, error) {
+func (c *Client) GetTxStatus(address string) (model.ReceiveGetResponse, error) {
var resp model.ReceiveGetResponse
url := c.endpoint.JoinPath(receivePath, address)
- req, err := http.NewRequestWithContext(ctx, http.MethodGet, url.String(), nil)
+ req, err := http.NewRequest(http.MethodGet, url.String(), nil)
if err != nil {
return resp, err
}
@@ -88,7 +93,7 @@ func (c *Client) GetTxStatus(ctx context.Context, address string) (model.Receive
return resp, err
}
-func (c *Client) postReceive(ctx context.Context, amount uint64, description string, callbackUrl string) (model.ReceivePostResponse, error) {
+func (c *Client) postReceive(amount uint64, description string, callbackUrl string) (model.ReceivePostResponse, error) {
var resp model.ReceivePostResponse
body := new(bytes.Buffer)
@@ -99,7 +104,7 @@ func (c *Client) postReceive(ctx context.Context, amount uint64, description str
}
url := c.endpoint.JoinPath(receivePath)
- req, err := http.NewRequestWithContext(ctx, http.MethodPost, url.String(), body)
+ req, err := http.NewRequest(http.MethodPost, url.String(), body)
if err != nil {
return resp, err
}