Skip to content
Open
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
1 change: 1 addition & 0 deletions types/custom-types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ export type WalletSave = {

export interface TxSend {
toAddr: string;
fromAddr: string|undefined;
amount: number;
fee: number;
//tx?: kaspacore.Transaction;
Expand Down
10 changes: 6 additions & 4 deletions wallet/utxo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,9 +200,10 @@ export class UtxoSet extends EventTargetImpl {
/**
* Naively select UTXOs.
* @param txAmount Provide the amount that the UTXOs should cover.
* @param fromAddr Select UTXOs only from this address
* @throws Error message if the UTXOs can't cover the `txAmount`
*/
selectUtxos(txAmount: number): {
selectUtxos(txAmount: number, fromAddr?: string): {
utxoIds: string[];
utxos: UnspentOutput[],
mass: number
Expand All @@ -213,7 +214,7 @@ export class UtxoSet extends EventTargetImpl {
let list = [...this.utxos.confirmed.values()];

list = list.filter((utxo) => {
return !this.inUse.includes(utxo.id);
return !this.inUse.includes(utxo.id) && (!fromAddr || utxo.address.toString() === fromAddr);
});

list.sort((a: UnspentOutput, b: UnspentOutput): number => {
Expand Down Expand Up @@ -243,8 +244,9 @@ export class UtxoSet extends EventTargetImpl {
/**
* Naively collect UTXOs.
* @param maxCount Provide the max UTXOs count.
* @param fromAddr collect UTXOs only from this address
*/
collectUtxos(maxCount: number = 10000): {
collectUtxos(maxCount: number = 10000, fromAddr?: string): {
utxoIds: string[];
utxos: UnspentOutput[],
amount: number,
Expand All @@ -256,7 +258,7 @@ export class UtxoSet extends EventTargetImpl {
let list = [...this.utxos.confirmed.values()];

list = list.filter((utxo) => {
return !this.inUse.includes(utxo.id);
return !this.inUse.includes(utxo.id) && (!fromAddr || utxo.address.toString() === fromAddr);
});

list.sort((a: UnspentOutput, b: UnspentOutput): number => {
Expand Down
6 changes: 4 additions & 2 deletions wallet/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -765,6 +765,7 @@ class Wallet extends EventTargetImpl {
*/
composeTx({
toAddr,
fromAddr,
amount,
fee = DEFAULT_FEE,
changeAddrOverride,
Expand All @@ -783,9 +784,9 @@ class Wallet extends EventTargetImpl {
//if (!Number.isSafeInteger(amount)) throw new Error(`Amount ${amount} is too large`);
let utxos, utxoIds, mass;
if(compoundingUTXO){
({utxos, utxoIds, amount, mass} = this.utxoSet.collectUtxos(compoundingUTXOMaxCount));
({utxos, utxoIds, amount, mass} = this.utxoSet.collectUtxos(compoundingUTXOMaxCount, fromAddr));
}else{
({utxos, utxoIds, mass} = this.utxoSet.selectUtxos(amount + fee));
({utxos, utxoIds, mass} = this.utxoSet.selectUtxos(amount + fee, fromAddr));
}
//if(mass > Wallet.MaxMassUTXOs){
// throw new Error(`Maximum number of inputs (UTXOs) reached. Please reduce this transaction amount.`);
Expand Down Expand Up @@ -1164,6 +1165,7 @@ class Wallet extends EventTargetImpl {

let txParamsArg = {
toAddr,
fromAddr: undefined,
changeAddrOverride:toAddr,
amount: -1,
fee,
Expand Down