Skip to content

Commit

Permalink
add impl
Browse files Browse the repository at this point in the history
  • Loading branch information
juanbono committed Jan 15, 2024
1 parent 01f45c3 commit f533942
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,12 @@ impl<G: L1GasPriceProvider + Send + Sync + 'static> ZksNamespaceT for ZksNamespa
}

fn get_native_token_address(&self) -> BoxFuture<Result<Address>> {
todo!()
let self_ = self.clone();
Box::pin(async move {
self_
.get_native_token_address_impl()
.map_err(into_jsrpc_error)
})
}

fn get_miniblock_range(&self, batch: L1BatchNumber) -> BoxFuture<Result<Option<(U64, U64)>>> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ impl<G: L1GasPriceProvider + Send + Sync + 'static> ZksNamespaceServer for ZksNa
}

async fn get_native_token_address(&self) -> RpcResult<Address> {
todo!()
self.get_native_token_address_impl()
.map_err(into_jsrpc_error)
}

async fn get_testnet_paymaster(&self) -> RpcResult<Option<Address>> {
Expand Down
27 changes: 21 additions & 6 deletions core/lib/zksync_core/src/api_server/web3/namespaces/zks.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{collections::HashMap, convert::TryInto};
use std::{collections::HashMap, convert::TryInto, fs::File, io::BufReader, str::FromStr};

use bigdecimal::{BigDecimal, Zero};
use zksync_dal::StorageProcessor;
Expand All @@ -15,9 +15,9 @@ use zksync_types::{
l2_to_l1_log::L2ToL1Log,
tokens::ETHEREUM_ADDRESS,
transaction_request::CallRequest,
AccountTreeId, L1BatchNumber, MiniblockNumber, StorageKey, Transaction, L1_MESSENGER_ADDRESS,
L2_ETH_TOKEN_ADDRESS, MAX_GAS_PER_PUBDATA_BYTE, REQUIRED_L1_TO_L2_GAS_PER_PUBDATA_BYTE, U256,
U64,
AccountTreeId, L1BatchNumber, MiniblockNumber, StorageKey, Transaction, H160,
L1_MESSENGER_ADDRESS, L2_ETH_TOKEN_ADDRESS, MAX_GAS_PER_PUBDATA_BYTE,
REQUIRED_L1_TO_L2_GAS_PER_PUBDATA_BYTE, U256, U64,
};
use zksync_utils::{address_to_h256, ratio_to_big_decimal_normalized};
use zksync_web3_decl::{
Expand Down Expand Up @@ -126,8 +126,23 @@ impl<G: L1GasPriceProvider> ZksNamespace<G> {
}

#[tracing::instrument(skip_all)]
pub fn get_native_token_address_impl(&self) -> Address {
todo!()
pub fn get_native_token_address_impl(&self) -> Result<Address, Web3Error> {
const METHOD_NAME: &str = "get_native_token_address";
const NATIVE_ERC20_FILE_PATH: &str = "etc/tokens/native_erc20.json";

// read the address from the native_erc20.json file.
// in the future it should be read from .init.env file
let native_erc20_file =
File::open(NATIVE_ERC20_FILE_PATH).map_err(|err| internal_error(METHOD_NAME, err))?;
let native_erc20_json: serde_json::Value =
serde_json::from_reader(BufReader::new(native_erc20_file))
.map_err(|err| internal_error(METHOD_NAME, err))?;

let native_erc20_address = native_erc20_json["address"]
.as_str()
.ok_or_else(|| internal_error(METHOD_NAME, "address not found in json"))?;

H160::from_str(native_erc20_address).map_err(|err| internal_error(METHOD_NAME, err))
}

#[tracing::instrument(skip(self))]
Expand Down

0 comments on commit f533942

Please sign in to comment.