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
18 changes: 18 additions & 0 deletions openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1412,6 +1412,8 @@ components:
recipient_id:
type: string
example: bcrt:utxob:cbgHUJ4e-7QyKY4U-Jsj5AZw-oI0gxZh-7fxQY2_-tFFUAZN-4CgpX
recipient_type:
$ref: '#/components/schemas/RecipientType'
asset_schema:
$ref: '#/components/schemas/AssetSchema'
asset_id:
Expand Down Expand Up @@ -1997,6 +1999,11 @@ components:
items:
type: integer
example: [6, 36, 87, 13, 5, 17]
RecipientType:
type: string
enum:
- Blind
- Witness
RefreshRequest:
type: object
properties:
Expand Down Expand Up @@ -2070,6 +2077,8 @@ components:
recipient_id:
type: string
example: bcrt:utxob:2FZsSuk-iyVQLVuU4-Gc6J4qkE8-mLS17N4jd-MEx6cWz9F-MFkyE1n
witness_data:
$ref: '#/components/schemas/WitnessData'
donation:
type: boolean
example: false
Expand Down Expand Up @@ -2411,6 +2420,15 @@ components:
colorable:
type: boolean
example: true
WitnessData:
type: object
properties:
amount_sat:
type: number
example: 1000
blinding:
type: number
example: 439017309
securitySchemes:
bearerAuth:
type: http
Expand Down
7 changes: 7 additions & 0 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,9 @@ pub enum APIError {
#[error("Invalid pubkey")]
InvalidPubkey,

#[error("The provided recipient data is invalid: {0}")]
InvalidRecipientData(String),

#[error("The provided recipient ID is neither a blinded UTXO or a script")]
InvalidRecipientID,

Expand Down Expand Up @@ -348,6 +351,9 @@ impl From<RgbLibError> for APIError {
RgbLibError::InvalidProxyProtocol { version } => {
APIError::InvalidProxyProtocol(version)
}
RgbLibError::InvalidRecipientData { details } => {
APIError::InvalidRecipientData(details)
}
RgbLibError::InvalidRecipientID => APIError::InvalidRecipientID,
RgbLibError::InvalidRecipientNetwork => APIError::InvalidRecipientNetwork,
RgbLibError::InvalidTicker { details } => APIError::InvalidTicker(details),
Expand Down Expand Up @@ -429,6 +435,7 @@ impl IntoResponse for APIError {
| APIError::InvalidPeerInfo(_)
| APIError::InvalidPrecision(_)
| APIError::InvalidPubkey
| APIError::InvalidRecipientData(_)
| APIError::InvalidRecipientID
| APIError::InvalidRecipientNetwork
| APIError::InvalidSwap(_)
Expand Down
41 changes: 38 additions & 3 deletions src/routes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ use rgb_lib::{
AssetCFA as RgbLibAssetCFA, AssetNIA as RgbLibAssetNIA, AssetUDA as RgbLibAssetUDA,
Balance as RgbLibBalance, EmbeddedMedia as RgbLibEmbeddedMedia, Invoice as RgbLibInvoice,
Media as RgbLibMedia, ProofOfReserves as RgbLibProofOfReserves, Recipient, RecipientInfo,
Token as RgbLibToken, TokenLight as RgbLibTokenLight, WitnessData,
RecipientType as RgbLibRecipientType, Token as RgbLibToken, TokenLight as RgbLibTokenLight,
WitnessData as RgbLibWitnessData,
},
AssetSchema as RgbLibAssetSchema, Assignment as RgbLibAssignment,
BitcoinNetwork as RgbLibNetwork, ContractId, RgbTransport,
Expand Down Expand Up @@ -472,6 +473,7 @@ pub(crate) struct DecodeRGBInvoiceRequest {
#[derive(Deserialize, Serialize)]
pub(crate) struct DecodeRGBInvoiceResponse {
pub(crate) recipient_id: String,
pub(crate) recipient_type: RecipientType,
pub(crate) asset_schema: Option<AssetSchema>,
pub(crate) asset_id: Option<String>,
pub(crate) assignment: Assignment,
Expand Down Expand Up @@ -885,6 +887,21 @@ impl From<RgbLibProofOfReserves> for ProofOfReserves {
}
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)]
pub(crate) enum RecipientType {
Blind,
Witness,
}

impl From<RgbLibRecipientType> for RecipientType {
fn from(value: RgbLibRecipientType) -> Self {
match value {
RgbLibRecipientType::Blind => Self::Blind,
RgbLibRecipientType::Witness => Self::Witness,
}
}
}

#[derive(Deserialize, Serialize)]
pub(crate) struct RefreshRequest {
pub(crate) skip_sync: bool,
Expand Down Expand Up @@ -929,6 +946,7 @@ pub(crate) struct SendAssetRequest {
pub(crate) asset_id: String,
pub(crate) assignment: Assignment,
pub(crate) recipient_id: String,
pub(crate) witness_data: Option<WitnessData>,
pub(crate) donation: bool,
pub(crate) fee_rate: u64,
pub(crate) min_confirmations: u8,
Expand Down Expand Up @@ -1172,6 +1190,21 @@ pub(crate) struct Utxo {
pub(crate) colorable: bool,
}

#[derive(Deserialize, Serialize)]
pub(crate) struct WitnessData {
pub(crate) amount_sat: u64,
pub(crate) blinding: Option<u64>,
}

impl From<WitnessData> for RgbLibWitnessData {
fn from(value: WitnessData) -> Self {
Self {
amount_sat: value.amount_sat,
blinding: value.blinding,
}
}
}

impl AppState {
fn check_changing_state(&self) -> Result<(), APIError> {
if *self.get_changing_state() {
Expand Down Expand Up @@ -1513,9 +1546,11 @@ pub(crate) async fn decode_rgb_invoice(
let _guard = state.get_unlocked_app_state();

let invoice_data = RgbLibInvoice::new(payload.invoice)?.invoice_data();
let recipient_info = RecipientInfo::new(invoice_data.recipient_id.clone())?;

Ok(Json(DecodeRGBInvoiceResponse {
recipient_id: invoice_data.recipient_id,
recipient_type: recipient_info.recipient_type.into(),
asset_schema: invoice_data.asset_schema.map(|s| s.into()),
asset_id: invoice_data.asset_id,
assignment: invoice_data.assignment.into(),
Expand Down Expand Up @@ -3046,7 +3081,7 @@ pub(crate) async fn open_channel(
let recipient_map = map! {
asset_id => vec![Recipient {
recipient_id,
witness_data: Some(WitnessData {
witness_data: Some(RgbLibWitnessData {
amount_sat: payload.capacity_sat,
blinding: Some(STATIC_BLINDING + 1),
}),
Expand Down Expand Up @@ -3301,7 +3336,7 @@ pub(crate) async fn send_asset(
let recipient_map = map! {
payload.asset_id => vec![Recipient {
recipient_id: payload.recipient_id,
witness_data: None,
witness_data: payload.witness_data.map(|w| w.into()),
assignment: payload.assignment.into(),
transport_endpoints: payload.transport_endpoints,
}]
Expand Down
2 changes: 2 additions & 0 deletions src/test/close_coop_nobtc_acceptor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ async fn close_coop_nobtc_acceptor() {
&asset_id,
Assignment::Fungible(700),
recipient_id,
None,
)
.await;
mine(false);
Expand All @@ -60,6 +61,7 @@ async fn close_coop_nobtc_acceptor() {
&asset_id,
Assignment::Fungible(50),
recipient_id,
None,
)
.await;
mine(false);
Expand Down
2 changes: 2 additions & 0 deletions src/test/close_coop_other_side.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ async fn close_coop_other_side() {
&asset_id,
Assignment::Fungible(700),
recipient_id,
None,
)
.await;
mine(false);
Expand All @@ -62,6 +63,7 @@ async fn close_coop_other_side() {
&asset_id,
Assignment::Fungible(50),
recipient_id,
None,
)
.await;
mine(false);
Expand Down
3 changes: 3 additions & 0 deletions src/test/close_coop_standard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ async fn close_coop_standard() {
&asset_id,
Assignment::Fungible(10),
recipient_id,
None,
)
.await;
mine(false);
Expand All @@ -115,6 +116,7 @@ async fn close_coop_standard() {
&asset_id,
Assignment::Fungible(690),
recipient_id,
None,
)
.await;
mine(false);
Expand All @@ -128,6 +130,7 @@ async fn close_coop_standard() {
&asset_id,
Assignment::Fungible(50),
recipient_id,
None,
)
.await;
mine(false);
Expand Down
9 changes: 8 additions & 1 deletion src/test/close_coop_zero_balance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,14 @@ async fn close_coop_zero_balance() {
assert_eq!(asset_balance_spendable(node2_addr, &asset_id).await, 0);

let recipient_id = rgb_invoice(node2_addr, None, false).await.recipient_id;
send_asset(node1_addr, &asset_id, Assignment::NonFungible, recipient_id).await;
send_asset(
node1_addr,
&asset_id,
Assignment::NonFungible,
recipient_id,
None,
)
.await;
mine(false);
refresh_transfers(node2_addr).await;
refresh_transfers(node2_addr).await;
Expand Down
2 changes: 2 additions & 0 deletions src/test/close_force_nobtc_acceptor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ async fn close_force_nobtc_acceptor() {
&asset_id,
Assignment::Fungible(700),
recipient_id,
None,
)
.await;
mine(false);
Expand All @@ -60,6 +61,7 @@ async fn close_force_nobtc_acceptor() {
&asset_id,
Assignment::Fungible(50),
recipient_id,
None,
)
.await;
mine(false);
Expand Down
2 changes: 2 additions & 0 deletions src/test/close_force_other_side.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ async fn close_force_other_side() {
&asset_id,
Assignment::Fungible(700),
recipient_id,
None,
)
.await;
mine(false);
Expand All @@ -61,6 +62,7 @@ async fn close_force_other_side() {
&asset_id,
Assignment::Fungible(50),
recipient_id,
None,
)
.await;
mine(false);
Expand Down
2 changes: 2 additions & 0 deletions src/test/close_force_standard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ async fn close_force_standard() {
&asset_id,
Assignment::Fungible(700),
recipient_id,
None,
)
.await;
mine(false);
Expand All @@ -66,6 +67,7 @@ async fn close_force_standard() {
&asset_id,
Assignment::Fungible(50),
recipient_id,
None,
)
.await;
mine(false);
Expand Down
4 changes: 3 additions & 1 deletion src/test/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ use crate::routes::{
PostAssetMediaResponse, RefreshRequest, RestoreRequest, RevokeTokenRequest, RgbInvoiceRequest,
RgbInvoiceResponse, SendAssetRequest, SendAssetResponse, SendBtcRequest, SendBtcResponse,
SendPaymentRequest, SendPaymentResponse, Swap, SwapStatus, TakerRequest, Transaction, Transfer,
UnlockRequest, Unspent,
UnlockRequest, Unspent, WitnessData,
};
use crate::utils::{hex_str_to_vec, ELECTRUM_URL_REGTEST, PROXY_ENDPOINT_LOCAL};

Expand Down Expand Up @@ -1332,6 +1332,7 @@ async fn send_asset(
asset_id: &str,
assignment: Assignment,
recipient_id: String,
witness_data: Option<WitnessData>,
) {
println!(
"sending on-chain {assignment:?} of asset {asset_id} from node {node_address} to {recipient_id}"
Expand All @@ -1340,6 +1341,7 @@ async fn send_asset(
asset_id: asset_id.to_string(),
assignment,
recipient_id,
witness_data,
donation: true,
fee_rate: FEE_RATE,
min_confirmations: 1,
Expand Down
4 changes: 4 additions & 0 deletions src/test/multi_hop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ async fn multi_hop() {
&asset_id,
Assignment::Fungible(400),
recipient_id,
None,
)
.await;
mine(false);
Expand Down Expand Up @@ -279,6 +280,7 @@ async fn multi_hop() {
&asset_id,
Assignment::Fungible(200),
recipient_id,
None,
)
.await;
mine(false);
Expand All @@ -292,6 +294,7 @@ async fn multi_hop() {
&asset_id,
Assignment::Fungible(150),
recipient_id,
None,
)
.await;
mine(false);
Expand All @@ -305,6 +308,7 @@ async fn multi_hop() {
&asset_id,
Assignment::Fungible(375),
recipient_id,
None,
)
.await;
mine(false);
Expand Down
2 changes: 2 additions & 0 deletions src/test/multi_open_close.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ async fn multi_open_close() {
&asset_id,
Assignment::Fungible(700),
recipient_id,
None,
)
.await;
mine(false);
Expand All @@ -79,6 +80,7 @@ async fn multi_open_close() {
&asset_id,
Assignment::Fungible(150),
recipient_id,
None,
)
.await;
mine(false);
Expand Down
4 changes: 4 additions & 0 deletions src/test/open_after_double_send.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ async fn open_after_double_send() {
&asset_id,
Assignment::Fungible(100),
recipient_id,
None,
)
.await;
mine(false);
Expand All @@ -44,6 +45,7 @@ async fn open_after_double_send() {
&asset_id,
Assignment::Fungible(200),
recipient_id,
None,
)
.await;
mine(false);
Expand Down Expand Up @@ -79,6 +81,7 @@ async fn open_after_double_send() {
&asset_id,
Assignment::Fungible(725),
recipient_id,
None,
)
.await;
mine(false);
Expand All @@ -92,6 +95,7 @@ async fn open_after_double_send() {
&asset_id,
Assignment::Fungible(225),
recipient_id,
None,
)
.await;
mine(false);
Expand Down
Loading
Loading