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
3 changes: 2 additions & 1 deletion bindings/c-ffi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,10 @@ pub extern "C" fn rgblib_create_utxos_begin(
size_opt: *const c_char,
fee_rate: *const c_char,
skip_sync: bool,
dry_run: bool,
) -> CResultString {
create_utxos_begin(
wallet, online, up_to, num_opt, size_opt, fee_rate, skip_sync,
wallet, online, up_to, num_opt, size_opt, fee_rate, skip_sync, dry_run,
)
.into()
}
Expand Down
4 changes: 3 additions & 1 deletion bindings/c-ffi/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ pub(crate) fn create_utxos(
Ok(serde_json::to_string(&res)?)
}

#[allow(clippy::too_many_arguments)]
pub(crate) fn create_utxos_begin(
wallet: &COpaqueStruct,
online: &COpaqueStruct,
Expand All @@ -236,13 +237,14 @@ pub(crate) fn create_utxos_begin(
size_opt: *const c_char,
fee_rate: *const c_char,
skip_sync: bool,
dry_run: bool,
) -> Result<String, Error> {
let wallet = Wallet::from_opaque(wallet)?;
let online = Online::from_opaque(online)?;
let num = convert_optional_number(num_opt)?;
let size = convert_optional_number(size_opt)?;
let fee_rate = ptr_to_num(fee_rate)?;
let res = wallet.create_utxos_begin(*online, up_to, num, size, fee_rate, skip_sync)?;
let res = wallet.create_utxos_begin(*online, up_to, num, size, fee_rate, skip_sync, dry_run)?;
Ok(res)
}

Expand Down
14 changes: 7 additions & 7 deletions bindings/uniffi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -928,9 +928,10 @@ impl Wallet {
size: Option<u32>,
fee_rate: u64,
skip_sync: bool,
dry_run: bool,
) -> Result<String, RgbLibError> {
self._get_wallet()
.create_utxos_begin(online, up_to, num, size, fee_rate, skip_sync)
.create_utxos_begin(online, up_to, num, size, fee_rate, skip_sync, dry_run)
}

fn create_utxos_end(
Expand All @@ -956,22 +957,20 @@ impl Wallet {
&self,
online: Online,
address: String,
destroy_assets: bool,
fee_rate: u64,
) -> Result<String, RgbLibError> {
self._get_wallet()
.drain_to(online, address, destroy_assets, fee_rate)
self._get_wallet().drain_to(online, address, fee_rate)
}

fn drain_to_begin(
&self,
online: Online,
address: String,
destroy_assets: bool,
fee_rate: u64,
dry_run: bool,
) -> Result<String, RgbLibError> {
self._get_wallet()
.drain_to_begin(online, address, destroy_assets, fee_rate)
.drain_to_begin(online, address, fee_rate, dry_run)
}

fn drain_to_end(&self, online: Online, signed_psbt: String) -> Result<String, RgbLibError> {
Expand Down Expand Up @@ -1243,9 +1242,10 @@ impl Wallet {
amount: u64,
fee_rate: u64,
skip_sync: bool,
dry_run: bool,
) -> Result<String, RgbLibError> {
self._get_wallet()
.send_btc_begin(online, address, amount, fee_rate, skip_sync)
.send_btc_begin(online, address, amount, fee_rate, skip_sync, dry_run)
}

fn send_btc_end(
Expand Down
14 changes: 9 additions & 5 deletions bindings/uniffi/src/rgb-lib.udl
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ interface RgbLibError {
AssetNotFound(string asset_id);
BatchTransferNotFound(i32 idx);
BitcoinNetworkMismatch();
CannotAbortPendingVanillaTx();
CannotChangeOnline();
CannotCombinePsbts();
CannotDeleteBatchTransfer();
Expand Down Expand Up @@ -465,7 +466,8 @@ enum TransactionType {
"RgbSend",
"Drain",
"CreateUtxos",
"User",
"SendBtc",
"Untracked",
};

[Remote]
Expand Down Expand Up @@ -765,7 +767,7 @@ interface Wallet {
[Throws=RgbLibError]
string create_utxos_begin(
Online online, boolean up_to, u8? num, u32? size, u64 fee_rate,
boolean skip_sync);
boolean skip_sync, boolean dry_run);

[Throws=RgbLibError]
u8 create_utxos_end(Online online, string signed_psbt, boolean skip_sync);
Expand All @@ -775,11 +777,12 @@ interface Wallet {

[Throws=RgbLibError]
string drain_to(
Online online, string address, boolean destroy_assets, u64 fee_rate);
Online online, string address, u64 fee_rate);

[Throws=RgbLibError]
string drain_to_begin(
Online online, string address, boolean destroy_assets, u64 fee_rate);
Online online, string address, u64 fee_rate,
boolean dry_run);

[Throws=RgbLibError]
string drain_to_end(Online online, string signed_psbt);
Expand Down Expand Up @@ -878,7 +881,8 @@ interface Wallet {

[Throws=RgbLibError]
string send_btc_begin(
Online online, string address, u64 amount, u64 fee_rate, boolean skip_sync);
Online online, string address, u64 amount, u64 fee_rate, boolean skip_sync,
boolean dry_run);

[Throws=RgbLibError]
string send_btc_end(Online online, string signed_psbt, boolean skip_sync);
Expand Down
2 changes: 2 additions & 0 deletions migration/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ mod m20230608_071249_init_db;
mod m20251017_074408_asset_update;
mod m20251105_132121_asset_update;
mod m20251215_124959_backup_info_update;
mod m20260414_134758_add_reserved_txo;

pub struct Migrator;

Expand All @@ -15,6 +16,7 @@ impl MigratorTrait for Migrator {
Box::new(m20251017_074408_asset_update::Migration),
Box::new(m20251105_132121_asset_update::Migration),
Box::new(m20251215_124959_backup_info_update::Migration),
Box::new(m20260414_134758_add_reserved_txo::Migration),
]
}
}
55 changes: 55 additions & 0 deletions migration/src/m20260414_134758_add_reserved_txo.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
use sea_orm_migration::{prelude::*, schema::*};

#[derive(DeriveMigrationName)]
pub struct Migration;

#[async_trait::async_trait]
impl MigrationTrait for Migration {
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
manager
.create_table(
Table::create()
.table(ReservedTxo::Table)
.if_not_exists()
.col(pk_auto(ReservedTxo::Idx))
.col(string(ReservedTxo::Txid))
.col(big_unsigned(ReservedTxo::Vout))
.col(integer_null(ReservedTxo::ReservedFor))
.foreign_key(
ForeignKey::create()
.name("fk-reservedtxo-wallettransaction")
.from(ReservedTxo::Table, ReservedTxo::ReservedFor)
.to(WalletTransaction::Table, WalletTransaction::Idx)
.on_delete(ForeignKeyAction::Cascade)
.on_update(ForeignKeyAction::Restrict),
)
.to_owned(),
)
.await?;

Ok(())
}

async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
manager
.drop_table(Table::drop().table(ReservedTxo::Table).to_owned())
.await?;

Ok(())
}
}

#[derive(DeriveIden)]
enum ReservedTxo {
Table,
Idx,
Txid,
Vout,
ReservedFor,
}

#[derive(DeriveIden)]
pub enum WalletTransaction {
Table,
Idx,
}
1 change: 1 addition & 0 deletions src/database/entities/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ pub mod batch_transfer;
pub mod coloring;
pub mod media;
pub mod pending_witness_script;
pub mod reserved_txo;
pub mod token;
pub mod token_media;
pub mod transfer;
Expand Down
1 change: 1 addition & 0 deletions src/database/entities/prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ pub use super::batch_transfer::Entity as BatchTransfer;
pub use super::coloring::Entity as Coloring;
pub use super::media::Entity as Media;
pub use super::pending_witness_script::Entity as PendingWitnessScript;
pub use super::reserved_txo::Entity as ReservedTxo;
pub use super::token::Entity as Token;
pub use super::token_media::Entity as TokenMedia;
pub use super::transfer::Entity as Transfer;
Expand Down
76 changes: 76 additions & 0 deletions src/database/entities/reserved_txo.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
//! `SeaORM` Entity, @generated by sea-orm-codegen 1.1.19

use sea_orm::entity::prelude::*;

#[derive(Copy, Clone, Default, Debug, DeriveEntity)]
pub struct Entity;

impl EntityName for Entity {
fn table_name(&self) -> &str {
"reserved_txo"
}
}

#[derive(Clone, Debug, PartialEq, DeriveModel, DeriveActiveModel, Eq)]
pub struct Model {
pub idx: i32,
pub txid: String,
pub vout: u32,
pub reserved_for: Option<i32>,
}

#[derive(Copy, Clone, Debug, EnumIter, DeriveColumn)]
pub enum Column {
Idx,
Txid,
Vout,
ReservedFor,
}

#[derive(Copy, Clone, Debug, EnumIter, DerivePrimaryKey)]
pub enum PrimaryKey {
Idx,
}

impl PrimaryKeyTrait for PrimaryKey {
type ValueType = i32;
fn auto_increment() -> bool {
true
}
}

#[derive(Copy, Clone, Debug, EnumIter)]
pub enum Relation {
WalletTransaction,
}

impl ColumnTrait for Column {
type EntityName = Entity;
fn def(&self) -> ColumnDef {
match self {
Self::Idx => ColumnType::Integer.def(),
Self::Txid => ColumnType::String(StringLen::None).def(),
Self::Vout => ColumnType::BigInteger.def(),
Self::ReservedFor => ColumnType::Integer.def().null(),
}
}
}

impl RelationTrait for Relation {
fn def(&self) -> RelationDef {
match self {
Self::WalletTransaction => Entity::belongs_to(super::wallet_transaction::Entity)
.from(Column::ReservedFor)
.to(super::wallet_transaction::Column::Idx)
.into(),
}
}
}

impl Related<super::wallet_transaction::Entity> for Entity {
fn to() -> RelationDef {
Relation::WalletTransaction.def()
}
}

impl ActiveModelBehavior for ActiveModel {}
14 changes: 12 additions & 2 deletions src/database/entities/wallet_transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ impl PrimaryKeyTrait for PrimaryKey {
}

#[derive(Copy, Clone, Debug, EnumIter)]
pub enum Relation {}
pub enum Relation {
ReservedTxo,
}

impl ColumnTrait for Column {
type EntityName = Entity;
Expand All @@ -55,7 +57,15 @@ impl ColumnTrait for Column {

impl RelationTrait for Relation {
fn def(&self) -> RelationDef {
panic!("No RelationDef")
match self {
Self::ReservedTxo => Entity::has_many(super::reserved_txo::Entity).into(),
}
}
}

impl Related<super::reserved_txo::Entity> for Entity {
fn to() -> RelationDef {
Relation::ReservedTxo.def()
}
}

Expand Down
4 changes: 3 additions & 1 deletion src/database/enums.rs
Original file line number Diff line number Diff line change
Expand Up @@ -296,13 +296,15 @@ impl TransferStatus {
}
}

#[derive(Debug, Copy, Clone, PartialEq, Eq, EnumIter, DeriveActiveEnum)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, EnumIter, DeriveActiveEnum, Deserialize, Serialize)]
#[sea_orm(rs_type = "u8", db_type = "TinyUnsigned")]
pub enum WalletTransactionType {
#[sea_orm(num_value = 1)]
CreateUtxos = 1,
#[sea_orm(num_value = 2)]
Drain = 2,
#[sea_orm(num_value = 3)]
SendBtc = 3,
}

/// An RGB assignment.
Expand Down
Loading
Loading