From a50c73fc7745955d3aa15342be195ee0358c6cc2 Mon Sep 17 00:00:00 2001 From: arkadiuszos4chain Date: Mon, 21 Aug 2023 15:16:41 +0200 Subject: [PATCH] fix(BUX-137): add unreserve utxos action --- action_utxo.go | 22 ++++++++++++++-------- interface.go | 1 + 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/action_utxo.go b/action_utxo.go index 0e50ae4a..2be46fc2 100644 --- a/action_utxo.go +++ b/action_utxo.go @@ -9,8 +9,8 @@ import ( // GetUtxos will get all the utxos from the Datastore func (c *Client) GetUtxos(ctx context.Context, metadataConditions *Metadata, - conditions *map[string]interface{}, queryParams *datastore.QueryParams, opts ...ModelOps) ([]*Utxo, error) { - + conditions *map[string]interface{}, queryParams *datastore.QueryParams, opts ...ModelOps, +) ([]*Utxo, error) { // Check for existing NewRelic transaction ctx = c.GetOrStartTxn(ctx, "get_utxos") @@ -31,8 +31,8 @@ func (c *Client) GetUtxos(ctx context.Context, metadataConditions *Metadata, // GetUtxosCount will get a count of all the utxos from the Datastore func (c *Client) GetUtxosCount(ctx context.Context, metadataConditions *Metadata, - conditions *map[string]interface{}, opts ...ModelOps) (int64, error) { - + conditions *map[string]interface{}, opts ...ModelOps, +) (int64, error) { // Check for existing NewRelic transaction ctx = c.GetOrStartTxn(ctx, "get_utxos_count") @@ -50,8 +50,8 @@ func (c *Client) GetUtxosCount(ctx context.Context, metadataConditions *Metadata // GetUtxosByXpubID will get utxos based on an xPub func (c *Client) GetUtxosByXpubID(ctx context.Context, xPubID string, metadata *Metadata, conditions *map[string]interface{}, - queryParams *datastore.QueryParams) ([]*Utxo, error) { - + queryParams *datastore.QueryParams, +) ([]*Utxo, error) { // Check for existing NewRelic transaction ctx = c.GetOrStartTxn(ctx, "get_utxos") @@ -76,7 +76,6 @@ func (c *Client) GetUtxosByXpubID(ctx context.Context, xPubID string, metadata * // GetUtxo will get a single utxo based on an xPub, the tx ID and the outputIndex func (c *Client) GetUtxo(ctx context.Context, xPubKey, txID string, outputIndex uint32) (*Utxo, error) { - // Check for existing NewRelic transaction ctx = c.GetOrStartTxn(ctx, "get_utxo") @@ -108,7 +107,6 @@ func (c *Client) GetUtxo(ctx context.Context, xPubKey, txID string, outputIndex // GetUtxoByTransactionID will get a single utxo based on the tx ID and the outputIndex func (c *Client) GetUtxoByTransactionID(ctx context.Context, txID string, outputIndex uint32) (*Utxo, error) { - // Check for existing NewRelic transaction ctx = c.GetOrStartTxn(ctx, "get_utxo_by_transaction_id") @@ -133,6 +131,14 @@ func (c *Client) GetUtxoByTransactionID(ctx context.Context, txID string, output return utxo, nil } +// UnReserveUtxos remove the reservation on the utxos for the given draft ID +func (c *Client) UnReserveUtxos(ctx context.Context, xPubID, draftID string) error { + // Check for existing NewRelic transaction + ctx = c.GetOrStartTxn(ctx, "unreserve_uxtos_by_draft_id") + + return unReserveUtxos(ctx, xPubID, draftID) +} + // should this be optional in the results? func (c *Client) enrichUtxoTransactions(ctx context.Context, utxos []*Utxo) { for index, utxo := range utxos { diff --git a/interface.go b/interface.go index fd60d581..8206b67d 100644 --- a/interface.go +++ b/interface.go @@ -162,6 +162,7 @@ type UTXOService interface { conditions *map[string]interface{}, opts ...ModelOps) (int64, error) GetUtxosByXpubID(ctx context.Context, xPubID string, metadata *Metadata, conditions *map[string]interface{}, queryParams *datastore.QueryParams) ([]*Utxo, error) + UnReserveUtxos(ctx context.Context, xPubID, draftID string) error } // XPubService is the xPub actions