mirror of
https://github.com/bitcoinbook/bitcoinbook
synced 2024-11-27 02:18:25 +00:00
28 lines
986 B
C++
28 lines
986 B
C++
/*
|
|
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();
|
|
// 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);
|
|
// 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;
|
|
}
|