Skip to content

Commit

Permalink
renaming options
Browse files Browse the repository at this point in the history
  • Loading branch information
ac4ch committed May 15, 2024
1 parent 513a5b6 commit bf02213
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 31 deletions.
38 changes: 19 additions & 19 deletions client_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,63 +14,63 @@ type WalletClientConfigurator interface {
Configure(c *WalletClient)
}

// WithXPriv sets the xPrivString field of a WalletClient
type WithXPriv struct {
// XPriv sets the xPrivString field of a WalletClient
type XPriv struct {
XPrivString *string
}

func (w *WithXPriv) Configure(c *WalletClient) {
func (w *XPriv) Configure(c *WalletClient) {
var err error
if c.xPriv, err = bitcoin.GenerateHDKeyFromString(*w.XPrivString); err != nil {
c.xPriv = nil
}
}

// WithXPub sets the xPubString on the client
type WithXPub struct {
// XPub sets the xPubString on the client
type XPub struct {
XPubString *string
}

func (w *WithXPub) Configure(c *WalletClient) {
func (w *XPub) Configure(c *WalletClient) {
var err error
if c.xPub, err = bitcoin.GetHDKeyFromExtendedPublicKey(*w.XPubString); err != nil {
w.XPubString = nil
}

}

// WithAccessKey sets the accessKeyString on the client
type WithAccessKey struct {
// AccessKey sets the accessKeyString on the client
type AccessKey struct {
AccessKeyString *string
}

func (w *WithAccessKey) Configure(c *WalletClient) {
func (w *AccessKey) Configure(c *WalletClient) {
var err error
if c.accessKey, err = w.initializeAccessKey(); err != nil {
c.accessKey = nil
}
}

// WithAdminKey sets the admin key for creating new xpubs
type WithAdminKey struct {
// AdminKey sets the admin key for creating new xpubs
type AdminKey struct {
AdminKeyString *string
}

func (w *WithAdminKey) Configure(c *WalletClient) {
func (w *AdminKey) Configure(c *WalletClient) {
var err error
c.adminXPriv, err = bitcoin.GenerateHDKeyFromString(*w.AdminKeyString)
if err != nil {
c.adminXPriv = nil
}
}

// WithHTTP sets the URL and HTTP client of a WalletClient
type WithHTTP struct {
// HTTP sets the URL and HTTP client of a WalletClient
type HTTP struct {
ServerURL *string
HTTPClient *http.Client
}

func (w *WithHTTP) Configure(c *WalletClient) {
func (w *HTTP) Configure(c *WalletClient) {
c.server = w.ServerURL
c.httpClient = w.HTTPClient
if w.HTTPClient != nil {
Expand All @@ -80,17 +80,17 @@ func (w *WithHTTP) Configure(c *WalletClient) {
}
}

// WithSignRequest configures whether to sign HTTP requests
type WithSignRequest struct {
// SignRequest configures whether to sign HTTP requests
type SignRequest struct {
Sign *bool
}

func (w *WithSignRequest) Configure(c *WalletClient) {
func (w *SignRequest) Configure(c *WalletClient) {
c.signRequest = w.Sign
}

// initializeAccessKey handles the specific initialization of the access key.
func (c *WithAccessKey) initializeAccessKey() (*bec.PrivateKey, error) {
func (c *AccessKey) initializeAccessKey() (*bec.PrivateKey, error) {
var err error
var privateKey *bec.PrivateKey
var decodedWIF *wif.WIF
Expand Down
24 changes: 12 additions & 12 deletions walletclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ type WalletClient struct {
// - `serverURL`: The URL of the server the client will interact with.
func NewWithXPriv(xPriv, serverURL string) *WalletClient {
return newWalletClient(
&WithXPriv{XPrivString: &xPriv},
&WithHTTP{ServerURL: &serverURL},
&WithSignRequest{Sign: Ptr(true)},
&XPriv{XPrivString: &xPriv},
&HTTP{ServerURL: &serverURL},
&SignRequest{Sign: Ptr(true)},
)
}

Expand All @@ -37,9 +37,9 @@ func NewWithXPriv(xPriv, serverURL string) *WalletClient {
// - `serverURL`: The URL of the server the client will interact with.
func NewWithXPub(xPub, serverURL string) *WalletClient {
return newWalletClient(
&WithXPub{XPubString: &xPub},
&WithHTTP{ServerURL: &serverURL},
&WithSignRequest{Sign: Ptr(false)},
&XPub{XPubString: &xPub},
&HTTP{ServerURL: &serverURL},
&SignRequest{Sign: Ptr(false)},
)
}

Expand All @@ -49,9 +49,9 @@ func NewWithXPub(xPub, serverURL string) *WalletClient {
// - `serverURL`: The URL of the server the client will interact with.
func NewWithAdminKey(adminKey, serverURL string) *WalletClient {
return newWalletClient(
&WithAdminKey{AdminKeyString: &adminKey},
&WithHTTP{ServerURL: &serverURL},
&WithSignRequest{Sign: Ptr(true)},
&AdminKey{AdminKeyString: &adminKey},
&HTTP{ServerURL: &serverURL},
&SignRequest{Sign: Ptr(true)},
)
}

Expand All @@ -61,9 +61,9 @@ func NewWithAdminKey(adminKey, serverURL string) *WalletClient {
// - `serverURL`: The URL of the server the client will interact with.
func NewWithAccessKey(accessKey, serverURL string) *WalletClient {
return newWalletClient(
&WithAccessKey{AccessKeyString: &accessKey},
&WithHTTP{ServerURL: &serverURL},
&WithSignRequest{Sign: Ptr(true)},
&AccessKey{AccessKeyString: &accessKey},
&HTTP{ServerURL: &serverURL},
&SignRequest{Sign: Ptr(true)},
)
}

Expand Down

0 comments on commit bf02213

Please sign in to comment.