Skip to content

Instantly share code, notes, and snippets.

View RCasatta's full-sized avatar
🦎

Riccardo Casatta RCasatta

🦎
View GitHub Profile
---
title: No HWW, no problem!
author: Riccardo Casatta
date: 2024
theme: Madrid
colortheme: dolphin
links-as-notes: true
# Sono Riccardo Casatta, ingegnere informatico, ho lavorato nella Consulenza prima di ammalarmi di bitcoin, al che invece di continuare a fare un lavoro becero e accumulare coin ho deciso di fare una startup, Eternity Wall che ha lavorato con Peter Todd per produrre il protocollo OpenTimestamps di cui ancora oggi mantengo uno dei calendar server ufficiali.
# Adesso lavoro in Blockstream, ma come vedete dalla prima slide, non ho messo affiliation a giudicare dal titolo non so se i miei colleghi di Jade sono felici. Non lo so forse dopo questa presentazione potrebbero anche aumentare le vendite, vediamo
# see https://github.com/alexeygumirov/pandoc-beamer-how-to for other fields
@RCasatta
RCasatta / measure-mempool.jq
Last active November 25, 2024 13:51
JQ program to parse output of `bitcoin-cli getrawmempool true` to have buckets of txs under a certain fee as a prometheus metric
[to_entries | .[].value.fees.base * 1000000 | floor] |
[
{
le: "1",
val: (map(select(.<=1)) | length)
},
{
le: "2",
val: (map(select(.<=2)) | length)
},
@RCasatta
RCasatta / gist:b89dc7799476fb4ef8b2ea1570462e2f
Created September 2, 2024 06:52
Core lightning, pay via a specific channel or with full channels. Shell script using `lightning-cli` and `jq`
```
$ cat pay-using-channel.sh
#!/bin/sh
CHANNEL=$1
BOLT11=$2
[ -z "$CHANNEL" ] && echo "first program argument should be a short channel id and it is unset or set to the empty string" && exit 1
[ -z "$BOLT11" ] && echo "second program argument should be a bolt11 invoice and it is unset or set to the empty string" && exit 1
use bitcoin::secp256k1::Secp256k1;
use electrum_client::ElectrumApi;
use electrum_client::Client;
use bitcoin::util::bip32;
use bitcoin::util::bip32::DerivationPath;
use bitcoin::Address;
use bitcoin::Network;
use std::str::FromStr;
fn main() {
@RCasatta
RCasatta / cpufreq.sh
Created April 9, 2022 13:33
Set the max frequency of the CPU
#!/bin/bash
# verify your available scaling frequency with:
# `cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_frequencies`
# and adapt this script
unset FREQ
case $1 in
@RCasatta
RCasatta / taproot_playground.rs
Created October 27, 2021 12:52
Some test code trying out taproot
#[cfg(test)]
mod tests {
use bitcoin::hashes::hex::{FromHex, ToHex};
use bitcoin::schnorr::{KeyPair, PublicKey};
use bitcoin::{Script, Address, Network, Transaction, TxIn, OutPoint, TxOut};
use bitcoin::blockdata::{script, opcodes};
use bitcoin::util::taproot::{TaprootSpendInfo, LeafVersion};
use bitcoin::util::address::WitnessVersion;
use bitcoin::util::sighash::{SigHashCache, ScriptPath, SigHashType};
use bitcoin::util::sighash::Prevouts;
@RCasatta
RCasatta / taproot.rs
Created October 19, 2021 10:55
taproot tests, trying to derive same taproot address from core and from rust
#[test]
fn taproot_tests() {
let secp = Secp256k1::new();
let secret = Vec::from_hex("6c068c2094c3f0986741cddbaff96399e338b4120671c6640216d3e474487a19").unwrap();
let pair = KeyPair::from_seckey_slice(&secp, &secret).unwrap();
let public = schnorr::PublicKey::from_keypair(&secp, &pair);
assert_eq!(public.to_hex(),"72ad3fb702bf1a2111b09c2bf1e72f4f52d4ceb2acdcfcd0c63abf70a59c36d6");
let second_secret = Vec::from_hex("1cbb4d11a771697c1d86d0bbbcf0344b1e8b70d0cc794c3d9d6eff613390ba5e").unwrap();
let second_pair = KeyPair::from_seckey_slice(&secp, &second_secret).unwrap();
@RCasatta
RCasatta / gist:32a579630b04259d580ae6596c715411
Created December 14, 2020 14:50
test create tx with send all
cargo run --example repl --features cli-utils,esplora,electrum -- --wallet single_change_deep --descriptor "wpkh(tpubD6NzVbkrYhZ4YmSHJMXPEvd6dnPgH55EwGBs2AJHyiBgnT7zJzQ1ywHDxxZveoApLeBeSFcjysjQ5PebSg4gsdrVdRxCLAgHK8jKUiydMrg/*)" sync --max_addresses 200
ADDRESS=$(cargo run --example repl --features cli-utils,esplora,electrum -- --wallet single_change_deep --descriptor "wpkh(tpubD6NzVbkrYhZ4YmSHJMXPEvd6dnPgH55EwGBs2AJHyiBgnT7zJzQ1ywHDxxZveoApLeBeSFcjysjQ5PebSg4gsdrVdRxCLAgHK8jKUiydMrg/*)" get_new_address | jq -r .address)
PSBT=$(cargo run --example repl --features cli-utils,esplora,electrum -- --wallet single_change_deep --descriptor "wpkh(tpubD6NzVbkrYhZ4YmSHJMXPEvd6dnPgH55EwGBs2AJHyiBgnT7zJzQ1ywHDxxZveoApLeBeSFcjysjQ5PebSg4gsdrVdRxCLAgHK8jKUiydMrg/*)" create_tx --to $ADDRESS:0 -a | jq -r .psbt)
bitcoin-cli decodepsbt $PSBT
OTHER_ADDRESS=$(cargo run --example repl --features cli-utils,esplora,electrum -- --wallet single_many_utxos --descriptor "wpkh(tpubD6NzVbkrYhZ4X2yy78HWrr1M9NT8dKeWfzNiQqDdMqqa9UmmGztG
@RCasatta
RCasatta / gist:31addef5e610666953144f51ad72b227
Created August 12, 2020 14:00
gdk-electrum exposed SPV
The following is a proposal to expose SPV validation.
gdk-electrum has SPV validation for:
- bitcoin: headers chain is downloaded verified and saved in a flat file, tx proof is downloaded for every wallet tx, and checked against the headers.
- liquid: no need to download the chain, tx proof is downloaded, the header of the block containing the tx is downloaded, the proof is checked against the Merkle root in the header, script, and challenge of the header are verified
This functionality must be exposed (so we can SPV validate on ios and remove bitcoinj on android), for liquid is quite easy since it is not required to download the headers chain which is done in a thread in gdk-electrum (this may change with dynafed). Running a thread without a session is problematic (because you don't know if you need to close it), for this reason, I was thinking an interface like the following:
```
use electrum_client::{Client, GetHistoryRes};
use bitcoin::util::bip32::{ChildNumber, ExtendedPubKey};
use bitcoin::secp256k1::{Secp256k1, All};
use bitcoin::{Address, Network, Script, Transaction, BlockHeader};
use bitcoin::consensus::{serialize, deserialize};
use std::str::FromStr;
use std::time::Instant;
use std::collections::{HashSet, HashMap};
use sled;