Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Coin selection #43

Merged
merged 6 commits into from
Mar 14, 2024
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
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
Loading