Skip to content

Commit

Permalink
adding admin contacts methods
Browse files Browse the repository at this point in the history
  • Loading branch information
ac4ch committed May 8, 2024
1 parent c8a64a8 commit 59a55c2
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 0 deletions.
29 changes: 29 additions & 0 deletions admin_contacts.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package walletclient

import (
"context"

"github.com/bitcoin-sv/spv-wallet/models"

"github.com/bitcoin-sv/spv-wallet-go-client/transports"
)

func (wc *WalletClient) AdminGetContacts(ctx context.Context, conditions map[string]interface{}, metadata *models.Metadata, queryParams *transports.QueryParams) ([]*models.Contact, transports.ResponseError) {
return wc.transport.AdminGetContacts(ctx, conditions, metadata, queryParams)
}

func (wc *WalletClient) AdminUpdateContact(ctx context.Context, id, fullName string, metadata *models.Metadata) (*models.Contact, transports.ResponseError) {
return wc.transport.AdminUpdateContact(ctx, id, fullName, metadata)
}

func (wc *WalletClient) AdminDeleteContact(ctx context.Context, id string) transports.ResponseError {
return wc.transport.AdminDeleteContact(ctx, id)
}

func (wc *WalletClient) AdminAcceptContact(ctx context.Context, id string) (*models.Contact, transports.ResponseError) {
return wc.transport.AdminAcceptContact(ctx, id)
}

func (wc *WalletClient) AdminRejectContact(ctx context.Context, id string) (*models.Contact, transports.ResponseError) {
return wc.transport.AdminRejectContact(ctx, id)
}
47 changes: 47 additions & 0 deletions transports/http_admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package transports
import (
"context"
"encoding/json"
"fmt"
"net/http"

"github.com/bitcoin-sv/spv-wallet/models"
Expand Down Expand Up @@ -316,3 +317,49 @@ func (h *TransportHTTP) AdminGetSharedConfig(ctx context.Context) (*models.Share

return model, nil
}

func (h *TransportHTTP) AdminGetContacts(ctx context.Context, conditions map[string]interface{}, metadata *models.Metadata, queryParams *QueryParams) ([]*models.Contact, ResponseError) {
jsonStr, err := json.Marshal(map[string]interface{}{
FieldConditions: conditions,
FieldMetadata: processMetadata(metadata),
FieldQueryParams: queryParams,
})
if err != nil {
return nil, WrapError(err)
}

var contacts []*models.Contact
err = h.doHTTPRequest(ctx, http.MethodPost, "admin/contact/search", jsonStr, h.adminXPriv, h.IsSignRequest(), contacts)
return contacts, WrapError(err)
}

func (h *TransportHTTP) AdminUpdateContact(ctx context.Context, id, fullName string, metadata *models.Metadata) (*models.Contact, ResponseError) {
jsonStr, err := json.Marshal(map[string]interface{}{
"fullName": fullName,
FieldMetadata: processMetadata(metadata),
})
if err != nil {
return nil, WrapError(err)
}
var contact *models.Contact
err = h.doHTTPRequest(ctx, http.MethodPatch, fmt.Sprintf("admin/contact/%s", id), jsonStr, h.adminXPriv, h.IsSignRequest(), contact)
return contact, WrapError(err)
}

func (h *TransportHTTP) AdminDeleteContact(ctx context.Context, id string) ResponseError {
var contact *models.Contact
err := h.doHTTPRequest(ctx, http.MethodDelete, "", nil, h.adminXPriv, h.IsSignRequest(), contact)
return WrapError(err)
}

func (h *TransportHTTP) AdminAcceptContact(ctx context.Context, id string) (*models.Contact, ResponseError) {
var contact *models.Contact
err := h.doHTTPRequest(ctx, http.MethodPatch, fmt.Sprintf("admin/contact/accepted/%s", id), nil, h.adminXPriv, h.IsSignRequest(), contact)
return contact, WrapError(err)
}

func (h *TransportHTTP) AdminRejectContact(ctx context.Context, id string) (*models.Contact, ResponseError) {
var contact *models.Contact
err := h.doHTTPRequest(ctx, http.MethodPatch, fmt.Sprintf("admin/contact/rejected/%s", id), nil, h.adminXPriv, h.IsSignRequest(), contact)
return contact, WrapError(err)
}
5 changes: 5 additions & 0 deletions transports/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@ type AdminService interface {
AdminGetXPubsCount(ctx context.Context, conditions map[string]interface{}, metadata *models.Metadata) (int64, ResponseError)
AdminRecordTransaction(ctx context.Context, hex string) (*models.Transaction, ResponseError)
AdminGetSharedConfig(ctx context.Context) (*models.SharedConfig, ResponseError)
AdminGetContacts(ctx context.Context, conditions map[string]interface{}, metadata *models.Metadata, queryParams *QueryParams) ([]*models.Contact, ResponseError)
AdminUpdateContact(ctx context.Context, id, fullName string, metadata *models.Metadata) (*models.Contact, ResponseError)
AdminDeleteContact(ctx context.Context, id string) ResponseError
AdminAcceptContact(ctx context.Context, id string) (*models.Contact, ResponseError)
AdminRejectContact(ctx context.Context, id string) (*models.Contact, ResponseError)
}

// TransportService the transport service interface
Expand Down

0 comments on commit 59a55c2

Please sign in to comment.