//---------------------------------------------------------------
  bool generate_genesis_block(
      block& bl
    , std::string const & genesis_tx
    , uint32_t nonce
    )
  {
    //genesis block
    bl = boost::value_initialized<block>();


    account_public_address ac = boost::value_initialized<account_public_address>();
    std::vector<size_t> sz;
    construct_miner_tx(0, 0, 0, 0, 0, ac, bl.miner_tx); // zero fee in genesis
    blobdata txb = tx_to_blob(bl.miner_tx);
    std::string hex_tx_represent = string_tools::buff_to_hex_nodelimer(txb);

    std::string genesis_coinbase_tx_hex = config::GENESIS_TX;

    blobdata tx_bl;
    string_tools::parse_hexstr_to_binbuff(genesis_coinbase_tx_hex, tx_bl);
    bool r = parse_and_validate_tx_from_blob(tx_bl, bl.miner_tx);
    CHECK_AND_ASSERT_MES(r, false, "failed to parse coinbase tx from hard coded blob");
    bl.major_version = CURRENT_BLOCK_MAJOR_VERSION;
    bl.minor_version = CURRENT_BLOCK_MINOR_VERSION;
    bl.timestamp = 0;
    bl.nonce = nonce;
    miner::find_nonce_for_given_block(bl, 1, 0);
    bl.invalidate_hashes();
    return true;
  }
Example #2
0
  //------------------------------------------------------------------------------------------------------------------------------
  bool wallet_rpc_server::on_clonetelepod(const wallet_rpc::COMMAND_RPC_CLONETELEPOD::request& req, wallet_rpc::COMMAND_RPC_CLONETELEPOD::response& res, epee::json_rpc::error& er, connection_context& cntx)
  {
    currency::transaction tx2 = AUTO_VAL_INIT(tx2);
    //new destination account 
    currency::account_base acc2 = AUTO_VAL_INIT(acc2);
    acc2.generate();

    if (!build_transaction_from_telepod(req.tpd, acc2.get_keys().m_account_address, tx2, res.status))
    {
      LOG_ERROR("Failed to build_transaction_from_telepod(...)");
      return true;
    }

    //send transaction to daemon
    currency::COMMAND_RPC_SEND_RAW_TX::request req_send_raw;
    req_send_raw.tx_as_hex = epee::string_tools::buff_to_hex_nodelimer(tx_to_blob(tx2));
    currency::COMMAND_RPC_SEND_RAW_TX::response rsp_send_raw;
    bool r = m_wallet.get_core_proxy()->call_COMMAND_RPC_SEND_RAW_TX(req_send_raw, rsp_send_raw);
    if (!r || rsp_send_raw.status != CORE_RPC_STATUS_OK)
    {
      LOG_ERROR("Problem with construct_tx(....), blobl size os too big: " << get_object_blobsize(tx2));
      res.status = "INTERNAL_ERROR";
      return true;
    }

    res.tpd.basement_tx_id_hex = string_tools::pod_to_hex(currency::get_transaction_hash(tx2));
    std::string acc2_buff = epee::serialization::store_t_to_binary(acc2);
    res.tpd.account_keys_hex = string_tools::buff_to_hex_nodelimer(acc2_buff);

    res.status = "OK";
    LOG_PRINT_GREEN("TELEPOD ISSUED [" << currency::print_money(currency::get_outs_money_amount(tx2)) << "BBR, base_tx_id: ]" << currency::get_transaction_hash(tx2), LOG_LEVEL_0);

    return true;
  }
Example #3
0
extern "C" uint64_t pNXT_submit_tx(currency::core *m_core,currency::simple_wallet *wallet,unsigned char *txbytes,int16_t size)
{
    int i,j;
    crypto::hash h;
    uint64_t txid = 0;
    blobdata txb,b;
    transaction tx = AUTO_VAL_INIT(tx);
    txin_to_key input_to_key = AUTO_VAL_INIT(input_to_key);
    NOTIFY_NEW_TRANSACTIONS::request req;
    currency_connection_context fake_context = AUTO_VAL_INIT(fake_context);
    tx_verification_context tvc = AUTO_VAL_INIT(tvc);
    if ( m_core == 0 || wallet == 0 )
    {
        printf("pNXT_submit_tx missing m_core.%p or wallet.%p\n",m_core,wallet);
        return(0);
    }
    tx.vin.clear();
    tx.vout.clear();
    tx.signatures.clear();
    keypair txkey = keypair::generate();
    add_tx_pub_key_to_extra(tx, txkey.pub);
    if ( sizeof(input_to_key.k_image) != 32 )
    {
        printf("FATAL: expected sizeof(input_to_key.k_image) to be 32!\n");
        return(0);
    }
    j = add_byte(&tx,&input_to_key,0,size&0xff);
    j = add_byte(&tx,&input_to_key,j,(size>>8)&0xff);
    for (i=0; i<size; i++)
        j = add_byte(&tx,&input_to_key,j,txbytes[i]);
    if ( j != 0 )
        tx.vin.push_back(input_to_key);
    tx.version = 0;
    txb = tx_to_blob(tx);
    printf("FROM submit jl777\n");
    if ( !m_core->handle_incoming_tx(txb,tvc,false) )
    {
        LOG_PRINT_L0("[on_send_raw_tx]: Failed to process tx");
        return(0);
    }
    if ( tvc.m_verifivation_failed )
    {
        LOG_PRINT_L0("[on_send_raw_tx]: tx verification failed");
        return(0);
    }
    if( !tvc.m_should_be_relayed )
    {
        LOG_PRINT_L0("[on_send_raw_tx]: tx accepted, but not relayed");
        return(0);
    }
    req.txs.push_back(txb);
    m_core->get_protocol()->relay_transactions(req,fake_context);
    get_transaction_hash(tx,h);
    txid = calc_txid((unsigned char *)&h,sizeof(h));
    return(txid);
}
Example #4
0
  //------------------------------------------------------------------------------------------------------------------------------
  bool wallet_rpc_server::on_withdrawtelepod(const wallet_rpc::COMMAND_RPC_WITHDRAWTELEPOD::request& req, wallet_rpc::COMMAND_RPC_WITHDRAWTELEPOD::response& res, epee::json_rpc::error& er, connection_context& cntx)
  {
    currency::transaction tx2 = AUTO_VAL_INIT(tx2);
    //parse destination add 
    currency::account_public_address acc_addr = AUTO_VAL_INIT(acc_addr);
    if (!currency::get_account_address_from_str(acc_addr, req.addr))
    {
      LOG_ERROR("Failed to build_transaction_from_telepod(...)");
      res.status = "BAD_ADDRESS";
      return true;
    }


    if (!build_transaction_from_telepod(req.tpd, acc_addr, tx2, res.status))
    {
      LOG_ERROR("Failed to build_transaction_from_telepod(...)");
      return true;
    }

    //send transaction to daemon
    currency::COMMAND_RPC_SEND_RAW_TX::request req_send_raw;
    req_send_raw.tx_as_hex = epee::string_tools::buff_to_hex_nodelimer(tx_to_blob(tx2));
    currency::COMMAND_RPC_SEND_RAW_TX::response rsp_send_raw;
    bool r = m_wallet.get_core_proxy()->call_COMMAND_RPC_SEND_RAW_TX(req_send_raw, rsp_send_raw);
    if (!r || rsp_send_raw.status != CORE_RPC_STATUS_OK)
    {
      LOG_ERROR("Problem with construct_tx(....), blobl size os too big: " << get_object_blobsize(tx2));
      res.status = "INTERNAL_ERROR";
      return true;
    }

    res.status = "OK";
    LOG_PRINT_GREEN("TELEPOD WITHDRAWN [" << currency::print_money(currency::get_outs_money_amount(tx2)) << "BBR, tx_id: ]" << currency::get_transaction_hash(tx2), LOG_LEVEL_0);

    return true;
  }
  bool core::queryBlocks(const std::list<crypto::hash>& knownBlockIds, uint64_t timestamp,
      uint64_t& resStartHeight, uint64_t& resCurrentHeight, uint64_t& resFullOffset, std::list<BlockFullInfo>& entries) {

    LockedBlockchainStorage lbs(m_blockchain_storage);

    uint64_t currentHeight = lbs->get_current_blockchain_height();
    uint64_t startOffset = 0;

    if (!lbs->find_blockchain_supplement(knownBlockIds, startOffset)) {
      return false;
    }

    uint64_t startFullOffset = 0;

    if (!lbs->getLowerBound(timestamp, startOffset, startFullOffset))
      startFullOffset = startOffset;

    resFullOffset = startFullOffset;

    if (startOffset != startFullOffset) {
      std::list<crypto::hash> blockIds;
      if (!lbs->getBlockIds(startOffset, std::min(uint64_t(BLOCKS_IDS_SYNCHRONIZING_DEFAULT_COUNT), startFullOffset - startOffset), blockIds)) {
        return false;
      }

      for (const auto& id : blockIds) {
        entries.push_back(BlockFullInfo());
        entries.back().block_id = id;
      }
    }

    auto blocksLeft = std::min(BLOCKS_IDS_SYNCHRONIZING_DEFAULT_COUNT - entries.size(), size_t(BLOCKS_SYNCHRONIZING_DEFAULT_COUNT));

    if (blocksLeft) {
      std::list<Block> blocks;
      lbs->get_blocks(startFullOffset, blocksLeft, blocks);

      for (auto& b : blocks) {
        BlockFullInfo item;

        item.block_id = get_block_hash(b);

        if (b.timestamp >= timestamp) {
          // query transactions
          std::list<Transaction> txs;
          std::list<crypto::hash> missedTxs;
          lbs->get_transactions(b.txHashes, txs, missedTxs);

          // fill data
          block_complete_entry& completeEntry = item;
          completeEntry.block = block_to_blob(b);
          for (auto& tx : txs) {
            completeEntry.txs.push_back(tx_to_blob(tx));
          }
        }

        entries.push_back(std::move(item));
      }
    }

    resCurrentHeight = currentHeight;
    resStartHeight = startOffset;

    return true;
  }