Type Definition flow_sdk::client::TonicHyperFlowClient [−][src]
pub type TonicHyperFlowClient = FlowClient<TonicHyperClient>;
Expand description
A flow client that uses TonicHyperClient
as gRPC client.
Implementations
Connects to a static endpoint URI.
Connects to the Mainnet access node provided by Dapper Labs.
Examples found in repository
More examples
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
fn main() -> Result<(), Box<dyn Error + Send + Sync>> {
let mut client = TonicHyperFlowClient::mainnet().await?;
client.ping().await?;
let ret = client
.execute_script_at_latest_block(
SIMPLE_SCRIPT,
[ValueRef::Int(cadence_json::BigInt::from(32))],
)
.await?
.parse()?;
println!("{:#?}", ret);
let ret = client
.execute_script_at_latest_block(COMPLEX_SCRIPT, [ValueRef::String("John Doe")])
.await?
.parse()?;
println!("{:#?}", ret);
Ok(())
}
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
fn main() -> Result<(), Box<dyn Error + Send + Sync>> {
let stdin = stdin();
let mut stdin = stdin.lock();
let mut buf = String::new();
println!("Enter the account's address:");
stdin.read_line(&mut buf)?;
let addr = buf.trim();
let address: AddressOwned = addr.parse()?;
let mut net = TonicHyperFlowClient::mainnet().await?;
let account = net.account_at_latest_block(&address.data).await?;
let latest_block_height = net.latest_block_header(Seal::Sealed).await?.height;
let account1 = net
.account_at_block_height(&address.data, latest_block_height)
.await?;
println!("{:#?}", account);
assert_eq!(account, account1);
Ok(())
}
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
fn main() -> Result<(), Box<dyn Error + Send + Sync>> {
let mut client = TonicHyperFlowClient::mainnet().await?;
client.ping().await?;
let mut latest_block = client.latest_block(Seal::Sealed).await?;
// traverse latest blocks until we find a collection guarantee.
let collection_guarrantee = loop {
if latest_block.collection_guarantees.is_empty() {
// Go to the next block
latest_block = client.block_by_id(&latest_block.parent_id).await?;
} else {
break latest_block.collection_guarantees.pop().unwrap();
}
};
// retrieve the collection by id.
let collection = client
.collection_by_id(&collection_guarrantee.collection_id)
.await?;
println!("OK: {:#?}", collection);
Ok(())
}
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
fn main() -> Result<(), Box<dyn Error + Send + Sync>> {
let mut client = TonicHyperFlowClient::mainnet().await?;
client.ping().await?;
let latest_block_height = client.latest_block_header(Seal::Sealed).await?.height;
let start_height = latest_block_height - 20;
println!(
"Searching for accounts created within the last 20 blocks ({}-{})...",
start_height, latest_block_height
);
for events in client
.events_for_height_range("flow.AccountCreated", start_height, latest_block_height)
.await?
.results
.iter()
{
if events.events.is_empty() {
continue;
}
println!(
"\nBlock #{} ({}):",
events.block_height,
hex::encode(&events.block_id)
);
for event in events.events.iter() {
let val = event.parse_payload()?;
println!(" - {:#?}", val);
}
}
Ok(())
}
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
fn main() -> Result<(), Box<dyn Error + Send + Sync>> {
let mut client = TonicHyperFlowClient::mainnet().await?;
client.ping().await?;
let latest_block_height = client.latest_block_header(Seal::Sealed).await?.height;
let start_height = latest_block_height - 100;
println!(
"Searching for accounts created within the last 100 blocks ({}-{})...",
start_height, latest_block_height
);
let mut accounts = Vec::new();
for events in client
.events_for_height_range("flow.AccountCreated", start_height, latest_block_height)
.await?
.results
.iter()
{
for event in events.events.iter() {
let val: cadence_json::ValueOwned = serde_json::from_slice(&event.payload)?;
if let cadence_json::ValueOwned::Event(c) = val {
for field in c.fields.into_iter().filter(|f| f.name == "address") {
if let cadence_json::ValueOwned::Address(addr) = field.value {
accounts.push(client.account_at_latest_block(&addr.data).await?);
}
}
}
}
}
println!("Found {} accounts.", accounts.len());
if let Some(acc) = accounts.into_iter().max_by_key(|acc| acc.balance) {
println!(
"\nThe richest account is 0x{} with a balance of {}.",
hex::encode(acc.address),
acc.balance
);
}
Ok(())
}
Connects to the Testnet access node provided by Dapper Labs.
Examples found in repository
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
fn main() -> Result<(), Box<dyn Error + Send + Sync>> {
let mut client = TonicHyperFlowClient::testnet().await?;
client.ping().await?;
let latest_block = client.latest_block(Seal::Sealed).await?;
let block_by_id = client.block_by_id(&latest_block.id).await?;
let block_by_height = client.block_by_height(latest_block.height).await?;
assert_eq!(latest_block, block_by_id);
assert_eq!(latest_block, block_by_height);
println!("OK: {:#?}", latest_block);
Ok(())
}
More examples
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
fn main() -> Result<(), Box<dyn Error + Send + Sync>> {
let mut net = TonicHyperFlowClient::testnet().await?;
let _ = net.ping().await?;
let latest_block_header = net.latest_block_header(Seal::Sealed).await?;
println!("{:?}", latest_block_header);
let Timestamp { nanos, seconds } = latest_block_header.timestamp;
println!("{}", Utc.timestamp(seconds, nanos as u32));
println!("----------------");
let block_header2 = net
.block_header_by_height(latest_block_header.height)
.await?;
println!("{:?}", block_header2);
let Timestamp { nanos, seconds } = block_header2.timestamp;
println!("{}", Utc.timestamp(seconds, nanos as u32));
assert_eq!(latest_block_header, block_header2);
Ok(())
}
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
fn main() -> Result<(), Box<dyn Error + Send + Sync>> {
let stdin = stdin();
let mut stdin = stdin.lock();
let mut buf = String::new();
// Let's make a transaction!
// First, generate a keypair for us to use.
let secp = Secp256k1::signing_only();
// `EntropyRng` is a secure random number generator.
let mut rng = secp256k1::rand::rngs::EntropyRng::new();
let secret_key = SecretKey::new(&mut rng);
let public_key = PublicKey::from_secret_key(&secp, &secret_key);
// Print the public key as a hexadecimal.
println!("This is your public key:");
let public_key_bytes = public_key.serialize_uncompressed();
// There is a leading 0x04 which we don't need to emit
// https://bitcoin.stackexchange.com/a/3043
for ch in &public_key_bytes[1..] {
print!("{:02x}", *ch);
}
println!();
println!("Go to https://flow-faucet.vercel.app/, select secp256k1 and sha3 and create your testnet account.");
println!("Paste the address you get and press ENTER to continue");
stdin.read_line(&mut buf)?;
let addr = buf.trim();
let address: AddressOwned = addr.parse()?;
let net = TonicHyperFlowClient::testnet().await?;
let mut account = Account::<_, _>::new(net, &address.data, secret_key).await?;
let create_account = CreateAccountTransaction {
public_keys: &[public_key],
};
let create_account_header = create_account.to_header::<_, tiny_keccak::Sha3>(account.signer());
let res = account
.send_transaction_header(&create_account_header)
.await?;
println!(
"Just made {} to create another account :p",
hex::encode(&res.id)
);
let response = res.finalize(account.client()).await?;
match response {
Some(res) => {
for ev in res.events.iter() {
if ev.ty == "flow.AccountCreated" {
let payload = ev.parse_payload()?;
let addr = payload
.fields
.into_iter()
.find(|field| field.name == "address")
.map(|field| field.value)
.unwrap();
if let ValueOwned::Address(addr) = addr {
println!("Created account's address is: {}", addr);
}
}
}
}
None => {
panic!("The transaction did not get sealed... Perhaps the network is malfunctioning?")
}
}
Ok(())
}
Connects to a static endpoint URI. Does not connect until we try to send a request.
Note: You must have entered the tokio runtime context before calling this function.
You can do so by writing the code down below, or it will automatically be entered, if
you have an .await
before calling this. Consider using the async
functions instead.
let handle = tokio::runtime::Handle::current();
handle.enter();
Connects to an endpoint. Does not connect until we try to send a request.
Note: You must have entered the tokio runtime context before calling this function.
You can do so by writing the code down below, or it will automatically be entered, if
you have an .await
before calling this. Consider using the async
functions instead.
let handle = tokio::runtime::Handle::current();
handle.enter();
Builds a lazy connection to the Mainnet access node provided by Dapper Labs.
Note: You must have entered the tokio runtime context before calling this function.
You can do so by writing the code down below, or it will automatically be entered, if
you have an .await
before calling this. Consider using the async
functions instead.
let handle = tokio::runtime::Handle::current();
handle.enter();
Builds a lazy connection to the Testnet access node provided by Dapper Labs.
Note: You must have entered the tokio runtime context before calling this function.
You can do so by writing the code down below, or it will automatically be entered, if
you have an .await
before calling this. Consider using the async
functions instead.
let handle = tokio::runtime::Handle::current();
handle.enter();