Skip to content

Commit

Permalink
Respect lock contract from argument (instead of config) (#3188)
Browse files Browse the repository at this point in the history
  • Loading branch information
scx1332 authored Apr 24, 2024
1 parent 0e63cb1 commit 0a7280a
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 26 deletions.
10 changes: 5 additions & 5 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 = "0e693a31ed62a293b7cf11f926a9b159f785107b" }
erc20_processor = { git = "https://github.com/golemfactory/erc20_payment_lib", rev = "0e693a31ed62a293b7cf11f926a9b159f785107b" }
erc20_payment_lib = { git = "https://github.com/golemfactory/erc20_payment_lib", rev = "9c9224dfdb0818d905876c241bb7b6312975f1cb" }
erc20_processor = { git = "https://github.com/golemfactory/erc20_payment_lib", rev = "9c9224dfdb0818d905876c241bb7b6312975f1cb" }
#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
6 changes: 3 additions & 3 deletions core/model/src/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ pub struct SchedulePayment {
sender: String,
recipient: String,
platform: String,
deposit_id: Option<String>,
deposit_id: Option<Deposit>,
due_date: DateTime<Utc>,
}

Expand All @@ -326,7 +326,7 @@ impl SchedulePayment {
sender: String,
recipient: String,
platform: String,
deposit_id: Option<String>,
deposit_id: Option<Deposit>,
due_date: DateTime<Utc>,
) -> SchedulePayment {
SchedulePayment {
Expand Down Expand Up @@ -355,7 +355,7 @@ impl SchedulePayment {
self.platform.clone()
}

pub fn deposit_id(&self) -> Option<String> {
pub fn deposit_id(&self) -> Option<Deposit> {
self.deposit_id.clone()
}

Expand Down
53 changes: 38 additions & 15 deletions core/payment-driver/erc20/src/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use chrono::{DateTime, Duration, Utc};
// Extrnal crates
use erc20_payment_lib::config::AdditionalOptions;
use erc20_payment_lib::faucet_client::faucet_donate;
use erc20_payment_lib::model::{TokenTransferDbObj, TxDbObj};
use erc20_payment_lib::model::{DepositId, TokenTransferDbObj, TxDbObj};
use erc20_payment_lib::runtime::{
PaymentRuntime, TransferArgs, TransferType, VerifyTransactionResult,
};
Expand Down Expand Up @@ -119,7 +119,7 @@ impl Erc20Driver {
amount: &BigDecimal,
network: &str,
deadline: Option<DateTime<Utc>>,
deposit_id: Option<String>,
deposit_id: Option<Deposit>,
) -> Result<String, GenericError> {
self.is_account_active(sender).await?;
let sender = H160::from_str(sender)
Expand All @@ -130,6 +130,21 @@ impl Erc20Driver {

let payment_id = Uuid::new_v4().to_simple().to_string();

let deposit_id = if let Some(deposit) = deposit_id {
Some(DepositId {
deposit_id: U256::from_str(&deposit.id).map_err(|err| {
GenericError::new(format!("Error when parsing deposit id {err:?}"))
})?,
lock_address: Address::from_str(&deposit.contract).map_err(|err| {
GenericError::new(format!(
"Error when parsing deposit contract address {err:?}"
))
})?,
})
} else {
None
};

self.payment_runtime
.transfer_guess_account(TransferArgs {
network: network.to_string(),
Expand Down Expand Up @@ -438,7 +453,13 @@ impl Erc20Driver {

let deposit_details = self
.payment_runtime
.deposit_details(network.to_string(), deposit_id, deposit_contract)
.deposit_details(
network.to_string(),
DepositId {
deposit_id,
lock_address: deposit_contract,
},
)
.await
.map_err(GenericError::new)?;
let deposit_balance = BigDecimal::new(
Expand Down Expand Up @@ -1079,18 +1100,20 @@ impl PaymentDriver for Erc20Driver {
H160::from_str(&msg.from).map_err(|e| {
GenericError::new(format!("`{}` address parsing error: {}", msg.from, e))
})?,
H160::from_str(&msg.deposit_contract).map_err(|e| {
GenericError::new(format!(
"`{}` address parsing error: {}",
msg.deposit_contract, e
))
})?,
U256::from_str(&msg.deposit_id).map_err(|e| {
GenericError::new(format!(
"`{}` deposit id parsing error: {}",
msg.deposit_id, e
))
})?,
DepositId {
lock_address: H160::from_str(&msg.deposit_contract).map_err(|e| {
GenericError::new(format!(
"`{}` address parsing error: {}",
msg.deposit_contract, e
))
})?,
deposit_id: U256::from_str(&msg.deposit_id).map_err(|e| {
GenericError::new(format!(
"`{}` deposit id parsing error: {}",
msg.deposit_id, e
))
})?,
},
)
.await
.map_err(|err| GenericError::new(format!("Error releasing deposit: {}", err)))?;
Expand Down
2 changes: 1 addition & 1 deletion core/payment/src/processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,7 @@ impl PaymentProcessor {
.get(msg.allocation_id.clone(), msg.payer_id)
.await?;
let deposit_id = if let AllocationStatus::Active(allocation) = allocation_status {
allocation.deposit.clone().map(|deposit| deposit.id)
allocation.deposit
} else {
None
};
Expand Down

0 comments on commit 0a7280a

Please sign in to comment.