Skip to content

Commit

Permalink
Merge pull request #43 from dominant-strategies/coin-selection
Browse files Browse the repository at this point in the history
Coin selection
  • Loading branch information
Denis2626 authored Mar 14, 2024
2 parents 919a355 + a4ab9eb commit d33246b
Show file tree
Hide file tree
Showing 47 changed files with 2,448 additions and 18 deletions.
2 changes: 2 additions & 0 deletions lib.commonjs/_tests/test-utxo-coinselection.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export {};
//# sourceMappingURL=test-utxo-coinselection.d.ts.map
1 change: 1 addition & 0 deletions lib.commonjs/_tests/test-utxo-coinselection.d.ts.map

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

101 changes: 101 additions & 0 deletions lib.commonjs/_tests/test-utxo-coinselection.js

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

1 change: 1 addition & 0 deletions lib.commonjs/_tests/test-utxo-coinselection.js.map

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

50 changes: 50 additions & 0 deletions lib.commonjs/transaction/abstract-coinselector.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { UTXO, UTXOLike } from "./utxo.js";
export type SpendTarget = {
address: string;
value: bigint;
};
export type SelectedCoinsResult = {
inputs: UTXO[];
spendOutputs: UTXO[];
changeOutputs: UTXO[];
};
/**
* An **AbstractCoinSelector** provides a base class for other sub-classes to
* implement the functionality for selecting UTXOs for a spend and to properly
* handle spend and change outputs.
*
* This class is abstract and should not be used directly. Sub-classes should
* implement the [[performSelection]] method to provide the actual coin
* selection logic.
*
* @abstract
*/
export declare abstract class AbstractCoinSelector {
#private;
get availableUXTOs(): UTXO[];
set availableUXTOs(value: UTXOLike[]);
get spendOutputs(): UTXO[];
set spendOutputs(value: UTXOLike[]);
get changeOutputs(): UTXO[];
set changeOutputs(value: UTXOLike[]);
/**
* Constructs a new AbstractCoinSelector instance with an empty UTXO array.
*/
constructor(availableUXTOs?: UTXOLike[]);
/**
* This method should be implemented by sub-classes to provide the actual
* coin selection logic. It should select UTXOs from the available UTXOs
* that sum to the target amount and return the selected UTXOs as well as
* the spend and change outputs.
* @param target The target amount to select UTXOs for.
*/
abstract performSelection(target: SpendTarget): SelectedCoinsResult;
/**
* Validates the provided UTXO instance. In order to be valid for coin
* selection, the UTXO must have a valid address and denomination.
* @param utxo The UTXO instance to validate.
* @throws An error if the UTXO instance is invalid.
*/
protected _validateUTXO(utxo: UTXO): void;
}
//# sourceMappingURL=abstract-coinselector.d.ts.map
1 change: 1 addition & 0 deletions lib.commonjs/transaction/abstract-coinselector.d.ts.map

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

64 changes: 64 additions & 0 deletions lib.commonjs/transaction/abstract-coinselector.js

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

1 change: 1 addition & 0 deletions lib.commonjs/transaction/abstract-coinselector.js.map

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

Loading

0 comments on commit d33246b

Please sign in to comment.