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

Commit

Permalink
Merge pull request #371 from 4chain-ag/fix-unreserve-utxos
Browse files Browse the repository at this point in the history
fix: add unreserve utxos action
  • Loading branch information
mergify[bot] authored Aug 23, 2023
2 parents 31ba65a + a50c73f commit 23d3f63
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
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

0 comments on commit 23d3f63

Please sign in to comment.