diff --git a/examples/register_xpub/register_xpub.go b/examples/register_xpub/register_xpub.go index f0df0d5..5eab577 100644 --- a/examples/register_xpub/register_xpub.go +++ b/examples/register_xpub/register_xpub.go @@ -5,24 +5,24 @@ import ( "fmt" buxmodels "github.com/BuxOrg/bux-models" "github.com/BuxOrg/go-buxclient" - "github.com/BuxOrg/go-buxclient/xpriv" ) func main() { - // Generate keys - keys, _ := xpriv.Generate() + // Replace with your admin keys + adminXpriv := "xprv9s21ZrQH143K3CbJXirfrtpLvhT3Vgusdo8coBritQ3rcS7Jy7sxWhatuxG5h2y1Cqj8FKmPp69536gmjYRpfga2MJdsGyBsnB12E19CESK" + adminXpub := "xpub661MyMwAqRbcFgfmdkPgE2m5UjHXu9dj124DbaGLSjaqVESTWfCD4VuNmEbVPkbYLCkykwVZvmA8Pbf8884TQr1FgdG2nPoHR8aB36YdDQh" // Create a client buxClient, _ := buxclient.New( - buxclient.WithXPriv(keys.XPriv()), + buxclient.WithXPriv(adminXpriv), buxclient.WithHTTP("localhost:3003/v1"), buxclient.WithSignRequest(true), ) ctx := context.Background() - _ = buxClient.NewXpub( - ctx, keys.XPub().String(), &buxmodels.Metadata{"example_field": "example_data"}, + _ = buxClient.AdminNewXpub( + ctx, adminXpub, &buxmodels.Metadata{"example_field": "example_data"}, ) xpubKey, err := buxClient.GetXPub(ctx) diff --git a/paymail_addresses.go b/paymail_addresses.go deleted file mode 100644 index ef28753..0000000 --- a/paymail_addresses.go +++ /dev/null @@ -1,13 +0,0 @@ -package buxclient - -import ( - "context" - - buxmodels "github.com/BuxOrg/bux-models" - "github.com/BuxOrg/go-buxclient/transports" -) - -// NewPaymail will create a new paymail -func (b *BuxClient) NewPaymail(ctx context.Context, rawXPub, paymailAddress, avatar, publicName string, metadata *buxmodels.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 7cd4275..0000000 --- a/paymail_addresses_test.go +++ /dev/null @@ -1,32 +0,0 @@ -package buxclient - -import ( - "context" - "testing" - - "github.com/stretchr/testify/assert" - - "github.com/BuxOrg/go-buxclient/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 := getTestBuxClient(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 71615fd..e958bb0 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 *buxmodels.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) (*buxmodels.Xpub, ResponseError) { var xPub buxmodels.Xpub diff --git a/transports/http_admin.go b/transports/http_admin.go index d15ebbb..6ff7639 100644 --- a/transports/http_admin.go +++ b/transports/http_admin.go @@ -8,8 +8,8 @@ import ( buxmodels "github.com/BuxOrg/bux-models" ) -// NewXpub will register an xPub -func (h *TransportHTTP) NewXpub(ctx context.Context, rawXPub string, metadata *buxmodels.Metadata) ResponseError { +// AdminNewXpub will register an xPub +func (h *TransportHTTP) AdminNewXpub(ctx context.Context, rawXPub string, metadata *buxmodels.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 *b var xPubData buxmodels.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 *buxmodels.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) (*buxmodels.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 *buxmodels.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 a1f0136..f80cfa7 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) (*buxmodels.Xpub, ResponseError) - NewXpub(ctx context.Context, rawXPub string, metadata *buxmodels.Metadata) ResponseError - RegisterXpub(ctx context.Context, rawXPub string, metadata *buxmodels.Metadata) ResponseError UpdateXPubMetadata(ctx context.Context, metadata *buxmodels.Metadata) (*buxmodels.Xpub, ResponseError) } @@ -51,12 +49,6 @@ type TransactionService interface { GetUtxosCount(ctx context.Context, conditions map[string]interface{}, metadata *buxmodels.Metadata) (int64, ResponseError) } -// PaymailService is the paymail related requests -type PaymailService interface { - NewPaymail(ctx context.Context, rawXpub, paymailAddress, avatar, publicName string, metadata *buxmodels.Metadata) ResponseError - DeletePaymail(ctx context.Context, paymailAddress string) ResponseError -} - // AdminService is the admin related requests type AdminService interface { AdminGetStatus(ctx context.Context) (bool, ResponseError) @@ -71,11 +63,12 @@ type AdminService interface { AdminGetPaymails(ctx context.Context, conditions map[string]interface{}, metadata *buxmodels.Metadata, queryParams *QueryParams) ([]*buxmodels.PaymailAddress, ResponseError) AdminGetPaymailsCount(ctx context.Context, conditions map[string]interface{}, metadata *buxmodels.Metadata) (int64, ResponseError) AdminCreatePaymail(ctx context.Context, xPubID string, address string, publicName string, avatar string) (*buxmodels.PaymailAddress, ResponseError) - AdminDeletePaymail(ctx context.Context, address string) (*buxmodels.PaymailAddress, ResponseError) + AdminDeletePaymail(ctx context.Context, address string) ResponseError AdminGetTransactions(ctx context.Context, conditions map[string]interface{}, metadata *buxmodels.Metadata, queryParams *QueryParams) ([]*buxmodels.Transaction, ResponseError) AdminGetTransactionsCount(ctx context.Context, conditions map[string]interface{}, metadata *buxmodels.Metadata) (int64, ResponseError) AdminGetUtxos(ctx context.Context, conditions map[string]interface{}, metadata *buxmodels.Metadata, queryParams *QueryParams) ([]*buxmodels.Utxo, ResponseError) AdminGetUtxosCount(ctx context.Context, conditions map[string]interface{}, metadata *buxmodels.Metadata) (int64, ResponseError) + AdminNewXpub(ctx context.Context, rawXPub string, metadata *buxmodels.Metadata) ResponseError AdminGetXPubs(ctx context.Context, conditions map[string]interface{}, metadata *buxmodels.Metadata, queryParams *QueryParams) ([]*buxmodels.Xpub, ResponseError) AdminGetXPubsCount(ctx context.Context, conditions map[string]interface{}, metadata *buxmodels.Metadata) (int64, ResponseError) AdminRecordTransaction(ctx context.Context, hex string) (*buxmodels.Transaction, ResponseError) @@ -86,7 +79,6 @@ type TransportService interface { AccessKeyService AdminService DestinationService - PaymailService TransactionService XpubService Init() error diff --git a/xpubs.go b/xpubs.go index 435cc61..2098da5 100644 --- a/xpubs.go +++ b/xpubs.go @@ -7,11 +7,6 @@ import ( "github.com/BuxOrg/go-buxclient/transports" ) -// NewXpub registers a new xpub - admin key needed -func (b *BuxClient) NewXpub(ctx context.Context, rawXPub string, metadata *buxmodels.Metadata) transports.ResponseError { - return b.transport.NewXpub(ctx, rawXPub, metadata) -} - // GetXPub gets the current xpub func (b *BuxClient) GetXPub(ctx context.Context) (*buxmodels.Xpub, transports.ResponseError) { return b.transport.GetXPub(ctx) diff --git a/xpubs_test.go b/xpubs_test.go index d9f349a..44cba9b 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 := getTestBuxClient(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 := getTestBuxClient(transportHandler, true)