Skip to content

Commit

Permalink
chore: format
Browse files Browse the repository at this point in the history
  • Loading branch information
jjyr committed Apr 14, 2022
1 parent d0f4543 commit c9858b9
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 11 deletions.
5 changes: 4 additions & 1 deletion crates/tools/src/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,10 @@ pub async fn short_script_hash_to_account_id(
short_script_hash: &GwBytes,
) -> Result<Option<u32>> {
let bytes = JsonBytes::from_bytes(short_script_hash.clone());
let script_hash = match godwoken_rpc_client.get_script_hash_by_short_script_hash(bytes).await? {
let script_hash = match godwoken_rpc_client
.get_script_hash_by_short_script_hash(bytes)
.await?
{
Some(h) => h,
None => {
return Err(anyhow!(
Expand Down
8 changes: 6 additions & 2 deletions crates/tools/src/address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,10 @@ pub fn to_godwoken_short_script_hash(
Ok(())
}

pub async fn to_eth_eoa_address(godwoken_rpc_url: &str, godwoken_short_script_hash: &str) -> Result<()> {
pub async fn to_eth_eoa_address(
godwoken_rpc_url: &str,
godwoken_short_script_hash: &str,
) -> Result<()> {
if godwoken_short_script_hash.len() != 42 || !godwoken_short_script_hash.starts_with("0x") {
return Err(anyhow!("godwoken short script hash format error!"));
}
Expand All @@ -68,7 +71,8 @@ pub async fn to_eth_eoa_address(godwoken_rpc_url: &str, godwoken_short_script_ha
)?);

let script_hash = godwoken_rpc_client
.get_script_hash_by_short_script_hash(JsonBytes::from_bytes(short_script_hash)).await?;
.get_script_hash_by_short_script_hash(JsonBytes::from_bytes(short_script_hash))
.await?;

let script = match script_hash {
Some(h) => godwoken_rpc_client.get_script(h).await?,
Expand Down
19 changes: 13 additions & 6 deletions crates/tools/src/create_creator_account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,9 @@ async fn create_eth_addr_reg_account(
hex::encode(eth_addr_reg_script_hash)
);

let eth_addr_reg_id =
godwoken_rpc_client.get_account_id_by_script_hash(eth_addr_reg_script_hash.into()).await?;
let eth_addr_reg_id = godwoken_rpc_client
.get_account_id_by_script_hash(eth_addr_reg_script_hash.into())
.await?;
if let Some(id) = eth_addr_reg_id {
log::info!("ETH Address Registry account already exists, id = {}", id);
return Ok(id);
Expand All @@ -77,7 +78,9 @@ async fn create_eth_addr_reg_account(
.build();

let sender_script_hash = godwoken_rpc_client.get_script_hash(from_id).await?;
let receiver_script_hash = godwoken_rpc_client.get_script_hash(RESERVED_ACCOUNT_ID).await?;
let receiver_script_hash = godwoken_rpc_client
.get_script_hash(RESERVED_ACCOUNT_ID)
.await?;

let message = generate_transaction_message_to_sign(
&raw_l2tx,
Expand All @@ -97,7 +100,8 @@ async fn create_eth_addr_reg_account(
wait_for_l2_tx(godwoken_rpc_client, &tx_hash, 180, false)?;

let eth_addr_reg_id = godwoken_rpc_client
.get_account_id_by_script_hash(eth_addr_reg_script_hash.into()).await?
.get_account_id_by_script_hash(eth_addr_reg_script_hash.into())
.await?
.expect("ETH Address Registry account id");
log::info!("ETH Address Registry account id: {}", eth_addr_reg_id);

Expand Down Expand Up @@ -131,7 +135,8 @@ pub async fn create_creator_account(
fee,
&config,
&scripts_deployment,
).await
)
.await
.expect("create_eth_addr_reg_account success");

let from_address =
Expand Down Expand Up @@ -183,7 +188,9 @@ pub async fn create_creator_account(
.build();

let sender_script_hash = godwoken_rpc_client.get_script_hash(from_id).await?;
let receiver_script_hash = godwoken_rpc_client.get_script_hash(RESERVED_ACCOUNT_ID).await?;
let receiver_script_hash = godwoken_rpc_client
.get_script_hash(RESERVED_ACCOUNT_ID)
.await?;

let message = generate_transaction_message_to_sign(
&account_raw_l2_transaction,
Expand Down
3 changes: 2 additions & 1 deletion crates/tools/src/get_balance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ use crate::{account::parse_account_short_script_hash, godwoken_rpc::GodwokenRpcC

pub async fn get_balance(godwoken_rpc_url: &str, account: &str, sudt_id: u32) -> Result<()> {
let mut godwoken_rpc_client = GodwokenRpcClient::new(godwoken_rpc_url);
let short_script_hash = parse_account_short_script_hash(&mut godwoken_rpc_client, account).await?;
let short_script_hash =
parse_account_short_script_hash(&mut godwoken_rpc_client, account).await?;
let addr = JsonBytes::from_bytes(short_script_hash);
let balance = godwoken_rpc_client.get_balance(addr, sudt_id).await?;
log::info!("Balance: {}", balance);
Expand Down
2 changes: 1 addition & 1 deletion crates/tools/src/report_accounts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ async fn producer(client: GodwokenRpcClient, tx: tokio::sync::mpsc::Sender<Task>
let client = client.clone();
let task = tokio::spawn(async move {
let script_hash = client.get_script_hash(account_id).await?;
if script_hash.as_bytes() == &[0u8; 32] {
if script_hash.as_bytes() == [0u8; 32] {
return Ok::<_, anyhow::Error>(None);
}
let script = client
Expand Down

0 comments on commit c9858b9

Please sign in to comment.