Skip to content

Commit

Permalink
add support for UDA schema + media improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
zoedberg committed Dec 12, 2023
1 parent 837ace6 commit 96d7e83
Show file tree
Hide file tree
Showing 26 changed files with 2,297 additions and 332 deletions.
145 changes: 143 additions & 2 deletions migration/src/m20230608_071249_init_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ impl MigrationTrait for Migration {
.primary_key(),
)
.col(ColumnDef::new(Txo::Txid).string().not_null())
.col(ColumnDef::new(Txo::Vout).unsigned().not_null())
.col(ColumnDef::new(Txo::Vout).big_unsigned().not_null())
.col(ColumnDef::new(Txo::BtcAmount).string().not_null())
.col(ColumnDef::new(Txo::Spent).boolean().not_null())
.to_owned(),
Expand All @@ -37,6 +37,29 @@ impl MigrationTrait for Migration {
)
.await?;

manager
.create_table(
Table::create()
.table(Media::Table)
.if_not_exists()
.col(
ColumnDef::new(Media::Idx)
.integer()
.not_null()
.auto_increment()
.primary_key(),
)
.col(
ColumnDef::new(Media::Digest)
.string()
.not_null()
.unique_key(),
)
.col(ColumnDef::new(Media::Mime).string().not_null())
.to_owned(),
)
.await?;

manager
.create_table(
Table::create()
Expand All @@ -49,6 +72,7 @@ impl MigrationTrait for Migration {
.auto_increment()
.primary_key(),
)
.col(ColumnDef::new(Asset::MediaIdx).integer())
.col(
ColumnDef::new(Asset::AssetId)
.string()
Expand All @@ -63,6 +87,14 @@ impl MigrationTrait for Migration {
.col(ColumnDef::new(Asset::Precision).tiny_unsigned().not_null())
.col(ColumnDef::new(Asset::Ticker).string())
.col(ColumnDef::new(Asset::Timestamp).big_unsigned().not_null())
.foreign_key(
ForeignKey::create()
.name("fk-asset-media")
.from(Asset::Table, Asset::MediaIdx)
.to(Media::Table, Media::Idx)
.on_delete(ForeignKeyAction::Restrict)
.on_update(ForeignKeyAction::Cascade),
)
.to_owned(),
)
.await?;
Expand Down Expand Up @@ -214,7 +246,7 @@ impl MigrationTrait for Migration {
.col(ColumnDef::new(Transfer::RecipientType).tiny_unsigned())
.col(ColumnDef::new(Transfer::RecipientID).string())
.col(ColumnDef::new(Transfer::Ack).boolean())
.col(ColumnDef::new(Transfer::Vout).unsigned())
.col(ColumnDef::new(Transfer::Vout).big_unsigned())
.foreign_key(
ForeignKey::create()
.name("fk-transfer-assettransfer")
Expand Down Expand Up @@ -329,6 +361,72 @@ impl MigrationTrait for Migration {
)
.await?;

manager
.create_table(
Table::create()
.table(Token::Table)
.if_not_exists()
.col(
ColumnDef::new(Token::Idx)
.integer()
.not_null()
.auto_increment()
.primary_key(),
)
.col(ColumnDef::new(Token::AssetIdx).integer().not_null())
.col(ColumnDef::new(Token::Index).big_unsigned().not_null())
.col(ColumnDef::new(Token::Ticker).string())
.col(ColumnDef::new(Token::Name).string())
.col(ColumnDef::new(Token::Details).string())
.col(ColumnDef::new(Token::EmbeddedMedia).boolean().not_null())
.col(ColumnDef::new(Token::Reserves).boolean().not_null())
.foreign_key(
ForeignKey::create()
.name("fk-token-asset")
.from(Token::Table, Token::AssetIdx)
.to(Asset::Table, Asset::Idx)
.on_delete(ForeignKeyAction::Cascade)
.on_update(ForeignKeyAction::Cascade),
)
.to_owned(),
)
.await?;

manager
.create_table(
Table::create()
.table(TokenMedia::Table)
.if_not_exists()
.col(
ColumnDef::new(TokenMedia::Idx)
.integer()
.not_null()
.auto_increment()
.primary_key(),
)
.col(ColumnDef::new(TokenMedia::TokenIdx).integer().not_null())
.col(ColumnDef::new(TokenMedia::MediaIdx).integer().not_null())
.col(ColumnDef::new(TokenMedia::AttachmentId).tiny_unsigned())
.foreign_key(
ForeignKey::create()
.name("fk-tokenmedia-token")
.from(TokenMedia::Table, TokenMedia::TokenIdx)
.to(Token::Table, Token::Idx)
.on_delete(ForeignKeyAction::Cascade)
.on_update(ForeignKeyAction::Cascade),
)
.foreign_key(
ForeignKey::create()
.name("fk-tokenmedia-media")
.from(TokenMedia::Table, TokenMedia::MediaIdx)
.to(Media::Table, Media::Idx)
.on_delete(ForeignKeyAction::Restrict)
.on_update(ForeignKeyAction::Restrict),
)
.to_owned(),
)
.await?;

manager
.create_table(
Table::create()
Expand Down Expand Up @@ -427,6 +525,18 @@ impl MigrationTrait for Migration {
)
.await?;

manager
.drop_table(Table::drop().table(Token::Table).to_owned())
.await?;

manager
.drop_table(Table::drop().table(Media::Table).to_owned())
.await?;

manager
.drop_table(Table::drop().table(TokenMedia::Table).to_owned())
.await?;

manager
.drop_table(Table::drop().table(WalletTransaction::Table).to_owned())
.await?;
Expand All @@ -451,6 +561,7 @@ pub enum Txo {
pub enum Asset {
Table,
Idx,
MediaIdx,
AssetId,
Schema,
AddedAt,
Expand Down Expand Up @@ -523,6 +634,36 @@ pub enum TransferTransportEndpoint {
Used,
}

#[derive(DeriveIden)]
enum Token {
Table,
Idx,
AssetIdx,
Index,
Ticker,
Name,
Details,
EmbeddedMedia,
Reserves,
}

#[derive(DeriveIden)]
enum Media {
Table,
Idx,
Digest,
Mime,
}

#[derive(DeriveIden)]
enum TokenMedia {
Table,
Idx,
TokenIdx,
MediaIdx,
AttachmentId,
}

#[derive(DeriveIden)]
enum WalletTransaction {
Table,
Expand Down
12 changes: 6 additions & 6 deletions rgb-lib-ffi/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 26 additions & 0 deletions rgb-lib-ffi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,21 @@ type AssetCFA = rgb_lib::wallet::AssetCFA;
type AssetIface = rgb_lib::wallet::AssetIface;
type AssetNIA = rgb_lib::wallet::AssetNIA;
type AssetSchema = rgb_lib::AssetSchema;
type AssetUDA = rgb_lib::wallet::AssetUDA;
type Assets = rgb_lib::wallet::Assets;
type Balance = rgb_lib::wallet::Balance;
type BitcoinNetwork = rgb_lib::BitcoinNetwork;
type BlockTime = rgb_lib::wallet::BlockTime;
type BtcBalance = rgb_lib::wallet::BtcBalance;
type DatabaseType = rgb_lib::wallet::DatabaseType;
type EmbeddedMedia = rgb_lib::wallet::EmbeddedMedia;
type InvoiceData = rgb_lib::wallet::InvoiceData;
type Keys = rgb_lib::keys::Keys;
type Media = rgb_lib::wallet::Media;
type Metadata = rgb_lib::wallet::Metadata;
type Online = rgb_lib::wallet::Online;
type Outpoint = rgb_lib::wallet::Outpoint;
type ProofOfReserves = rgb_lib::wallet::ProofOfReserves;
type ReceiveData = rgb_lib::wallet::ReceiveData;
type RecipientData = rgb_lib::wallet::RecipientData;
type RefreshFilter = rgb_lib::wallet::RefreshFilter;
Expand All @@ -34,6 +37,8 @@ type RgbLibInvoice = rgb_lib::wallet::Invoice;
type RgbLibRecipient = rgb_lib::wallet::Recipient;
type RgbLibTransportEndpoint = rgb_lib::wallet::TransportEndpoint;
type RgbLibWallet = rgb_lib::wallet::Wallet;
type Token = rgb_lib::wallet::Token;
type TokenLight = rgb_lib::wallet::TokenLight;
type Transaction = rgb_lib::wallet::Transaction;
type TransactionType = rgb_lib::wallet::TransactionType;
type Transfer = rgb_lib::wallet::Transfer;
Expand Down Expand Up @@ -316,6 +321,27 @@ impl Wallet {
.issue_asset_nia(online, ticker, name, precision, amounts)
}

fn issue_asset_uda(
&self,
online: Online,
ticker: String,
name: String,
details: Option<String>,
precision: u8,
media_file_path: Option<String>,
attachments_file_paths: Vec<String>,
) -> Result<AssetUDA, RgbLibError> {
self._get_wallet().issue_asset_uda(
online,
ticker,
name,
details,
precision,
media_file_path,
attachments_file_paths,
)
}

fn issue_asset_cfa(
&self,
online: Online,
Expand Down
Loading

0 comments on commit 96d7e83

Please sign in to comment.