implement inital account capital with system transaction

This commit is contained in:
DSeeLP 2025-04-17 10:29:04 +02:00
parent ce13d854c1
commit 52917f4128
2 changed files with 8 additions and 3 deletions

View File

@ -29,6 +29,8 @@ mod socket;
mod transactions;
mod user;
pub use transactions::TransactionBuilder;
pub use interop::router as interop_router;
use transactions::TARGET_NOT_FOUND;

View File

@ -7,6 +7,8 @@ use tokio_postgres::Row;
use tracing::instrument;
use uuid::{NoContext, Timestamp, Uuid};
use crate::api::TransactionBuilder;
use super::count;
fn account_info_from_row(row: Row) -> AccountInfo {
@ -40,9 +42,10 @@ impl Accounts {
)
.await?;
let id = id.unwrap_or_else(|| Uuid::new_v7(Timestamp::now(NoContext)));
let balance: i64 = if id == user { 1000 * 100 } else { 0 };
client
.execute(&stmt, &[&id, &user, &name, &balance])
client.execute(&stmt, &[&id, &user, &name, &0i64]).await?;
TransactionBuilder::new(client, 1000 * 100)
.await?
.system(id, Some("Initial capital".into()))
.await?;
Ok(id)
}