Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(SPV-1344): add shared config API implementation to admin API. #49

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
Loading