Skip to content

Instantly share code, notes, and snippets.

//Shows how to print a bitcoin script to stdout
#include <iostream>
#include "core_write.h"
cout << "Script being executed: " << ScriptToAsmStr(script) << std::endl;
@Christewart
Christewart / gist:dcd622b4ae8832a91c3d
Created March 19, 2016 20:50
Running bitcoin core test case and getting tx hex to stdout
chris@chris:~/.../src/test$ ./test_bitcoin -t script_tests/script_valid
Running 1 test case...
tests: [["Automatically generated test cases"],["0x47 0x304402200a5c6163f07b8d3b013c4d1d6dba25e780b39658d79ba37af7057a3b7f15ffa102201fd9b4eaa9943f734928b99a83592c2e7bf342ea2680f6a2bb705167966b742001","0x41 0x0479be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8 CHECKSIG","","P2PK"]]
Transaction: 01000000019ce5586f04dd407719ab7e2ed3583583b9022f29652702cfac5ed082013461fe000000004847304402200a5c6163f07b8d3b013c4d1d6dba25e780b39658d79ba37af7057a3b7f15ffa102201fd9b4eaa9943f734928b99a83592c2e7bf342ea2680f6a2bb705167966b742001ffffffff0100000000000000000000000000
Done
*** No errors detected
@Christewart
Christewart / tx_to_stdout_hex.cpp
Created March 19, 2016 20:39
Bitcoin Core transaction to stdout in hex format
CDataStream ss(SER_NETWORK, PROTOCOL_VERSION);
ss << tx;
printf("Transaction: %s\n", HexStr(ss).c_str());
//OP_0 OP_IF,OP_1, OP_IF,OP_RETURN, OP_ELSE, OP_RETURN, OP_ELSE, OP_RETURN,OP_ENDIF,
//OP_ELSE, OP_1,OP_IF,OP_1,OP_ELSE,
//OP_RETURN,OP_ELSE,OP_1,OP_ENDIF, OP_ELSE,OP_RETURN,OP_ENDIF,OP_ADD,OP_2,OP_EQUAL
OP_0
OP_IF
OP_1
OP_IF
OP_RETURN
OP_ELSE
OP_RETURN
//"0", "IF 1 IF RETURN ELSE RETURN ELSE RETURN ENDIF ELSE 1 IF 1 ELSE RETURN ELSE 1 ENDIF ELSE RETURN ENDIF ADD 2 EQUAL
0
OP_IF
1
OP_IF
OP_RETURN
OP_ELSE
OP_RETURN
OP_ELSE
//1 OP_IF, OP_IF, OP_1, OP_ELSE, OP_0, OP_ENDIF, OP_ELSE, OP_IF, OP_0, OP_ELSE, OP_1, OP_ENDIF, OP_ENDIF
1
OP_IF
OP_IF
OP_1
OP_ELSE
OP_0
OP_ENDIF
OP_ELSE
OP_IF
//original script
//0 IF 1 IF RETURN ELSE RETURN ELSE RETURN ENDIF ELSE 1 IF 1 ELSE RETURN ELSE 1 ENDIF ELSE RETURN ENDIF ADD 2 EQUAL
//OP_IF RULE
//If the top stack value is not 0, the statements are executed. The top stack value is removed.
//OP_ELSE RULE
//If the preceding OP_IF or OP_NOTIF or OP_ELSE was not executed then these statements are and
//if the preceding OP_IF or OP_NOTIF or OP_ELSE was executed then these statements are not.
0