Skip to content

Commit

Permalink
[docs-examples] Format rust code in examples
Browse files Browse the repository at this point in the history
  • Loading branch information
gregnazario committed Jul 21, 2022
1 parent 04b7b16 commit bae85ab
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 10 deletions.
16 changes: 12 additions & 4 deletions developer-docs-site/static/examples/rust/first_coin/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// Copyright (c) Aptos
// SPDX-License-Identifier: Apache-2.0

use first_transaction::{Account, FaucetClient, FAUCET_URL, TESTNET_URL};
use first_coin::FirstCoinClient;
use first_transaction::{Account, FaucetClient, FAUCET_URL, TESTNET_URL};
use hello_blockchain::HelloBlockchainClient;
use std::env;

Expand Down Expand Up @@ -42,7 +42,9 @@ fn main() -> () {
println!("Publishing MoonCoinType module...");
let hello_blockchain_client = HelloBlockchainClient::new(TESTNET_URL.to_string());
let mut tx_hash = hello_blockchain_client.publish_module(&mut alice, &module_hex);
hello_blockchain_client.rest_client.wait_for_transaction(&tx_hash);
hello_blockchain_client
.rest_client
.wait_for_transaction(&tx_hash);

println!("Alice will initialize the new coin");
tx_hash = client.initialize_coin(&mut alice);
Expand All @@ -51,10 +53,16 @@ fn main() -> () {
println!("Bob registers the newly created coin so he can receive it from Alice");
tx_hash = client.register_coin(&mut bob, &alice.address());
client.rest_client.wait_for_transaction(&tx_hash);
println!("Bob's initial balance: {}", client.get_balance(&bob.address(), &alice.address()));
println!(
"Bob's initial balance: {}",
client.get_balance(&bob.address(), &alice.address())
);

println!("Alice mints Bob some of the new coin");
tx_hash = client.mint_coin(&mut alice, &bob.address(), 100);
client.rest_client.wait_for_transaction(&tx_hash);
println!("Bob's updated balance: {}", client.get_balance(&bob.address(), &alice.address()));
println!(
"Bob's updated balance: {}",
client.get_balance(&bob.address(), &alice.address())
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use std::{

use ed25519_dalek::{ExpandedSecretKey, PublicKey, SecretKey};
use hex::ToHex;
use rand::{rngs::OsRng, Rng, SeedableRng, RngCore};
use rand::{rngs::OsRng, Rng, RngCore, SeedableRng};
use reqwest;
use tiny_keccak::{Hasher, Sha3};

Expand All @@ -30,7 +30,7 @@ impl Account {
let mut bytes = [0; 32];
rng.fill_bytes(&mut bytes);
SecretKey::from_bytes(&bytes).unwrap()
},
}
};

Account { signing_key }
Expand Down Expand Up @@ -265,8 +265,11 @@ impl RestClient {
//:!:>section_5
/// Returns the test coin balance associated with the account
pub fn account_balance(&self, account_address: &str) -> Option<u64> {
self.account_resource(account_address, "0x1::coin::CoinStore<0x1::aptos_coin::AptosCoin>")
.unwrap()["data"]["coin"]["value"]
self.account_resource(
account_address,
"0x1::coin::CoinStore<0x1::aptos_coin::AptosCoin>",
)
.unwrap()["data"]["coin"]["value"]
.as_str()
.and_then(|s| s.parse::<u64>().ok())
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ impl HelloBlockchainClient {
"type": "module_bundle_payload",
"modules": [{"bytecode": format!("0x{}", module_hex)}],
});
self.rest_client.execution_transaction_with_payload(account_from, payload)
self.rest_client
.execution_transaction_with_payload(account_from, payload)
}
//<:!:section_1
//:!:>section_2
Expand Down Expand Up @@ -50,7 +51,8 @@ impl HelloBlockchainClient {
"type_arguments": [],
"arguments": [message_hex]
});
self.rest_client.execution_transaction_with_payload(account_from, payload)
self.rest_client
.execution_transaction_with_payload(account_from, payload)
}
//<:!:section_3
}

0 comments on commit bae85ab

Please sign in to comment.