Skip to content

Commit

Permalink
Optimized call for balance. Removed duplicated RPCs, one call instead…
Browse files Browse the repository at this point in the history
… of few for getting balance
  • Loading branch information
scx1332 authored and kamirr committed Jul 9, 2024
1 parent c69c131 commit 3475ff2
Show file tree
Hide file tree
Showing 16 changed files with 447 additions and 1,462 deletions.
20 changes: 10 additions & 10 deletions Cargo.lock

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

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,8 @@ members = [
# diesel 1.4.* supports up to 0.23.0, but sqlx 0.5.9 requires 0.22.0
# sqlx 0.5.10 need 0.23.2, so 0.5.9 is last version possible
derive_more = "0.99.11"
erc20_payment_lib = { git = "https://github.com/golemfactory/erc20_payment_lib", rev = "1009a0272de4ea31b50c262e87627bd0032352bf" }
erc20_processor = { git = "https://github.com/golemfactory/erc20_payment_lib", rev = "1009a0272de4ea31b50c262e87627bd0032352bf" }
erc20_payment_lib = { git = "https://github.com/golemfactory/erc20_payment_lib", rev = "4f29f90faa31739ff86fe9ea7481e581c17c3593" }
erc20_processor = { git = "https://github.com/golemfactory/erc20_payment_lib", rev = "4f29f90faa31739ff86fe9ea7481e581c17c3593" }
#erc20_payment_lib = { path = "../../payments/erc20_payment_lib/crates/erc20_payment_lib" }
#erc20_processor = { path = "../../payments/erc20_payment_lib" }
#erc20_payment_lib = { version = "=0.4.1" }
Expand Down
39 changes: 9 additions & 30 deletions core/model/src/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,38 +125,17 @@ impl GetAccountBalance {
}
}

impl RpcMessage for GetAccountBalance {
const ID: &'static str = "GetAccountBalance";
type Item = BigDecimal;
type Error = GenericError;
}

// ************************** GET ACCOUNT GAS BALANCE **************************

#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct GetAccountGasBalance {
address: String,
platform: String,
}

impl GetAccountGasBalance {
pub fn new(address: String, platform: String) -> Self {
Self { address, platform }
}
}

impl GetAccountGasBalance {
pub fn address(&self) -> String {
self.address.clone()
}
pub fn platform(&self) -> String {
self.platform.clone()
}
#[derive(Clone, Debug, Default, Serialize, Deserialize)]
pub struct GetAccountBalanceResult {
pub gas_details: Option<GasDetails>,
pub token_balance: BigDecimal,
pub block_number: u64,
pub block_datetime: DateTime<Utc>,
}

impl RpcMessage for GetAccountGasBalance {
const ID: &'static str = "GetAccountGasBalance";
type Item = Option<GasDetails>;
impl RpcMessage for GetAccountBalance {
const ID: &'static str = "GetAccountBalance";
type Item = GetAccountBalanceResult;
type Error = GenericError;
}

Expand Down
2 changes: 2 additions & 0 deletions core/model/src/payment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,8 @@ pub mod local {
pub network: String,
pub token: String,
pub gas: Option<GasDetails>,
pub block_number: u64,
pub block_datetime: DateTime<Utc>,
}

#[derive(Clone, Debug, Serialize, Deserialize)]
Expand Down
3 changes: 0 additions & 3 deletions core/payment-driver/base/src/bus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,6 @@ pub async fn bind_service<Driver: PaymentDriver + 'static>(
.bind_with_processor(
move |_, dr, c, m| async move { dr.get_account_balance( c, m).await }
)
.bind_with_processor(
move |_, dr, c, m| async move { dr.get_account_gas_balance( c, m).await }
)
.bind_with_processor(
move |_, dr, c, m| async move { dr.init( c, m).await }
)
Expand Down
9 changes: 1 addition & 8 deletions core/payment-driver/base/src/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,7 @@ pub trait PaymentDriver {
&self,
caller: String,
msg: GetAccountBalance,
) -> Result<BigDecimal, GenericError>;

async fn get_account_gas_balance(
&self,

_caller: String,
msg: GetAccountGasBalance,
) -> Result<Option<GasDetails>, GenericError>;
) -> Result<GetAccountBalanceResult, GenericError>;

async fn enter(&self, caller: String, msg: Enter) -> Result<String, GenericError>;

Expand Down
6 changes: 2 additions & 4 deletions core/payment-driver/dummy/src/service.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
use crate::{DRIVER_NAME, NETWORK_NAME, PLATFORM_NAME, TOKEN_NAME};
use bigdecimal::BigDecimal;
use chrono::Utc;
use maplit::hashmap;
use std::str::FromStr;
use uuid::Uuid;
use ya_client_model::payment::{DriverDetails, Network};
use ya_core_model::driver::*;
Expand Down Expand Up @@ -76,10 +74,10 @@ async fn get_account_balance(
_db: (),
_caller: String,
msg: GetAccountBalance,
) -> Result<BigDecimal, GenericError> {
) -> Result<GetAccountBalanceResult, GenericError> {
log::info!("get account balance: {:?}", msg);

BigDecimal::from_str("1000000000000000000000000").map_err(GenericError::new)
Ok(GetAccountBalanceResult::default())
}

async fn schedule_payment(
Expand Down
4 changes: 3 additions & 1 deletion core/payment-driver/erc20/config-payments.toml
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,12 @@ currency-symbol = "tETH"
priority-fee = 0.000001
max-fee-per-gas = 10.0
transaction-timeout = 100
wrapper-contract = { address = "0xE168bCa171ccf51066E2106d8955BF22705a6905" }
token = { address = "0x8888888815bf4DB87e57B609A50f938311EEd068", symbol = "tGLM" }
multi-contract = { address = "0xAaAAAaA00E1841A63342db7188abA84BDeE236c7", max-at-once = 10 }
mint-contract = { address = "0xFACe100969FF47EB58d2CF603321B581A84bcEaC", max-glm-allowed = 400 }
distributor-contract = { address = "0xb7Fb99e86f93dc3047A12932052236d853065173" }
faucet-client = { max-eth-allowed = 0.009, faucet-srv = "_holesky-faucet._tcp", faucet-host = "faucet.testnet.golem.network", faucet-lookup-domain = "dev.golem.network", faucet-srv-port = 4002 }
lock-contract = { address = "0xA3D86ebF4FAC94114526f4D09C3fA093898347a6" }
confirmation-blocks = 0
block-explorer-url = "https://holesky.etherscan.io"
external-source-check-interval = 300
Expand Down Expand Up @@ -174,6 +175,7 @@ priority-fee = 30.111
max-fee-per-gas = 500.0
transaction-timeout = 100
token = { address = "0x0B220b82F3eA3B7F6d9A1D8ab58930C064A2b5Bf", symbol = "GLM" }
wrapper-contract = { address = "0xbB6aad747990BB6F7f56851556A3277e474C656a" }
multi-contract = { address = "0x50100d4faf5f3b09987dea36dc2eddd57a3e561b", max-at-once = 10 }
confirmation-blocks = 1
block-explorer-url = "https://polygonscan.com"
Expand Down
Loading

0 comments on commit 3475ff2

Please sign in to comment.