1
2
3
4
5
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
51
52
53
54
55
56
57
use std::error::Error;
use cadence_json::ValueRef;
use flow_sdk::prelude::TonicHyperFlowClient;
const SIMPLE_SCRIPT: &str = "
pub fun main(a: Int): Int {
return a + 10
}
";
const COMPLEX_SCRIPT: &str = "
pub struct User {
pub var balance: UFix64
pub var address: Address
pub var name: String
init(name: String, address: Address, balance: UFix64) {
self.name = name
self.address = address
self.balance = balance
}
}
pub fun main(name: String): User {
return User(
name: name,
address: 0x1,
balance: 10.0
)
}
";
#[tokio::main]
async 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(())
}