Skip to content

Commit

Permalink
fix: remove auto committing in /v1/wallet/subscribe
Browse files Browse the repository at this point in the history
  • Loading branch information
zensh committed Oct 21, 2023
1 parent 9fc3bc7 commit 4b4a1a0
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 13 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "walletbase"
version = "1.0.3"
version = "1.0.4"
edition = "2021"
rust-version = "1.64"
description = ""
Expand Down
18 changes: 7 additions & 11 deletions src/api/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Arc<AppState>>,
Extension(ctx): Extension<Arc<ReqContext>>,
to: PackObject<SpendInput>,
Expand All @@ -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()),
Expand All @@ -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?;
Expand All @@ -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<Arc<AppState>>,
Extension(ctx): Extension<Arc<ReqContext>>,
to: PackObject<SpendInput>,
Expand All @@ -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()),
Expand All @@ -330,7 +326,7 @@ pub async fn subscribe(
&app.scylla,
&app.mac,
payee,
db::TransactionKind::Subscribe,
db::TransactionKind::Sponsor,
input.amount,
)
.await?;
Expand Down

0 comments on commit 4b4a1a0

Please sign in to comment.