Skip to content

Commit 6b98c50

Browse files
committed
chore: cleaning
1 parent eb009c9 commit 6b98c50

3 files changed

Lines changed: 15 additions & 45 deletions

File tree

src/models/account_enums.rs

Lines changed: 4 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -85,36 +85,15 @@ pub struct Account {
8585
pub base64url: Address,
8686
}
8787

88-
impl Account {
89-
pub fn from_wc_and_address(workchain_id: i32, address: String) -> Self {
90-
let account = format!("{workchain_id}:{address}");
91-
let base64url = match StdAddr::from_str(&account) {
92-
Ok(account) => Address(account.display_base64_url(true).to_string()),
93-
Err(error) => {
94-
tracing::error!(
95-
workchain_id,
96-
address,
97-
?error,
98-
"failed to format account as base64url"
99-
);
100-
Address(account)
101-
}
102-
};
103-
104-
Self {
105-
workchain_id,
106-
hex: Address(address),
107-
base64url,
108-
}
109-
}
110-
}
111-
11288
impl From<AddressDb> for Account {
11389
fn from(a: AddressDb) -> Self {
90+
let account = StdAddr::from_str(&format!("{}:{}", a.workchain_id, a.hex)).unwrap();
91+
let base64url = Address(account.display_base64_url(true).to_string());
92+
11493
Self {
11594
workchain_id: a.workchain_id,
11695
hex: Address(a.hex),
117-
base64url: Address(a.base64url),
96+
base64url,
11897
}
11998
}
12099
}

src/sqlx_client/last_key_blocks.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@ use crate::sqlx_client::*;
55

66
impl SqlxClient {
77
pub async fn create_last_key_block(&self, block_id: &str) -> Result<()> {
8-
sqlx::query(r#"INSERT INTO last_key_blocks (block_id) VALUES ($1) ON CONFLICT DO NOTHING"#)
9-
.bind(block_id)
10-
.execute(&self.pool)
11-
.await?;
8+
sqlx::query!(
9+
r#"INSERT INTO last_key_blocks (block_id) VALUES ($1)"#,
10+
block_id
11+
)
12+
.execute(&self.pool)
13+
.await?;
1214

1315
Ok(())
1416
}

src/utils/token_wallet.rs

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,8 @@ pub fn prepare_token_transfer(
4444
TokenWalletVersion::Tip3 => {
4545
use crate::utils::token_wallets;
4646
let function = token_wallets::transfer();
47-
let amount = to_uint128(&tokens, "amount")?;
4847
let tokens = [
49-
AbiValue::uint(128, amount).named("amount"),
48+
AbiValue::uint(128, tokens.to_u128().unwrap()).named("amount"),
5049
AbiValue::address(destination).named("recipient"),
5150
AbiValue::uint(128, INITIAL_BALANCE).named("deployWalletValue"),
5251
AbiValue::address(send_gas_to).named("remainingGasTo"),
@@ -87,9 +86,8 @@ pub fn prepare_token_burn(
8786
use crate::utils::token_wallets;
8887

8988
let function = token_wallets::burnable::burn();
90-
let amount = to_uint128(&tokens, "amount")?;
9189
let tokens = [
92-
AbiValue::uint(128, amount).named("amount"),
90+
AbiValue::uint(128, tokens.to_u128().unwrap()).named("amount"),
9391
AbiValue::address(send_gas_to).named("remainingGasTo"),
9492
AbiValue::address(callback_to).named("callbackTo"),
9593
AbiValue::Cell(payload).named("payload"),
@@ -127,12 +125,11 @@ pub fn prepare_token_mint(
127125
TokenWalletVersion::Tip3 => {
128126
use crate::utils::token_wallets;
129127
let function = token_wallets::mint();
130-
let amount = to_uint128(&tokens, "amount")?;
131-
let deploy_wallet_value = to_uint128(&deploy_wallet_value, "deployWalletValue")?;
132128
let tokens = [
133-
AbiValue::uint(128, amount).named("amount"),
129+
AbiValue::uint(128, tokens.to_u128().unwrap()).named("amount"),
134130
AbiValue::address(recipient).named("recipient"),
135-
AbiValue::uint(128, deploy_wallet_value).named("deployWalletValue"),
131+
AbiValue::uint(128, deploy_wallet_value.to_u128().unwrap())
132+
.named("deployWalletValue"),
136133
AbiValue::address(send_gas_to).named("remainingGasTo"),
137134
AbiValue::Bool(notify).named("notify"),
138135
AbiValue::Cell(payload).named("payload"),
@@ -231,16 +228,8 @@ pub fn get_root_token_version(
231228
Ok(version)
232229
}
233230

234-
fn to_uint128(value: &BigUint, field: &'static str) -> Result<u128> {
235-
value
236-
.to_u128()
237-
.ok_or_else(|| TokenWalletError::InvalidUint128(field).into())
238-
}
239-
240231
#[derive(thiserror::Error, Debug)]
241232
enum TokenWalletError {
242233
#[error("not supported OldTip3v4 tokens")]
243234
NotSupported,
244-
#[error("{0} does not fit into uint128")]
245-
InvalidUint128(&'static str),
246235
}

0 commit comments

Comments
 (0)