Skip to content

Instantly share code, notes, and snippets.

// don't forget to import!
use solana_program::{
account_info::{AccountInfo, next_account_info}
};
// code inside of `process_instruction`
let accounts_iter = &mut accounts.iter(); // accounts here refers to the argument denoting the array of `AccountInfo`s
let account_one = next_account_info(accounts_iter)?;
let account_two = next_account_info(accounts_iter)?;
let account_three = next_account_info(accounts_iter)?;
...
@alecchendev
alecchendev / solana-install-m1-no-rosetta.md
Created November 14, 2021 07:08
Solana Installation Guide for M1 Without Rosetta

Solana Installation Guide for M1 Without Rosetta (v1.8.2)

Figured out how to install solana on M1 without Rosetta and I haven't found a totally complete guide elsewhere so here you go:

NOTE: Haven't done exhaustive development testing but most fundamental stuff seems to work - test validator, airdrop, transactions, deployment

Install rust.

curl --proto '=https' --tlsv1.2 [https://sh.rustup.rs](https://sh.rustup.rs/) -sSf | sh
@alecchendev
alecchendev / invertTree.py
Created January 9, 2021 06:08
Invert Binary Tree Solution
class Solution:
def invertTree(self, root: TreeNode) -> TreeNode:
if not root:
return None
left = root.left
right = root.right
root.left = self.invertTree(right)
root.right = self.invertTree(left)
return root
@alecchendev
alecchendev / player.rs
Created December 24, 2020 01:08
OOP in rust article - AABB trait
trait AABB {
fn min(&self) -> Vec3;
fn max(&self) -> Vec3;
fn collision(&self, other: &impl AABB, vel: &Vec3) -> Vec3 {
// default implementation
}
}
@alecchendev
alecchendev / animal.rs
Created December 24, 2020 01:05
OOP in rust article - impl animal enum
impl Animal {
fn speak(&self) {
match self {
Animal::Dog(_) => println!("Woof!"),
Animal::Cat(_) => println!("Meow!"),
Animal::Pig(_) => println!("Oink!"),
}
}
}
@alecchendev
alecchendev / animal.rs
Created December 24, 2020 01:04
OOP in rust article - animal enum 2
enum Animal {
Dog,
Cat = 0,
Pig { cooked: bool },
Cow(String),
Goat(Goat),
}
struct Goat {
age: u32,
}
@alecchendev
alecchendev / main.rs
Last active December 24, 2020 01:04
OOP in rust article - animal enum
enum Animal {
Dog(String),
Cat(String),
Pig(bool),
}
fn main() {
let example_animal = Animal::Pig(true);
match example_animal {
Animal::Dog(name) => println!("It's a dog named {}!", name),
@alecchendev
alecchendev / dog.rs
Last active December 24, 2020 00:58
OOP in rust article - dog struct
struct Dog {
name: String,
}
impl Dog {
fn speak(&self) {
println!("Woof. My name is {}.", self.name);
}
}