Skip to content

Commit

Permalink
update rgb-lib to 0.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
zoedberg committed Nov 8, 2023
1 parent 00cf6d5 commit 4fed2a9
Show file tree
Hide file tree
Showing 10 changed files with 189 additions and 207 deletions.
335 changes: 153 additions & 182 deletions Cargo.lock

Large diffs are not rendered by default.

16 changes: 8 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,14 @@ walkdir = "2.3.3"
zip = { version = "0.6.6", default-features = false, features = ["time", "zstd"] }

# RGB-related deps
amplify = "=4.0.1"
bp-core = "=0.10.9"
rgb-lib = "=0.2.0-alpha.5"
rgb-std = "=0.10.8"
rgb-wallet = "=0.10.8"
rgb_core = { package = "rgb-core", version = "=0.10.7" }
strict_encoding = "=2.5.0"
strict_types = "=1.6.1"
amplify = "=4.5.0"
bp-core = "=0.10.11"
rgb-lib = "=0.2.0"
rgb-std = "=0.10.9"
rgb-wallet = "=0.10.9"
rgb_core = { package = "rgb-core", version = "=0.10.8" }
strict_encoding = "=2.6.1"
strict_types = "=1.6.3"

[dev-dependencies]
dircmp = "0.2.0"
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ Also note that the following RGB projects (included in this project as git
sumbodules) have been modified in order to make the creation of static
consignments (without entropy) possible. Here links to compare the applied
changes:
- [client_side_validation](https://github.com/RGB-Tools/client_side_validation/compare/v0.10.5...static_0.10.5)
- [rgb-wallet](https://github.com/RGB-Tools/rgb-wallet/compare/v0.10.8...static_v0.10.8)
- [client_side_validation](https://github.com/RGB-Tools/client_side_validation/compare/v0.10.6...static_0.10.6)
- [rgb-wallet](https://github.com/RGB-Tools/rgb-wallet/compare/v0.10.9...static_v0.10.9)

But most importantly [rust-lightning] has been changed in order to support
RGB channels,
Expand Down
2 changes: 1 addition & 1 deletion rust-lightning
9 changes: 5 additions & 4 deletions src/ldk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ use lightning_net_tokio::SocketDescriptor;
use lightning_persister::fs_store::FilesystemStore;
use rand::{thread_rng, Rng, RngCore};
use rgb_lib::wallet::{DatabaseType, Recipient, RecipientData, Wallet as RgbLibWallet, WalletData};
use rgb_lib::{AssetSchema, BitcoinNetwork};
use rgb_lib::AssetSchema;
use rgbstd::containers::{Bindle, Transfer as RgbTransfer};
use rgbstd::persistence::Inventory;
use rgbstd::Txid as RgbTxid;
Expand All @@ -70,7 +70,7 @@ use crate::disk::{self, INBOUND_PAYMENTS_FNAME, OUTBOUND_PAYMENTS_FNAME};
use crate::disk::{FilesystemLogger, PENDING_SPENDABLE_OUTPUT_DIR};
use crate::error::APIError;
use crate::proxy::post_consignment;
use crate::rgb::{update_transition_beneficiary, RgbUtilities};
use crate::rgb::{get_bitcoin_network, update_transition_beneficiary, RgbUtilities};
use crate::routes::HTLCStatus;
use crate::utils::{do_connect_peer, hex_str, AppState, StaticState, UnlockedAppState};

Expand Down Expand Up @@ -912,7 +912,7 @@ async fn _spend_outputs(
}

if !vanilla_output_descriptors.is_empty() {
let address_str = unlocked_state.get_rgb_wallet().get_address();
let address_str = unlocked_state.get_rgb_wallet().get_address().unwrap();
let address = Address::from_str(&address_str).unwrap().assume_checked();
let script_buf = address.script_pubkey();
let bdk_script = BdkScript::from(script_buf.into_bytes());
Expand Down Expand Up @@ -1098,7 +1098,7 @@ pub(crate) async fn start_ldk(
let ldk_announced_listen_addr = static_state.ldk_announced_listen_addr.clone();
let ldk_announced_node_name = static_state.ldk_announced_node_name;
let electrum_url = static_state.electrum_url.clone();
let bitcoin_network: BitcoinNetwork = network.into();
let bitcoin_network = get_bitcoin_network(&network);

// Initialize the FeeEstimator
// BitcoindClient implements the FeeEstimator trait, so it'll act as our fee estimator.
Expand Down Expand Up @@ -1438,6 +1438,7 @@ pub(crate) async fn start_ldk(
max_allocations_per_utxo: 1,
pubkey,
mnemonic: Some(mnemonic.to_string()),
vanilla_keychain: None,
})
.expect("valid rgb-lib wallet")
})
Expand Down
11 changes: 9 additions & 2 deletions src/rgb.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use amplify::RawArray;
use amplify::ByteArray;
use bdk::bitcoin::psbt::PartiallySignedTransaction;
use bitcoin::Network;
use bitcoin_30::hashes::Hash;
use bitcoin_30::psbt::PartiallySignedTransaction as RgbPsbt;
use bp::seals::txout::blind::{BlindSeal, SingleBlindSeal};
Expand All @@ -8,6 +9,7 @@ use bp::Outpoint as RgbOutpoint;
use lightning::rgb_utils::STATIC_BLINDING;
use rgb_core::Operation;
use rgb_lib::utils::RgbRuntime;
use rgb_lib::BitcoinNetwork;
use rgbstd::containers::{Bindle, BuilderSeal, Transfer as RgbTransfer};
use rgbstd::contract::{ContractId, GraphSeal};
use rgbstd::interface::{TransitionBuilder, TypedState};
Expand Down Expand Up @@ -76,6 +78,11 @@ pub(crate) fn update_transition_beneficiary(
(seal_vout, asset_transition_builder)
}

// TODO: remove after updating to bitcoin 0.30
pub(crate) fn get_bitcoin_network(network: &Network) -> BitcoinNetwork {
BitcoinNetwork::from_str(&network.to_string()).unwrap()
}

pub(crate) trait RgbUtilities {
fn send_rgb(
&mut self,
Expand Down Expand Up @@ -166,7 +173,7 @@ impl RgbUtilities for RgbRuntime {
.into_iter()
.map(|b| match b {
BuilderSeal::Revealed(graph_seal) => BuilderSeal::Revealed(
graph_seal.resolve(RgbTxid::from_raw_array(witness_txid.to_byte_array())),
graph_seal.resolve(RgbTxid::from_byte_array(witness_txid.to_byte_array())),
),
BuilderSeal::Concealed(seal) => BuilderSeal::Concealed(seal),
})
Expand Down
11 changes: 7 additions & 4 deletions src/routes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ use std::{
use crate::backup::{do_backup, restore_backup};
use crate::disk::{INBOUND_PAYMENTS_FNAME, OUTBOUND_PAYMENTS_FNAME};
use crate::ldk::{start_ldk, stop_ldk, MIN_CHANNEL_CONFIRMATIONS};
use crate::rgb::match_rgb_lib_error;
use crate::rgb::{get_bitcoin_network, match_rgb_lib_error};
use crate::utils::{
check_already_initialized, check_locked, check_password_strength, check_password_validity,
check_unlocked, encrypt_and_save_mnemonic, get_mnemonic_path, hex_str,
Expand Down Expand Up @@ -579,7 +579,10 @@ pub(crate) async fn address(
) -> Result<Json<AddressResponse>, APIError> {
let unlocked_state = check_unlocked(&state)?.clone().unwrap();

let address = unlocked_state.get_rgb_wallet().get_address();
let address = unlocked_state
.get_rgb_wallet()
.get_address()
.map_err(|e| match_rgb_lib_error(&e, APIError::Unexpected))?;

Ok(Json(AddressResponse { address }))
}
Expand Down Expand Up @@ -882,7 +885,7 @@ pub(crate) async fn init(
let mnemonic_path = get_mnemonic_path(&state.static_state.storage_dir_path);
check_already_initialized(&mnemonic_path)?;

let keys = generate_keys(state.static_state.network.into());
let keys = generate_keys(get_bitcoin_network(&state.static_state.network));

let mnemonic = keys.mnemonic;

Expand Down Expand Up @@ -1230,7 +1233,7 @@ pub(crate) async fn list_transfers(
let mut transfers = vec![];
for transfer in unlocked_state
.get_rgb_wallet()
.list_transfers(payload.asset_id)
.list_transfers(Some(payload.asset_id))
.map_err(|e| match_rgb_lib_error(&e, APIError::Unexpected))?
{
transfers.push(Transfer {
Expand Down
4 changes: 2 additions & 2 deletions src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ use lightning_persister::fs_store::FilesystemStore;
use magic_crypt::{new_magic_crypt, MagicCryptTrait};
use reqwest::Client as RestClient;
use rgb_lib::wallet::{Online, Wallet as RgbLibWallet};
use rgb_lib::BitcoinNetwork;
use std::{
fmt::Write,
fs,
Expand All @@ -35,6 +34,7 @@ use crate::{
ChannelManager, InboundPaymentInfoStorage, LdkBackgroundServices, NetworkGraph,
OnionMessenger, OutboundPaymentInfoStorage, PeerManager,
},
rgb::get_bitcoin_network,
};

pub(crate) const LOGS_DIR: &str = "logs";
Expand Down Expand Up @@ -394,7 +394,7 @@ pub(crate) async fn start_daemon(args: LdkUserInfo) -> Result<Arc<AppState>, App
electrum_url,
)
.expect("able to write");
let bitcoin_network: BitcoinNetwork = network.into();
let bitcoin_network = get_bitcoin_network(&network);
fs::write(
format!("{}/{BITCOIN_NETWORK_FNAME}", args.storage_dir_path),
bitcoin_network.to_string(),
Expand Down

0 comments on commit 4fed2a9

Please sign in to comment.