Skip to content

Commit

Permalink
Cleanup API and docs
Browse files Browse the repository at this point in the history
  • Loading branch information
scx1332 authored Feb 6, 2024
1 parent c40d9fc commit 288001d
Show file tree
Hide file tree
Showing 34 changed files with 614 additions and 514 deletions.
1,008 changes: 553 additions & 455 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 0 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ actix-web = { version = "4", default-features = false, features = [
] }
actix-web-actors = { version = "4", default-features = false }
anyhow = "1"
async-trait = "0.1"
awc = { version = "3.1", features = ["rustls"] }
base64 = "0.21"
bollard = "0.14"
Expand Down Expand Up @@ -82,7 +81,6 @@ actix-cors = { workspace = true }
actix-files = { workspace = true }
actix-web = { workspace = true }
anyhow = { workspace = true }
async-trait = { workspace = true }
awc = { workspace = true }
chrono = { workspace = true }
csv = { workspace = true }
Expand Down
1 change: 0 additions & 1 deletion crates/erc20_payment_lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ actix = { workspace = true }
actix-files = { workspace = true }
actix-web = { workspace = true }
actix-web-actors = { workspace = true }
async-trait = { workspace = true }
awc = { workspace = true }
chrono = { workspace = true, features = ["serde"] }
dotenv = { workspace = true }
Expand Down
6 changes: 3 additions & 3 deletions crates/erc20_payment_lib/src/eth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pub struct GetBalanceResult {
pub block_number: u64,
}

pub async fn get_deposit_balance(
pub(crate) async fn get_deposit_balance(
web3: Arc<Web3RpcPool>,
lock_address: Address,
address: Address,
Expand Down Expand Up @@ -262,7 +262,7 @@ pub fn average_block_time(web3: &Web3RpcPool) -> Option<u32> {
}
}

pub async fn get_transaction_count(
pub(crate) async fn get_transaction_count(
address: Address,
web3: Arc<Web3RpcPool>,
pending: bool,
Expand All @@ -277,7 +277,7 @@ pub async fn get_transaction_count(
Ok(nonce.as_u64())
}

pub fn get_eth_addr_from_secret(secret_key: &SecretKey) -> Address {
pub(crate) fn get_eth_addr_from_secret(secret_key: &SecretKey) -> Address {
Address::from_slice(
&Keccak256::digest(
&PublicKey::from_secret_key(&secp256k1::Secp256k1::new(), secret_key)
Expand Down
17 changes: 8 additions & 9 deletions crates/erc20_payment_lib/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
mod account_balance;
pub mod config;
pub mod contracts;
mod contracts;
pub mod db;
pub mod eth;
pub mod faucet_client;
pub mod misc;
pub mod multi;
mod multi;
pub mod runtime;
pub mod service;
pub mod setup;
pub mod transaction;
//@todo - add feature
pub mod account_balance;
pub mod faucet_client;
mod sender;
pub mod server;
pub mod service;
pub mod setup;
pub mod signer;
pub mod transaction;

pub use erc20_payment_lib_common::*;
use erc20_payment_lib_common::*;
pub use sender::process_allowance;
2 changes: 1 addition & 1 deletion crates/erc20_payment_lib/src/multi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use web3::types::{Address, U256};
use crate::err_custom_create;
use crate::error::PaymentError;

pub fn pack_transfers_for_multi_contract(
pub(crate) fn pack_transfers_for_multi_contract(
receivers: Vec<Address>,
amounts: Vec<U256>,
) -> Result<(Vec<[u8; 32]>, U256), PaymentError> {
Expand Down
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 @@ -463,7 +463,7 @@ impl PaymentRuntime {
let notify_ = notify.clone();
let extra_testing_ = payment_runtime_args.extra_testing.clone();
let config_ = payment_runtime_args.config.clone();
let jh = tokio::spawn(async move {
let jh = tokio::task::spawn(async move {
if let Some(balance_check_loop) =
extra_testing_.clone().and_then(|e| e.balance_check_loop)
{
Expand Down
16 changes: 9 additions & 7 deletions crates/erc20_payment_lib/src/signer.rs
Original file line number Diff line number Diff line change
@@ -1,25 +1,27 @@
use crate::contracts::DUMMY_RPC_PROVIDER;
use crate::eth::get_eth_addr_from_secret;
use async_trait::async_trait;
use secp256k1::SecretKey;
use std::future::Future;
use web3::types::{SignedTransaction, TransactionParameters, H160};

#[derive(Debug)]
pub struct SignerError {
pub message: String,
}

#[async_trait]
pub trait Signer {
pub trait Signer: Send + Sync {
/// Check if signer can sign transaction for given public address
async fn check_if_sign_possible(&self, pub_address: H160) -> Result<(), SignerError>;
fn check_if_sign_possible(
&self,
pub_address: H160,
) -> impl Future<Output = Result<(), SignerError>> + std::marker::Send;

/// Sign transaction for given public address (look at PrivateKeySigner for example)
async fn sign(
fn sign(
&self,
pub_address: H160,
tp: TransactionParameters,
) -> Result<SignedTransaction, SignerError>;
) -> impl Future<Output = Result<SignedTransaction, SignerError>> + std::marker::Send;
}

/// PrivateKeySigner is implementation of Signer trait that stores private keys in memory and use
Expand All @@ -42,7 +44,7 @@ impl PrivateKeySigner {
})
}
}
#[async_trait]

impl Signer for PrivateKeySigner {
async fn check_if_sign_possible(&self, pub_address: H160) -> Result<(), SignerError> {
self.get_private_key(pub_address)?;
Expand Down
1 change: 0 additions & 1 deletion crates/erc20_payment_lib_common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ license = "MIT"
[dependencies]
actix-files = { workspace = true }
actix-web = { workspace = true }
async-trait = { workspace = true }
awc = { workspace = true }
chrono = { workspace = true, features = ["serde"] }
dotenv = { workspace = true }
Expand Down
2 changes: 1 addition & 1 deletion crates/erc20_payment_lib_extra/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ edition = "2021"
license = "MIT"

[dependencies]
async-trait = { workspace = true }
web3 = { workspace = true }
tokio = { workspace = true }
secp256k1 = { workspace = true }
Expand Down Expand Up @@ -36,4 +35,5 @@ serde_json = { workspace = true }
uuid = { workspace = true }

erc20_payment_lib = { path = "../erc20_payment_lib", version = "0.3.20" }
erc20_payment_lib_common = { path = "../erc20_payment_lib_common", version = "0.3.20" }
erc20_rpc_pool = { path = "../erc20_rpc_pool", version = "0.3.20" }
7 changes: 4 additions & 3 deletions crates/erc20_payment_lib_extra/src/account_balance.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use erc20_payment_lib::error::PaymentError;
use erc20_payment_lib::config;
use erc20_payment_lib::eth::get_balance;
use erc20_payment_lib::setup::PaymentSetup;
use erc20_payment_lib::utils::U256ConvExt;
use erc20_payment_lib::{config, err_custom_create};
use erc20_payment_lib_common::err_custom_create;
use erc20_payment_lib_common::error::*;
use erc20_payment_lib_common::utils::U256ConvExt;
use futures_util::{stream, StreamExt};
use serde::{Deserialize, Serialize};
use std::cell::RefCell;
Expand Down
6 changes: 4 additions & 2 deletions crates/erc20_payment_lib_extra/src/generate_transactions.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
use csv::WriterBuilder;
use erc20_payment_lib::db::ops::insert_token_transfer;
use erc20_payment_lib::error::*;
use erc20_payment_lib::misc::{
create_test_amount_pool, generate_transaction_batch, ordered_address_pool, random_address_pool,
};
use erc20_payment_lib::{config, err_create, err_custom_create, err_from};
use erc20_payment_lib_common::error::*;

use erc20_payment_lib::config;
use erc20_payment_lib_common::*;
use futures_util::StreamExt;
use futures_util::TryStreamExt;
use sqlx::SqlitePool;
Expand Down
1 change: 0 additions & 1 deletion crates/erc20_payment_lib_test/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ license = "MIT"
[dependencies]
anyhow = { workspace = true }
bollard = { workspace = true }
async-trait = { workspace = true }
web3 = { workspace = true }
tokio = { workspace = true }
secp256k1 = { workspace = true }
Expand Down
2 changes: 1 addition & 1 deletion crates/erc20_payment_lib_test/src/blockchain_setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use anyhow::anyhow;
use bollard::container::StopContainerOptions;
use bollard::models::{PortBinding, PortMap};
use bollard::{container, image, service::HostConfig, Docker};
use erc20_payment_lib::utils::get_env_bool_value;
use erc20_payment_lib_common::utils::*;
use futures_util::TryStreamExt;
use lazy_static::lazy_static;
use std::collections::HashMap;
Expand Down
2 changes: 1 addition & 1 deletion crates/erc20_payment_lib_test/src/config_setup.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use erc20_payment_lib::config;
use erc20_payment_lib::config::{Chain, Config, Engine, MultiContractSettings, RpcSettings, Token};
use erc20_payment_lib::db::create_sqlite_connection;
use erc20_payment_lib::utils::get_env_bool_value;
use erc20_payment_lib_common::utils::get_env_bool_value;
use rust_decimal::prelude::FromPrimitive;
use rust_decimal::Decimal;
use sqlx::SqlitePool;
Expand Down
5 changes: 3 additions & 2 deletions crates/erc20_payment_lib_test/src/durabily2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ use crate::{
};
use erc20_payment_lib::config::AdditionalOptions;
use erc20_payment_lib::db::ops::get_transfer_stats;
use erc20_payment_lib::error::PaymentError;

use erc20_payment_lib::misc::load_private_keys;
use erc20_payment_lib::runtime::{PaymentRuntime, PaymentRuntimeArgs};
use erc20_payment_lib::signer::PrivateKeySigner;
use erc20_payment_lib::utils::U256ConvExt;
use erc20_payment_lib_common::error::PaymentError;
use erc20_payment_lib_common::utils::U256ConvExt;
use erc20_payment_lib_common::DriverEvent;
use erc20_payment_lib_common::DriverEventContent::*;
use erc20_payment_lib_extra::{generate_test_payments, GenerateOptions};
Expand Down
2 changes: 1 addition & 1 deletion crates/erc20_payment_lib_test/src/get_balance.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::config_setup::create_default_config_setup;
use erc20_payment_lib::error::PaymentError;
use erc20_payment_lib_common::error::PaymentError;
use erc20_payment_lib_extra::{account_balance, BalanceOptions, BalanceResult};
use std::collections::BTreeMap;

Expand Down
4 changes: 2 additions & 2 deletions crates/erc20_payment_lib_test/src/multi_erc20_transfer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ use crate::{
};
use erc20_payment_lib::config::AdditionalOptions;
use erc20_payment_lib::db::ops::get_transfer_stats;
use erc20_payment_lib::error::PaymentError;
use erc20_payment_lib::misc::load_private_keys;
use erc20_payment_lib::runtime::{PaymentRuntime, PaymentRuntimeArgs};
use erc20_payment_lib::signer::PrivateKeySigner;
use erc20_payment_lib::utils::U256ConvExt;
use erc20_payment_lib_common::error::PaymentError;
use erc20_payment_lib_common::utils::U256ConvExt;
use erc20_payment_lib_common::DriverEvent;
use erc20_payment_lib_common::DriverEventContent::*;
use erc20_payment_lib_extra::{generate_test_payments, GenerateOptions};
Expand Down
1 change: 0 additions & 1 deletion crates/erc20_rpc_pool/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ license = "MIT"
actix-files = { workspace = true }
actix-web = { workspace = true }
anyhow = { workspace = true }
async-trait = { workspace = true }
awc = { workspace = true }
bollard = { workspace = true }
chrono = { workspace = true, features = ["serde"] }
Expand Down
1 change: 1 addition & 0 deletions crates/web3_test_proxy_client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ chrono = { workspace = true, features = ["serde"] }
tokio = { workspace = true }
web3 = { workspace = true }
erc20_payment_lib = { path = "../erc20_payment_lib", version = "0.3.20" }
erc20_payment_lib_common = { path = "../erc20_payment_lib_common", version = "0.3.20" }
2 changes: 1 addition & 1 deletion crates/web3_test_proxy_client/src/list_txs.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::{get_calls, JSONRPCResult};
use erc20_payment_lib::utils::U256ConvExt;
use erc20_payment_lib_common::utils::*;
use web3::types::U256;

/// List transactions captured by web3 proxy in human readable format
Expand Down
2 changes: 1 addition & 1 deletion src/actions/allocation_details.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use crate::options::CheckAllocationOptions;
use erc20_payment_lib::config::Config;
use erc20_payment_lib::error::PaymentError;
use erc20_payment_lib::runtime::allocation_details;
use erc20_payment_lib::setup::PaymentSetup;
use erc20_payment_lib_common::err_custom_create;
use erc20_payment_lib_common::error::PaymentError;

pub async fn allocation_details_local(
check_allocation_options: CheckAllocationOptions,
Expand Down
2 changes: 1 addition & 1 deletion src/actions/cancel_allocation.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use erc20_payment_lib::config::Config;
use erc20_payment_lib::error::PaymentError;
use erc20_payment_lib::runtime::{cancel_allocation, CancelAllocationOptionsInt};
use erc20_payment_lib::setup::PaymentSetup;
use erc20_payment_lib_common::err_custom_create;
use erc20_payment_lib_common::error::PaymentError;
use sqlx::SqlitePool;
use structopt::StructOpt;
use web3::types::Address;
Expand Down
2 changes: 1 addition & 1 deletion src/actions/check_rpc.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::options::CheckWeb3RpcOptions;
use erc20_payment_lib::config::Config;
use erc20_payment_lib::error::PaymentError;
use erc20_payment_lib_common::err_custom_create;
use erc20_payment_lib_common::error::PaymentError;
use erc20_rpc_pool::{
resolve_txt_record_to_string_array, Web3EndpointParams, Web3ExternalEndpointList, Web3RpcPool,
Web3RpcSingleParams,
Expand Down
2 changes: 1 addition & 1 deletion src/actions/make_allocation.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use erc20_payment_lib::config::Config;
use erc20_payment_lib::error::PaymentError;
use erc20_payment_lib::runtime::{make_allocation, MakeAllocationOptionsInt};
use erc20_payment_lib::setup::PaymentSetup;
use erc20_payment_lib_common::err_custom_create;
use erc20_payment_lib_common::error::PaymentError;
use rand::Rng;
use sqlx::SqlitePool;
use structopt::StructOpt;
Expand Down
2 changes: 1 addition & 1 deletion src/actions/withdraw.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use crate::options::WithdrawTokensOptions;
use erc20_payment_lib::config::Config;
use erc20_payment_lib::error::PaymentError;
use erc20_payment_lib::runtime::withdraw_funds;
use erc20_payment_lib::setup::PaymentSetup;
use erc20_payment_lib_common::err_custom_create;
use erc20_payment_lib_common::error::PaymentError;
use sqlx::SqlitePool;
use web3::types::Address;

Expand Down
8 changes: 5 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,16 @@ use erc20_payment_lib::db::ops::{
update_token_transfer, upsert_scan_info,
};
use erc20_payment_lib::signer::PrivateKeySigner;
use erc20_payment_lib_common::error::*;
use erc20_payment_lib_common::*;

use erc20_payment_lib::{
config, err_custom_create, err_from,
error::*,
config,
misc::{display_private_keys, load_private_keys},
process_allowance,
runtime::PaymentRuntime,
};

use std::env;
use std::str::FromStr;

Expand All @@ -41,9 +43,9 @@ use erc20_payment_lib::server::web::{runtime_web_scope, ServerData};
use erc20_payment_lib::service::transaction_from_chain_and_into_db;
use erc20_payment_lib::setup::PaymentSetup;
use erc20_payment_lib::transaction::{import_erc20_txs, ImportErc20TxsArgs};
use erc20_payment_lib::utils::{DecimalConvExt, StringConvExt, U256ConvExt};
use erc20_payment_lib_common::init_metrics;
use erc20_payment_lib_common::model::{ScanDao, TokenTransferDao};
use erc20_payment_lib_common::utils::{DecimalConvExt, StringConvExt, U256ConvExt};
use erc20_payment_lib_extra::{account_balance, generate_test_payments};
use rust_decimal::Decimal;
use std::sync::Arc;
Expand Down
8 changes: 4 additions & 4 deletions src/stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ use erc20_payment_lib::db::ops::{
get_chain_transfers_by_chain_id, get_chain_txs_by_chain_id, get_transfer_stats,
get_transfer_stats_from_blockchain, TransferStatsPart,
};
use erc20_payment_lib::error::ErrorBag;
use erc20_payment_lib::error::PaymentError;
use erc20_payment_lib::utils::{u256_eth_from_str, U256ConvExt};
use erc20_payment_lib::{err_custom_create, err_from};
use erc20_payment_lib_common::error::ErrorBag;
use erc20_payment_lib_common::error::PaymentError;
use erc20_payment_lib_common::model::ChainTxDao;
use erc20_payment_lib_common::utils::{u256_eth_from_str, U256ConvExt};
use erc20_payment_lib_common::{err_custom_create, err_from};
use itertools::Itertools;
use rust_decimal::Decimal;
use sqlx::{Executor, SqlitePool};
Expand Down
2 changes: 1 addition & 1 deletion tests/docker_01_basic/single_erc20_transfer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ use erc20_payment_lib::misc::load_private_keys;
use erc20_payment_lib::runtime::{verify_transaction, PaymentRuntime, PaymentRuntimeArgs};
use erc20_payment_lib::signer::PrivateKeySigner;
use erc20_payment_lib::transaction::create_token_transfer;
use erc20_payment_lib::utils::U256ConvExt;
use erc20_payment_lib_common::model::TxDao;
use erc20_payment_lib_common::utils::U256ConvExt;
use erc20_payment_lib_common::DriverEvent;
use erc20_payment_lib_common::DriverEventContent::*;
use erc20_payment_lib_test::*;
Expand Down
2 changes: 1 addition & 1 deletion tests/docker_01_basic/single_gas_transfer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use erc20_payment_lib::misc::load_private_keys;
use erc20_payment_lib::runtime::{PaymentRuntime, PaymentRuntimeArgs};
use erc20_payment_lib::signer::PrivateKeySigner;
use erc20_payment_lib::transaction::create_token_transfer;
use erc20_payment_lib::utils::U256ConvExt;
use erc20_payment_lib_common::utils::U256ConvExt;
use erc20_payment_lib_common::DriverEvent;
use erc20_payment_lib_common::DriverEventContent::*;
use erc20_payment_lib_test::*;
Expand Down
2 changes: 1 addition & 1 deletion tests/docker_02_errors/wrong_chain_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use erc20_payment_lib::misc::load_private_keys;
use erc20_payment_lib::runtime::{PaymentRuntime, PaymentRuntimeArgs};
use erc20_payment_lib::signer::PrivateKeySigner;
use erc20_payment_lib::transaction::create_token_transfer;
use erc20_payment_lib::utils::U256ConvExt;
use erc20_payment_lib_common::utils::U256ConvExt;
use erc20_payment_lib_common::DriverEventContent::*;
use erc20_payment_lib_common::{DriverEvent, TransactionFailedReason};
use erc20_payment_lib_test::*;
Expand Down
Loading

0 comments on commit 288001d

Please sign in to comment.