Skip to content

Commit 45c88d7

Browse files
committed
update rgb-lib to 0.3.0-alpha.13
1 parent 332dfd7 commit 45c88d7

File tree

3 files changed

+73
-21
lines changed

3 files changed

+73
-21
lines changed

lightning-invoice/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ serde = { version = "1.0.118", optional = true }
2424
bitcoin = { version = "0.32.2", default-features = false, features = ["secp-recovery"] }
2525

2626
# RGB and related
27-
rgb-lib = { version = "0.3.0-alpha.12", features = [
27+
rgb-lib = { version = "0.3.0-alpha.13", features = [
2828
"electrum",
2929
"esplora",
3030
] }

lightning/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ libm = { version = "0.2", optional = true, default-features = false }
5353

5454
# RGB and related
5555
futures = "0.3"
56-
rgb-lib = { version = "0.3.0-alpha.12", features = [
56+
rgb-lib = { version = "0.3.0-alpha.13", features = [
5757
"electrum",
5858
"esplora",
5959
] }

lightning/src/rgb_utils/mod.rs

Lines changed: 71 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use rgb_lib::{
2424
DatabaseType, Outpoint, WalletData,
2525
},
2626
BitcoinNetwork, ConsignmentExt, ContractId, Error as RgbLibError, FileContent, RgbTransfer,
27-
RgbTransport, RgbTxid, Wallet,
27+
RgbTransport, RgbTxid, Wallet, WitnessOrd,
2828
};
2929
use serde::{Deserialize, Serialize};
3030
use tokio::runtime::Handle;
@@ -43,15 +43,18 @@ pub const BITCOIN_NETWORK_FNAME: &str = "bitcoin_network";
4343
pub const INDEXER_URL_FNAME: &str = "indexer_url";
4444
/// Name of the file containing the wallet fingerprint
4545
pub const WALLET_FINGERPRINT_FNAME: &str = "wallet_fingerprint";
46-
/// Name of the file containing the wallet account xPub
47-
pub const WALLET_ACCOUNT_XPUB_FNAME: &str = "wallet_account_xpub";
46+
/// Name of the file containing the account-level xPub of the vanilla-side of the wallet
47+
pub const WALLET_ACCOUNT_XPUB_VANILLA_FNAME: &str = "wallet_account_xpub_vanilla";
48+
/// Name of the file containing the account-level xPub of the colored-side of the wallet
49+
pub const WALLET_ACCOUNT_XPUB_COLORED_FNAME: &str = "wallet_account_xpub_colored";
4850
const INBOUND_EXT: &str = "inbound";
4951
const OUTBOUND_EXT: &str = "outbound";
5052

5153
/// RGB channel info
5254
#[derive(Debug, Clone, Deserialize, Serialize)]
5355
pub struct RgbInfo {
5456
/// Channel contract ID
57+
#[serde(with = "contract_id_serde")]
5558
pub contract_id: ContractId,
5659
/// Channel RGB local amount
5760
pub local_rgb_amount: u64,
@@ -63,6 +66,7 @@ pub struct RgbInfo {
6366
#[derive(Debug, Clone, Deserialize, Serialize)]
6467
pub struct RgbPaymentInfo {
6568
/// RGB contract ID
69+
#[serde(with = "contract_id_serde")]
6670
pub contract_id: ContractId,
6771
/// RGB payment amount
6872
pub amount: u64,
@@ -80,11 +84,33 @@ pub struct RgbPaymentInfo {
8084
#[derive(Debug, Clone, Deserialize, Serialize)]
8185
pub struct TransferInfo {
8286
/// Transfer contract ID
87+
#[serde(with = "contract_id_serde")]
8388
pub contract_id: ContractId,
8489
/// Transfer RGB amount
8590
pub rgb_amount: u64,
8691
}
8792

93+
mod contract_id_serde {
94+
use super::*;
95+
use serde::{Deserializer, Serializer};
96+
use std::str::FromStr;
97+
98+
pub fn serialize<S>(id: &ContractId, serializer: S) -> Result<S::Ok, S::Error>
99+
where
100+
S: Serializer,
101+
{
102+
serializer.serialize_str(&id.to_string())
103+
}
104+
105+
pub fn deserialize<'de, D>(deserializer: D) -> Result<ContractId, D::Error>
106+
where
107+
D: Deserializer<'de>,
108+
{
109+
let s = String::deserialize(deserializer)?;
110+
ContractId::from_str(&s).map_err(serde::de::Error::custom)
111+
}
112+
}
113+
88114
fn _get_file_in_parent(ldk_data_dir: &Path, fname: &str) -> PathBuf {
89115
ldk_data_dir.parent().unwrap().join(fname)
90116
}
@@ -103,49 +129,63 @@ fn _get_bitcoin_network(ldk_data_dir: &Path) -> BitcoinNetwork {
103129
BitcoinNetwork::from_str(&bitcoin_network).unwrap()
104130
}
105131

106-
fn _get_account_xpub(ldk_data_dir: &Path) -> String {
107-
_read_file_in_parent(ldk_data_dir, WALLET_ACCOUNT_XPUB_FNAME)
132+
fn _get_account_xpub_colored(ldk_data_dir: &Path) -> String {
133+
_read_file_in_parent(ldk_data_dir, WALLET_ACCOUNT_XPUB_COLORED_FNAME)
134+
}
135+
136+
fn _get_account_xpub_vanilla(ldk_data_dir: &Path) -> String {
137+
_read_file_in_parent(ldk_data_dir, WALLET_ACCOUNT_XPUB_VANILLA_FNAME)
108138
}
109139

110140
fn _get_indexer_url(ldk_data_dir: &Path) -> String {
111141
_read_file_in_parent(ldk_data_dir, INDEXER_URL_FNAME)
112142
}
113143

114-
fn _new_rgb_wallet(data_dir: String, bitcoin_network: BitcoinNetwork, pubkey: String) -> Wallet {
144+
fn _new_rgb_wallet(
145+
data_dir: String, bitcoin_network: BitcoinNetwork, account_xpub_vanilla: String,
146+
account_xpub_colored: String,
147+
) -> Wallet {
115148
Wallet::new(WalletData {
116149
data_dir,
117150
bitcoin_network,
118151
database_type: DatabaseType::Sqlite,
119152
max_allocations_per_utxo: 1,
120-
pubkey,
153+
account_xpub_vanilla,
154+
account_xpub_colored,
121155
mnemonic: None,
122156
vanilla_keychain: None,
123157
})
124158
.expect("valid rgb-lib wallet")
125159
}
126160

127-
fn _get_wallet_data(ldk_data_dir: &Path) -> (String, BitcoinNetwork, String) {
161+
fn _get_wallet_data(ldk_data_dir: &Path) -> (String, BitcoinNetwork, String, String) {
128162
let data_dir = ldk_data_dir.parent().unwrap().to_string_lossy().to_string();
129163
let bitcoin_network = _get_bitcoin_network(ldk_data_dir);
130-
let pubkey = _get_account_xpub(ldk_data_dir);
131-
(data_dir, bitcoin_network, pubkey)
164+
let account_xpub_vanilla = _get_account_xpub_vanilla(ldk_data_dir);
165+
let account_xpub_colored = _get_account_xpub_colored(ldk_data_dir);
166+
(data_dir, bitcoin_network, account_xpub_vanilla, account_xpub_colored)
132167
}
133168

134169
async fn _get_rgb_wallet(ldk_data_dir: &Path) -> Wallet {
135-
let (data_dir, bitcoin_network, pubkey) = _get_wallet_data(ldk_data_dir);
136-
tokio::task::spawn_blocking(move || _new_rgb_wallet(data_dir, bitcoin_network, pubkey))
137-
.await
138-
.unwrap()
170+
let (data_dir, bitcoin_network, account_xpub_vanilla, account_xpub_colored) =
171+
_get_wallet_data(ldk_data_dir);
172+
tokio::task::spawn_blocking(move || {
173+
_new_rgb_wallet(data_dir, bitcoin_network, account_xpub_vanilla, account_xpub_colored)
174+
})
175+
.await
176+
.unwrap()
139177
}
140178

141179
async fn _accept_transfer(
142180
ldk_data_dir: &Path, funding_txid: String, consignment_endpoint: RgbTransport,
143181
) -> Result<(RgbTransfer, u64), RgbLibError> {
144182
let funding_vout = 1;
145-
let (data_dir, bitcoin_network, pubkey) = _get_wallet_data(ldk_data_dir);
183+
let (data_dir, bitcoin_network, account_xpub_vanilla, account_xpub_colored) =
184+
_get_wallet_data(ldk_data_dir);
146185
let indexer_url = _get_indexer_url(ldk_data_dir);
147186
tokio::task::spawn_blocking(move || {
148-
let mut wallet = _new_rgb_wallet(data_dir, bitcoin_network, pubkey);
187+
let mut wallet =
188+
_new_rgb_wallet(data_dir, bitcoin_network, account_xpub_vanilla, account_xpub_colored);
149189
wallet.go_online(true, indexer_url).unwrap();
150190
wallet.accept_transfer(
151191
funding_txid.clone(),
@@ -340,7 +380,11 @@ where
340380
commitment_transaction.built = BuiltCommitmentTransaction { transaction: modified_tx, txid };
341381

342382
wallet
343-
.consume_fascia(fascia.clone(), RgbTxid::from_str(&txid.to_string()).unwrap(), None)
383+
.consume_fascia(
384+
fascia.clone(),
385+
RgbTxid::from_str(&txid.to_string()).unwrap(),
386+
Some(WitnessOrd::Ignored),
387+
)
344388
.unwrap();
345389

346390
// save RGB transfer data to disk
@@ -400,7 +444,11 @@ pub(crate) fn color_htlc(
400444
let txid = &modified_tx.compute_txid();
401445

402446
wallet
403-
.consume_fascia(fascia.clone(), RgbTxid::from_str(&txid.to_string()).unwrap(), None)
447+
.consume_fascia(
448+
fascia.clone(),
449+
RgbTxid::from_str(&txid.to_string()).unwrap(),
450+
Some(WitnessOrd::Ignored),
451+
)
404452
.unwrap();
405453

406454
// save RGB transfer data to disk
@@ -474,7 +522,11 @@ pub(crate) fn color_closing(
474522
closing_transaction.built = modified_tx;
475523

476524
wallet
477-
.consume_fascia(fascia.clone(), RgbTxid::from_str(&txid.to_string()).unwrap(), None)
525+
.consume_fascia(
526+
fascia.clone(),
527+
RgbTxid::from_str(&txid.to_string()).unwrap(),
528+
Some(WitnessOrd::Ignored),
529+
)
478530
.unwrap();
479531

480532
// save RGB transfer data to disk

0 commit comments

Comments
 (0)