Skip to content

Commit 75a7329

Browse files
committed
handle IFA reject list
1 parent b047565 commit 75a7329

File tree

26 files changed

+1193
-160
lines changed

26 files changed

+1193
-160
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@
33
**/rgblib.h*
44
**/target
55
**/tests/tmp
6+
**/tests/lists
67
/.vim
78
/.vscode

bindings/c-ffi/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ pub extern "C" fn rgblib_issue_asset_ifa(
198198
amounts: *const c_char,
199199
inflation_amounts: *const c_char,
200200
replace_rights_num: *const c_char,
201+
reject_list_url_opt: *const c_char,
201202
) -> CResultString {
202203
issue_asset_ifa(
203204
wallet,
@@ -207,6 +208,7 @@ pub extern "C" fn rgblib_issue_asset_ifa(
207208
amounts,
208209
inflation_amounts,
209210
replace_rights_num,
211+
reject_list_url_opt,
210212
)
211213
.into()
212214
}

bindings/c-ffi/src/utils.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,7 @@ pub(crate) fn issue_asset_cfa(
332332
Ok(serde_json::to_string(&res)?)
333333
}
334334

335+
#[allow(clippy::too_many_arguments)]
335336
pub(crate) fn issue_asset_ifa(
336337
wallet: &COpaqueStruct,
337338
ticker: *const c_char,
@@ -340,19 +341,22 @@ pub(crate) fn issue_asset_ifa(
340341
amounts: *const c_char,
341342
inflation_amounts: *const c_char,
342343
replace_rights_num: *const c_char,
344+
reject_list_url_opt: *const c_char,
343345
) -> Result<String, Error> {
344346
let wallet = Wallet::from_opaque(wallet)?;
345347
let precision = ptr_to_num(precision)?;
346348
let amounts = convert_strings_array(amounts)?;
347349
let inflation_amounts = convert_strings_array(inflation_amounts)?;
348350
let replace_rights_num = ptr_to_num(replace_rights_num)?;
351+
let reject_list_url = convert_optional_string(reject_list_url_opt);
349352
let res = wallet.issue_asset_ifa(
350353
ptr_to_string(ticker),
351354
ptr_to_string(name),
352355
precision,
353356
amounts,
354357
inflation_amounts,
355358
replace_rights_num,
359+
reject_list_url,
356360
)?;
357361
Ok(serde_json::to_string(&res)?)
358362
}

bindings/uniffi/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -613,6 +613,7 @@ impl Wallet {
613613
amounts: Vec<u64>,
614614
inflation_amounts: Vec<u64>,
615615
replace_rights_num: u8,
616+
reject_list_url: Option<String>,
616617
) -> Result<AssetIFA, RgbLibError> {
617618
self._get_wallet().issue_asset_ifa(
618619
ticker,
@@ -621,6 +622,7 @@ impl Wallet {
621622
amounts,
622623
inflation_amounts,
623624
replace_rights_num,
625+
reject_list_url,
624626
)
625627
}
626628

bindings/uniffi/src/rgb-lib.udl

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ interface RgbLibError {
6060
InvalidRecipientData(string details);
6161
InvalidRecipientID();
6262
InvalidRecipientNetwork();
63+
InvalidRejectListUrl(string details);
6364
InvalidTicker(string details);
6465
InvalidTransportEndpoint(string details);
6566
InvalidTransportEndpoints(string details);
@@ -79,6 +80,8 @@ interface RgbLibError {
7980
Proxy(string details);
8081
RecipientIDAlreadyUsed();
8182
RecipientIDDuplicated();
83+
RejectListService(string details);
84+
RestClientBuild(string details);
8285
TooHighInflationAmounts();
8386
TooHighIssuanceAmounts();
8487
UnknownRgbSchema(string schema_id);
@@ -174,6 +177,7 @@ dictionary AssetIFA {
174177
i64 added_at;
175178
Balance balance;
176179
Media? media;
180+
string? reject_list_url;
177181
};
178182

179183
[Remote]
@@ -333,6 +337,7 @@ dictionary Metadata {
333337
string? ticker;
334338
string? details;
335339
Token? token;
340+
string? reject_list_url;
336341
};
337342

338343
[Remote]
@@ -597,7 +602,8 @@ interface Wallet {
597602
[Throws=RgbLibError]
598603
AssetIFA issue_asset_ifa(
599604
string ticker, string name, u8 precision, sequence<u64> amounts,
600-
sequence<u64> inflation_amounts, u8 replace_rights_num);
605+
sequence<u64> inflation_amounts, u8 replace_rights_num,
606+
string? reject_list_url);
601607

602608
[Throws=RgbLibError]
603609
Assets list_assets(sequence<AssetSchema> filter_asset_schemas);

migration/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ pub use sea_orm_migration::prelude::*;
22

33
mod m20230608_071249_init_db;
44
mod m20251017_074408_asset_update;
5+
mod m20251105_132121_asset_update;
56

67
pub struct Migrator;
78

@@ -11,6 +12,7 @@ impl MigratorTrait for Migrator {
1112
vec![
1213
Box::new(m20230608_071249_init_db::Migration),
1314
Box::new(m20251017_074408_asset_update::Migration),
15+
Box::new(m20251105_132121_asset_update::Migration),
1416
]
1517
}
1618
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
use sea_orm_migration::prelude::*;
2+
3+
#[derive(DeriveMigrationName)]
4+
pub struct Migration;
5+
6+
#[async_trait::async_trait]
7+
impl MigrationTrait for Migration {
8+
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
9+
manager
10+
.alter_table(
11+
Table::alter()
12+
.table(Asset::Table)
13+
.add_column(ColumnDef::new(Asset::RejectListUrl).string().null())
14+
.to_owned(),
15+
)
16+
.await?;
17+
18+
Ok(())
19+
}
20+
21+
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
22+
manager
23+
.alter_table(
24+
Table::alter()
25+
.table(Asset::Table)
26+
.drop_column(Asset::RejectListUrl)
27+
.to_owned(),
28+
)
29+
.await?;
30+
31+
Ok(())
32+
}
33+
}
34+
35+
#[derive(DeriveIden)]
36+
pub enum Asset {
37+
Table,
38+
RejectListUrl,
39+
}

src/api/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
#[cfg(any(feature = "electrum", feature = "esplora"))]
22
pub(crate) mod proxy;
33

4+
#[cfg(any(feature = "electrum", feature = "esplora"))]
5+
pub(crate) mod reject_list;
6+
47
#[cfg(any(feature = "electrum", feature = "esplora"))]
58
use super::*;

src/api/proxy.rs

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,10 @@ impl Proxy for RestClient {
118118
.post(url)
119119
.header(CONTENT_TYPE, JSON)
120120
.json(&body)
121-
.send()?
121+
.send()
122+
.map_err(|e| Error::Proxy {
123+
details: e.to_string(),
124+
})?
122125
.json::<JsonRpcResponse<ServerInfoResponse>>()
123126
.map_err(InternalError::from)?)
124127
}
@@ -134,7 +137,10 @@ impl Proxy for RestClient {
134137
.post(url)
135138
.header(CONTENT_TYPE, JSON)
136139
.json(&body)
137-
.send()?
140+
.send()
141+
.map_err(|e| Error::Proxy {
142+
details: e.to_string(),
143+
})?
138144
.json::<JsonRpcResponse<bool>>()
139145
.map_err(InternalError::from)?)
140146
}
@@ -154,7 +160,10 @@ impl Proxy for RestClient {
154160
.post(url)
155161
.header(CONTENT_TYPE, JSON)
156162
.json(&body)
157-
.send()?
163+
.send()
164+
.map_err(|e| Error::Proxy {
165+
details: e.to_string(),
166+
})?
158167
.json::<JsonRpcResponse<GetConsignmentResponse>>()
159168
.map_err(InternalError::from)?)
160169
}
@@ -170,7 +179,10 @@ impl Proxy for RestClient {
170179
.post(url)
171180
.header(CONTENT_TYPE, JSON)
172181
.json(&body)
173-
.send()?
182+
.send()
183+
.map_err(|e| Error::Proxy {
184+
details: e.to_string(),
185+
})?
174186
.json::<JsonRpcResponse<String>>()
175187
.map_err(InternalError::from)?)
176188
}
@@ -191,7 +203,10 @@ impl Proxy for RestClient {
191203
.post(url)
192204
.header(CONTENT_TYPE, JSON)
193205
.json(&body)
194-
.send()?
206+
.send()
207+
.map_err(|e| Error::Proxy {
208+
details: e.to_string(),
209+
})?
195210
.json::<JsonRpcResponse<bool>>()
196211
.map_err(InternalError::from)?)
197212
}
@@ -224,7 +239,10 @@ impl Proxy for RestClient {
224239
Ok(self
225240
.post(url)
226241
.multipart(form)
227-
.send()?
242+
.send()
243+
.map_err(|e| Error::Proxy {
244+
details: e.to_string(),
245+
})?
228246
.json::<JsonRpcResponse<bool>>()
229247
.map_err(InternalError::from)?)
230248
}
@@ -248,7 +266,10 @@ impl Proxy for RestClient {
248266
Ok(self
249267
.post(url)
250268
.multipart(form)
251-
.send()?
269+
.send()
270+
.map_err(|e| Error::Proxy {
271+
details: e.to_string(),
272+
})?
252273
.json::<JsonRpcResponse<bool>>()
253274
.map_err(InternalError::from)?)
254275
}

src/api/reject_list.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
use super::*;
2+
3+
pub(crate) trait RejectList {
4+
fn get_reject_list(self, url: &str) -> Result<String, Error>;
5+
}
6+
7+
impl RejectList for RestClient {
8+
fn get_reject_list(self, url: &str) -> Result<String, Error> {
9+
Ok(self
10+
.get(url)
11+
.send()
12+
.map_err(|e| Error::RejectListService {
13+
details: e.to_string(),
14+
})?
15+
.text()
16+
.map_err(InternalError::from)?)
17+
}
18+
}

0 commit comments

Comments
 (0)