Skip to content

Commit

Permalink
1. Add list_credits api; 2. Improve code.
Browse files Browse the repository at this point in the history
  • Loading branch information
zensh committed Sep 13, 2023
1 parent 708abac commit b53159b
Show file tree
Hide file tree
Showing 8 changed files with 206 additions and 200 deletions.
86 changes: 43 additions & 43 deletions 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 = "0.4.0"
version = "0.4.1"
edition = "2021"
rust-version = "1.64"
description = ""
Expand Down
19 changes: 15 additions & 4 deletions src/api/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ use axum_web::context::ReqContext;
use axum_web::erring::{HTTPError, SuccessResponse};
use axum_web::object::PackObject;

use crate::api::{
get_fields, token_from_xid, token_to_xid, AppState, Pagination, QueryUidId,
};
use crate::db;
use crate::{
api::{get_fields, token_from_xid, token_to_xid, AppState, Pagination, QueryUidId},
db::TransactionKind,
};

#[derive(Debug, Default, Deserialize, Serialize)]
pub struct TransactionOutput {
Expand All @@ -22,6 +23,8 @@ pub struct TransactionOutput {
pub payee: PackObject<xid::Id>,
#[serde(skip_serializing_if = "Option::is_none")]
pub sub_payee: Option<PackObject<xid::Id>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub payer: Option<PackObject<xid::Id>>,
pub status: i8,
pub kind: String,
pub amount: i64,
Expand All @@ -40,13 +43,21 @@ impl TransactionOutput {
sequence: val.sequence,
payee: to.with(val.payee),
status: val.status,
kind: val.kind,
kind: val.kind.clone(),
amount: val.amount,
sys_fee: val.sys_fee,
sub_shares: val.sub_shares,
..Default::default()
};

match TransactionKind::from_str(&val.kind) {
Ok(TransactionKind::Award)
| Ok(TransactionKind::Topup)
| Ok(TransactionKind::Sponsor)
| Ok(TransactionKind::Subscribe) => rt.payer = to.with_option(Some(val.uid)),
_ => {}
}

for v in val._fields {
match v.as_str() {
"sub_payee" => rt.sub_payee = to.with_option(val.sub_payee),
Expand Down
Loading

0 comments on commit b53159b

Please sign in to comment.