Skip to content

Commit

Permalink
codeTemplate added
Browse files Browse the repository at this point in the history
  • Loading branch information
vasylcode authored Sep 9, 2023
1 parent 996cb47 commit 98acb80
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 26 deletions.
4 changes: 3 additions & 1 deletion docs/zetachain/sync/state-sync.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ description: State Sync
import SelectPaste from '@site/src/components/SelectPaste';

import { stateSync } from '@site/src/components/SelectPaste/stateSync.ts';

export let rpc = [
'https://rpc1.node1111.test9999999.com',
'https://rpc2.node2222.test9999999.com',
Expand All @@ -20,4 +22,4 @@ export let rpc = [
'https://rpc8.node8888.test9999999.com',
];

<SelectPaste rpc={rpc} />
<SelectPaste rpc={rpc} codeTemplate={stateSync} />
29 changes: 5 additions & 24 deletions src/components/SelectPaste/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,41 +4,22 @@ import Admonition from "@theme/Admonition";

interface SelectPasteProps {
rpc: string[];
codeTemplate: string;
}

const SelectPaste: React.FC<SelectPasteProps> = ({ rpc }) => {
const SelectPaste: React.FC<SelectPasteProps> = ({ rpc, codeTemplate }) => {
const [selectedRpc, setSelectedRpc] = useState<string>(rpc[0]);

const renderedCode = codeTemplate.replace("{{selectedRpc}}", selectedRpc);

return (
<div>
<Admonition type="tip" icon="📘" title="How to Use">
<p>Click on any RPC to paste it into the code block.</p>
</Admonition>

<CodeBlock language="bash" showLineNumbers>
{`sudo systemctl stop zetacored
cp $HOME/.zetacored/data/priv_validator_state.json $HOME/.zetacored/priv_validator_state.json.backup
zetacored tendermint unsafe-reset-all --home $HOME/.zetacored --keep-addr-book
CUSTOM_RPC="${selectedRpc}"
LATEST_HEIGHT=$(curl -s $CUSTOM_RPC/block | jq -r .result.block.header.height)
BLOCK_HEIGHT=$((LATEST_HEIGHT - 1500))
TRUST_HASH=$(curl -s "$CUSTOM_RPC/block?height=$BLOCK_HEIGHT" | jq -r .result.block_id.hash)
echo $LATEST_HEIGHT $BLOCK_HEIGHT $TRUST_HASH
sed -i 's|^enable *=.*|enable = true|' $HOME/.zetacored/config/config.toml
sed -i 's|^rpc_servers *=.*|rpc_servers = "'$CUSTOM_RPC,$CUSTOM_RPC'"|' $HOME/.zetacored/config/config.toml
sed -i 's|^trust_height *=.*|trust_height = '$BLOCK_HEIGHT'|' $HOME/.zetacored/config/config.toml
sed -i 's|^trust_hash *=.*|trust_hash = "'$TRUST_HASH'"|' $HOME/.zetacored/config/config.toml
mv $HOME/.zetacored/priv_validator_state.json.backup $HOME/.zetacored/data/priv_validator_state.json
sudo systemctl restart zetacored
sudo journalctl -u zetacored -f --no-hostname -o cat
`}
{renderedCode}
</CodeBlock>

<div className="button-group card">
Expand Down
22 changes: 22 additions & 0 deletions src/components/SelectPaste/stateSync.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
export const stateSync = `sudo systemctl stop zetacored
cp $HOME/.zetacored/data/priv_validator_state.json $HOME/.zetacored/priv_validator_state.json.backup
zetacored tendermint unsafe-reset-all --home $HOME/.zetacored --keep-addr-book
CUSTOM_RPC="{{selectedRpc}}"
LATEST_HEIGHT=$(curl -s $CUSTOM_RPC/block | jq -r .result.block.header.height)
BLOCK_HEIGHT=$((LATEST_HEIGHT - 1500))
TRUST_HASH=$(curl -s "$CUSTOM_RPC/block?height=$BLOCK_HEIGHT" | jq -r .result.block_id.hash)
echo $LATEST_HEIGHT $BLOCK_HEIGHT $TRUST_HASH
sed -i 's|^enable *=.*|enable = true|' $HOME/.zetacored/config/config.toml
sed -i 's|^rpc_servers *=.*|rpc_servers = "'$CUSTOM_RPC,$CUSTOM_RPC'"|' $HOME/.zetacored/config/config.toml
sed -i 's|^trust_height *=.*|trust_height = '$BLOCK_HEIGHT'|' $HOME/.zetacored/config/config.toml
sed -i 's|^trust_hash *=.*|trust_hash = "'$TRUST_HASH'"|' $HOME/.zetacored/config/config.toml
mv $HOME/.zetacored/priv_validator_state.json.backup $HOME/.zetacored/data/priv_validator_state.json
sudo systemctl restart zetacored
sudo journalctl -u zetacored -f --no-hostname -o cat`;
2 changes: 1 addition & 1 deletion static/img/undraw3.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 98acb80

Please sign in to comment.