Skip to content

Instantly share code, notes, and snippets.

@bitcartel
bitcartel / alert.cpp
Created July 15, 2016 15:55 — forked from lukem512/alert.cpp
Generate Alert Tests in Bitcoin Core (SignAndSave alternative)
// Sign CAlert with stored private key
bool SignAlert(CAlert &alert)
{
// key in WIF format
const char* pszPrivKey = "";
// serialize alert data
CDataStream sMsg(SER_NETWORK, PROTOCOL_VERSION);
sMsg << *(CUnsignedAlert*)&alert;
alert.vchMsg = std::vector<unsigned char>(sMsg.begin(), sMsg.end());

How to test bitcoin alerts

Motivation

Programming for bitcoin can be a bit of a pain at times. There's a lot of esoteric knowledge required and not everything is documented that well, though with some of the newer documentation projects like the [bitcoin developer documentation][devdocs], it's getting easier.

One thing I ran into recently is the existence of bitcoin alerts. These are alerts that are sent by the core developers onto the entire bitcoin network to warn of serious security events. They don't come up very often (there's [only been 8][alertlist] in the entire history of bitcoin as of this writing), but if your application is built on top of it, you'd better handle it.

The problem, though, is that the alerts are actually signed by a key controlled by the core developers. You can't just create new alerts for testnet, for example, as every other bitcoin client, including your own, will ignore them. So how do you test them?

@bitcartel
bitcartel / sendalert.cpp
Created July 15, 2016 05:36 — forked from gavinandresen/sendalert.cpp
Bitcoin CAlert code (without private key, of course)
#include "headers.h"
#include "net.h"
static const int64 DAYS = 24 * 60 * 60;
void ThreadSendAlert();
class CSendAlert
{
public:
@bitcartel
bitcartel / scriptPubKey-templates-0-400000.json
Created March 5, 2016 16:17 — forked from FelixWeis/scriptPubKey-templates-0-400000.json
Bitcoin output script types by frequency (P2PK, P2PKH, MULTISIG, P2SH, OP_RETURN, ...)
{
"OP_DUP OP_HASH160 20 OP_EQUALVERIFY OP_CHECKSIG": 319721182,
"OP_HASH160 20 OP_EQUAL": 10083919,
"65 OP_CHECKSIG": 887766,
"OP_RETURN": 288521,
"OP_1 33 33 33 OP_3 OP_CHECKMULTISIG": 224438,
"": 219175,
"OP_1 33 33 OP_2 OP_CHECKMULTISIG": 206415,
"33 OP_CHECKSIG": 101306,
"OP_RETURN 40": 65287,
@bitcartel
bitcartel / sendalert.cpp
Created January 14, 2016 20:46 — forked from laanwj/sendalert.cpp
Bitcoin send alert code
/*
So you need to broadcast an alert...
... here's what to do:
1. Copy sendalert.cpp into your bitcoind build directory
2. Decrypt the alert keys
copy the decrypted file as alertkeys.h into the src/ directory.
3. Modify the alert parameters in sendalert.cpp
@bitcartel
bitcartel / hack.sh
Created March 31, 2012 16:03 — forked from erikh/hack.sh
OSX For Hackers
#!/usr/bin/env sh
##
# This is script with usefull tips taken from:
# https://github.com/mathiasbynens/dotfiles/blob/master/.osx
#
# install it:
# curl -sL https://raw.github.com/gist/2108403/hack.sh | sh
#
@bitcartel
bitcartel / tlc.lua
Created March 28, 2012 15:44 — forked from fjolnir/tlc.lua
LuaJIT ObjC bridge
-- TLC - The Tiny Lua Cocoa bridge
-- Note: Only tested with LuaJit 2 Beta 9 on x86_64 with OS X >=10.7.3 & iPhone 4 with iOS 5
-- Copyright (c) 2012, Fjölnir Ásgeirsson
-- Permission to use, copy, modify, and/or distribute this software for any
-- purpose with or without fee is hereby granted, provided that the above
-- copyright notice and this permission notice appear in all copies.
-- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
@bitcartel
bitcartel / UIImage+Resize.m
Created March 23, 2012 05:15 — forked from erans/UIImage+Resize.m
UIImage+Resize.m Fix for Rotation / Orientation on iOS 5
- (UIImage *)resizedImage:(CGSize)newSize interpolationQuality:(CGInterpolationQuality)quality {
BOOL drawTransposed;
CGAffineTransform transform = CGAffineTransformIdentity;
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 5.0) {
// Apprently in iOS 5 the image is already correctly rotated, so we don't need to rotate it manually
drawTransposed = NO;
} else {
switch (self.imageOrientation) {
case UIImageOrientationLeft:
@bitcartel
bitcartel / UIImage+Additions.h
Created March 23, 2012 02:46 — forked from Shilo/UIImage+Additions.h
A UIImage category that will replace or remove colors. This allows multiple colors to be changed on a single image, until it has alpha values.
//
// UIImage+Additions.h
// Sparrow
//
// Created by Shilo White on 10/16/11.
// Copyright 2011 Shilocity Productions. All rights reserved.
//
#define COLOR_PART_RED(color) (((color) >> 16) & 0xff)
#define COLOR_PART_GREEN(color) (((color) >> 8) & 0xff)