Skip to content

Commit

Permalink
fix: fixing deposit id string
Browse files Browse the repository at this point in the history
  • Loading branch information
scx1332 committed Apr 22, 2024
1 parent 0ac4875 commit 139438d
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 8 deletions.
2 changes: 1 addition & 1 deletion crates/erc20_payment_lib/src/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ pub struct TransferArgs {
pub amount: U256,
pub payment_id: String,
pub deadline: Option<DateTime<Utc>>,
pub deposit_id: Option<String>,
pub deposit_id: Option<DepositId>,
}

impl PaymentRuntime {
Expand Down
5 changes: 3 additions & 2 deletions crates/erc20_payment_lib/src/server/web.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use actix_web::http::{header, StatusCode};
use actix_web::web::Data;
use actix_web::{web, HttpRequest, HttpResponse, Responder, Scope};
use chrono::{DateTime, Utc};
use erc20_payment_lib_common::model::DepositId;
use erc20_payment_lib_common::ops::*;
use erc20_payment_lib_common::utils::datetime_from_u256_timestamp;
use erc20_payment_lib_common::{export_metrics_to_prometheus, FaucetData};
Expand Down Expand Up @@ -582,7 +583,7 @@ struct TransactionRequest {
chain: i64,
due_date: Option<String>,
payment_id: Option<String>,
deposit_id: Option<String>,
deposit_id: Option<DepositId>,
}

async fn new_transfer(
Expand Down Expand Up @@ -632,7 +633,7 @@ async fn new_transfer(
amount: U256::from_dec_str(&new_transfer.amount).unwrap(),
payment_id,
deadline: due_date,
deposit_id: new_transfer.deposit_id.clone(),
deposit_id: new_transfer.deposit_id,
};

let account = match data
Expand Down
6 changes: 3 additions & 3 deletions crates/erc20_payment_lib/src/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::utils::{datetime_from_u256_timestamp, ConversionError, StringConvExt,
use crate::{err_custom_create, err_from};
use chrono::Utc;
use erc20_payment_lib_common::model::{
ChainTransferDbObj, ChainTxDbObj, TokenTransferDbObj, TxDbObj,
ChainTransferDbObj, ChainTxDbObj, DepositId, TokenTransferDbObj, TxDbObj,
};
use erc20_payment_lib_common::CantSignContent;
use erc20_payment_lib_common::{
Expand Down Expand Up @@ -119,7 +119,7 @@ pub fn create_token_transfer(
payment_id: Option<&str>,
token_addr: Option<Address>,
token_amount: U256,
deposit_id: Option<String>,
deposit_id: Option<DepositId>,
) -> TokenTransferDbObj {
TokenTransferDbObj {
id: 0,
Expand All @@ -129,7 +129,7 @@ pub fn create_token_transfer(
chain_id,
token_addr: token_addr.map(|addr| format!("{addr:#x}")),
token_amount: token_amount.to_string(),
deposit_id,
deposit_id: deposit_id.map(|d| d.to_db_string()),
deposit_finish: 0,
create_date: Utc::now(),
tx_id: None,
Expand Down
28 changes: 26 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,14 @@ use erc20_payment_lib::runtime::{
use erc20_payment_lib::server::web::{runtime_web_scope, ServerData};
use erc20_payment_lib::setup::PaymentSetup;
use erc20_payment_lib_common::init_metrics;
use erc20_payment_lib_common::model::TokenTransferDbObj;
use erc20_payment_lib_common::model::{DepositId, TokenTransferDbObj};
use erc20_payment_lib_common::utils::{DecimalConvExt, StringConvExt};
use erc20_payment_lib_extra::{account_balance, generate_test_payments};
use rust_decimal::Decimal;
use std::sync::Arc;
use structopt::StructOpt;
use tokio::sync::{broadcast, Mutex};
use web3::types::U256;

async fn main_internal() -> Result<(), PaymentError> {
dotenv::dotenv().ok();
Expand Down Expand Up @@ -552,6 +553,29 @@ async fn main_internal() -> Result<(), PaymentError> {
};
let amount_decimal = amount_str.to_eth().unwrap();

let deposit_id_str = if let Some(deposit_id) = single_transfer_options.deposit_id {
let lock_contract =
if let Some(lock_contract) = single_transfer_options.lock_contract {
lock_contract
} else {
chain_cfg
.lock_contract
.clone()
.map(|c| c.address)
.expect("No lock contract found")
};

Some(
DepositId {
deposit_id: U256::from_str_radix(&deposit_id, 16)
.map_err(|e| err_custom_create!("Invalid deposit id: {}", e))?,
lock_address: lock_contract,
}
.to_db_string(),
)
} else {
None
};
let mut tt = insert_token_transfer_with_deposit_check(
&conn.clone().unwrap(),
&TokenTransferDbObj {
Expand All @@ -562,7 +586,7 @@ async fn main_internal() -> Result<(), PaymentError> {
chain_id: chain_cfg.chain_id,
token_addr: token,
token_amount: amount_str,
deposit_id: single_transfer_options.deposit_id,
deposit_id: deposit_id_str,
deposit_finish: 0,
create_date: Default::default(),
tx_id: None,
Expand Down
6 changes: 6 additions & 0 deletions src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,12 @@ pub struct TransferOptions {

#[structopt(long = "deposit-id")]
pub deposit_id: Option<String>,

#[structopt(
long = "lock-contract",
help = "Lock contract address (if not specified, it will be taken from config)"
)]
pub lock_contract: Option<Address>,
}

#[derive(StructOpt)]
Expand Down

0 comments on commit 139438d

Please sign in to comment.