lightningdevkit / ldk-sample

Sample node implementation using LDK
Apache License 2.0
166 stars 94 forks source link

Get Wallet Balance #127

Closed spirrello closed 7 months ago

spirrello commented 10 months ago

Hi, really like this sample project and its been for learning lightning/ldk. If one would like to write a function for getting the current Wallet balance is there a method in LDK for this purpose? I looked over docs and couldn't find anything.

Let me know if I should instead ask this question in Discord (please include the channel).

spirrello commented 10 months ago

I checked in Discord about this and they recommended to use rpc directly to get the balance. I tried this in a local branch and it worked.

New match case in poll_for_user_input function.

"walletbalance" => {
    let runtime =
        tokio::runtime::Builder::new_current_thread().enable_all().build().unwrap();
    runtime.block_on(wallet_balance(bitcoin_client.clone()));
    continue;
}

Function for returning the wallet balance.

async fn wallet_balance(bitcoin: Arc<BitcoindClient>) {
    let params: &[serde_json::Value] =
        &[serde_json::Value::String("*".to_string()), serde_json::Value::Number(6.into())];
    let available_balance: serde_json::Value =
        bitcoin.bitcoind_rpc_client.call_method("getbalance", params).await.unwrap();
    println!("balance: {}", available_balance);
}
ikeogu commented 7 months ago

Good day @spirrello can I contribute to this?

spirrello commented 7 months ago

Good day @spirrello can I contribute to this?

@ikeogu yes absolutely

ikeogu commented 7 months ago

Alright, please can you assist me with more details?

ikeogu commented 7 months ago

please can I get more clarity , and also how to raise the PR.

TheBlueMatt commented 7 months ago

Given this is just a sample focused on how to interact with LDK, I'm not sure we want a method to fetch the Bitcoin Core balance. That's generally outside the scope of LDK and more "stuff" in the sample detracts from the goal of an easy-to-read small-ish codebase.

ikeogu commented 7 months ago

alright @TheBlueMatt , let me find another issue to resolve.

tnull commented 7 months ago

Thanks, @ikeogu!

Closing this as not planned.