diff --git a/openapi.yaml b/openapi.yaml index 182abc0..f223600 100644 --- a/openapi.yaml +++ b/openapi.yaml @@ -2045,6 +2045,8 @@ components: asset_id: type: string example: rgb:CJkb4YZw-jRiz2sk-~PARPio-wtVYI1c-XAEYCqO-wTfvRZ8 + assignment: + $ref: '#/components/schemas/Assignment' duration_seconds: type: integer example: 86400 diff --git a/src/ldk.rs b/src/ldk.rs index 30788a5..195b3f6 100644 --- a/src/ldk.rs +++ b/src/ldk.rs @@ -1294,7 +1294,13 @@ impl OutputSpender for RgbOutputSpender { new_asset = true; let receive_data = self .rgb_wallet_wrapper - .witness_receive(None, None, vec![self.proxy_endpoint.clone()], 0) + .witness_receive( + None, + Assignment::Any, + None, + vec![self.proxy_endpoint.clone()], + 0, + ) .unwrap(); let script_pubkey = script_buf_from_recipient_id(receive_data.recipient_id.clone()) .unwrap() diff --git a/src/rgb.rs b/src/rgb.rs index e38f0eb..9c6de3a 100644 --- a/src/rgb.rs +++ b/src/rgb.rs @@ -34,12 +34,14 @@ impl UnlockedAppState { pub(crate) fn rgb_blind_receive( &self, asset_id: Option, + assignment: Assignment, duration_seconds: Option, transport_endpoints: Vec, min_confirmations: u8, ) -> Result { self.rgb_wallet_wrapper.blind_receive( asset_id, + assignment, duration_seconds, transport_endpoints, min_confirmations, @@ -280,12 +282,14 @@ impl UnlockedAppState { pub(crate) fn rgb_witness_receive( &self, asset_id: Option, + assignment: Assignment, duration_seconds: Option, transport_endpoints: Vec, min_confirmations: u8, ) -> Result { self.rgb_wallet_wrapper.witness_receive( asset_id, + assignment, duration_seconds, transport_endpoints, min_confirmations, @@ -314,13 +318,14 @@ impl RgbLibWalletWrapper { pub(crate) fn blind_receive( &self, asset_id: Option, + assignment: Assignment, duration_seconds: Option, transport_endpoints: Vec, min_confirmations: u8, ) -> Result { self.get_rgb_wallet().blind_receive( asset_id, - Assignment::Any, + assignment, duration_seconds, transport_endpoints, min_confirmations, @@ -614,13 +619,14 @@ impl RgbLibWalletWrapper { pub(crate) fn witness_receive( &self, asset_id: Option, + assignment: Assignment, duration_seconds: Option, transport_endpoints: Vec, min_confirmations: u8, ) -> Result { self.get_rgb_wallet().witness_receive( asset_id, - Assignment::Any, + assignment, duration_seconds, transport_endpoints, min_confirmations, diff --git a/src/routes.rs b/src/routes.rs index e01ae3d..f2876aa 100644 --- a/src/routes.rs +++ b/src/routes.rs @@ -928,6 +928,7 @@ pub(crate) struct RgbAllocation { #[derive(Deserialize, Serialize)] pub(crate) struct RgbInvoiceRequest { pub(crate) asset_id: Option, + pub(crate) assignment: Option, pub(crate) duration_seconds: Option, pub(crate) min_confirmations: u8, pub(crate) witness: bool, @@ -3322,9 +3323,12 @@ pub(crate) async fn rgb_invoice( return Err(APIError::OpenChannelInProgress); } + let assignment = payload.assignment.unwrap_or(Assignment::Any).into(); + let receive_data = if payload.witness { unlocked_state.rgb_witness_receive( payload.asset_id, + assignment, payload.duration_seconds, vec![unlocked_state.proxy_endpoint.clone()], payload.min_confirmations, @@ -3332,6 +3336,7 @@ pub(crate) async fn rgb_invoice( } else { unlocked_state.rgb_blind_receive( payload.asset_id, + assignment, payload.duration_seconds, vec![unlocked_state.proxy_endpoint.clone()], payload.min_confirmations, diff --git a/src/test/mod.rs b/src/test/mod.rs index ea4721f..d4f04a0 100644 --- a/src/test/mod.rs +++ b/src/test/mod.rs @@ -1299,6 +1299,15 @@ async fn rgb_invoice( node_address: SocketAddr, asset_id: Option, witness: bool, +) -> RgbInvoiceResponse { + rgb_invoice_with_assignment(node_address, asset_id, None, witness).await +} + +async fn rgb_invoice_with_assignment( + node_address: SocketAddr, + asset_id: Option, + assignment: Option, + witness: bool, ) -> RgbInvoiceResponse { println!( "generating RGB invoice{} for node {node_address}", @@ -1311,6 +1320,7 @@ async fn rgb_invoice( let payload = RgbInvoiceRequest { min_confirmations: 1, asset_id, + assignment, duration_seconds: None, witness, }; diff --git a/src/test/send_receive.rs b/src/test/send_receive.rs index e3584a7..d031fbc 100644 --- a/src/test/send_receive.rs +++ b/src/test/send_receive.rs @@ -44,7 +44,13 @@ async fn send_receive() { recipient_id, invoice, .. - } = rgb_invoice(node1_addr, Some(asset_id.clone()), true).await; + } = rgb_invoice_with_assignment( + node1_addr, + Some(asset_id.clone()), + Some(Assignment::Fungible(300)), + true, + ) + .await; let witness_data = WitnessData { amount_sat: 1200, blinding: None, @@ -69,12 +75,15 @@ async fn send_receive() { assert_eq!(decoded.recipient_id, recipient_id); assert!(matches!(decoded.asset_schema, Some(AssetSchema::Nia))); assert_eq!(decoded.asset_id, Some(asset_id.clone())); - assert_eq!(decoded.assignment, Assignment::Fungible(0)); + assert_eq!(decoded.assignment, Assignment::Fungible(300)); assert!(matches!(decoded.network, BitcoinNetwork::Regtest)); assert!(decoded.expiration_timestamp.is_some()); assert_eq!(decoded.transport_endpoints, vec![PROXY_ENDPOINT_LOCAL]); - let recipient_id = rgb_invoice(node2_addr, None, false).await.recipient_id; + let recipient_id = + rgb_invoice_with_assignment(node2_addr, None, Some(Assignment::Fungible(200)), false) + .await + .recipient_id; send_asset( node1_addr, &asset_id,