forked from matter-labs/zksync
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1777 from matter-labs/perekopskiy-zks-753-impleme…
…nt-web3-methods-with-logs Implement web3 methods with logs
- Loading branch information
Showing
42 changed files
with
4,325 additions
and
438 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
[package] | ||
name = "mint_nft_nonce_migration" | ||
version = "1.0.0" | ||
edition = "2018" | ||
authors = ["The Matter Labs Team <[email protected]>"] | ||
homepage = "https://zksync.io/" | ||
repository = "https://github.com/matter-labs/zksync" | ||
license = "Apache-2.0" | ||
keywords = ["blockchain", "zksync"] | ||
categories = ["cryptography"] | ||
publish = false # We don't want to publish our binaries. | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
zksync_storage = { path = "../../lib/storage", version = "1.0" } | ||
zksync_config = { path = "../../lib/config", version = "1.0" } | ||
tokio = { version = "0.2", features = ["full"] } | ||
anyhow = "1.0" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
use zksync_storage::StorageProcessor; | ||
|
||
#[tokio::main] | ||
async fn main() -> anyhow::Result<()> { | ||
let mut storage = StorageProcessor::establish_connection().await?; | ||
storage | ||
.chain() | ||
.state_schema() | ||
.mint_nft_updates_set_nonces() | ||
.await?; | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
// Built-in uses | ||
use std::convert::TryInto; | ||
// External uses | ||
use jsonrpc_core::{Error, Result}; | ||
use num::BigUint; | ||
// Workspace uses | ||
use zksync_storage::StorageProcessor; | ||
// Local uses | ||
use super::types::{BlockNumber, Bytes, CommonLogData, Log, Transaction, TxData, H160, H256, U256}; | ||
|
||
pub fn u256_from_biguint(number: BigUint) -> U256 { | ||
U256::from_dec_str(&number.to_string()).unwrap() | ||
} | ||
|
||
pub async fn resolve_block_number( | ||
storage: &mut StorageProcessor<'_>, | ||
number: Option<BlockNumber>, | ||
) -> Result<Option<zksync_types::BlockNumber>> { | ||
let last_saved_block = storage | ||
.chain() | ||
.block_schema() | ||
.get_last_saved_block() | ||
.await | ||
.map_err(|_| Error::internal_error())?; | ||
|
||
let number = match number { | ||
Some(number) => number, | ||
None => { | ||
return Ok(Some(last_saved_block)); | ||
} | ||
}; | ||
|
||
let number = match number { | ||
BlockNumber::Earliest => zksync_types::BlockNumber(0), | ||
BlockNumber::Committed => storage | ||
.chain() | ||
.block_schema() | ||
.get_last_committed_confirmed_block() | ||
.await | ||
.map_err(|_| Error::internal_error())?, | ||
BlockNumber::Finalized => storage | ||
.chain() | ||
.block_schema() | ||
.get_last_verified_confirmed_block() | ||
.await | ||
.map_err(|_| Error::internal_error())?, | ||
BlockNumber::Latest | BlockNumber::Pending => last_saved_block, | ||
BlockNumber::Number(number) => { | ||
if number.as_u64() > last_saved_block.0 as u64 { | ||
return Ok(None); | ||
} | ||
// Unwrap can be safely used because `number` is not greater than `last_saved_block` | ||
// which is `u32` variable. | ||
zksync_types::BlockNumber(number.as_u64().try_into().unwrap()) | ||
} | ||
}; | ||
Ok(Some(number)) | ||
} | ||
|
||
pub fn transaction_from_tx_data(tx: TxData) -> Transaction { | ||
Transaction { | ||
hash: tx.tx_hash, | ||
nonce: tx.nonce.into(), | ||
block_hash: Some(tx.block_hash), | ||
block_number: Some(tx.block_number.into()), | ||
transaction_index: tx.block_index.map(Into::into), | ||
from: Some(tx.from), | ||
to: tx.to, | ||
value: 0.into(), | ||
gas_price: 0.into(), | ||
gas: 0.into(), | ||
input: Vec::new().into(), | ||
v: None, | ||
r: None, | ||
s: None, | ||
raw: None, | ||
transaction_type: None, | ||
access_list: None, | ||
} | ||
} | ||
|
||
pub fn log( | ||
address: H160, | ||
topic: H256, | ||
data: Bytes, | ||
common_data: CommonLogData, | ||
transaction_log_index: U256, | ||
) -> Log { | ||
Log { | ||
address, | ||
topics: vec![topic], | ||
data, | ||
block_hash: common_data.block_hash, | ||
block_number: common_data.block_number, | ||
transaction_hash: Some(common_data.transaction_hash), | ||
transaction_index: common_data.transaction_index, | ||
log_index: None, | ||
transaction_log_index: Some(transaction_log_index), | ||
log_type: None, | ||
removed: Some(false), | ||
} | ||
} |
Oops, something went wrong.