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 branch 'dev' into dvush-new-sc
- Loading branch information
Showing
59 changed files
with
2,574 additions
and
273 deletions.
There are no files selected for viewing
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
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,44 @@ | ||
//! Helpers collection shared between the different API implementations. | ||
// Built-in uses | ||
|
||
// External uses | ||
|
||
// Workspace uses | ||
use zksync_types::{tx::TxHash, H256}; | ||
|
||
// Local uses | ||
|
||
pub fn remove_prefix(query: &str) -> &str { | ||
if let Some(query) = query.strip_prefix("0x") { | ||
query | ||
} else if let Some(query) = query.strip_prefix("sync-bl:") { | ||
query | ||
} else if let Some(query) = query.strip_prefix("sync-tx:") { | ||
query | ||
} else { | ||
query | ||
} | ||
} | ||
|
||
pub fn try_parse_hash(query: &str) -> Result<H256, hex::FromHexError> { | ||
const HASH_SIZE: usize = 32; // 32 bytes | ||
|
||
let mut slice = [0_u8; HASH_SIZE]; | ||
|
||
let tx_hex = remove_prefix(query); | ||
hex::decode_to_slice(&tx_hex, &mut slice)?; | ||
|
||
Ok(H256::from_slice(&slice)) | ||
} | ||
|
||
pub fn try_parse_tx_hash(query: &str) -> Result<TxHash, hex::FromHexError> { | ||
const HASH_SIZE: usize = 32; // 32 bytes | ||
|
||
let mut slice = [0_u8; HASH_SIZE]; | ||
|
||
let tx_hex = remove_prefix(query); | ||
hex::decode_to_slice(&tx_hex, &mut slice)?; | ||
|
||
Ok(TxHash::from_slice(&slice).unwrap()) | ||
} |
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
53 changes: 53 additions & 0 deletions
53
core/bin/zksync_api/src/api_server/rest/v1/accounts/client.rs
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,53 @@ | ||
//! Accounts API client implementation | ||
// Built-in uses | ||
|
||
// External uses | ||
|
||
// Workspace uses | ||
|
||
// Local uses | ||
use crate::api_server::v1::client::{Client, ClientError}; | ||
|
||
use super::types::{ | ||
AccountInfo, AccountQuery, AccountReceipts, AccountReceiptsQuery, AccountTxReceipt, | ||
PendingAccountTxReceipt, | ||
}; | ||
|
||
/// Accounts API part. | ||
impl Client { | ||
/// Gets account information | ||
pub async fn account_info( | ||
&self, | ||
account: impl Into<AccountQuery>, | ||
) -> Result<Option<AccountInfo>, ClientError> { | ||
let account = account.into(); | ||
|
||
self.get(&format!("accounts/{}", account)).send().await | ||
} | ||
|
||
pub async fn account_receipts( | ||
&self, | ||
account: impl Into<AccountQuery>, | ||
from: AccountReceipts, | ||
limit: u32, | ||
) -> Result<Vec<AccountTxReceipt>, ClientError> { | ||
let account = account.into(); | ||
|
||
self.get(&format!("accounts/{}/receipts", account)) | ||
.query(&AccountReceiptsQuery::new(from, limit)) | ||
.send() | ||
.await | ||
} | ||
|
||
pub async fn account_pending_receipts( | ||
&self, | ||
account: impl Into<AccountQuery>, | ||
) -> Result<Vec<PendingAccountTxReceipt>, ClientError> { | ||
let account = account.into(); | ||
|
||
self.get(&format!("accounts/{}/receipts/pending", account)) | ||
.send() | ||
.await | ||
} | ||
} |
Oops, something went wrong.