Skip to content

Commit 57a8803

Browse files
committed
add burn API
1 parent 23bd2c7 commit 57a8803

19 files changed

Lines changed: 1589 additions & 90 deletions

File tree

bindings/c-ffi/src/lib.rs

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,57 @@ pub extern "C" fn rgblib_backup_info(wallet: &COpaqueStruct) -> CResultString {
6666
backup_info(wallet).into()
6767
}
6868

69+
#[unsafe(no_mangle)]
70+
pub extern "C" fn rgblib_burn(
71+
wallet: &COpaqueStruct,
72+
online: *const c_char,
73+
asset_id: *const c_char,
74+
amount: *const c_char,
75+
fee_rate: *const c_char,
76+
min_confirmations: *const c_char,
77+
) -> CResultString {
78+
burn(
79+
wallet,
80+
online,
81+
asset_id,
82+
amount,
83+
fee_rate,
84+
min_confirmations,
85+
)
86+
.into()
87+
}
88+
89+
#[unsafe(no_mangle)]
90+
pub extern "C" fn rgblib_burn_begin(
91+
wallet: &COpaqueStruct,
92+
online: *const c_char,
93+
asset_id: *const c_char,
94+
amount: *const c_char,
95+
fee_rate: *const c_char,
96+
min_confirmations: *const c_char,
97+
dry_run: bool,
98+
) -> CResultString {
99+
burn_begin(
100+
wallet,
101+
online,
102+
asset_id,
103+
amount,
104+
fee_rate,
105+
min_confirmations,
106+
dry_run,
107+
)
108+
.into()
109+
}
110+
111+
#[unsafe(no_mangle)]
112+
pub extern "C" fn rgblib_burn_end(
113+
wallet: &COpaqueStruct,
114+
online: *const c_char,
115+
signed_psbt: *const c_char,
116+
) -> CResultString {
117+
burn_end(wallet, online, signed_psbt).into()
118+
}
119+
69120
#[unsafe(no_mangle)]
70121
pub extern "C" fn rgblib_blind_receive(
71122
wallet: &COpaqueStruct,

bindings/c-ffi/src/utils.rs

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,62 @@ pub(crate) fn backup_info(wallet: &COpaqueStruct) -> Result<String, Error> {
185185
Ok(serde_json::to_string(&res)?)
186186
}
187187

188+
pub(crate) fn burn(
189+
wallet: &COpaqueStruct,
190+
online: *const c_char,
191+
asset_id: *const c_char,
192+
amount: *const c_char,
193+
fee_rate: *const c_char,
194+
min_confirmations: *const c_char,
195+
) -> Result<String, Error> {
196+
let wallet = Wallet::from_opaque(wallet)?;
197+
let online = convert_online(online)?;
198+
let asset_id = ptr_to_string(asset_id);
199+
let amount = ptr_to_num(amount)?;
200+
let fee_rate = ptr_to_num(fee_rate)?;
201+
let min_confirmations = ptr_to_num(min_confirmations)?;
202+
let res = wallet.burn(online, asset_id, amount, fee_rate, min_confirmations)?;
203+
Ok(serde_json::to_string(&res)?)
204+
}
205+
206+
pub(crate) fn burn_begin(
207+
wallet: &COpaqueStruct,
208+
online: *const c_char,
209+
asset_id: *const c_char,
210+
amount: *const c_char,
211+
fee_rate: *const c_char,
212+
min_confirmations: *const c_char,
213+
dry_run: bool,
214+
) -> Result<String, Error> {
215+
let wallet = Wallet::from_opaque(wallet)?;
216+
let online = convert_online(online)?;
217+
let asset_id = ptr_to_string(asset_id);
218+
let amount = ptr_to_num(amount)?;
219+
let fee_rate = ptr_to_num(fee_rate)?;
220+
let min_confirmations = ptr_to_num(min_confirmations)?;
221+
let res = wallet.burn_begin(
222+
online,
223+
asset_id,
224+
amount,
225+
fee_rate,
226+
min_confirmations,
227+
dry_run,
228+
)?;
229+
Ok(serde_json::to_string(&res)?)
230+
}
231+
232+
pub(crate) fn burn_end(
233+
wallet: &COpaqueStruct,
234+
online: *const c_char,
235+
signed_psbt: *const c_char,
236+
) -> Result<String, Error> {
237+
let wallet = Wallet::from_opaque(wallet)?;
238+
let online = convert_online(online)?;
239+
let signed_psbt = ptr_to_string(signed_psbt);
240+
let res = wallet.burn_end(online, signed_psbt)?;
241+
Ok(serde_json::to_string(&res)?)
242+
}
243+
188244
pub(crate) fn blind_receive(
189245
wallet: &COpaqueStruct,
190246
asset_id_opt: *const c_char,

bindings/uniffi/src/lib.rs

Lines changed: 125 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ use rgb_lib::{
1313
utils::BitcoinNetwork,
1414
wallet::{
1515
Address as RgbLibAddress, AssetCFA, AssetIFA, AssetNIA, AssetUDA, Assets,
16-
AssignmentsCollection, Balance, BlockTime, BtcBalance, Cosigner as CosignerData,
17-
DatabaseType, EmbeddedMedia, HubInfo, InflateBeginResult, InflateDetails,
18-
InitOperationResult, Invoice as RgbLibInvoice, InvoiceData as RgbLibInvoiceData, Media,
19-
Metadata, MultisigKeys, MultisigOnlineOptions,
16+
AssignmentsCollection, Balance, BlockTime, BtcBalance, BurnBeginResult, BurnDetails,
17+
Cosigner as CosignerData, DatabaseType, EmbeddedMedia, HubInfo, InflateBeginResult,
18+
InflateDetails, InitOperationResult, Invoice as RgbLibInvoice,
19+
InvoiceData as RgbLibInvoiceData, Media, Metadata, MultisigKeys, MultisigOnlineOptions,
2020
MultisigVotingStatus as RgbLibMultisigVotingStatus, MultisigWallet as RgbLibMultisigWallet,
2121
Online, OnlineOptions, Operation as RgbLibOperation, OperationInfo as RgbLibOperationInfo,
2222
OperationResult, Outpoint, ProofOfReserves, PsbtInputInfo, PsbtInspection, PsbtOutputInfo,
@@ -448,6 +448,24 @@ pub enum Operation {
448448
details: InflateDetails,
449449
status: MultisigVotingStatus,
450450
},
451+
BurnToReview {
452+
psbt: String,
453+
details: BurnDetails,
454+
status: MultisigVotingStatus,
455+
},
456+
BurnPending {
457+
details: BurnDetails,
458+
status: MultisigVotingStatus,
459+
},
460+
BurnCompleted {
461+
txid: String,
462+
details: BurnDetails,
463+
status: MultisigVotingStatus,
464+
},
465+
BurnDiscarded {
466+
details: BurnDetails,
467+
status: MultisigVotingStatus,
468+
},
451469
IssuanceCompleted {
452470
asset_id: String,
453471
},
@@ -575,6 +593,32 @@ impl From<RgbLibOperation> for Operation {
575593
status: status.into(),
576594
}
577595
}
596+
RgbLibOperation::BurnToReview {
597+
psbt,
598+
details,
599+
status,
600+
} => Operation::BurnToReview {
601+
psbt,
602+
details,
603+
status: status.into(),
604+
},
605+
RgbLibOperation::BurnPending { status, details } => Operation::BurnPending {
606+
details,
607+
status: status.into(),
608+
},
609+
RgbLibOperation::BurnCompleted {
610+
txid,
611+
details,
612+
status,
613+
} => Operation::BurnCompleted {
614+
txid,
615+
details,
616+
status: status.into(),
617+
},
618+
RgbLibOperation::BurnDiscarded { details, status } => Operation::BurnDiscarded {
619+
details,
620+
status: status.into(),
621+
},
578622
RgbLibOperation::IssuanceCompleted { asset_id } => {
579623
Operation::IssuanceCompleted { asset_id }
580624
}
@@ -676,6 +720,32 @@ impl From<Operation> for RgbLibOperation {
676720
status: status.into(),
677721
}
678722
}
723+
Operation::BurnToReview {
724+
psbt,
725+
details,
726+
status,
727+
} => RgbLibOperation::BurnToReview {
728+
psbt,
729+
details,
730+
status: status.into(),
731+
},
732+
Operation::BurnPending { status, details } => RgbLibOperation::BurnPending {
733+
details,
734+
status: status.into(),
735+
},
736+
Operation::BurnCompleted {
737+
txid,
738+
details,
739+
status,
740+
} => RgbLibOperation::BurnCompleted {
741+
txid,
742+
details,
743+
status: status.into(),
744+
},
745+
Operation::BurnDiscarded { details, status } => RgbLibOperation::BurnDiscarded {
746+
details,
747+
status: status.into(),
748+
},
679749
Operation::IssuanceCompleted { asset_id } => {
680750
RgbLibOperation::IssuanceCompleted { asset_id }
681751
}
@@ -1049,6 +1119,45 @@ impl Wallet {
10491119
self._get_wallet().go_online(online_options)
10501120
}
10511121

1122+
fn burn(
1123+
&self,
1124+
online: Online,
1125+
asset_id: String,
1126+
amount: u64,
1127+
fee_rate: u64,
1128+
min_confirmations: u8,
1129+
) -> Result<OperationResult, RgbLibError> {
1130+
self._get_wallet()
1131+
.burn(online, asset_id, amount, fee_rate, min_confirmations)
1132+
}
1133+
1134+
fn burn_begin(
1135+
&self,
1136+
online: Online,
1137+
asset_id: String,
1138+
amount: u64,
1139+
fee_rate: u64,
1140+
min_confirmations: u8,
1141+
dry_run: bool,
1142+
) -> Result<BurnBeginResult, RgbLibError> {
1143+
self._get_wallet().burn_begin(
1144+
online,
1145+
asset_id,
1146+
amount,
1147+
fee_rate,
1148+
min_confirmations,
1149+
dry_run,
1150+
)
1151+
}
1152+
1153+
fn burn_end(
1154+
&self,
1155+
online: Online,
1156+
signed_psbt: String,
1157+
) -> Result<OperationResult, RgbLibError> {
1158+
self._get_wallet().burn_end(online, signed_psbt)
1159+
}
1160+
10521161
fn inflate(
10531162
&self,
10541163
online: Online,
@@ -1458,6 +1567,18 @@ impl MultisigWallet {
14581567
self._get_wallet().hub_info(online)
14591568
}
14601569

1570+
fn burn_init(
1571+
&self,
1572+
online: Online,
1573+
asset_id: String,
1574+
amount: u64,
1575+
fee_rate: u64,
1576+
min_confirmations: u8,
1577+
) -> Result<InitOperationResult, RgbLibError> {
1578+
self._get_wallet()
1579+
.burn_init(online, asset_id, amount, fee_rate, min_confirmations)
1580+
}
1581+
14611582
fn inflate_init(
14621583
&self,
14631584
online: Online,

bindings/uniffi/src/rgb-lib.udl

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ interface RgbLibError {
8585
Network(string details);
8686
NoConsignment();
8787
NoCosignersSupplied();
88+
NoBurnAmount();
8889
NoInflationAmounts();
8990
NoIssuanceAmounts();
9091
NoKeysSupplied();
@@ -107,6 +108,7 @@ interface RgbLibError {
107108
UnknownRgbSchema(string schema_id);
108109
UnknownTransfer(string txid);
109110
UnsupportedBackupVersion(string version);
111+
UnsupportedBurn(AssetSchema asset_schema);
110112
UnsupportedInflation(AssetSchema asset_schema);
111113
UnsupportedLayer1(string layer_1);
112114
UnsupportedSchema(AssetSchema asset_schema);
@@ -479,6 +481,7 @@ enum TransferKind {
479481
"ReceiveWitness",
480482
"Send",
481483
"Inflation",
484+
"Burn",
482485
};
483486

484487
[Remote]
@@ -591,6 +594,20 @@ dictionary MultisigVotingStatus {
591594
boolean? my_response;
592595
};
593596

597+
[Remote]
598+
dictionary BurnDetails {
599+
string fascia_path;
600+
u8 min_confirmations;
601+
u64 entropy;
602+
};
603+
604+
[Remote]
605+
dictionary BurnBeginResult {
606+
string psbt;
607+
i32? batch_transfer_idx;
608+
BurnDetails details;
609+
};
610+
594611
[Remote]
595612
dictionary InflateDetails {
596613
string fascia_path;
@@ -638,6 +655,10 @@ interface Operation {
638655
InflationPending(InflateDetails details, MultisigVotingStatus status);
639656
InflationCompleted(string txid, InflateDetails details, MultisigVotingStatus status);
640657
InflationDiscarded(InflateDetails details, MultisigVotingStatus status);
658+
BurnToReview(string psbt, BurnDetails details, MultisigVotingStatus status);
659+
BurnPending(BurnDetails details, MultisigVotingStatus status);
660+
BurnCompleted(string txid, BurnDetails details, MultisigVotingStatus status);
661+
BurnDiscarded(BurnDetails details, MultisigVotingStatus status);
641662
IssuanceCompleted(string asset_id);
642663
BlindReceiveCompleted(ReceiveData details);
643664
WitnessReceiveCompleted(ReceiveData details);
@@ -708,6 +729,7 @@ dictionary RgbOperationInfo {
708729
enum TypeOfTransition {
709730
"Inflate",
710731
"Transfer",
732+
"Burn",
711733
};
712734

713735
[Remote]
@@ -851,6 +873,19 @@ interface Wallet {
851873
[Throws=RgbLibError]
852874
Online go_online(OnlineOptions online_options);
853875

876+
[Throws=RgbLibError]
877+
OperationResult burn(
878+
Online online, string asset_id, u64 amount, u64 fee_rate,
879+
u8 min_confirmations);
880+
881+
[Throws=RgbLibError]
882+
BurnBeginResult burn_begin(
883+
Online online, string asset_id, u64 amount, u64 fee_rate,
884+
u8 min_confirmations, boolean dry_run);
885+
886+
[Throws=RgbLibError]
887+
OperationResult burn_end(Online online, string signed_psbt);
888+
854889
[Throws=RgbLibError]
855890
OperationResult inflate(
856891
Online online, string asset_id, sequence<u64> inflation_amounts,
@@ -999,6 +1034,11 @@ interface MultisigWallet {
9991034
[Throws=RgbLibError]
10001035
HubInfo hub_info(Online online);
10011036

1037+
[Throws=RgbLibError]
1038+
InitOperationResult burn_init(
1039+
Online online, string asset_id, u64 amount, u64 fee_rate,
1040+
u8 min_confirmations);
1041+
10021042
[Throws=RgbLibError]
10031043
InitOperationResult inflate_init(
10041044
Online online, string asset_id, sequence<u64> inflation_amounts,

src/api/multisig_hub.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ pub(crate) enum OperationType {
126126
Inflation = 5,
127127
BlindReceive = 6,
128128
WitnessReceive = 7,
129+
Burn = 8,
129130
}
130131

131132
#[derive(Debug, Deserialize, Serialize)]

0 commit comments

Comments
 (0)