Skip to content

Instantly share code, notes, and snippets.

@Krulknul
Krulknul / lib.rs
Last active April 11, 2025 09:29
Recursive scrypto types example
use scrypto::prelude::*;
#[blueprint]
#[events(RecursiveEvent)]
mod hello {
struct Hello {
// Define what resources and data will be managed by Hello components
sample_vault: Vault,
}
@Krulknul
Krulknul / piers.rs
Last active April 4, 2025 17:16
Piers Rugyard Auctions generated schemas
const Bid = s.struct({
amount: s.decimal(),
bidder: s.address(),
timestamp: s.instant(),
transaction_hash: s.array(s.number()),
});
const Auction = s.struct({
id: s.number(),
start_timestamp: s.instant(),
end_timestamp: s.instant(),
@Krulknul
Krulknul / schema.ts
Last active April 4, 2025 16:56
Generated sbor-ez-mode schema for ociswap precision pool
const Type3 = s.tuple([]);
const Node = s.struct({
key: s.number(),
value: Type3,
left_child: s.option(s.number()),
right_child: s.option(s.number()),
parent: s.option(s.number()),
next: s.option(s.number()),
prev: s.option(s.number()),
@Krulknul
Krulknul / schema.rs
Created April 3, 2025 15:18
Displaying the structure of a Scrypto SBOR schema
use sbor::{LocalTypeId, Schema, TypeKind, TypeMetadata};
use scrypto::prelude::{
scrypto_decode, ScryptoCustomSchema, ScryptoCustomTypeKind,
};
fn print_type_structure(
schema: &Schema<ScryptoCustomSchema>,
type_name: &str,
indent_size: usize,
) {
@Krulknul
Krulknul / polymorphism.ml
Last active March 25, 2025 18:14
A demonstration of interface based polymorphism in OCaml
(** This file demonstrates a basic example of polymorphism in OCaml, where we
are interested in:
- Creating an interface with some generic functionality, which could in
practice be
- a data layer for an application that has different implementations (In-memory, SQL, etc.)
- a network layer with different implementations (HTTP, gRPC, etc.)
But in our case, it's multiple ways of getting a fact about cats.
- Creating different implementations of this interface, which may be
instantiated in distinct ways, for example one implementation may not need
@Krulknul
Krulknul / +page.svelte
Created January 17, 2025 18:37
A nice way to handle async requests in Svelte 5
<script lang="ts">
import {
GatewayApiClient,
RadixNetwork,
type NetworkConfigurationResponse,
type StateEntityDetailsVaultResponseItem,
} from "@radixdlt/babylon-gateway-api-sdk";
// Initialize the Gateway client
const gatewayApi = GatewayApiClient.initialize({
@Krulknul
Krulknul / trove.rs
Last active June 9, 2024 09:12
An example for reading instantiation events of Trove components and publishing them to Redis pubsub
use radix_engine_common::network::NetworkDefinition;
use radix_engine_common::{
data::scrypto::model::NonFungibleLocalId,
types::{ComponentAddress, ResourceAddress},
ScryptoSbor,
};
use radix_event_stream::encodings::encode_bech32m;
use radix_event_stream::error::EventHandlerError;
use radix_event_stream::sources::gateway::GatewayTransactionStream;
use radix_event_stream::{anyhow, macros::event_handler};
@Krulknul
Krulknul / winner.py
Created July 5, 2023 21:04
Winner selection script for Radix Staking giveaway
import psycopg2
import pandas as pd
import numpy as np
def execute_query():
try:
# Establish a connection to the database
conn = psycopg2.connect(
dbname="radix_ledger",
user="radix",