Skip to content

Instantly share code, notes, and snippets.


John Newbery jnewbery

View GitHub Profile
jnewbery / duplicates.cpp
Created Mar 13, 2021
Simulate the number of expected number of duplicate nonces in the Bitcoin block chain
View duplicates.cpp
#include <algorithm>
#include <iostream>
#include <random>
constexpr uint16_t REPEATS{100};
constexpr uint32_t BLOCK_HEIGHT{674293};
uint16_t run(int seed)
std::seed_seq seq{seed};
jnewbery / shared_ptr.cpp
Created Apr 18, 2020
Passing shared pointers
View shared_ptr.cpp
#include <iostream>
#include <memory>
struct Base
Base() { std::cout << " Base::Base()\n"; }
~Base() { std::cout << " Base::~Base()\n"; }
struct TraceByVal
jnewbery /
Last active Jul 8, 2020
Labitconf schnorr/taproot presentation links and notes
jnewbery /
Last active Sep 22, 2020
Wallet development

Wallet development

What are a wallet’s functions?

  • Key management
    • Identify owned transactions
    • Generating new addresses
    • Determining how to sign transactions
  • Constructing and sending transactions
    • Parsing addresses and turning them into txOuts
jnewbery /
Last active Jul 17, 2019
P2P peer prioritization logic for tx relay


Bitcoin nodes relay txs to each other over the P2P network. If a node receives a valid tx from a peer, it adds it to the mempool and relays it to its other peers. If it receives an invalid tx from a peer, it must decide what action to take. We distinguish three cases:

  1. a transaction which is valid according to consensus rules, but invalid according to the node's policy rules.
  2. a transaction which is valid according to long-established consensus rules,
#!/usr/bin/env python3
import subprocess
import os
if == 'posix':
RED = "\033[1;31m"
BLUE = "\033[0;34m"
CYAN = "\033[0;36m"
GREEN = "\033[0;32m"
RESET = "\033[0;0m"