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

27 lines
962 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.
2017-07-18 04:07:31 +00:00
bc::chain::block block = bc::chain::block::genesis_mainnet();
2014-09-28 15:52:50 +00:00
// Genesis block contains a single coinbase transaction.
2017-07-18 04:07:31 +00:00
assert(block.transactions().size() == 1);
2014-09-28 15:52:50 +00:00
// Get first transaction in block (coinbase).
2017-07-18 04:07:31 +00:00
const bc::chain::transaction& coinbase_tx = block.transactions()[0];
2014-09-28 15:52:50 +00:00
// Coinbase tx has a single input.
2017-07-18 04:07:31 +00:00
assert(coinbase_tx.inputs().size() == 1);
const bc::chain::input& coinbase_input = coinbase_tx.inputs()[0];
2014-09-28 15:52:50 +00:00
// Convert the input script to its raw format.
2017-07-18 04:07:31 +00:00
const auto prefix = false;
const bc::data_chunk& raw_message = coinbase_input.script().to_data(prefix);
// Convert this to a std::string.
std::string message(raw_message.begin(), raw_message.end());
2014-09-28 15:52:50 +00:00
// Display the genesis block message.
std::cout << message << std::endl;
return 0;
}