Skip to content

Commit

Permalink
feat(SPV-1344): add shared config API implementation to admin API. (#49)
Browse files Browse the repository at this point in the history
  • Loading branch information
mgosek-4chain authored Dec 31, 2024
1 parent dc73034 commit fc7736c
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 3 deletions.
15 changes: 15 additions & 0 deletions admin_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/bitcoin-sv/spv-wallet-go-client/internal/api/v1/admin/utxos"
"github.com/bitcoin-sv/spv-wallet-go-client/internal/api/v1/admin/webhooks"
"github.com/bitcoin-sv/spv-wallet-go-client/internal/api/v1/admin/xpubs"
"github.com/bitcoin-sv/spv-wallet-go-client/internal/api/v1/configs"
"github.com/bitcoin-sv/spv-wallet-go-client/internal/auth"
"github.com/bitcoin-sv/spv-wallet-go-client/internal/restyutil"
"github.com/bitcoin-sv/spv-wallet-go-client/queries"
Expand All @@ -35,6 +36,7 @@ import (
// Methods may return wrapped errors, including models.SPVError or
// ErrUnrecognizedAPIResponse, depending on the behavior of the SPV Wallet API.
type AdminAPI struct {
configsAPI *configs.API
xpubsAPI *xpubs.API
paymailsAPI *paymails.API
accessKeyAPI *accesskeys.API
Expand All @@ -47,6 +49,18 @@ type AdminAPI struct {
statsAPI *stats.API
}

// SharedConfig retrieves the shared configuration via the configurations API.
// The response is unmarshaled into a response.SharedConfig.
// Returns an error if the request fails or the response cannot be decoded.
func (a *AdminAPI) SharedConfig(ctx context.Context) (*response.SharedConfig, error) {
res, err := a.configsAPI.SharedConfig(ctx)
if err != nil {
return nil, configs.HTTPErrorFormatter("retrieve shared configuration", err).FormatGetErr()
}

return res, nil
}

// CreateXPub creates a new XPub record via the Admin XPubs API.
// The provided command contains the necessary parameters to define the XPub record.
//
Expand Down Expand Up @@ -394,6 +408,7 @@ func initAdminAPI(cfg config.Config, auth authenticator) (*AdminAPI, error) {
}

return &AdminAPI{
configsAPI: configs.NewAPI(url, httpClient),
paymailsAPI: paymails.NewAPI(url, httpClient),
transactionsAPI: transactions.NewAPI(url, httpClient),
xpubsAPI: xpubs.NewAPI(url, httpClient),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (

const (
route = "api/v1/configs"
api = "User Shared Config API"
api = "Shared Config API"
)

type API struct {
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions user_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import (

"github.com/bitcoin-sv/spv-wallet-go-client/commands"
"github.com/bitcoin-sv/spv-wallet-go-client/config"
"github.com/bitcoin-sv/spv-wallet-go-client/internal/api/v1/configs"
"github.com/bitcoin-sv/spv-wallet-go-client/internal/api/v1/user/accesskeys"
"github.com/bitcoin-sv/spv-wallet-go-client/internal/api/v1/user/configs"
"github.com/bitcoin-sv/spv-wallet-go-client/internal/api/v1/user/contacts"
"github.com/bitcoin-sv/spv-wallet-go-client/internal/api/v1/user/invitations"
"github.com/bitcoin-sv/spv-wallet-go-client/internal/api/v1/user/merkleroots"
Expand Down Expand Up @@ -149,7 +149,7 @@ func (u *UserAPI) RejectInvitation(ctx context.Context, paymail string) error {
return nil
}

// SharedConfig retrieves the shared configuration via the user configurations API.
// SharedConfig retrieves the shared configuration via the configurations API.
// The response is unmarshaled into a response.SharedConfig.
// Returns an error if the request fails or the response cannot be decoded.
func (u *UserAPI) SharedConfig(ctx context.Context) (*response.SharedConfig, error) {
Expand Down

0 comments on commit fc7736c

Please sign in to comment.