wallet: refresh with proxy
Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
This commit is contained in:
parent
8074b0650a
commit
516e8072d2
|
@ -2339,6 +2339,20 @@ dependencies = [
|
|||
"minimal-lexical",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "nosql_db"
|
||||
version = "0.0.2"
|
||||
source = "git+https://github.com/vincenzopalazzo/nosql-db.git#fc4bfdac7d29dd367c860f783213de252b7472ff"
|
||||
|
||||
[[package]]
|
||||
name = "nosql_sled"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/vincenzopalazzo/nosql-db.git#fc4bfdac7d29dd367c860f783213de252b7472ff"
|
||||
dependencies = [
|
||||
"nosql_db",
|
||||
"sled",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ntest"
|
||||
version = "0.9.2"
|
||||
|
@ -3009,6 +3023,8 @@ dependencies = [
|
|||
"futures",
|
||||
"hex",
|
||||
"lightning 0.0.118",
|
||||
"nosql_db",
|
||||
"nosql_sled",
|
||||
"reqwest",
|
||||
"rgb-contracts",
|
||||
"rgb-core",
|
||||
|
|
|
@ -19,7 +19,7 @@ use clightningrpc::LightningRPC;
|
|||
use clightningrpc_plugin::error;
|
||||
use clightningrpc_plugin::errors::PluginError;
|
||||
use clightningrpc_plugin::{commands::RPCCommand, plugin::Plugin};
|
||||
use clightningrpc_plugin_macros::{plugin, rpc_method};
|
||||
use clightningrpc_plugin_macros::{notification, plugin, rpc_method};
|
||||
|
||||
use rgb_common::anyhow;
|
||||
use rgb_common::bitcoin::bip32::ExtendedPrivKey;
|
||||
|
@ -69,7 +69,9 @@ pub fn build_plugin() -> anyhow::Result<Plugin<State>> {
|
|||
let mut plugin = plugin! {
|
||||
state: State::new(),
|
||||
dynamic: true,
|
||||
notification: [ ],
|
||||
notification: [
|
||||
on_block_added,
|
||||
],
|
||||
methods: [
|
||||
rgb_balance,
|
||||
rgb_fundchannel,
|
||||
|
@ -121,6 +123,15 @@ fn rgb_info(plugin: &mut Plugin<State>, request: Value) -> Result<Value, PluginE
|
|||
Ok(info)
|
||||
}
|
||||
|
||||
#[notification(on = "block_added")]
|
||||
fn on_block_added(plugin: &mut Plugin<State>, request: &Value) {
|
||||
let manager = plugin.state.manager();
|
||||
let Err(err) = manager.refresh() else {
|
||||
return;
|
||||
};
|
||||
log::error!("{err}");
|
||||
}
|
||||
|
||||
fn read_secret(file: fs::File, network: &str) -> anyhow::Result<ExtendedPrivKey> {
|
||||
let buffer = io::BufReader::new(file);
|
||||
let network = vlsbtc::Network::from_str(network)?;
|
||||
|
|
|
@ -78,11 +78,11 @@ pub fn fund_rgb_channel(plugin: &mut Plugin<State>, request: Value) -> Result<Va
|
|||
.map_err(|err| error!("decoding contract id return error: `{err}`"))?;
|
||||
// FIXME: Check if we are connected with the peer otherwise connect to them
|
||||
|
||||
let manager = plugin.state.manager();
|
||||
|
||||
// FIXME: we need the magic of core lightning here
|
||||
let balance = request.amount_msat;
|
||||
let assert_balance = plugin
|
||||
.state
|
||||
.manager()
|
||||
let assert_balance = manager
|
||||
.assert_balance(contract_id.to_string())
|
||||
.map_err(|err| error!("{err}"))?;
|
||||
log::info!("rgbalance {:?}", balance);
|
||||
|
@ -126,17 +126,10 @@ pub fn fund_rgb_channel(plugin: &mut Plugin<State>, request: Value) -> Result<Va
|
|||
remote_rgb_amount: 0,
|
||||
};
|
||||
|
||||
plugin
|
||||
.state
|
||||
.manager()
|
||||
manager
|
||||
.add_rgb_info(&info, true)
|
||||
.map_err(|err| error!("{err}"))?;
|
||||
let Ok(psbt) =
|
||||
plugin
|
||||
.state
|
||||
.manager()
|
||||
.build_rgb_funding_transaction(&info, scriptpubkey, 1.1, 6)
|
||||
else {
|
||||
let Ok(psbt) = manager.build_rgb_funding_transaction(&info, scriptpubkey, 1.1, 6) else {
|
||||
let _: json::Value = plugin
|
||||
.state
|
||||
.call(
|
||||
|
@ -209,6 +202,13 @@ pub fn rgb_receive(plugin: &mut Plugin<State>, request: Value) -> Result<Value,
|
|||
.create_utxos(fee as f32, |psbt| wallet.sing_with_master_key(psbt))
|
||||
.map_err(|err| error!("{err}"))?;
|
||||
log::info!("get the new blind receive");
|
||||
if let Some(ref asset_id) = request.asset_id {
|
||||
plugin
|
||||
.state
|
||||
.manager()
|
||||
.listen_for(asset_id)
|
||||
.map_err(|err| error!("{err}"))?;
|
||||
}
|
||||
let receive = wallet
|
||||
// FIXME: add the blocks inside the plugin configuration
|
||||
.new_blind_receive(request.asset_id, 6)
|
||||
|
|
|
@ -27,5 +27,8 @@ strict_encoding = "=2.6.2"
|
|||
tokio = { version = "1.36", features = ["macros", "rt-multi-thread"] }
|
||||
bdk = "0.29.0"
|
||||
|
||||
nosql_db = { git = "https://github.com/vincenzopalazzo/nosql-db.git" }
|
||||
nosql_sled = { git = "https://github.com/vincenzopalazzo/nosql-db.git" }
|
||||
|
||||
# Fixing dependencies resolution :/
|
||||
amplify_num = "=0.5.1"
|
||||
|
|
|
@ -156,6 +156,16 @@ impl Wallet {
|
|||
Ok(assert)
|
||||
}
|
||||
|
||||
pub fn refresh(&self) -> anyhow::Result<()> {
|
||||
let online = self
|
||||
.online_wallet
|
||||
.clone()
|
||||
.ok_or(anyhow::anyhow!("Wallet is not online"))?;
|
||||
let wallet = self.wallet.lock().unwrap();
|
||||
wallet.refresh(online, None, vec![])?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn new_addr(&self) -> anyhow::Result<String> {
|
||||
let addr = self.wallet.lock().unwrap().get_address()?;
|
||||
Ok(addr)
|
||||
|
|
|
@ -83,10 +83,8 @@ impl ConsignmentClient {
|
|||
.text("params", serde_json::to_string(¶ms)?)
|
||||
.part("file", consignment_file);
|
||||
|
||||
// FIXME: add a URL for this
|
||||
let url = format!("{}/TODO", self.url);
|
||||
self.inner
|
||||
.post(format!("{url}"))
|
||||
.post(format!("{}", self.url))
|
||||
.header(CONTENT_TYPE, JSON)
|
||||
.multipart(form)
|
||||
.send()?
|
||||
|
|
|
@ -95,7 +95,24 @@ impl RGBManager {
|
|||
self.storage.write_rgb_info(&info.channel_id, pending, info)
|
||||
}
|
||||
|
||||
/// Using the rgb proxy we to sync up if there is
|
||||
/// anything for us that we need to sync.
|
||||
///
|
||||
/// An example is when we receive a payment, we have something
|
||||
/// the proxy that need to be signed, so this operation is doing
|
||||
/// exactly this.
|
||||
pub fn refresh(&self) -> anyhow::Result<()> {
|
||||
self.wallet().refresh()?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn listen_for(&self, asset_id: &str) -> anyhow::Result<()> {
|
||||
self.storage.listen_for_asset(asset_id)
|
||||
}
|
||||
|
||||
/// Modify the funding transaction before sign it with the node signer.
|
||||
///
|
||||
/// Please note that this will also propagate rgb cosigment to the network.
|
||||
pub fn build_rgb_funding_transaction(
|
||||
&self,
|
||||
rgb_info: &RgbInfo,
|
||||
|
|
|
@ -21,6 +21,10 @@ pub trait RGBStorage {
|
|||
is_pending: bool,
|
||||
info: &RgbInfo,
|
||||
) -> anyhow::Result<()>;
|
||||
|
||||
fn listen_for_asset(&self, asset_id: &str) -> anyhow::Result<()>;
|
||||
|
||||
fn get_assets_list(&self) -> anyhow::Result<Vec<String>>;
|
||||
}
|
||||
|
||||
pub struct InMemoryStorage {
|
||||
|
@ -44,6 +48,31 @@ impl RGBStorage for InMemoryStorage {
|
|||
})
|
||||
}
|
||||
|
||||
fn listen_for_asset(&self, asset_id: &str) -> anyhow::Result<()> {
|
||||
let key = "rgb/assets".to_owned();
|
||||
let mut map = self.inner.borrow_mut();
|
||||
let mut assets: Vec<String> = if let Some(value) = map.get(&key) {
|
||||
serde_json::from_str(value)?
|
||||
} else {
|
||||
vec![]
|
||||
};
|
||||
assets.push(asset_id.to_owned());
|
||||
let assets = serde_json::to_string(&assets)?;
|
||||
map.insert(key, assets);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn get_assets_list(&self) -> anyhow::Result<Vec<String>> {
|
||||
let key = "rgb/assets".to_owned();
|
||||
let map = self.inner.borrow();
|
||||
let assets: Vec<String> = if let Some(value) = map.get(&key) {
|
||||
serde_json::from_str(value)?
|
||||
} else {
|
||||
vec![]
|
||||
};
|
||||
Ok(assets)
|
||||
}
|
||||
|
||||
fn get_rgb_channel_info(&self, channel_id: &str) -> anyhow::Result<RgbInfo> {
|
||||
let key = self.derive_channel_db_key(channel_id, false)?;
|
||||
let map = self.inner.borrow();
|
||||
|
|
Loading…
Reference in New Issue