Skip to content

Commit 8773468

Browse files
committed
add inflate API
1 parent 12ae3cf commit 8773468

File tree

23 files changed

+1189
-232
lines changed

23 files changed

+1189
-232
lines changed

bindings/c-ffi/src/lib.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,26 @@ pub extern "C" fn rgblib_go_online(
157157
go_online(wallet, skip_consistency_check, electrum_url).into()
158158
}
159159

160+
#[unsafe(no_mangle)]
161+
pub extern "C" fn rgblib_inflate(
162+
wallet: &COpaqueStruct,
163+
online: &COpaqueStruct,
164+
asset_id: *const c_char,
165+
inflation_amounts: *const c_char,
166+
fee_rate: *const c_char,
167+
min_confirmations: *const c_char,
168+
) -> CResultString {
169+
inflate(
170+
wallet,
171+
online,
172+
asset_id,
173+
inflation_amounts,
174+
fee_rate,
175+
min_confirmations,
176+
)
177+
.into()
178+
}
179+
160180
#[unsafe(no_mangle)]
161181
pub extern "C" fn rgblib_issue_asset_cfa(
162182
wallet: &COpaqueStruct,

bindings/c-ffi/src/utils.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,30 @@ pub(crate) fn go_online(
290290
Ok(wallet.go_online(skip_consistency_check, ptr_to_string(electrum_url))?)
291291
}
292292

293+
pub(crate) fn inflate(
294+
wallet: &COpaqueStruct,
295+
online: &COpaqueStruct,
296+
asset_id: *const c_char,
297+
inflation_amounts: *const c_char,
298+
fee_rate: *const c_char,
299+
min_confirmations: *const c_char,
300+
) -> Result<String, Error> {
301+
let wallet = Wallet::from_opaque(wallet)?;
302+
let online = Online::from_opaque(online)?;
303+
let asset_id = ptr_to_string(asset_id);
304+
let inflation_amounts = convert_strings_array(inflation_amounts)?;
305+
let fee_rate = ptr_to_num(fee_rate)?;
306+
let min_confirmations = ptr_to_num(min_confirmations)?;
307+
let res = wallet.inflate(
308+
(*online).clone(),
309+
asset_id,
310+
inflation_amounts,
311+
fee_rate,
312+
min_confirmations,
313+
)?;
314+
Ok(serde_json::to_string(&res)?)
315+
}
316+
293317
pub(crate) fn issue_asset_cfa(
294318
wallet: &COpaqueStruct,
295319
name: *const c_char,

bindings/uniffi/src/lib.rs

Lines changed: 49 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ use rgb_lib::{
1313
Address as RgbLibAddress, AssetCFA, AssetIFA, AssetNIA, AssetUDA, Assets,
1414
AssignmentsCollection, Balance, BlockTime, BtcBalance, DatabaseType, EmbeddedMedia,
1515
Invoice as RgbLibInvoice, InvoiceData as RgbLibInvoiceData, Media, Metadata, Online,
16-
Outpoint, ProofOfReserves, ReceiveData, Recipient as RgbLibRecipient,
16+
OperationResult, Outpoint, ProofOfReserves, ReceiveData, Recipient as RgbLibRecipient,
1717
RecipientInfo as RgbLibRecipientInfo, RefreshFilter, RefreshTransferStatus,
18-
RefreshedTransfer, RgbAllocation as RgbLibRgbAllocation, SendResult, Token, TokenLight,
19-
Transaction, TransactionType, Transfer as RgbLibTransfer, TransferKind,
20-
TransferTransportEndpoint, TransportEndpoint as RgbLibTransportEndpoint,
21-
Unspent as RgbLibUnspent, Utxo, Wallet as RgbLibWallet, WalletData, WitnessData,
18+
RefreshedTransfer, RgbAllocation as RgbLibRgbAllocation, Token, TokenLight, Transaction,
19+
TransactionType, Transfer as RgbLibTransfer, TransferKind, TransferTransportEndpoint,
20+
TransportEndpoint as RgbLibTransportEndpoint, Unspent as RgbLibUnspent, Utxo,
21+
Wallet as RgbLibWallet, WalletData, WitnessData,
2222
},
2323
};
2424

@@ -521,6 +521,48 @@ impl Wallet {
521521
.go_online(skip_consistency_check, indexer_url)
522522
}
523523

524+
fn inflate(
525+
&self,
526+
online: Online,
527+
asset_id: String,
528+
inflation_amounts: Vec<u64>,
529+
fee_rate: u64,
530+
min_confirmations: u8,
531+
) -> Result<OperationResult, RgbLibError> {
532+
self._get_wallet().inflate(
533+
online,
534+
asset_id,
535+
inflation_amounts,
536+
fee_rate,
537+
min_confirmations,
538+
)
539+
}
540+
541+
fn inflate_begin(
542+
&self,
543+
online: Online,
544+
asset_id: String,
545+
inflation_amounts: Vec<u64>,
546+
fee_rate: u64,
547+
min_confirmations: u8,
548+
) -> Result<String, RgbLibError> {
549+
self._get_wallet().inflate_begin(
550+
online,
551+
asset_id,
552+
inflation_amounts,
553+
fee_rate,
554+
min_confirmations,
555+
)
556+
}
557+
558+
fn inflate_end(
559+
&self,
560+
online: Online,
561+
signed_psbt: String,
562+
) -> Result<OperationResult, RgbLibError> {
563+
self._get_wallet().inflate_end(online, signed_psbt)
564+
}
565+
524566
fn issue_asset_nia(
525567
&self,
526568
ticker: String,
@@ -636,7 +678,7 @@ impl Wallet {
636678
fee_rate: u64,
637679
min_confirmations: u8,
638680
skip_sync: bool,
639-
) -> Result<SendResult, RgbLibError> {
681+
) -> Result<OperationResult, RgbLibError> {
640682
self._get_wallet().send(
641683
online,
642684
_convert_recipient_map(recipient_map),
@@ -669,7 +711,7 @@ impl Wallet {
669711
online: Online,
670712
signed_psbt: String,
671713
skip_sync: bool,
672-
) -> Result<SendResult, RgbLibError> {
714+
) -> Result<OperationResult, RgbLibError> {
673715
self._get_wallet().send_end(online, signed_psbt, skip_sync)
674716
}
675717

bindings/uniffi/src/rgb-lib.udl

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ interface RgbLibError {
6969
MinFeeNotMet(string txid);
7070
Network(string details);
7171
NoConsignment();
72+
NoInflationAmounts();
7273
NoIssuanceAmounts();
7374
NoSupportedSchemas();
7475
NoValidTransportEndpoint();
@@ -83,6 +84,7 @@ interface RgbLibError {
8384
UnknownRgbSchema(string schema_id);
8485
UnknownTransfer(string txid);
8586
UnsupportedBackupVersion(string version);
87+
UnsupportedInflation(AssetSchema asset_schema);
8688
UnsupportedLayer1(string layer_1);
8789
UnsupportedSchema(AssetSchema asset_schema);
8890
UnsupportedTransportType();
@@ -139,7 +141,6 @@ dictionary AssetUDA {
139141
string name;
140142
string? details;
141143
u8 precision;
142-
u64 issued_supply;
143144
i64 timestamp;
144145
i64 added_at;
145146
Balance balance;
@@ -166,7 +167,9 @@ dictionary AssetIFA {
166167
string name;
167168
string? details;
168169
u8 precision;
169-
u64 issued_supply;
170+
u64 initial_supply;
171+
u64 max_supply;
172+
u64 known_circulating_supply;
170173
i64 timestamp;
171174
i64 added_at;
172175
Balance balance;
@@ -321,7 +324,9 @@ dictionary Token {
321324
[Remote]
322325
dictionary Metadata {
323326
AssetSchema asset_schema;
324-
u64 issued_supply;
327+
u64 initial_supply;
328+
u64 max_supply;
329+
u64 known_circulating_supply;
325330
i64 timestamp;
326331
string name;
327332
u8 precision;
@@ -349,7 +354,7 @@ dictionary WitnessData {
349354
};
350355

351356
[Remote]
352-
dictionary SendResult {
357+
dictionary OperationResult {
353358
string txid;
354359
i32 batch_transfer_idx;
355360
};
@@ -398,6 +403,7 @@ enum TransferKind {
398403
"ReceiveBlind",
399404
"ReceiveWitness",
400405
"Send",
406+
"Inflation",
401407
};
402408

403409
[Remote]
@@ -561,6 +567,19 @@ interface Wallet {
561567
[Throws=RgbLibError]
562568
Online go_online(boolean skip_consistency_check, string indexer_url);
563569

570+
[Throws=RgbLibError]
571+
OperationResult inflate(
572+
Online online, string asset_id, sequence<u64> inflation_amounts,
573+
u64 fee_rate, u8 min_confirmations);
574+
575+
[Throws=RgbLibError]
576+
string inflate_begin(
577+
Online online, string asset_id, sequence<u64> inflation_amounts,
578+
u64 fee_rate, u8 min_confirmations);
579+
580+
[Throws=RgbLibError]
581+
OperationResult inflate_end(Online online, string signed_psbt);
582+
564583
[Throws=RgbLibError]
565584
AssetNIA issue_asset_nia(
566585
string ticker, string name, u8 precision, sequence<u64> amounts);
@@ -599,7 +618,7 @@ interface Wallet {
599618
boolean skip_sync);
600619

601620
[Throws=RgbLibError]
602-
SendResult send(
621+
OperationResult send(
603622
Online online, record<DOMString, sequence<Recipient>> recipient_map,
604623
boolean donation, u64 fee_rate, u8 min_confirmations, boolean skip_sync);
605624

@@ -609,7 +628,7 @@ interface Wallet {
609628
boolean donation, u64 fee_rate, u8 min_confirmations);
610629

611630
[Throws=RgbLibError]
612-
SendResult send_end(Online online, string signed_psbt, boolean skip_sync);
631+
OperationResult send_end(Online online, string signed_psbt, boolean skip_sync);
613632

614633
[Throws=RgbLibError]
615634
string send_btc(

migration/src/lib.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
pub use sea_orm_migration::prelude::*;
22

33
mod m20230608_071249_init_db;
4+
mod m20251017_074408_asset_update;
45

56
pub struct Migrator;
67

78
#[async_trait::async_trait]
89
impl MigratorTrait for Migrator {
910
fn migrations() -> Vec<Box<dyn MigrationTrait>> {
10-
vec![Box::new(m20230608_071249_init_db::Migration)]
11+
vec![
12+
Box::new(m20230608_071249_init_db::Migration),
13+
Box::new(m20251017_074408_asset_update::Migration),
14+
]
1115
}
1216
}
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
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+
.rename_column(Asset::IssuedSupply, Asset::InitialSupply)
14+
.to_owned(),
15+
)
16+
.await?;
17+
18+
manager
19+
.alter_table(
20+
Table::alter()
21+
.table(Asset::Table)
22+
.add_column(ColumnDef::new(Asset::MaxSupply).string().null())
23+
.to_owned(),
24+
)
25+
.await?;
26+
27+
manager
28+
.alter_table(
29+
Table::alter()
30+
.table(Asset::Table)
31+
.add_column(
32+
ColumnDef::new(Asset::KnownCirculatingSupply)
33+
.string()
34+
.null(),
35+
)
36+
.to_owned(),
37+
)
38+
.await?;
39+
40+
Ok(())
41+
}
42+
43+
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
44+
manager
45+
.alter_table(
46+
Table::alter()
47+
.table(Asset::Table)
48+
.rename_column(Asset::InitialSupply, Asset::IssuedSupply)
49+
.to_owned(),
50+
)
51+
.await?;
52+
53+
manager
54+
.alter_table(
55+
Table::alter()
56+
.table(Asset::Table)
57+
.drop_column(Asset::MaxSupply)
58+
.to_owned(),
59+
)
60+
.await?;
61+
62+
manager
63+
.alter_table(
64+
Table::alter()
65+
.table(Asset::Table)
66+
.drop_column(Asset::KnownCirculatingSupply)
67+
.to_owned(),
68+
)
69+
.await?;
70+
71+
Ok(())
72+
}
73+
}
74+
75+
#[derive(DeriveIden)]
76+
pub enum Asset {
77+
Table,
78+
IssuedSupply,
79+
InitialSupply,
80+
MaxSupply,
81+
KnownCirculatingSupply,
82+
}

src/database/entities/asset.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,13 @@ pub struct Model {
2121
pub schema: AssetSchema,
2222
pub added_at: i64,
2323
pub details: Option<String>,
24-
pub issued_supply: String,
24+
pub initial_supply: String,
2525
pub name: String,
2626
pub precision: u8,
2727
pub ticker: Option<String>,
2828
pub timestamp: i64,
29+
pub max_supply: Option<String>,
30+
pub known_circulating_supply: Option<String>,
2931
}
3032

3133
#[derive(Copy, Clone, Debug, EnumIter, DeriveColumn)]
@@ -36,11 +38,13 @@ pub enum Column {
3638
Schema,
3739
AddedAt,
3840
Details,
39-
IssuedSupply,
41+
InitialSupply,
4042
Name,
4143
Precision,
4244
Ticker,
4345
Timestamp,
46+
MaxSupply,
47+
KnownCirculatingSupply,
4448
}
4549

4650
#[derive(Copy, Clone, Debug, EnumIter, DerivePrimaryKey)]
@@ -72,11 +76,13 @@ impl ColumnTrait for Column {
7276
Self::Schema => ColumnType::SmallInteger.def(),
7377
Self::AddedAt => ColumnType::BigInteger.def(),
7478
Self::Details => ColumnType::String(StringLen::None).def().null(),
75-
Self::IssuedSupply => ColumnType::String(StringLen::None).def(),
79+
Self::InitialSupply => ColumnType::String(StringLen::None).def(),
7680
Self::Name => ColumnType::String(StringLen::None).def(),
7781
Self::Precision => ColumnType::SmallInteger.def(),
7882
Self::Ticker => ColumnType::String(StringLen::None).def().null(),
7983
Self::Timestamp => ColumnType::BigInteger.def(),
84+
Self::MaxSupply => ColumnType::String(StringLen::None).def().null(),
85+
Self::KnownCirculatingSupply => ColumnType::String(StringLen::None).def().null(),
8086
}
8187
}
8288
}

0 commit comments

Comments
 (0)