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

Segregate unconfirmed balance from confirmed ones in Balance struct #407

Open
rishkwal opened this issue Feb 8, 2025 · 6 comments
Open
Labels
enhancement This enhances the code and improves stuffs good first issue issues suitable for early contributors

Comments

@rishkwal
Copy link
Collaborator

rishkwal commented Feb 8, 2025

Currently if you use taker get-balances to fetch the balance of taker's wallet it shows unconfirmed balance as spendable:

get-balances
{
  "contract": 0,
  "regular": 10000000,
  "spendable": 10000000,
  "swap": 0
}
list-utxo
{
  "addr": "bcrt1qd3wxljjc4v9f7v3rfugnvat0fqzewrtc2ytr40",
  "amount": 5000000,
  "confirmations": 0,
  "utxo_type": "regular"
}
{
  "addr": "bcrt1qd3wxljjc4v9f7v3rfugnvat0fqzewrtc2ytr40",
  "amount": 5000000,
  "confirmations": 0,
  "utxo_type": "regular"
}

We should add another field to discern unconfirmed balance from spendable balance.
Something like:

get-balances
{
  "contract": 0,
  "regular": 10000000,
  "spendable": 0,
  "unconfirmed": 10000000,
  "swap": 0
}
@rishkwal rishkwal added enhancement This enhances the code and improves stuffs good first issue issues suitable for early contributors labels Feb 8, 2025
@mojoX911
Copy link

mojoX911 commented Feb 8, 2025

Yes we can do that. But unconfirmed are also spendable. I don't have a strong opinion either way, this will required another API in the wallet to filter only unconfirmed utxos.

@khadar1020
Copy link

I would like to take up this issue

@KnowWhoami
Copy link
Collaborator

KnowWhoami commented Feb 26, 2025

I think it's good to segregate unconfirmed utxo balance from the confirmed ones as a part of enhancement in cli-apps.

But my question is :
Is it good to have a single unconfirmed balance section to denote balance of any UTXO type?

I don't have a strong opinion either way, this will required another API in the wallet to filter only unconfirmed utxos.

IMO, we just need to modify get_balance api for this task.

coinswap/src/wallet/api.rs

Lines 325 to 353 in d38fc63

pub fn get_balances(
&self,
all_utxos: Option<&Vec<ListUnspentResultEntry>>,
) -> Result<Balances, WalletError> {
let regular = self
.list_descriptor_utxo_spend_info(all_utxos)?
.iter()
.fold(Amount::ZERO, |sum, (utxo, _)| sum + utxo.amount);
let contract = self
.list_live_timelock_contract_spend_info(all_utxos)?
.iter()
.fold(Amount::ZERO, |sum, (utxo, _)| sum + utxo.amount);
let swap = self
.list_incoming_swap_coin_utxo_spend_info(all_utxos)?
.iter()
.fold(Amount::ZERO, |sum, (utxo, _)| sum + utxo.amount);
let fidelity = self
.list_fidelity_spend_info(all_utxos)?
.iter()
.fold(Amount::ZERO, |sum, (utxo, _)| sum + utxo.amount);
let spendable = regular + swap;
Ok(Balances {
regular,
swap,
contract,
fidelity,
spendable,
})

@KnowWhoami KnowWhoami changed the title taker get-balances shows unconfirmed balance as "spendable" Segregate unconfirmed balance from confirmed ones in Balance struct Feb 26, 2025
@KnowWhoami
Copy link
Collaborator

But unconfirmed are also spendable

modified the issue title.

@Sansh2356
Copy link

Is this issue still pending can i take it up?

@KnowWhoami
Copy link
Collaborator

Currently we have not come to any sort of conclusion regarding it...
So would prefer to skip this issue for now. There are other important stuffs that you can pick up..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement This enhances the code and improves stuffs good first issue issues suitable for early contributors
Projects
None yet
Development

No branches or pull requests

5 participants