Skip to content

Instantly share code, notes, and snippets.

@ochaloup
ochaloup / byte_bits.rs
Last active June 6, 2024 11:42
Shifting with bytes bits in Rust
fn main() {
let data: &mut [u8] = &mut [0, 0, 0, 0]; // your byte slice
let index: usize = 2; // the position where you want to write the byte
let byte: u8 = 42; // the byte you want to write; 42 =>
// Write the byte to the specified position in the byte slice
data[index] = byte;
print_byte(&byte);
@ochaloup
ochaloup / spl-pool-loader.sh
Last active June 6, 2024 07:40
Loading data about mint pubkey for the SPL Pool program
#!/bin/bash
# Using different scripts from the gist
# bintodec.sh
# - https://discord.com/channels/@me/1017776053873287258/1247924569319149649
# arraybyindex.sh
# - https://gist.github.com/ochaloup/4d6ca93a6826a65c3f1f781d5af59d4b
# tobase58.py
# - https://discord.com/channels/@me/1017776053873287258/1247924569319149649
@ochaloup
ochaloup / bintodec.sh
Last active June 5, 2024 14:56
Binary format to decimal bytes format
if [ "$1" == "-h" ] || [ $# -eq 0 ] || [ $# -gt 1 ]; then
echo "Expecting one parameter, a path to binary file, e.g. 'solana -um account -o /tmp/data.bin'"
echo "$0 /tmp/data.bin"
exit 0
fi
FILE="$1"
decimal_array=($(od -v -An -t u1 < "$FILE"))
echo -n '['$(echo -n ${decimal_array[@]} | sed 's/ /,/g')']'
@ochaloup
ochaloup / buildkite-test.yml
Created April 28, 2024 06:05
Buildkite script managing upload artifacts and failures
agents:
queue: "snapshots"
steps:
- label: ":mega: Notification setup"
commands:
- 'notification_color="8388863"'
- 'buildkite-agent meta-data set notification_color "$$notification_color"'
- |
epoch=333
echo "$$DISCORD_WEBHOOK_VALIDATOR_BONDS" -H "Content-Type: application/json" -d '{
@ochaloup
ochaloup / #search_solana_vote_and_stake_account
Last active June 6, 2024 12:39
Solana search for VoteAccount - by validator identity (node_pubkey) and StakeAcccount - by staker/withdrawer/voter
Changing name:
https://stackoverflow.com/questions/19896900/how-to-change-the-name-of-a-gist-in-github/62398008#62398008
@ochaloup
ochaloup / generate-keypairs-solana.sh
Created March 25, 2024 12:53
SH script generating keypairs for Solana for testing purposes
#!/bin/bash
is_valid_directory() {
if [ -d "$1" ]; then
echo "$1 is a valid directory."
return 0
else
echo "$1 is not a valid directory."
return 1
fi
@ochaloup
ochaloup / Cargo.toml
Created February 29, 2024 11:20
Marinade state verification onchain program
[package]
name = "test"
version = "0.1.0"
description = "Created with Anchor"
edition = "2021"
[lib]
crate-type = ["cdylib", "lib"]
name = "test"
@ochaloup
ochaloup / fixture-change.sh
Last active February 13, 2024 11:28
fixture account change script
# solana account -um vbMaRfmTCg92HWGzmd53APkMNpPnGVGZTUHwUJQkXAU --output json -o fixtures/solana-accounts/vbMaRfmTCg92HWGzmd53APkMNpPnGVGZTUHwUJQkXAU.json
function to_bash_arr() {
ARR="$@"
echo $ARR | sed 's/[,]/ /g' | sed 's/\[\|\]/ /g'
}
EXPECTED_LEN=260
@ochaloup
ochaloup / snapshot-ledger-error-investigation.sh
Last active July 26, 2024 12:24
solana snapshot parsing ledger tool
# --- Working with etl snapshot DB ---
# speed up queries with index creation
create index token_account_mint on token_account(mint);
create index token_account_owner on token_account(owner);
# loading token accounts without system account from sqlite DB
SELECT sum(token_account.amount) FROM token_account
LEFT JOIN account ON token_account.owner = account.pubkey
#!/usr/bin/env bash
BINDIR=./target/debug
TESTDIR=./gen-ledger
FAUCET_KEYPAIR="$TESTDIR"/bootstrap/faucet-keypair.json
CONFIG="$TESTDIR"/config.yml
VALIDATOR_CNT=4
BOOTSTRAP_RPC="http://127.0.0.1:8899"
BOOTSTRAP_GOSSIP="127.0.0.1:8000"
WARMUP_SLOT=20