mirror of
https://github.com/bitcoinbook/bitcoinbook
synced 2024-12-23 15:18:11 +00:00
27 lines
962 B
C++
27 lines
962 B
C++
/*
|
|
Display the genesis block message by Satoshi.
|
|
*/
|
|
#include <iostream>
|
|
#include <bitcoin/bitcoin.hpp>
|
|
|
|
int main()
|
|
{
|
|
// Create genesis block.
|
|
bc::chain::block block = bc::chain::block::genesis_mainnet();
|
|
// Genesis block contains a single coinbase transaction.
|
|
assert(block.transactions().size() == 1);
|
|
// Get first transaction in block (coinbase).
|
|
const bc::chain::transaction& coinbase_tx = block.transactions()[0];
|
|
// Coinbase tx has a single input.
|
|
assert(coinbase_tx.inputs().size() == 1);
|
|
const bc::chain::input& coinbase_input = coinbase_tx.inputs()[0];
|
|
// Convert the input script to its raw format.
|
|
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());
|
|
// Display the genesis block message.
|
|
std::cout << message << std::endl;
|
|
return 0;
|
|
}
|