Skip to content

Instantly share code, notes, and snippets.

@ochaloup
ochaloup / solana-bankrun-update.md
Created September 9, 2024 10:37
solana-bankrun code update
@ochaloup
ochaloup / RUST_OPTION_RESULT_CONVERSIONS.md
Created August 27, 2024 10:15 — forked from novafacing/RUST_OPTION_RESULT_CONVERSIONS.md
Rust Option/Result conversion functions

I used to have a site bookmarked with a table of all these functions, but the link is dead. Here's a matrix of Option and Result conversion functions. These become second nature once you have used Rust for any significant length of time, but it's useful to have a table reference.

For each of the below:

  • T is the value possibly contained in an input Ok Result or Some Option.
  • U is a new value created by transforming or replacing an input T. Note that when U appears in methods like map, U ?= T, for example by calling
@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 September 1, 2024 15:36
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