mirror of
https://git.dirksys.ovh/dirk/bankserver.git
synced 2025-12-20 02:59:20 +01:00
implement inital account capital with system transaction
This commit is contained in:
parent
ce13d854c1
commit
52917f4128
@ -29,6 +29,8 @@ mod socket;
|
|||||||
mod transactions;
|
mod transactions;
|
||||||
mod user;
|
mod user;
|
||||||
|
|
||||||
|
pub use transactions::TransactionBuilder;
|
||||||
|
|
||||||
pub use interop::router as interop_router;
|
pub use interop::router as interop_router;
|
||||||
use transactions::TARGET_NOT_FOUND;
|
use transactions::TARGET_NOT_FOUND;
|
||||||
|
|
||||||
|
|||||||
@ -7,6 +7,8 @@ use tokio_postgres::Row;
|
|||||||
use tracing::instrument;
|
use tracing::instrument;
|
||||||
use uuid::{NoContext, Timestamp, Uuid};
|
use uuid::{NoContext, Timestamp, Uuid};
|
||||||
|
|
||||||
|
use crate::api::TransactionBuilder;
|
||||||
|
|
||||||
use super::count;
|
use super::count;
|
||||||
|
|
||||||
fn account_info_from_row(row: Row) -> AccountInfo {
|
fn account_info_from_row(row: Row) -> AccountInfo {
|
||||||
@ -40,9 +42,10 @@ impl Accounts {
|
|||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
let id = id.unwrap_or_else(|| Uuid::new_v7(Timestamp::now(NoContext)));
|
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, &0i64]).await?;
|
||||||
client
|
TransactionBuilder::new(client, 1000 * 100)
|
||||||
.execute(&stmt, &[&id, &user, &name, &balance])
|
.await?
|
||||||
|
.system(id, Some("Initial capital".into()))
|
||||||
.await?;
|
.await?;
|
||||||
Ok(id)
|
Ok(id)
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user