1
0
mirror of https://github.com/bitcoinbook/bitcoinbook synced 2024-11-05 14:59:38 +00:00
bitcoinbook/code/satoshi-words.cpp

28 lines
986 B
C++
Raw Normal View History

2014-09-28 15:52:50 +00:00
/*
Display the genesis block message by Satoshi.
*/
#include <iostream>
#include <bitcoin/bitcoin.hpp>
int main()
{
// Create genesis block.
const bc::block_type block = bc::genesis_block();
2014-09-28 15:52:50 +00:00
// Genesis block contains a single coinbase transaction.
assert(block.transactions.size() == 1);
// Get first transaction in block (coinbase).
const bc::transaction_type& coinbase_tx = block.transactions[0];
// Coinbase tx has a single input.
assert(coinbase_tx.inputs.size() == 1);
const bc::transaction_input_type& coinbase_input = coinbase_tx.inputs[0];
// Convert the input script to its raw format.
const bc::data_chunk raw_message = save_script(coinbase_input.script);
2014-09-28 15:52:50 +00:00
// Convert this to an std::string.
std::string message;
message.resize(raw_message.size());
std::copy(raw_message.begin(), raw_message.end(), message.begin());
// Display the genesis block message.
std::cout << message << std::endl;
return 0;
}