Skip to content

Commit

Permalink
chore(feat-223): adjust bux-client methods
Browse files Browse the repository at this point in the history
  • Loading branch information
pawellewandowski98 committed Feb 16, 2024
1 parent fa60394 commit 73ddd5d
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 61 deletions.
29 changes: 1 addition & 28 deletions domain/transactions/transactions_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,18 +115,10 @@ func tryRecordTransaction(buxClient users.UserBuxClient, draftTx users.DraftTran
retries := uint(3)
tx, recordErr := tryRecord(buxClient, draftTx, metadata, log, retries)

// unreserve utxos if failed
if recordErr != nil {
log.Error().
Str("draftTxId", draftTx.GetDraftTransactionId()).
Msgf("record transaction failed: %s", recordErr.Error())

unreserveErr := tryUnreserve(buxClient, draftTx, log, retries)
if unreserveErr != nil {
log.Error().
Str("draftTxId", draftTx.GetDraftTransactionId()).
Msgf("unreserve transaction failed: %s", unreserveErr.Error())
}
Msgf("error while recording transaction: %v", recordErr.Error())
return nil, recordErr
}

Expand Down Expand Up @@ -158,22 +150,3 @@ func tryRecord(buxClient users.UserBuxClient, draftTx users.DraftTransaction, me
)
return tx, err
}

func tryUnreserve(buxClient users.UserBuxClient, draftTx users.DraftTransaction, log *zerolog.Logger, retries uint) error {
log.Debug().
Str("draftTxId", draftTx.GetDraftTransactionId()).
Msg("unreserve UTXOs from draft")

return retry.Do(
func() error {
return buxClient.UnreserveUtxos(draftTx.GetDraftTransactionId())
},
retry.Attempts(retries),
retry.Delay(1*time.Second),
retry.OnRetry(func(n uint, err error) {
log.Warn().
Str("draftTxId", draftTx.GetDraftTransactionId()).
Msgf("%d retry UnreserveUtxos after error: %v", n, err.Error())
}),
)
}
1 change: 0 additions & 1 deletion domain/users/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ type (
GetTransactionsCount() (int64, error)
CreateAndFinalizeTransaction(recipients []*transports.Recipients, metadata *buxmodels.Metadata) (DraftTransaction, error)
RecordTransaction(hex, draftTxId string, metadata *buxmodels.Metadata) (*buxmodels.Transaction, error)
UnreserveUtxos(draftTxId string) error
}

// AdmBuxClient defines methods for bux client with admin key.
Expand Down
14 changes: 0 additions & 14 deletions tests/mocks/users_interfaces_mq.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions transports/bux/client/admin_bux_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func (c *AdminBuxClient) RegisterXpub(xpriv *bip32.ExtendedKey) (string, error)
}

// Register new xpub in BUX.
err = c.client.NewXpub(
err = c.client.AdminNewXpub(

Check failure on line 33 in transports/bux/client/admin_bux_client.go

View workflow job for this annotation

GitHub Actions / lint

c.client.AdminNewXpub undefined (type *"github.com/BuxOrg/go-buxclient".BuxClient has no field or method AdminNewXpub)) (typecheck)

Check failure on line 33 in transports/bux/client/admin_bux_client.go

View workflow job for this annotation

GitHub Actions / lint

c.client.AdminNewXpub undefined (type *"github.com/BuxOrg/go-buxclient".BuxClient has no field or method AdminNewXpub)) (typecheck)

Check failure on line 33 in transports/bux/client/admin_bux_client.go

View workflow job for this annotation

GitHub Actions / lint

c.client.AdminNewXpub undefined (type *"github.com/BuxOrg/go-buxclient".BuxClient has no field or method AdminNewXpub)) (typecheck)

Check failure on line 33 in transports/bux/client/admin_bux_client.go

View workflow job for this annotation

GitHub Actions / lint

c.client.AdminNewXpub undefined (type *"github.com/BuxOrg/go-buxclient".BuxClient has no field or method AdminNewXpub)) (typecheck)

Check failure on line 33 in transports/bux/client/admin_bux_client.go

View workflow job for this annotation

GitHub Actions / lint

c.client.AdminNewXpub undefined (type *"github.com/BuxOrg/go-buxclient".BuxClient has no field or method AdminNewXpub) (typecheck)

Check failure on line 33 in transports/bux/client/admin_bux_client.go

View workflow job for this annotation

GitHub Actions / test

c.client.AdminNewXpub undefined (type *"github.com/BuxOrg/go-buxclient".BuxClient has no field or method AdminNewXpub)
context.Background(), xpub.String(), &buxmodels.Metadata{},
)

Expand All @@ -55,8 +55,8 @@ func (c *AdminBuxClient) RegisterPaymail(alias, xpub string) (string, error) {
// Get avatar url from env.
avatar := viper.GetString(config.EnvBuxPaymailAvatar)

// Register new xpub in BUX.
err := c.client.NewPaymail(context.Background(), xpub, address, avatar, alias, &buxmodels.Metadata{})
// Register new paymail in BUX.
_, err := c.client.AdminCreatePaymail(context.Background(), xpub, address, avatar, alias)

if err != nil {
c.log.Error().Msgf("Error while registering new paymail: %v", err.Error())
Expand Down
5 changes: 0 additions & 5 deletions transports/bux/client/bux_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,11 +146,6 @@ func (c *BuxClient) RecordTransaction(hex, draftTxId string, metadata *buxmodels
return tx, nil
}

// UnreserveUtxos removes utxos from draft transaction in BUX.
func (c *BuxClient) UnreserveUtxos(draftTxId string) error {
return c.client.UnreserveUtxos(context.Background(), draftTxId)
}

// GetTransactions returns all transactions.
func (c *BuxClient) GetTransactions(queryParam transports.QueryParams, userPaymail string) ([]users.Transaction, error) {
conditions := make(map[string]interface{})
Expand Down
16 changes: 6 additions & 10 deletions transports/bux/client/buxclient_factory_adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,13 @@ func NewBuxClientFactory(log *zerolog.Logger) users.BuxClientFactory {
func (bf *buxclientFactory) CreateAdminBuxClient() (users.AdmBuxClient, error) {
// Get env variables.
xpriv := viper.GetString(config.EnvBuxAdminXpriv)
serverUrl, debug, signRequest := getServerData()
serverUrl, signRequest := getServerData()

// Init bux client.
buxClient, err := buxclient.New(
buxclient.WithXPriv(xpriv),
buxclient.WithAdminKey(xpriv),
buxclient.WithHTTP(serverUrl),
buxclient.WithDebugging(debug),
buxclient.WithSignRequest(signRequest),
)

Expand All @@ -49,13 +48,12 @@ func (bf *buxclientFactory) CreateAdminBuxClient() (users.AdmBuxClient, error) {
// CreateWithXpriv creates instance of Bux Client with given xpriv.
func (bf *buxclientFactory) CreateWithXpriv(xpriv string) (users.UserBuxClient, error) {
// Get env variables.
serverUrl, debug, signRequest := getServerData()
serverUrl, signRequest := getServerData()

// Init bux client with generated xpub.
buxClient, err := buxclient.New(
buxclient.WithXPriv(xpriv),
buxclient.WithHTTP(serverUrl),
buxclient.WithDebugging(debug),
buxclient.WithSignRequest(signRequest),
)

Expand All @@ -69,16 +67,15 @@ func (bf *buxclientFactory) CreateWithXpriv(xpriv string) (users.UserBuxClient,
}, nil
}

// CreateWithXpriv creates instance of Bux Client with given xpriv.
// CreateWithAccessKey creates instance of Bux Client with given xpriv.
func (bf *buxclientFactory) CreateWithAccessKey(accessKey string) (users.UserBuxClient, error) {
// Get env variables.
serverUrl, debug, signRequest := getServerData()
serverUrl, signRequest := getServerData()

// Init bux client with generated xpub.
buxClient, err := buxclient.New(
buxclient.WithAccessKey(accessKey),
buxclient.WithHTTP(serverUrl),
buxclient.WithDebugging(debug),
buxclient.WithSignRequest(signRequest),
)

Expand All @@ -92,11 +89,10 @@ func (bf *buxclientFactory) CreateWithAccessKey(accessKey string) (users.UserBux
}, nil
}

func getServerData() (serverUrl string, debug, signRequest bool) {
func getServerData() (serverUrl string, signRequest bool) {
// Get env variables.
serverUrl = viper.GetString(config.EnvBuxServerUrl)
debug = viper.GetBool(config.EnvBuxWithDebug)
signRequest = viper.GetBool(config.EnvBuxSignRequest)

return serverUrl, debug, signRequest
return serverUrl, signRequest
}

0 comments on commit 73ddd5d

Please sign in to comment.