示例#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;
}
bool leveldb_chain_keeper::remove_address(leveldb::WriteBatch& batch,
    const script& output_script, const output_point& outpoint)
{
    payment_address address;
    if (!extract(address, output_script))
        return false;
    data_chunk raw_address = create_address_key(address);
    BITCOIN_ASSERT(!raw_address.empty());
    data_chunk outpoint_value = create_spent_key(outpoint);
    bool is_found = false;
    leveldb_iterator it(address_iterator(db_.addr, raw_address));
    for (; valid_address_iterator(it, raw_address); it->Next())
    {
        if (slice_to_output_point(it->value()) != outpoint)
            continue;
        // We found the address entry we were looking for.
        BITCOIN_ASSERT(!is_found);
        is_found = true;
        // Put changes into batch finally.
        batch.Delete(it->key());
        break;
    }
    BITCOIN_ASSERT(it->status().ok());
    if (!is_found)
        return false;
    return true;
}
示例#3
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;
}
示例#4
0
文件: c_seq.cpp 项目: Mignet/zstorage
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);
}
bool remove_credit(leveldb::WriteBatch& batch,
    const transaction_output_type& output, const output_point& outpoint)
{
    payment_address address;
    // Not a Bitcoin address so skip this output.
    if (!extract(address, output.script))
        return true;
    data_chunk addr_key = create_address_key(address, outpoint);
    batch.Delete(slice(addr_key));
    return true;
}
示例#6
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;
}
示例#7
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();

			}
示例#8
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;
}
示例#9
0
文件: c_seq.cpp 项目: Mignet/zstorage
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);
	}
}
示例#10
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();

			}
示例#11
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;
}
示例#12
0
文件: c_seq.cpp 项目: Mignet/zstorage
void c_seq::seq_del(uint32 keyId, leveldb::WriteBatch& bh)
{
	bh.Delete(__tos(m_key << "@" << keyId));
	m_seq_head.s_count(m_seq_head.g_count() - 1);
	//LOG4_ERROR("SEQ DEL KEY:" << __tos(m_key << "@" << keyId));
}
示例#13
0
					void Clear()
					{
						batch.Clear();
						count = 0;
					}