Skip to content

Commit 1adb812

Browse files
committed
print metadata.
1 parent c64dc87 commit 1adb812

File tree

11 files changed

+3374
-1746
lines changed

11 files changed

+3374
-1746
lines changed

chain-prometheus-exporter/Cargo.lock

Lines changed: 412 additions & 230 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cis2-client/Cargo.lock

Lines changed: 368 additions & 256 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cis2-client/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@ reqwest = {version = "0.11", features = ["json"]}
1515
concordium-rust-sdk = { path = "../deps/concordium-rust-sdk", version = "*" }
1616
serde_json = "1.0"
1717
chrono = "0.4"
18+
sha2 = "0.10.8"

cis2-client/src/main.rs

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
use anyhow::{ensure, Context};
22
use clap::Parser;
3+
use sha2::Digest;
34
use concordium_rust_sdk::{
45
cis2::{
56
self, AdditionalData, Cis2TransactionMetadata, OperatorUpdate, Receiver, TokenAmount,
67
TokenId, Transfer,
78
},
89
common::types::{Amount, TransactionTime},
910
types::{
10-
hashes::{BlockHash, TransactionHash},
11+
hashes::{BlockHash, TransactionHash, Hash},
1112
smart_contracts::OwnedReceiveName,
1213
transactions::send::GivenEnergy,
1314
Address, ContractAddress, WalletAccount,
@@ -253,19 +254,29 @@ async fn handle_contract_command(
253254
.token_metadata_single(&block, token_id.clone())
254255
.await
255256
.context("Unable to get token metadata URL.")?;
256-
println!(
257-
"Metadata URL for token {} in contract {} is {}.",
258-
token_id,
259-
contract,
260-
metadata_url.url(),
261-
);
257+
if let Some(hash) = metadata_url.hash() {
258+
println!(
259+
"Metadata URL for token {} in contract {} is {} with hash {hash}",
260+
token_id,
261+
contract,
262+
metadata_url.url()
263+
);
264+
} else {
265+
println!(
266+
"Metadata URL for token {} in contract {} is {} without hash.",
267+
token_id,
268+
contract,
269+
metadata_url.url()
270+
);
271+
};
262272

263273
let resp = reqwest::get(metadata_url.url())
264274
.await
265275
.context("Cannot get metadata.")?;
266-
let r = resp
267-
.json::<serde_json::Value>()
268-
.await
276+
let bytes = resp.bytes().await?;
277+
let computed_hash: Hash = <[u8; 32]>::from(sha2::Sha256::digest(&bytes)).into();
278+
println!("Computed hash {computed_hash}");
279+
let r: serde_json::Value = serde_json::from_slice(&bytes)
269280
.context("Unable to parse metadata as JSON.")?;
270281
println!("{}", serde_json::to_string_pretty(&r)?)
271282
}

0 commit comments

Comments
 (0)