Ejemplo n.º 1
0
int IndexDbLevelDb::writeUsrDb(const map<string, SiMap>& usrFidMap, leveldb::DB* dbUsrDb, leveldb::WriteBatch& wb_usrdb, const string& dbName)
{
    // lookup map
    for(const auto& itr : usrFidMap) {
        const string& usr = itr.first;
        if(usr != "") {
            SiMap file_list_map = itr.second;
#ifdef USE_USR2FILE_TABLE2
            for(const auto& itr_str : file_list_map) {
                wb_usrdb.Put(dbName + "|" + usr + "|" + itr_str.first, "1");
            }
#else
            // check if already registered
            string value;
            int rv = dbRead(value, dbUsrDb, dbName + "|" + usr);
            if(rv == 0) {
                const string delim = ",";
                list<string> old_list;
                boost::split(old_list, value, boost::is_any_of(delim));
                for(const auto& itr_old : old_list) {
                    file_list_map[itr_old] = 0;
                }
            }
            string file_list_string = "";
            for(const auto& itr_str : file_list_map) {
                file_list_string.append(itr_str.first+",");
            }
            file_list_string = file_list_string.substr(0, file_list_string.size()-1);
            wb_usrdb.Put(dbName + "|" + usr, file_list_string);
#endif
        }
    }
    return 0;
}
Ejemplo n.º 2
0
bool mark_spent_outputs(leveldb::WriteBatch& spend_batch,
    const output_point& previous_output, const input_point& spent_inpoint)
{
    data_chunk spent_key = create_spent_key(previous_output),
        spend_value = create_spent_key(spent_inpoint);
    spend_batch.Put(slice(spent_key), slice(spend_value));
    return true;
}
Ejemplo n.º 3
0
void c_seq::seq_update(leveldb::WriteBatch& bh)
{
	m_seq_head.s_uptime(time(0));
	m_seq_head.m_head.s_crc(c_crc::crc16(0, 
		(uint8*)&m_seq_head + sizeof(_zmsg_head), 
		sizeof(m_seq_head) - sizeof(_zmsg_head)));
	leveldb::Slice value( (const char*)&m_seq_head, sizeof(m_seq_head) );
	bh.Put(m_key, value);
}
Ejemplo n.º 4
0
TxId DatabaseHelper::txSave(leveldb::WriteBatch& batch, const Hash256& txHash, const DbTransaction& dbTx)
{
	auto buffer = bufferTLS.get();
	if (buffer == NULL)
	{
		bufferTLS.reset(buffer = new std::string());
	}

	auto index = txGetOrCreateId(txHash);

	Serialize(*buffer, dbTx);

	char searchKey2[1 + sizeof(TxId)];
	searchKey2[0] = (uint8_t)DatabaseKeyHeader::Tx;
	*(TxId*) &searchKey2[1] = swapByteOrder(index);
	batch.Put(leveldb::Slice((const char*)searchKey2, sizeof(searchKey2)), *buffer);

	return index;
}
Ejemplo n.º 5
0
			Status Put(const std::vector<std::pair<std::string, std::string>>& writes)
			{
				leveldb::WriteBatch batch;

				for (auto kv : writes)
				{
					batch.Put(kv.first, kv.second);
				}

				leveldb::Status s = db->Write(leveldb::WriteOptions(), &batch);

				if (s.ok())
				{
					return Status::OK();
				}

				return Status::NotFound();

			}
Ejemplo n.º 6
0
bool add_credit(leveldb::WriteBatch& batch,
    const payment_address& address, uint64_t output_value,
    const output_point& outpoint, uint32_t block_height)
{
    data_chunk addr_key = create_address_key(address, outpoint);
    // outpoint, value, block_height
    data_chunk row_info(36 + 8 + 4);
    auto serial = make_serializer(row_info.begin());
    // outpoint
    serial.write_hash(outpoint.hash);
    serial.write_4_bytes(outpoint.index);
    // value
    serial.write_8_bytes(output_value);
    // block_height
    serial.write_4_bytes(block_height);
    BITCOIN_ASSERT(
        std::distance(row_info.begin(), serial.iterator()) == 36 + 8 + 4);
    batch.Put(slice(addr_key), slice(row_info));
    return true;
}
Ejemplo n.º 7
0
void c_seq::seq_set(leveldb::WriteBatch& bh, leveldb::Slice& value)
{
	uint32 keyId = m_seq_head.g_index() + 1;

	m_seq_head.s_index(keyId);
	m_seq_head.s_count(m_seq_head.g_count() + 1);

	_zmsg_head head;
	head.type = T_SEQ_VALUE;
	head.s_effective(time(0));
	head.s_crc(c_crc::crc16(0, (uint8*)value.data(), value.size()));

	memcpy(TSEQ_BUF(), &head, sizeof(_zmsg_head));
	memcpy(TSEQ_BUF() + sizeof(_zmsg_head), (void*)value.data(), value.size());
	int len = sizeof(_zmsg_head) + value.size();
	if (len > 0)
	{
		leveldb::Slice data(TSEQ_BUF(), len);
		bh.Put(__tos(m_key << "@" << keyId), data);
	}
}
Ejemplo n.º 8
0
			Status Put(const std::vector<std::pair<unsigned int, std::string>>& writes)
			{
				leveldb::WriteBatch batch;

				for (auto kv : writes)
				{
					std::string keystr;
					ZUtil::PutVarint64(keystr, kv.first);
					batch.Put(keystr, kv.second);
				}

				leveldb::Status s = db->Write(leveldb::WriteOptions(), &batch);

				if (s.ok())
				{
					return Status::OK();
				}

				return Status::NotFound();

			}
Ejemplo n.º 9
0
bool add_debit(leveldb::WriteBatch& batch,
    const transaction_input_type& input, const input_point& inpoint,
    uint32_t block_height)
{
    payment_address address;
    // Not a Bitcoin address so skip this output.
    if (!extract(address, input.script))
        return true;
    data_chunk addr_key = create_address_key(address, input.previous_output);
    // inpoint
    data_chunk row_info(36 + 4);
    auto serial = make_serializer(row_info.begin());
    // inpoint
    serial.write_hash(inpoint.hash);
    serial.write_4_bytes(inpoint.index);
    // block_height
    serial.write_4_bytes(block_height);
    BITCOIN_ASSERT(
        std::distance(row_info.begin(), serial.iterator()) == 36 + 4);
    batch.Put(slice(addr_key), slice(row_info));
    return true;
}