Skip to content

Commit

Permalink
chore(SPV-846): add more errors and refactor methods
Browse files Browse the repository at this point in the history
  • Loading branch information
pawellewandowski98 committed Jun 27, 2024
1 parent 355b613 commit ae50a5c
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 82 deletions.
4 changes: 2 additions & 2 deletions authentication.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
)

// SetSignature will set the signature on the header for the request
func setSignature(header *http.Header, xPriv *bip32.ExtendedKey, bodyString string) *models.SPVError {
func setSignature(header *http.Header, xPriv *bip32.ExtendedKey, bodyString string) error {
// Create the signature
authData, err := createSignature(xPriv, bodyString)
if err != nil {
Expand Down Expand Up @@ -135,7 +135,7 @@ func getUnlockingScript(tx *bt.Tx, inputIndex uint32, privateKey *bec.PrivateKey
func createSignature(xPriv *bip32.ExtendedKey, bodyString string) (payload *models.AuthPayload, err error) {
// No key?
if xPriv == nil {
err = CreateErrorResponse("error-unauthorized-missing-xpriv", "missing xpriv")
err = ErrMissingXpriv
return
}

Expand Down
10 changes: 6 additions & 4 deletions errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,18 @@ package walletclient

import (
"encoding/json"
"errors"
"github.com/bitcoin-sv/spv-wallet/models"
"net/http"
)

// ErrAdminKey admin key not set
var ErrAdminKey = errors.New("an admin key must be set to be able to create an xpub")
var ErrAdminKey = models.SPVError{Message: "an admin key must be set to be able to create an xpub", StatusCode: 401, Code: "error-unauthorized-admin-key-not-set"}

// ErrNoClientSet is when no client is set
var ErrNoClientSet = errors.New("no transport client set")
// ErrMissingXpriv is when xpriv is missing
var ErrMissingXpriv = models.SPVError{Message: "xpriv missing", StatusCode: 401, Code: "error-unauthorized-xpriv-missing"}

// ErrCouldNotFindDraftTransaction is when draft transaction is not found
var ErrCouldNotFindDraftTransaction = models.SPVError{Message: "could not find draft transaction", StatusCode: 404, Code: "error-draft-transaction-not-found"}

// WrapError wraps an error into SPVError
func WrapError(err error) *models.SPVError {
Expand Down
1 change: 1 addition & 0 deletions examples/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit ae50a5c

Please sign in to comment.