Skip to content

Commit

Permalink
update examples for testnet
Browse files Browse the repository at this point in the history
  • Loading branch information
JossDuff committed Jun 5, 2024
1 parent d68e704 commit b2ca7d1
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 28 deletions.
6 changes: 5 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
[workspace]
resolver = "2"

members = [ "examples/asset-id", "examples/predicate-root", "examples/simple-logs",
members = [
"examples/asset-id",
"examples/predicate-root",
"examples/find-receipt-ordering",
"examples/simple-logs",
"hyperfuel-client",
"hyperfuel-format",
"hyperfuel-net-types",
Expand Down
2 changes: 1 addition & 1 deletion examples/asset-id/README.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
We query from blocks 7980000 (inclusive) to 7980100 (exclusive) for all `Inputs` where the address `0x0000000000000000000000000000000000000000000000000000000000000000` matches on the `asset_id` field.
We query from blocks 0 (inclusive) to 1299067 (exclusive) for all `Inputs` where the address `0x2a0d0ed9d2217ec7f32dcd9a1902ce2a66d68437aeff84e3a3cc8bebee0d2eea` matches on the `asset_id` field.
15 changes: 10 additions & 5 deletions examples/asset-id/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,25 @@ use url::Url;
#[tokio::main]
async fn main() {
let client_config = Config {
url: Url::parse("https://fuel-15.hypersync.xyz").unwrap(),
url: Url::parse("https://fuel-testnet.hypersync.xyz").unwrap(),
bearer_token: None,
http_req_timeout_millis: NonZeroU64::new(30000).unwrap(),
};
let client = Client::new(client_config).unwrap();

// Construct query in json. Can also construct it as a typed struct (see predicate-root example)
let query: Query = serde_json::from_value(serde_json::json!({
"from_block": 7980000,
"to_block": 7980100,
// start query from block 0
"from_block": 0,
// if to_block is not set, query runs to the end of the chain
"to_block": 1299067,
// load inputs that have `asset_id` = 0x2a0d0ed9d2217ec7f32dcd9a1902ce2a66d68437aeff84e3a3cc8bebee0d2eea
"inputs": [
{
"asset_id": ["0x0000000000000000000000000000000000000000000000000000000000000000"]
"asset_id": ["0x2a0d0ed9d2217ec7f32dcd9a1902ce2a66d68437aeff84e3a3cc8bebee0d2eea"]
}
],
// fields we want returned from loaded inputs
"field_selection": {
"input": [
"block_height",
Expand All @@ -35,5 +40,5 @@ async fn main() {

let res = client.get_selected_data(&query).await.unwrap();

println!("inputs: {:?}", res.data);
println!("inputs: {:?}", res.data.inputs);
}
2 changes: 1 addition & 1 deletion examples/predicate-root/README.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
This example returns `input` field data from an input where the `owner` field matches the predicate root 0x48a0f31c78e1c837ff6a885785ceb7c2090f86ed93db3ed2d8821d13739fe981 `owner` is ["The owning address or predicate root."](https://docs.fuel.network/docs/beta-4/graphql/reference/objects/#inputcoin) of an InputCoin Input type
This example returns `input` field data from an input where the `owner` field matches the predicate root 0x94a8e322ff02baeb1d625e83dadf5ec88870ac801da370d4b15bbd5f0af01169 `owner` is ["The owning address or predicate root."](https://docs.fuel.network/docs/graphql/reference/objects/#inputcoin) of an InputCoin Input type
34 changes: 19 additions & 15 deletions examples/predicate-root/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,35 +7,39 @@ use url::Url;
#[tokio::main]
async fn main() {
let client_config = Config {
url: Url::parse("https://fuel-15.hypersync.xyz").unwrap(),
url: Url::parse("https://fuel-testnet.hypersync.xyz").unwrap(),
bearer_token: None,
http_req_timeout_millis: NonZeroU64::new(30000).unwrap(),
};
let client = Client::new(client_config).unwrap();

// Construct query as a typed struct. Can also construct it in json (see asset-id example)
let query = Query {
from_block: 4105960,
to_block: Some(4106000),
// start query from block 0
from_block: 0,
// if to_block is not set, query runs to the end of the chain
to_block: Some(1427625),
// load inputs that have `owner` = 0x94a8e322ff02baeb1d625e83dadf5ec88870ac801da370d4b15bbd5f0af01169
inputs: vec![InputSelection {
owner: vec![hex_literal::hex!(
"48a0f31c78e1c837ff6a885785ceb7c2090f86ed93db3ed2d8821d13739fe981"
"94a8e322ff02baeb1d625e83dadf5ec88870ac801da370d4b15bbd5f0af01169"
)
.into()],
..Default::default()
}],
// fields we want returned from loaded inputs
field_selection: FieldSelection {
input: maplit::btreeset! {
"tx_id".to_owned(),
"block_height".to_owned(),
"input_type".to_owned(),
"utxo_id".to_owned(),
"owner".to_owned(),
"amount".to_owned(),
"asset_id".to_owned(),
"predicate_gas_used".to_owned(),
"predicate".to_owned(),
"predicate_data".to_owned(),

"block_height".to_owned(),
"input_type".to_owned(),
"utxo_id".to_owned(),
"owner".to_owned(),
"amount".to_owned(),
"asset_id".to_owned(),
"predicate_gas_used".to_owned(),
"predicate".to_owned(),
"predicate_data".to_owned(),
},
..Default::default()
},
Expand All @@ -44,5 +48,5 @@ async fn main() {

let res = client.get_selected_data(&query).await.unwrap();

println!("inputs: {:?}", res.data);
println!("inputs: {:?}", res.data.inputs);
}
2 changes: 1 addition & 1 deletion examples/simple-logs/README.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
This example will simply fetch the logs from a vector of contracts over a specified block range.
This example will simply fetch the logs from a vector of contracts over a specified block range. Returns all log data necessary for fuel's decoder.
11 changes: 7 additions & 4 deletions examples/simple-logs/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,20 @@ use url::Url;
#[tokio::main]
async fn main() {
let client_config = Config {
url: Url::parse("https://fuel-15.hypersync.xyz").unwrap(),
url: Url::parse("https://fuel-testnet.hypersync.xyz").unwrap(),
bearer_token: None,
http_req_timeout_millis: NonZeroU64::new(30000).unwrap(),
};
let client = Client::new(client_config).unwrap();

// contract to get logs from
let contracts = vec![hex_literal::hex!(
"ff63ad3cdb5fde197dfa2d248330d458bffe631bda65938aa7ab7e37efa561d0"
"4a2ce054e3e94155f7092f7365b212f7f45105b74819c623744ebcc5d065c6ac"
)];
let from_block = 8076516;
let to_block = Some(8076517);
// start query from block 0
let from_block = 0;
// if to_block is not set, query runs to the end of the chain
let to_block = Some(1627509);

let logs = client
.preset_query_get_logs(contracts, from_block, to_block)
Expand Down

0 comments on commit b2ca7d1

Please sign in to comment.