mirror of
https://github.com/bitcoinbook/bitcoinbook
synced 2024-11-01 13:10:04 +00:00
29 lines
982 B
C++
29 lines
982 B
C++
|
/*
|
||
|
Display the genesis block message by Satoshi.
|
||
|
*/
|
||
|
#include <iostream>
|
||
|
#include <bitcoin/bitcoin.hpp>
|
||
|
|
||
|
int main()
|
||
|
{
|
||
|
// Create genesis block.
|
||
|
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;
|
||
|
}
|
||
|
|