Skip to content

Commit

Permalink
bump eth-block-meta example to allow human-readable keys
Browse files Browse the repository at this point in the history
  • Loading branch information
sduchesneau committed Jan 11, 2023
1 parent cd71cfc commit e83ba3c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 14 deletions.
31 changes: 18 additions & 13 deletions connect-web-example/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ function App() {
}[]
>([]);
return <>
<h2>Enter a block ID to get the value from the kv store</h2>
<h1>Example UI for substreams-eth-block-meta</h1>
<h2>Enter a key to get the value from the kv store (ex: month:last:201511)</h2>
<ol>
{messages.map((msg, index) => (
<li key={index}>
Expand All @@ -55,21 +56,25 @@ function App() {
const response = await client.get({
key: inputValue.replace("0x", ""),
});
const blkmeta = BlockMeta.fromBinary(response.value);
const prettyJSON = JSON.stringify(blkmeta, (key, value) => {
if (key === "hash") {
return "0x" + bufferToHex(blkmeta.hash);
}
if (key === "parentHash") {
return "0x" + bufferToHex(blkmeta.parentHash);
}
return value;
}, 2);
console.log(prettyJSON);
let output: string;
try {
const blkmeta = BlockMeta.fromBinary(response.value);
output = JSON.stringify(blkmeta, (key, value) => {
if (key === "hash") {
return "0x" + bufferToHex(blkmeta.hash);
}
if (key === "parentHash") {
return "0x" + bufferToHex(blkmeta.parentHash);
}
return value;
}, 2);
} catch (e) {
output = "0x" + bufferToHex(response.value);
}
setMessages((prev) => [
...prev,
{
message: prettyJSON,
message: output,
color: "lightblue",
},
]);
Expand Down
2 changes: 1 addition & 1 deletion devel/local/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ main() {
$sink run \
${dsn} \
"${SUBSTREAMS_ENDPOINT:-"mainnet.eth.streamingfast.io:443"}" \
"${SUBSTREAMS_MANIFEST:-"https://github.com/streamingfast/substreams-eth-block-meta/releases/download/v0.3.1/substreams-eth-block-meta-v0.3.1.spkg"}" \
"${SUBSTREAMS_MANIFEST:-"https://github.com/streamingfast/substreams-eth-block-meta/releases/download/v0.4.0/substreams-eth-block-meta-v0.4.0.spkg"}" \
"${SUBSTREAMS_MODULE:-"kv_out"}" \
"$@"
}
Expand Down

0 comments on commit e83ba3c

Please sign in to comment.