Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Transaction confirmation #61

Merged
merged 13 commits into from
Oct 29, 2024
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

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

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

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

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

2 changes: 2 additions & 0 deletions crates/sage-api/src/records.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ mod nft;
mod peer;
mod pending_transaction;
mod sync_status;
mod transaction_summary;

pub use cat::*;
pub use coin::*;
Expand All @@ -13,3 +14,4 @@ pub use nft::*;
pub use peer::*;
pub use pending_transaction::*;
pub use sync_status::*;
pub use transaction_summary::*;
1 change: 0 additions & 1 deletion crates/sage-api/src/records/pending_transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,4 @@ pub struct PendingTransactionRecord {
pub transaction_id: String,
pub fee: Amount,
pub submitted_at: Option<String>,
pub expiration_height: Option<u32>,
}
53 changes: 53 additions & 0 deletions crates/sage-api/src/records/transaction_summary.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
use serde::{Deserialize, Serialize};
use specta::Type;

use crate::Amount;

#[derive(Debug, Clone, Serialize, Deserialize, Type)]
pub struct TransactionSummary {
pub fee: Amount,
pub inputs: Vec<Input>,
pub data: String,
}

#[derive(Debug, Clone, Serialize, Deserialize, Type)]
pub struct Input {
pub coin_id: String,
pub amount: Amount,
pub address: String,
#[serde(flatten)]
pub kind: InputKind,
pub outputs: Vec<Output>,
}

#[derive(Debug, Clone, Serialize, Deserialize, Type)]
pub struct Output {
pub coin_id: String,
pub amount: Amount,
pub address: String,
pub receiving: bool,
}

#[derive(Debug, Clone, Serialize, Deserialize, Type)]
#[serde(tag = "type", rename_all = "snake_case")]
pub enum InputKind {
Unknown,
Xch,
Launcher,
Cat {
asset_id: String,
name: Option<String>,
ticker: Option<String>,
icon_url: Option<String>,
},
Did {
launcher_id: String,
name: Option<String>,
},
Nft {
launcher_id: String,
image_data: Option<String>,
image_mime_type: Option<String>,
name: Option<String>,
},
}
3 changes: 2 additions & 1 deletion crates/sage-api/src/requests/bulk_mint_nfts.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use serde::{Deserialize, Serialize};
use specta::Type;

use crate::Amount;
use crate::{Amount, TransactionSummary};

#[derive(Debug, Clone, Serialize, Deserialize, Type)]
pub struct BulkMintNfts {
Expand All @@ -24,4 +24,5 @@ pub struct NftMint {
#[derive(Debug, Clone, Serialize, Deserialize, Type)]
pub struct BulkMintNftsResponse {
pub nft_ids: Vec<String>,
pub summary: TransactionSummary,
}
11 changes: 1 addition & 10 deletions crates/sage-database/src/coin_states.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,16 +88,7 @@ async fn insert_coin_state(
`synced`,
`transaction_id`
)
VALUES (
?,
?,
?,
?,
?,
?,
?,
?
)
VALUES (?, ?, ?, ?, ?, ?, ?, ?)
",
coin_id_ref,
parent_coin_id,
Expand Down
4 changes: 4 additions & 0 deletions crates/sage-database/src/derivations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ impl Database {
pub async fn synthetic_key_index(&self, synthetic_key: PublicKey) -> Result<Option<u32>> {
synthetic_key_index(&self.pool, synthetic_key).await
}

pub async fn is_p2_puzzle_hash(&self, p2_puzzle_hash: Bytes32) -> Result<bool> {
is_p2_puzzle_hash(&self.pool, p2_puzzle_hash).await
}
}

impl<'a> DatabaseTx<'a> {
Expand Down
24 changes: 24 additions & 0 deletions crates/sage-database/src/primitives/dids.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ impl Database {
pub async fn did(&self, did_id: Bytes32) -> Result<Option<Did<Program>>> {
did(&self.pool, did_id).await
}

pub async fn did_name(&self, launcher_id: Bytes32) -> Result<Option<String>> {
did_name(&self.pool, launcher_id).await
}
}

impl<'a> DatabaseTx<'a> {
Expand Down Expand Up @@ -271,3 +275,23 @@ async fn did(conn: impl SqliteExecutor<'_>, did_id: Bytes32) -> Result<Option<Di
},
}))
}

async fn did_name(conn: impl SqliteExecutor<'_>, launcher_id: Bytes32) -> Result<Option<String>> {
let launcher_id = launcher_id.as_ref();

let Some(row) = sqlx::query!(
"
SELECT `name`
FROM `dids`
WHERE `launcher_id` = ?
",
launcher_id
)
.fetch_optional(conn)
.await?
else {
return Ok(None);
};

Ok(row.name)
}
4 changes: 4 additions & 0 deletions crates/sage-database/src/primitives/nfts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ impl Database {
pub async fn nft(&self, launcher_id: Bytes32) -> Result<Option<Nft<Program>>> {
nft(&self.pool, launcher_id).await
}

pub async fn fetch_nft_data(&self, hash: Bytes32) -> Result<Option<NftData>> {
fetch_nft_data(&self.pool, hash).await
}
}

impl<'a> DatabaseTx<'a> {
Expand Down
24 changes: 5 additions & 19 deletions crates/sage-database/src/transactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ pub struct TransactionRow {
pub transaction_id: Bytes32,
pub fee: u64,
pub submitted_at: Option<i64>,
pub expiration_height: Option<u32>,
}

impl Database {
Expand All @@ -34,16 +33,8 @@ impl<'a> DatabaseTx<'a> {
transaction_id: Bytes32,
aggregated_signature: Signature,
fee: u64,
expiration_height: Option<u32>,
) -> Result<()> {
insert_transaction(
&mut *self.tx,
transaction_id,
aggregated_signature,
fee,
expiration_height,
)
.await
insert_transaction(&mut *self.tx, transaction_id, aggregated_signature, fee).await
}

pub async fn insert_transaction_spend(
Expand Down Expand Up @@ -89,7 +80,6 @@ async fn insert_transaction(
transaction_id: Bytes32,
aggregated_signature: Signature,
fee: u64,
expiration_height: Option<u32>,
) -> Result<()> {
let transaction_id = transaction_id.as_ref();
let aggregated_signature = aggregated_signature.to_bytes();
Expand All @@ -102,15 +92,13 @@ async fn insert_transaction(
INSERT INTO `transactions` (
`transaction_id`,
`aggregated_signature`,
`fee`,
`expiration_height`
`fee`
)
VALUES (?, ?, ?, ?)
VALUES (?, ?, ?)
",
transaction_id,
aggregated_signature,
fee,
expiration_height
fee
)
.execute(conn)
.await?;
Expand Down Expand Up @@ -190,8 +178,7 @@ async fn transactions(conn: impl SqliteExecutor<'_>) -> Result<Vec<TransactionRo
SELECT
`transaction_id`,
`fee`,
`submitted_at`,
`expiration_height`
`submitted_at`
FROM `transactions`
ORDER BY `submitted_at` DESC, `transaction_id` ASC
"
Expand All @@ -205,7 +192,6 @@ async fn transactions(conn: impl SqliteExecutor<'_>) -> Result<Vec<TransactionRo
transaction_id: to_bytes32(&row.transaction_id)?,
fee: u64::from_be_bytes(to_bytes(&row.fee)?),
submitted_at: row.submitted_at,
expiration_height: row.expiration_height.map(TryInto::try_into).transpose()?,
})
})
.collect()
Expand Down
Loading