diff --git a/examples/register_xpub/register_xpub.go b/examples/register_xpub/register_xpub.go index d097748..f26e51e 100644 --- a/examples/register_xpub/register_xpub.go +++ b/examples/register_xpub/register_xpub.go @@ -5,26 +5,24 @@ import ( "fmt" walletclient "github.com/bitcoin-sv/spv-wallet-go-client" - "github.com/bitcoin-sv/spv-wallet-go-client/xpriv" "github.com/bitcoin-sv/spv-wallet/models" ) func main() { - // Generate keys - keys, _ := xpriv.Generate() + // Replace with your admin keys + adminXpriv := "xprv9s21ZrQH143K3CbJXirfrtpLvhT3Vgusdo8coBritQ3rcS7Jy7sxWhatuxG5h2y1Cqj8FKmPp69536gmjYRpfga2MJdsGyBsnB12E19CESK" + adminXpub := "xpub661MyMwAqRbcFgfmdkPgE2m5UjHXu9dj124DbaGLSjaqVESTWfCD4VuNmEbVPkbYLCkykwVZvmA8Pbf8884TQr1FgdG2nPoHR8aB36YdDQh" // Create a client walletClient, _ := walletclient.New( - walletclient.WithXPriv(keys.XPriv()), + walletclient.WithXPriv(adminXpriv), walletclient.WithHTTP("localhost:3003/v1"), walletclient.WithSignRequest(true), ) ctx := context.Background() - _ = walletClient.NewXpub( - ctx, keys.XPub().String(), &models.Metadata{"example_field": "example_data"}, - ) + _ = walletClient.AdminNewXpub(ctx, adminXpub, &models.Metadata{"example_field": "example_data"}) xpubKey, err := walletClient.GetXPub(ctx) if err != nil { diff --git a/paymail_addresses.go b/paymail_addresses.go deleted file mode 100644 index 6255177..0000000 --- a/paymail_addresses.go +++ /dev/null @@ -1,15 +0,0 @@ -package walletclient - -import ( - "context" - - "github.com/bitcoin-sv/spv-wallet-go-client/transports" - "github.com/bitcoin-sv/spv-wallet/models" -) - -// NewPaymail will create a new paymail -// -// paymailAddress: The paymail address to create (e.g., example@bux.org) -func (b *WalletClient) NewPaymail(ctx context.Context, rawXPub, paymailAddress, avatar, publicName string, metadata *models.Metadata) transports.ResponseError { - return b.transport.NewPaymail(ctx, rawXPub, paymailAddress, avatar, publicName, metadata) -} diff --git a/paymail_addresses_test.go b/paymail_addresses_test.go deleted file mode 100644 index 5f45a1e..0000000 --- a/paymail_addresses_test.go +++ /dev/null @@ -1,32 +0,0 @@ -package walletclient - -import ( - "context" - "testing" - - "github.com/stretchr/testify/assert" - - "github.com/bitcoin-sv/spv-wallet-go-client/fixtures" -) - -// TestPaymailAddresses will test Paymail Addresses methods -func TestPaymailAddresses(t *testing.T) { - transportHandler := testTransportHandler{ - Type: fixtures.RequestType, - Path: "/paymail", - Result: "null", - ClientURL: fixtures.ServerURL, - Client: WithHTTPClient, - } - - t.Run("NewPaymail", func(t *testing.T) { - // given - client := getTestWalletClient(transportHandler, false) - - // when - err := client.NewPaymail(context.Background(), fixtures.XPubString, fixtures.PaymailAddress, "", "", fixtures.TestMetadata) - - // then - assert.NoError(t, err) - }) -} diff --git a/transports/http.go b/transports/http.go index a2f3a45..c827953 100644 --- a/transports/http.go +++ b/transports/http.go @@ -48,44 +48,6 @@ func (h *TransportHTTP) SetAdminKey(adminKey *bip32.ExtendedKey) { h.adminXPriv = adminKey } -// NewPaymail will register a new paymail -func (h *TransportHTTP) NewPaymail(ctx context.Context, rawXpub, paymailAddress, avatar, publicName string, metadata *models.Metadata) ResponseError { - jsonStr, err := json.Marshal(map[string]interface{}{ - FieldAddress: paymailAddress, - FieldAvatar: avatar, - FieldPublicName: publicName, - FieldMetadata: processMetadata(metadata), - FieldXpubKey: rawXpub, - }) - if err != nil { - return WrapError(err) - } - - var paymailData interface{} - - return h.doHTTPRequest( - ctx, http.MethodPost, "/paymail", jsonStr, h.xPriv, true, &paymailData, - ) -} - -// DeletePaymail will delete a paymail address -func (h *TransportHTTP) DeletePaymail(ctx context.Context, paymailAddress string) ResponseError { - jsonStr, err := json.Marshal(map[string]interface{}{ - FieldAddress: paymailAddress, - }) - if err != nil { - return WrapError(err) - } - - if err := h.doHTTPRequest( - ctx, http.MethodDelete, "/paymail", jsonStr, h.xPriv, true, nil, - ); err != nil { - return WrapError(err) - } - - return nil -} - // GetXPub will get the xpub of the current xpub func (h *TransportHTTP) GetXPub(ctx context.Context) (*models.Xpub, ResponseError) { var xPub models.Xpub diff --git a/transports/http_admin.go b/transports/http_admin.go index 11a13bc..9942c64 100644 --- a/transports/http_admin.go +++ b/transports/http_admin.go @@ -8,8 +8,8 @@ import ( "github.com/bitcoin-sv/spv-wallet/models" ) -// NewXpub will register an xPub -func (h *TransportHTTP) NewXpub(ctx context.Context, rawXPub string, metadata *models.Metadata) ResponseError { +// AdminNewXpub will register an xPub +func (h *TransportHTTP) AdminNewXpub(ctx context.Context, rawXPub string, metadata *models.Metadata) ResponseError { // Adding a xpub needs to be signed by an admin key if h.adminXPriv == nil { return WrapError(ErrAdminKey) @@ -26,15 +26,10 @@ func (h *TransportHTTP) NewXpub(ctx context.Context, rawXPub string, metadata *m var xPubData models.Xpub return h.doHTTPRequest( - ctx, http.MethodPost, "/xpub", jsonStr, h.adminXPriv, true, &xPubData, + ctx, http.MethodPost, "/admin/xpub", jsonStr, h.adminXPriv, true, &xPubData, ) } -// RegisterXpub alias for NewXpub -func (h *TransportHTTP) RegisterXpub(ctx context.Context, rawXPub string, metadata *models.Metadata) ResponseError { - return h.NewXpub(ctx, rawXPub, metadata) -} - // AdminGetStatus get whether admin key is valid func (h *TransportHTTP) AdminGetStatus(ctx context.Context) (bool, ResponseError) { var status bool @@ -177,22 +172,21 @@ func (h *TransportHTTP) AdminCreatePaymail(ctx context.Context, xPubID string, a } // AdminDeletePaymail delete a paymail address from the database -func (h *TransportHTTP) AdminDeletePaymail(ctx context.Context, address string) (*models.PaymailAddress, ResponseError) { +func (h *TransportHTTP) AdminDeletePaymail(ctx context.Context, address string) ResponseError { jsonStr, err := json.Marshal(map[string]interface{}{ FieldAddress: address, }) if err != nil { - return nil, WrapError(err) + return WrapError(err) } - var model *models.PaymailAddress if err := h.doHTTPRequest( - ctx, http.MethodDelete, "/admin/paymail/delete", jsonStr, h.xPriv, true, &model, + ctx, http.MethodDelete, "/admin/paymail/delete", jsonStr, h.xPriv, true, nil, ); err != nil { - return nil, err + return err } - return model, nil + return nil } // AdminGetTransactions get all block transactions filtered by conditions diff --git a/transports/interface.go b/transports/interface.go index a1898a3..c3127a2 100644 --- a/transports/interface.go +++ b/transports/interface.go @@ -10,8 +10,6 @@ import ( // XpubService is the xPub related requests type XpubService interface { GetXPub(ctx context.Context) (*models.Xpub, ResponseError) - NewXpub(ctx context.Context, rawXPub string, metadata *models.Metadata) ResponseError - RegisterXpub(ctx context.Context, rawXPub string, metadata *models.Metadata) ResponseError UpdateXPubMetadata(ctx context.Context, metadata *models.Metadata) (*models.Xpub, ResponseError) } @@ -51,12 +49,6 @@ type TransactionService interface { GetUtxosCount(ctx context.Context, conditions map[string]interface{}, metadata *models.Metadata) (int64, ResponseError) } -// PaymailService is the paymail related requests -type PaymailService interface { - NewPaymail(ctx context.Context, rawXpub, paymailAddress, avatar, publicName string, metadata *models.Metadata) ResponseError - DeletePaymail(ctx context.Context, paymailAddress string) ResponseError -} - // AdminService is the admin related requests type AdminService interface { AdminGetStatus(ctx context.Context) (bool, ResponseError) @@ -70,15 +62,13 @@ type AdminService interface { AdminGetPaymail(ctx context.Context, address string) (*models.PaymailAddress, ResponseError) AdminGetPaymails(ctx context.Context, conditions map[string]interface{}, metadata *models.Metadata, queryParams *QueryParams) ([]*models.PaymailAddress, ResponseError) AdminGetPaymailsCount(ctx context.Context, conditions map[string]interface{}, metadata *models.Metadata) (int64, ResponseError) - // AdminCreatePaymail Create a paymail. - // - // Paymail address (ie. example@bux.org) AdminCreatePaymail(ctx context.Context, xPubID string, address string, publicName string, avatar string) (*models.PaymailAddress, ResponseError) - AdminDeletePaymail(ctx context.Context, address string) (*models.PaymailAddress, ResponseError) + AdminDeletePaymail(ctx context.Context, address string) ResponseError AdminGetTransactions(ctx context.Context, conditions map[string]interface{}, metadata *models.Metadata, queryParams *QueryParams) ([]*models.Transaction, ResponseError) AdminGetTransactionsCount(ctx context.Context, conditions map[string]interface{}, metadata *models.Metadata) (int64, ResponseError) AdminGetUtxos(ctx context.Context, conditions map[string]interface{}, metadata *models.Metadata, queryParams *QueryParams) ([]*models.Utxo, ResponseError) AdminGetUtxosCount(ctx context.Context, conditions map[string]interface{}, metadata *models.Metadata) (int64, ResponseError) + AdminNewXpub(ctx context.Context, rawXPub string, metadata *models.Metadata) ResponseError AdminGetXPubs(ctx context.Context, conditions map[string]interface{}, metadata *models.Metadata, queryParams *QueryParams) ([]*models.Xpub, ResponseError) AdminGetXPubsCount(ctx context.Context, conditions map[string]interface{}, metadata *models.Metadata) (int64, ResponseError) AdminRecordTransaction(ctx context.Context, hex string) (*models.Transaction, ResponseError) @@ -89,7 +79,6 @@ type TransportService interface { AccessKeyService AdminService DestinationService - PaymailService TransactionService XpubService Init() error diff --git a/xpubs.go b/xpubs.go index 47df1f7..65beaa3 100644 --- a/xpubs.go +++ b/xpubs.go @@ -7,11 +7,6 @@ import ( "github.com/bitcoin-sv/spv-wallet/models" ) -// NewXpub registers a new xpub - admin key needed -func (b *WalletClient) NewXpub(ctx context.Context, rawXPub string, metadata *models.Metadata) transports.ResponseError { - return b.transport.NewXpub(ctx, rawXPub, metadata) -} - // GetXPub gets the current xpub func (b *WalletClient) GetXPub(ctx context.Context) (*models.Xpub, transports.ResponseError) { return b.transport.GetXPub(ctx) diff --git a/xpubs_test.go b/xpubs_test.go index 63eab9f..233d1c8 100644 --- a/xpubs_test.go +++ b/xpubs_test.go @@ -19,17 +19,6 @@ func TestXpub(t *testing.T) { Client: WithHTTPClient, } - t.Run("NewXpub", func(t *testing.T) { - // given - client := getTestWalletClient(transportHandler, true) - - // when - err := client.NewXpub(context.Background(), fixtures.XPubString, fixtures.TestMetadata) - - // then - assert.NoError(t, err) - }) - t.Run("GetXPub", func(t *testing.T) { // given client := getTestWalletClient(transportHandler, true)