示例#1
0
block_type genesis_block()
{
    block_type genesis;
    genesis.version = 1;
    genesis.previous_block_hash = null_hash;
    genesis.merkle = 
        hash_digest{0x4a, 0x5e, 0x1e, 0x4b, 0xaa, 0xb8, 0x9f, 0x3a,
                    0x32, 0x51, 0x8a, 0x88, 0xc3, 0x1b, 0xc8, 0x7f,
                    0x61, 0x8f, 0x76, 0x67, 0x3e, 0x2c, 0xc7, 0x7a, 
                    0xb2, 0x12, 0x7b, 0x7a, 0xfd, 0xed, 0xa3, 0x3b};
    genesis.timestamp = 1231006505;
    genesis.bits = 0x1d00ffff;
    genesis.nonce = 2083236893;

    transaction_type coinbase_tx;
    coinbase_tx.version = 1;
    coinbase_tx.locktime = 0;

    transaction_input_type coinbase_input;
    coinbase_input.previous_output.hash = null_hash;
    coinbase_input.previous_output.index = 
        std::numeric_limits<uint32_t>::max();
    // The Times 03/Jan/2009 Chancellor on brink of second bailout for banks
    coinbase_input.input_script = coinbase_script(
        data_chunk{0x04, 0xff, 0xff, 0x00, 0x1d, 0x01, 0x04, 0x45, 
                   0x54, 0x68, 0x65, 0x20, 0x54, 0x69, 0x6d, 0x65, 
                   0x73, 0x20, 0x30, 0x33, 0x2f, 0x4a, 0x61, 0x6e, 
                   0x2f, 0x32, 0x30, 0x30, 0x39, 0x20, 0x43, 0x68, 
                   0x61, 0x6e, 0x63, 0x65, 0x6c, 0x6c, 0x6f, 0x72, 
                   0x20, 0x6f, 0x6e, 0x20, 0x62, 0x72, 0x69, 0x6e, 
                   0x6b, 0x20, 0x6f, 0x66, 0x20, 0x73, 0x65, 0x63, 
                   0x6f, 0x6e, 0x64, 0x20, 0x62, 0x61, 0x69, 0x6c, 
                   0x6f, 0x75, 0x74, 0x20, 0x66, 0x6f, 0x72, 0x20, 
                   0x62, 0x61, 0x6e, 0x6b, 0x73});
    coinbase_input.sequence = std::numeric_limits<uint32_t>::max();
    coinbase_tx.inputs.push_back(coinbase_input);

    transaction_output_type coinbase_output;
    coinbase_output.value = coin_price(50);
    coinbase_output.output_script.push_operation(
        operation{opcode::special, 
            data_chunk{0x04, 0x67, 0x8a, 0xfd, 0xb0, 0xfe, 0x55, 0x48, 
                       0x27, 0x19, 0x67, 0xf1, 0xa6, 0x71, 0x30, 0xb7, 
                       0x10, 0x5c, 0xd6, 0xa8, 0x28, 0xe0, 0x39, 0x09, 
                       0xa6, 0x79, 0x62, 0xe0, 0xea, 0x1f, 0x61, 0xde, 
                       0xb6, 0x49, 0xf6, 0xbc, 0x3f, 0x4c, 0xef, 0x38, 
                       0xc4, 0xf3, 0x55, 0x04, 0xe5, 0x1e, 0xc1, 0x12, 
                       0xde, 0x5c, 0x38, 0x4d, 0xf7, 0xba, 0x0b, 0x8d, 
                       0x57, 0x8a, 0x4c, 0x70, 0x2b, 0x6b, 0xf1, 0x1d, 
                       0x5f}});
    coinbase_output.output_script.push_operation(
        operation{opcode::checksig, data_chunk()});
    coinbase_tx.outputs.push_back(coinbase_output);

    genesis.transactions.push_back(coinbase_tx);
    BITCOIN_ASSERT(genesis.transactions.size() == 1);
    BITCOIN_ASSERT(
        generate_merkle_root(genesis.transactions) == genesis.merkle);
    return genesis;
}
示例#2
0
// At the moment, test values are arbitrary and are not real hashes of previous txs or blocks
int main(void)
{
    //TRANSACTION GENERATION TESTING ////////////////////////////////////////////////////////////
    unshort version = __VERSION;
    size_t in_count = 1;
    size_t out_count = 1;
    unint time = 1435969063;
    
    // the following few things could be done in a loop in implementation for all the ins and outs
    unchar *ins[1];
    unchar *outs[1];
    
    
    ins[0] = malloc(TX_INPUT_BYTESIZE);
    outs[0] = malloc(TX_OUTPUT_BYTESIZE);
    
    ///// INPUT GENERATING /////
    unchar *ref_tx = malloc(SHA256_SIZE);
    hexstr_to_bytes("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", SHA256_SIZE, ref_tx);
    
    unchar *sig = malloc(RSA1024_SIZE);
    hexstr_to_bytes("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", RSA1024_SIZE, sig);
    
    
    generate_tx_input(ref_tx, sig, ins[0]);
    

    
    ///// OUTPUT GENERATING /////
    unchar *out_address = malloc(RSA1024_SIZE);
    hexstr_to_bytes("bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb", RSA1024_SIZE, out_address);
    unint amount = 0x00000001;
    generate_tx_output(out_address, amount, outs[0]);
    
    unchar *tx0 = malloc(TX_HEADER_SIZE + 1*TX_INPUT_BYTESIZE + 1*TX_OUTPUT_BYTESIZE);
    generate_transaction(version, in_count, out_count, time, ins, outs, tx0);

    
    // MERKLE ROOT TESTING ///////////////////////////////////////////////////////////////////////
    size_t size = (TX_HEADER_SIZE + TX_INPUT_BYTESIZE + TX_OUTPUT_BYTESIZE); // This is only computable like this because we know there's only 1 in and 1 out.
    unchar* hash = malloc(SHA256_SIZE);
    
    unchar *tx1 = malloc(TX_HEADER_SIZE + 1*TX_INPUT_BYTESIZE + 1*TX_OUTPUT_BYTESIZE);
    unchar *tx2 = malloc(TX_HEADER_SIZE + 1*TX_INPUT_BYTESIZE + 1*TX_OUTPUT_BYTESIZE);
    unchar *tx3 = malloc(TX_HEADER_SIZE + 1*TX_INPUT_BYTESIZE + 1*TX_OUTPUT_BYTESIZE);
    unchar *tx4 = malloc(TX_HEADER_SIZE + 1*TX_INPUT_BYTESIZE + 1*TX_OUTPUT_BYTESIZE);
    unchar *tx5 = malloc(TX_HEADER_SIZE + 1*TX_INPUT_BYTESIZE + 1*TX_OUTPUT_BYTESIZE);
    
    tx1=memcpy(tx1, tx0, size);
    tx2=memcpy(tx2, tx1, size);
    tx3=memcpy(tx3, tx2, size);
    tx4=memcpy(tx4, tx3, size);
    tx5=memcpy(tx5, tx4, size);

    unchar *txs[6] = {tx0,tx1,tx2,tx3,tx4,tx5};
    
    generate_merkle_root(txs, 6, hash);
    
    printf("Transaction:            ");
    int i;
    for(i=0;i<size;i++)
        printf("%02x",tx0[i]);
    printf("\n");
    
    printf("Merkle root: ");
    //int i;
    for(i=0; i<SHA256_SIZE; i++)
        printf("%02x", hash[i]);
    return 0;
};