Skip to content

Commit

Permalink
reomved pointers to sign and server
Browse files Browse the repository at this point in the history
  • Loading branch information
ac4ch committed May 15, 2024
1 parent bf02213 commit 83f9b02
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 26 deletions.
4 changes: 2 additions & 2 deletions client_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ type HTTP struct {
}

func (w *HTTP) Configure(c *WalletClient) {
c.server = w.ServerURL
c.server = *w.ServerURL
c.httpClient = w.HTTPClient
if w.HTTPClient != nil {
c.httpClient = w.HTTPClient
Expand All @@ -86,7 +86,7 @@ type SignRequest struct {
}

func (w *SignRequest) Configure(c *WalletClient) {
c.signRequest = w.Sign
c.signRequest = *w.Sign
}

// initializeAccessKey handles the specific initialization of the access key.
Expand Down
32 changes: 16 additions & 16 deletions http.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ import (

// SetSignRequest turn the signing of the http request on or off
func (wc *WalletClient) SetSignRequest(signRequest bool) {
wc.signRequest = &signRequest
wc.signRequest = signRequest
}

// IsSignRequest return whether to sign all requests
func (wc *WalletClient) IsSignRequest() bool {
return *wc.signRequest
return wc.signRequest
}

// SetAdminKey set the admin key
Expand Down Expand Up @@ -306,7 +306,7 @@ func (wc *WalletClient) UpdateDestinationMetadataByLockingScript(ctx context.Con
// GetTransaction will get a transaction by ID
func (wc *WalletClient) GetTransaction(ctx context.Context, txID string) (*models.Transaction, ResponseError) {
var transaction models.Transaction
if err := wc.doHTTPRequest(ctx, http.MethodGet, "/transaction?"+FieldID+"="+txID, nil, wc.getPrivKey(), *wc.signRequest, &transaction); err != nil {
if err := wc.doHTTPRequest(ctx, http.MethodGet, "/transaction?"+FieldID+"="+txID, nil, wc.getPrivKey(), wc.signRequest, &transaction); err != nil {
return nil, err
}

Expand All @@ -326,7 +326,7 @@ func (wc *WalletClient) GetTransactions(ctx context.Context, conditions map[stri

var transactions []*models.Transaction
if err := wc.doHTTPRequest(
ctx, http.MethodPost, "/transaction/search", jsonStr, wc.getPrivKey(), *wc.signRequest, &transactions,
ctx, http.MethodPost, "/transaction/search", jsonStr, wc.getPrivKey(), wc.signRequest, &transactions,
); err != nil {
return nil, err
}
Expand All @@ -348,7 +348,7 @@ func (wc *WalletClient) GetTransactionsCount(ctx context.Context, conditions map

var count int64
if err := wc.doHTTPRequest(
ctx, http.MethodPost, "/transaction/count", jsonStr, wc.getPrivKey(), *wc.signRequest, &count,
ctx, http.MethodPost, "/transaction/count", jsonStr, wc.getPrivKey(), wc.signRequest, &count,
); err != nil {
return 0, err
}
Expand Down Expand Up @@ -424,7 +424,7 @@ func (wc *WalletClient) RecordTransaction(ctx context.Context, hex, referenceID

var transaction models.Transaction
if err := wc.doHTTPRequest(
ctx, http.MethodPost, "/transaction/record", jsonStr, wc.getPrivKey(), *wc.signRequest, &transaction,
ctx, http.MethodPost, "/transaction/record", jsonStr, wc.getPrivKey(), wc.signRequest, &transaction,
); err != nil {
return nil, err
}
Expand All @@ -446,7 +446,7 @@ func (wc *WalletClient) UpdateTransactionMetadata(ctx context.Context, txID stri

var transaction models.Transaction
if err := wc.doHTTPRequest(
ctx, http.MethodPatch, "/transaction", jsonStr, wc.getPrivKey(), *wc.signRequest, &transaction,
ctx, http.MethodPatch, "/transaction", jsonStr, wc.getPrivKey(), wc.signRequest, &transaction,
); err != nil {
return nil, err
}
Expand Down Expand Up @@ -497,7 +497,7 @@ func (wc *WalletClient) GetUtxos(ctx context.Context, conditions map[string]inte

var utxos []*models.Utxo
if err := wc.doHTTPRequest(
ctx, http.MethodPost, "/utxo/search", jsonStr, wc.getPrivKey(), *wc.signRequest, &utxos,
ctx, http.MethodPost, "/utxo/search", jsonStr, wc.getPrivKey(), wc.signRequest, &utxos,
); err != nil {
return nil, err
}
Expand All @@ -517,7 +517,7 @@ func (wc *WalletClient) GetUtxosCount(ctx context.Context, conditions map[string

var count int64
if err := wc.doHTTPRequest(
ctx, http.MethodPost, "/utxo/count", jsonStr, wc.getPrivKey(), *wc.signRequest, &count,
ctx, http.MethodPost, "/utxo/count", jsonStr, wc.getPrivKey(), wc.signRequest, &count,
); err != nil {
return 0, err
}
Expand Down Expand Up @@ -559,7 +559,7 @@ func createSignatureAccessKey(privateKeyHex, bodyString string) (payload *models
func (wc *WalletClient) doHTTPRequest(ctx context.Context, method string, path string,
rawJSON []byte, xPriv *bip32.ExtendedKey, sign bool, responseJSON interface{},
) ResponseError {
req, err := http.NewRequestWithContext(ctx, method, *wc.server+path, bytes.NewBuffer(rawJSON))
req, err := http.NewRequestWithContext(ctx, method, wc.server+path, bytes.NewBuffer(rawJSON))
if err != nil {
return WrapError(err)
}
Expand Down Expand Up @@ -625,7 +625,7 @@ func (wc *WalletClient) authenticateWithAccessKey(req *http.Request, rawJSON []b
// AcceptContact will accept the contact associated with the paymail
func (wc *WalletClient) AcceptContact(ctx context.Context, paymail string) ResponseError {
if err := wc.doHTTPRequest(
ctx, http.MethodPatch, "/contact/accepted/"+paymail, nil, wc.getPrivKey(), *wc.signRequest, nil,
ctx, http.MethodPatch, "/contact/accepted/"+paymail, nil, wc.getPrivKey(), wc.signRequest, nil,
); err != nil {
return err
}
Expand All @@ -636,7 +636,7 @@ func (wc *WalletClient) AcceptContact(ctx context.Context, paymail string) Respo
// RejectContact will reject the contact associated with the paymail
func (wc *WalletClient) RejectContact(ctx context.Context, paymail string) ResponseError {
if err := wc.doHTTPRequest(
ctx, http.MethodPatch, "/contact/rejected/"+paymail, nil, wc.getPrivKey(), *wc.signRequest, nil,
ctx, http.MethodPatch, "/contact/rejected/"+paymail, nil, wc.getPrivKey(), wc.signRequest, nil,
); err != nil {
return err
}
Expand All @@ -656,7 +656,7 @@ func (wc *WalletClient) ConfirmContact(ctx context.Context, contact *models.Cont
}

if err := wc.doHTTPRequest(
ctx, http.MethodPatch, "/contact/confirmed/"+contact.Paymail, nil, wc.getPrivKey(), *wc.signRequest, nil,
ctx, http.MethodPatch, "/contact/confirmed/"+contact.Paymail, nil, wc.getPrivKey(), wc.signRequest, nil,
); err != nil {
return err
}
Expand All @@ -677,7 +677,7 @@ func (wc *WalletClient) GetContacts(ctx context.Context, conditions map[string]i

var result []*models.Contact
if err := wc.doHTTPRequest(
ctx, http.MethodPost, "/contact/search", jsonStr, wc.getPrivKey(), *wc.signRequest, &result,
ctx, http.MethodPost, "/contact/search", jsonStr, wc.getPrivKey(), wc.signRequest, &result,
); err != nil {
return nil, err
}
Expand Down Expand Up @@ -707,7 +707,7 @@ func (wc *WalletClient) UpsertContactForPaymail(ctx context.Context, paymail, fu

var result models.Contact
if err := wc.doHTTPRequest(
ctx, http.MethodPut, "/contact/"+paymail, jsonStr, wc.getPrivKey(), *wc.signRequest, &result,
ctx, http.MethodPut, "/contact/"+paymail, jsonStr, wc.getPrivKey(), wc.signRequest, &result,
); err != nil {
return nil, err
}
Expand Down Expand Up @@ -1004,7 +1004,7 @@ func (wc *WalletClient) AdminRecordTransaction(ctx context.Context, hex string)

var transaction models.Transaction
if err := wc.doHTTPRequest(
ctx, http.MethodPost, "/admin/transactions/record", jsonStr, wc.getPrivKey(), *wc.signRequest, &transaction,
ctx, http.MethodPost, "/admin/transactions/record", jsonStr, wc.getPrivKey(), wc.signRequest, &transaction,
); err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions walletclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import (

// WalletClient is the spv wallet Go client representation.
type WalletClient struct {
signRequest *bool
server *string
signRequest bool
server string
httpClient *http.Client
accessKey *bec.PrivateKey
adminXPriv *bip32.ExtendedKey
Expand Down
12 changes: 6 additions & 6 deletions walletclient_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func TestNewWalletClient(t *testing.T) {
require.NotNil(t, client.xPriv)
require.Equal(t, keys.XPriv(), client.xPriv.String())
require.NotNil(t, client.httpClient)
require.True(t, *client.signRequest)
require.True(t, client.signRequest)

// Ensure HTTP calls can be made
resp, err := client.httpClient.Get(server.URL)
Expand All @@ -48,7 +48,7 @@ func TestNewWalletClient(t *testing.T) {
require.NotNil(t, client.xPub)
require.Equal(t, keys.XPub().String(), client.xPub.String())
require.NotNil(t, client.httpClient)
require.False(t, *client.signRequest)
require.False(t, client.signRequest)

// Ensure HTTP calls can be made
resp, err := client.httpClient.Get(server.URL)
Expand All @@ -67,9 +67,9 @@ func TestNewWalletClient(t *testing.T) {
require.NotNil(t, client.adminXPriv)
require.Nil(t, client.xPriv)
require.Equal(t, fixtures.XPrivString, client.adminXPriv.String())
require.Equal(t, server.URL, *client.server)
require.Equal(t, server.URL, client.server)
require.NotNil(t, client.httpClient)
require.True(t, *client.signRequest)
require.True(t, client.signRequest)

// Ensure HTTP calls can be made
resp, err := client.httpClient.Get(server.URL)
Expand All @@ -89,8 +89,8 @@ func TestNewWalletClient(t *testing.T) {
client := NewWithAccessKey(accessKey, server.URL)
require.NotNil(t, client.accessKey)

require.Equal(t, &server.URL, client.server)
require.True(t, *client.signRequest)
require.Equal(t, server.URL, client.server)
require.True(t, client.signRequest)
require.NotNil(t, client.httpClient)

// Ensure HTTP calls can be made
Expand Down

0 comments on commit 83f9b02

Please sign in to comment.