diff --git a/Cargo.lock b/Cargo.lock index 1f2a7de..9409f46 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2534,7 +2534,7 @@ dependencies = [ [[package]] name = "walletbase" -version = "1.0.3" +version = "1.0.4" dependencies = [ "aes-gcm", "anyhow", diff --git a/Cargo.toml b/Cargo.toml index bf12912..5ce6835 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "walletbase" -version = "1.0.3" +version = "1.0.4" edition = "2021" rust-version = "1.64" description = "" diff --git a/src/api/wallet.rs b/src/api/wallet.rs index dc008e0..435749d 100644 --- a/src/api/wallet.rs +++ b/src/api/wallet.rs @@ -237,9 +237,9 @@ pub async fn spend( Ok(to.with(SuccessResponse::new(WalletOutput::from(wallet, &to)))) } -// the txn is committed. +// the txn is not committed, it should be committed or cancelled by the caller // returns payer's wallet -pub async fn sponsor( +pub async fn subscribe( State(app): State>, Extension(ctx): Extension>, to: PackObject, @@ -253,7 +253,7 @@ pub async fn sponsor( } let payee = *input.payee.unwrap(); ctx.set_kvs(vec![ - ("action", "sponsor".into()), + ("action", "subscribe".into()), ("payer", uid.to_string().into()), ("payee", payee.to_string().into()), ("amount", input.amount.into()), @@ -276,14 +276,10 @@ pub async fn sponsor( &app.scylla, &app.mac, payee, - db::TransactionKind::Sponsor, + db::TransactionKind::Subscribe, input.amount, ) .await?; - txn.commit(&app.scylla, &app.mac).await?; - - let mut credits = txn.credits(); - db::Credit::save_all(&app.scylla, &mut credits).await?; let mut wallet = db::Wallet::with_pk(uid); wallet.get_one(&app.scylla).await?; @@ -293,7 +289,7 @@ pub async fn sponsor( // the txn is committed. // returns payer's wallet -pub async fn subscribe( +pub async fn sponsor( State(app): State>, Extension(ctx): Extension>, to: PackObject, @@ -307,7 +303,7 @@ pub async fn subscribe( } let payee = *input.payee.unwrap(); ctx.set_kvs(vec![ - ("action", "subscribe".into()), + ("action", "sponsor".into()), ("payer", uid.to_string().into()), ("payee", payee.to_string().into()), ("amount", input.amount.into()), @@ -330,7 +326,7 @@ pub async fn subscribe( &app.scylla, &app.mac, payee, - db::TransactionKind::Subscribe, + db::TransactionKind::Sponsor, input.amount, ) .await?;