Skip to content
This repository has been archived by the owner on Apr 2, 2024. It is now read-only.

fix: add unreserve utxos action #371

Merged
merged 1 commit into from
Aug 23, 2023
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
22 changes: 14 additions & 8 deletions action_utxo.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand All @@ -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")

Expand All @@ -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")

Expand All @@ -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")

Expand Down Expand Up @@ -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")

Expand All @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down