Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2272,6 +2272,9 @@ components:
- string
- 'null'
example: rgb:CJkb4YZw-jRiz2sk-~PARPio-wtVYI1c-XAEYCqO-wTfvRZ8
push_asset_amount:
type: integer
example: 100
public:
type: boolean
example: true
Expand Down
2 changes: 1 addition & 1 deletion src/ldk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,7 @@ async fn handle_ldk_events(
&PathBuf::from(&static_state.ldk_data_dir),
);

let channel_rgb_amount: u64 = rgb_info.local_rgb_amount;
let channel_rgb_amount = rgb_info.local_rgb_amount + rgb_info.remote_rgb_amount;
let asset_id = rgb_info.contract_id.to_string();
let assignment = match rgb_info.schema {
AssetSchema::Nia | AssetSchema::Cfa => Assignment::Fungible(channel_rgb_amount),
Expand Down
22 changes: 20 additions & 2 deletions src/routes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -839,6 +839,7 @@ pub(crate) struct OpenChannelRequest {
pub(crate) push_msat: u64,
pub(crate) asset_amount: Option<u64>,
pub(crate) asset_id: Option<String>,
pub(crate) push_asset_amount: Option<u64>,
pub(crate) public: bool,
pub(crate) with_anchors: bool,
pub(crate) fee_base_msat: Option<u32>,
Expand Down Expand Up @@ -3044,6 +3045,21 @@ pub(crate) async fn open_channel(
)));
}

if let Some(push_asset_amount) = payload.push_asset_amount {
if colored_info.is_none() {
return Err(APIError::InvalidAmount(s!(
"push_asset_amount can only be used with RGB channels (asset_id must be specified)"
)));
}
if let Some((_, asset_amount)) = &colored_info {
if push_asset_amount > *asset_amount {
return Err(APIError::InvalidAmount(s!(
"push_asset_amount cannot be higher than asset_amount"
)));
}
}
}

if colored_info.is_some() && !payload.with_anchors {
return Err(APIError::AnchorsRequired);
}
Expand Down Expand Up @@ -3175,6 +3191,7 @@ pub(crate) async fn open_channel(
temporary_channel_id,
Some(config),
consignment_endpoint,
payload.push_asset_amount,
)
.map_err(|e| {
*unlocked_state.rgb_send_lock.lock().unwrap() = false;
Expand All @@ -3201,11 +3218,12 @@ pub(crate) async fn open_channel(
tracing::info!("EVENT: initiated channel with peer {}", peer_pubkey);

if let Some((contract_id, asset_amount)) = &colored_info {
let push_amount = payload.push_asset_amount.unwrap_or(0);
let rgb_info = RgbInfo {
contract_id: *contract_id,
schema: schema.unwrap(),
local_rgb_amount: *asset_amount,
remote_rgb_amount: 0,
local_rgb_amount: *asset_amount - push_amount,
remote_rgb_amount: push_amount,
};
write_rgb_channel_info(
&get_rgb_channel_info_path(
Expand Down
1 change: 1 addition & 0 deletions src/test/close_coop_vanilla.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ async fn without_anchors() {
None,
None,
None,
None,
false,
)
.await;
Expand Down
5 changes: 5 additions & 0 deletions src/test/concurrent_openchannel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ async fn concurrent_openchannel() {
Some(PUSH_MSAT),
Some(ASSET_AMOUNT),
Some(&asset_id),
None,
20,
),
open_channel_with_retry(
Expand All @@ -69,6 +70,7 @@ async fn concurrent_openchannel() {
Some(PUSH_MSAT),
Some(ASSET_AMOUNT),
Some(&asset_id),
None,
20,
),
open_channel_with_retry(
Expand All @@ -79,6 +81,7 @@ async fn concurrent_openchannel() {
Some(PUSH_MSAT),
Some(ASSET_AMOUNT),
Some(&asset_id),
None,
20,
),
open_channel_with_retry(
Expand All @@ -89,6 +92,7 @@ async fn concurrent_openchannel() {
Some(PUSH_MSAT),
Some(ASSET_AMOUNT),
Some(&asset_id),
None,
20,
),
open_channel_with_retry(
Expand All @@ -99,6 +103,7 @@ async fn concurrent_openchannel() {
Some(PUSH_MSAT),
Some(ASSET_AMOUNT),
Some(&asset_id),
None,
20,
)
);
Expand Down
1 change: 1 addition & 0 deletions src/test/getchannelid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ async fn getchannelid_success() {
Some(&asset_id),
None,
None,
None,
Some(&temporary_channel_id),
true,
)
Expand Down
18 changes: 17 additions & 1 deletion src/test/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1084,6 +1084,7 @@ async fn open_channel(
None,
None,
None,
None,
true,
)
.await
Expand All @@ -1098,6 +1099,7 @@ async fn open_channel_with_retry(
push_msat: Option<u64>,
asset_amount: Option<u64>,
asset_id: Option<&str>,
push_asset_amount: Option<u64>,
max_retries: u32,
) -> Channel {
let mut attempt = 0;
Expand All @@ -1111,6 +1113,7 @@ async fn open_channel_with_retry(
push_msat,
asset_amount,
asset_id,
push_asset_amount,
None,
None,
None,
Expand Down Expand Up @@ -1146,6 +1149,7 @@ async fn open_channel_raw(
push_msat: Option<u64>,
asset_amount: Option<u64>,
asset_id: Option<&str>,
push_asset_amount: Option<u64>,
fee_base_msat: Option<u32>,
fee_proportional_millionths: Option<u32>,
temporary_channel_id: Option<&str>,
Expand Down Expand Up @@ -1180,6 +1184,7 @@ async fn open_channel_raw(
push_msat: push_msat.unwrap_or(0),
asset_amount,
asset_id: asset_id.map(|a| a.to_string()),
push_asset_amount,
public: true,
with_anchors,
fee_base_msat,
Expand Down Expand Up @@ -1207,10 +1212,18 @@ async fn open_channel_raw(
tokio::time::sleep(std::time::Duration::from_secs(1)).await;
let channels = list_channels(node_address).await;
if let Some(channel) = channels.iter().find(|c| {
let asset_amounts_match = if asset_id.is_some() {
let local_amount = asset_amount.unwrap_or(0) - push_asset_amount.unwrap_or(0);
let remote_amount = push_asset_amount.unwrap_or(0);
c.asset_local_amount == Some(local_amount)
&& c.asset_remote_amount == Some(remote_amount)
} else {
c.asset_local_amount.is_none() && c.asset_remote_amount.is_none()
};
!c.ready
&& c.peer_pubkey == dest_peer_pubkey
&& c.asset_id == asset_id.map(|id| id.to_string())
&& c.asset_local_amount == asset_amount
&& asset_amounts_match
}) {
if let Some(txid) = &channel.funding_txid {
let txout = _get_txout(txid);
Expand Down Expand Up @@ -1254,6 +1267,7 @@ async fn open_channel_with_custom_data(
push_msat: Option<u64>,
asset_amount: Option<u64>,
asset_id: Option<&str>,
push_asset_amount: Option<u64>,
fee_base_msat: Option<u32>,
fee_proportional_millionths: Option<u32>,
temporary_channel_id: Option<&str>,
Expand All @@ -1267,6 +1281,7 @@ async fn open_channel_with_custom_data(
push_msat,
asset_amount,
asset_id,
push_asset_amount,
fee_base_msat,
fee_proportional_millionths,
temporary_channel_id,
Expand Down Expand Up @@ -1870,6 +1885,7 @@ mod multi_open_close;
mod open_after_double_send;
mod openchannel_fail;
mod openchannel_optional_addr;
mod openchannel_push_asset_amount;
mod payment;
mod refuse_high_fees;
mod restart;
Expand Down
Loading
Loading