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
2 changes: 2 additions & 0 deletions openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 7 additions & 1 deletion src/ldk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
10 changes: 8 additions & 2 deletions src/rgb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,14 @@ impl UnlockedAppState {
pub(crate) fn rgb_blind_receive(
&self,
asset_id: Option<String>,
assignment: Assignment,
duration_seconds: Option<u32>,
transport_endpoints: Vec<String>,
min_confirmations: u8,
) -> Result<ReceiveData, RgbLibError> {
self.rgb_wallet_wrapper.blind_receive(
asset_id,
assignment,
duration_seconds,
transport_endpoints,
min_confirmations,
Expand Down Expand Up @@ -280,12 +282,14 @@ impl UnlockedAppState {
pub(crate) fn rgb_witness_receive(
&self,
asset_id: Option<String>,
assignment: Assignment,
duration_seconds: Option<u32>,
transport_endpoints: Vec<String>,
min_confirmations: u8,
) -> Result<ReceiveData, RgbLibError> {
self.rgb_wallet_wrapper.witness_receive(
asset_id,
assignment,
duration_seconds,
transport_endpoints,
min_confirmations,
Expand Down Expand Up @@ -314,13 +318,14 @@ impl RgbLibWalletWrapper {
pub(crate) fn blind_receive(
&self,
asset_id: Option<String>,
assignment: Assignment,
duration_seconds: Option<u32>,
transport_endpoints: Vec<String>,
min_confirmations: u8,
) -> Result<ReceiveData, RgbLibError> {
self.get_rgb_wallet().blind_receive(
asset_id,
Assignment::Any,
assignment,
duration_seconds,
transport_endpoints,
min_confirmations,
Expand Down Expand Up @@ -614,13 +619,14 @@ impl RgbLibWalletWrapper {
pub(crate) fn witness_receive(
&self,
asset_id: Option<String>,
assignment: Assignment,
duration_seconds: Option<u32>,
transport_endpoints: Vec<String>,
min_confirmations: u8,
) -> Result<ReceiveData, RgbLibError> {
self.get_rgb_wallet().witness_receive(
asset_id,
Assignment::Any,
assignment,
duration_seconds,
transport_endpoints,
min_confirmations,
Expand Down
5 changes: 5 additions & 0 deletions src/routes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -928,6 +928,7 @@ pub(crate) struct RgbAllocation {
#[derive(Deserialize, Serialize)]
pub(crate) struct RgbInvoiceRequest {
pub(crate) asset_id: Option<String>,
pub(crate) assignment: Option<Assignment>,
pub(crate) duration_seconds: Option<u32>,
pub(crate) min_confirmations: u8,
pub(crate) witness: bool,
Expand Down Expand Up @@ -3322,16 +3323,20 @@ 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,
)?
} else {
unlocked_state.rgb_blind_receive(
payload.asset_id,
assignment,
payload.duration_seconds,
vec![unlocked_state.proxy_endpoint.clone()],
payload.min_confirmations,
Expand Down
10 changes: 10 additions & 0 deletions src/test/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1299,6 +1299,15 @@ async fn rgb_invoice(
node_address: SocketAddr,
asset_id: Option<String>,
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<String>,
assignment: Option<Assignment>,
witness: bool,
) -> RgbInvoiceResponse {
println!(
"generating RGB invoice{} for node {node_address}",
Expand All @@ -1311,6 +1320,7 @@ async fn rgb_invoice(
let payload = RgbInvoiceRequest {
min_confirmations: 1,
asset_id,
assignment,
duration_seconds: None,
witness,
};
Expand Down
15 changes: 12 additions & 3 deletions src/test/send_receive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down
Loading