예제 #1
0
void CoinEng::ExportToBootstrapDat(const path& pathBoostrap) {
	uint32_t n = Db->GetMaxHeight()+1;
	
#ifndef X_DEBUG//!!!T
	if (Mode == EngMode::Bootstrap) {
		CEngStateDescription stateDesc(_self, EXT_STR("Copying " << GetBootstrapPath() << " -> " << pathBoostrap));

		return (void)copy_file(GetBootstrapPath(), pathBoostrap, copy_options::overwrite_existing);
	}
#endif

	CEngStateDescription stateDesc(_self, EXT_STR("Exporting " << n << " blocks to " << pathBoostrap));

	FileStream fs(pathBoostrap, FileMode::Create, FileAccess::Write);
	BinaryWriter wr(fs);

	for (uint32_t i=0; i<n && Runned; ++i) {
		wr << ChainParams.ProtocolMagic;
		MemoryStream ms;

		Block block = GetBlockByHeight(i);
//!!!?		block.LoadToMemory();
//!!!?		EXT_FOR (const Tx& tx, block.Txes) {
//!!!?			//			tx.m_pimpl->m_nBytesOfHash = 0;
//!!!?		}	
//!!!?		block.m_pimpl->m_hash.reset();
//!!!?block.m_pimpl->m_txHashesOutNums.clear();

		block.Write(BinaryWriter(ms).Ref());
		wr << uint32_t(ms.Position);
		fs.WriteBuf(ms);
	}
}
예제 #2
0
파일: xml.cpp 프로젝트: coinhelper/coin
String LibxmlXmlException::get_Message() const {
	String r;
	if (!get_Reason().IsEmpty())
		r += get_Reason();
	if (!get_Url().IsEmpty())
		r +=" at "+get_Url()+" ";
	r += EXT_STR("(line: " << LineNumber << ", pos: " << LinePosition << ")");
	return r;
}
예제 #3
0
	SinceBlockInfo ListSinceBlock(const HashValue& hashBlock) override {
		SinceBlockInfo	r;
		VarValue v = !hashBlock ? Call("listsinceblock") : Call("listsinceblock", EXT_STR(hashBlock));
		r.LastBlock = HashValue(v["lastblock"].ToString());
		VarValue vtx = v["transactions"];
		r.Txes.resize(vtx.size());
		for (int i=0; i<r.Txes.size(); ++i)
			r.Txes[i] = ToTxInfo(vtx[i]);
		return r;
	}
예제 #4
0
	void DeleteBlock(int height, const vector<Int64>& txids) override {
		CoinEng& eng = Eng();

		ostringstream os;
		os << "DELETE FROM txes WHERE id IN (";
		for (int i=0; i<txids.size(); ++i)
			os << (i ? ", " : "") << txids[i];
		os << ")";
		//!!!R		SqliteCommand(EXT_STR("DELETE FROM txes WHERE blockord=" << height), m_db).ExecuteNonQuery();
		SqliteCommand(os.str(), m_db).ExecuteNonQuery();
		SqliteCommand(EXT_STR("DELETE FROM blocks WHERE id=" << height), m_db).ExecuteNonQuery();
	}
예제 #5
0
	vector<Block> GetBlocks(const LocatorHashes& locators, const HashValue& hashStop) override {
		vector<Block> r;
		int idx = locators.FindIndexInMainChain();
		EXT_LOCK (MtxSqlite) {
			SqliteCommand cmd(EXT_STR("SELECT id, hash, data, txhashes FROM blocks WHERE id>" << idx << " ORDER BY id LIMIT " << 2000 + locators.DistanceBack), m_db);
			for (DbDataReader dr = cmd.ExecuteReader(); dr.Read();) {
				Block block = LoadBlock(dr);
				r.push_back(block);
				if (Hash(block) == hashStop)
					break;
			}
		}
		return r;
	}
예제 #6
0
파일: namecoin.cpp 프로젝트: ufasoft/coin
	void OptionalDeleteExpiredDomains(uint32_t height) override {
		if (ResolverMode) {
			if (!(heightExpired & 0xFF)) {
				SqliteCommand(EXT_STR("DELETE FROM domains WHERE height <= " << heightExpired), m_db)
					.ExecuteNonQuery();
			}
		} else {
			Block blockExpired = GetBlockByHeight(heightExpired);
			EXT_FOR (const TxHashOutNum& hom, blockExpired.get_TxHashesOutNums()) {
				m_cmdDeleteDomain
					.Bind(1, ReducedHashValue(hom.HashTx))
					.ExecuteNonQuery();
			}
		}
	}
예제 #7
0
	BlockInfo GetBlock(const HashValue& hashBlock) override {
		BlockInfo r;
		VarValue v = Call("getblock", EXT_STR(hashBlock));
		r.Version = (int32_t)v["version"].ToInt64();
		r.Timestamp = DateTime::from_time_t(v["time"].ToInt64());
		r.Hash = HashValue(v["hash"].ToString());
		if (VarValue vpbh = v["previousblockhash"])
			r.PrevBlockHash = HashValue(vpbh.ToString());
		r.MerkleRoot = HashValue(v["merkleroot"].ToString());
		r.Height = (int)v["height"].ToInt64();
		r.Confirmations = (int)v["confirmations"].ToInt64();
		r.Difficulty = v["difficulty"].ToDouble();
		VarValue vtx = v["tx"];
		r.HashTxes.resize(vtx.size());
		for (size_t i=0; i<r.HashTxes.size(); ++i)
			r.HashTxes[i] = HashValue(vtx[i].ToString());
		return r;
	}
예제 #8
0
	void SubmitBlock(const ConstBuf& data, RCString workid) override {
		String sdata = EXT_STR(data);
		if (HasSubmitBlockMethod) {
			try {
				DBG_LOCAL_IGNORE_CONDITION(ExtErr::JSON_RPC_MethodNotFound);
				VarValue par;
				if (!workid.empty())
					par.Set("workid", workid);
				ProcessSubmitResult(Call("submitblock", sdata, par));
				return;
			} catch (const system_error& ex) {
				if (ex.code() != json_rpc_errc::MethodNotFound) {
					TRC(1, ex.what());
					throw;
				}
				HasSubmitBlockMethod = false;
			}
		}
		if (!HasSubmitBlockMethod) {
			VarValue par;
			par.Set("data", sdata);
			ProcessSubmitResult(Call("getblocktemplate", par));
		}
	}
예제 #9
0
	void GetWork(const ConstBuf& data) override {
		ProcessSubmitResult(Call("getwork", EXT_STR(data)));
	}
예제 #10
0
	TxInfo GetTransaction(const HashValue& hashTx) override {
		return ToTxInfo(Call("gettransaction", EXT_STR(hashTx)));
	}