コード例 #1
0
ファイル: anonymain.cpp プロジェクト: SoyPay/vmsdk
/*
* @brief 	step1:检查当前合约内容是否合法\n
* 			step2:遍历数据库中是有否有大于2条的数据,并且数据是有效的,输出指令流\n
* 			step3:写入当前tx的hash到数据库\n
*/
bool ProcessContract(const CONTRACT* const pContract)
{
	LogPrint("ProcessContract",sizeof("ProcessContract"),STRING);
	if(!CheckContact(pContract))
	{
		return false;
	}
	WriteOperate(pContract);
	bool flag = false;
	char hash[32]={0};
	if(!GetCurTxHash(&hash))
		return false;
	if(!WriteData(&hash,32,&flag,1))
		return false;

}
コード例 #2
0
ファイル: vmrunevn.cpp プロジェクト: sharkfund001/sharkfund
tuple<bool, uint64_t, string> CVmRunEvn::run(shared_ptr<CBaseTransaction>& Tx, CAccountViewCache& view, CScriptDBViewCache& VmDB, int nHeight,
		uint64_t nBurnFactor, uint64_t &uRunStep) {

	if(nBurnFactor == 0)
	{
//		assert(0);
		return std::make_tuple (false, 0, string("VmScript nBurnFactor == 0 \n"));
	}
	m_ScriptDBTip = &VmDB;

	CTransaction* tx = static_cast<CTransaction*>(Tx.get());
	if(tx->llFees <= CBaseTransaction::nMinTxFee) {
		return std::make_tuple (false, 0, string("vm run evn fee too litter\n"));
	}
	uint64_t maxstep = ((tx->llFees-CBaseTransaction::nMinTxFee)/ nBurnFactor) * 100;
	
	if(maxstep > MAX_BLOCK_RUN_STEP){
		maxstep = MAX_BLOCK_RUN_STEP;
	}
	LogPrint("vm", "tx hash:%s fees=%lld fuelrate=%lld maxstep:%d\n", Tx->GetHash().GetHex(), tx->llFees, nBurnFactor, maxstep);
	if (!intial(Tx, view, nHeight)) {
		return std::make_tuple (false, 0, string("VmScript inital Failed\n"));
	}

	int64_t step = pMcu.get()->run(maxstep,this);
	if (0 == step) {
		return std::make_tuple(false, 0, string("VmScript run Failed\n"));
	} else if (-1 == step) {
		return std::make_tuple(false, 0, string("execure tx contranct run step exceed the max step limit\n"));
	}else{
		uRunStep = step;
	}

	LogPrint("vm", "tx:%s,step:%ld\n", tx->ToString(view), uRunStep);

	if (!CheckOperate(m_output)) {
		return std::make_tuple (false, 0, string("VmScript CheckOperate Failed \n"));
	}

	if (!OpeatorAccount(m_output, view, nHeight)) {
		return std::make_tuple (false, 0, string("VmScript OpeatorAccount Failed\n"));
	}

	LogPrint("vm", "isCheckAccount:%d\n", isCheckAccount);
	if(isCheckAccount) {
		LogPrint("vm","isCheckAccount is true\n");
		if(!CheckAppAcctOperate(tx))
			return std::make_tuple (false, 0, string("VmScript CheckAppAcct Failed\n"));
	}

	if(!OpeatorAppAccount(MapAppOperate, *m_ScriptDBTip))
	{
		return std::make_tuple (false, 0, string("OpeatorApp Account Failed\n"));
	}

	if(SysCfg().GetOutPutLog() && m_output.size() > 0) {
		CScriptDBOperLog operlog;
		uint256 txhash = GetCurTxHash();
		if(!m_ScriptDBTip->WriteTxOutPut(txhash, m_output, operlog))
			return std::make_tuple (false, 0, string("write tx out put Failed \n"));
		m_dblog->push_back(operlog);
	}

	uint64_t spend = uRunStep * nBurnFactor;
		if((spend < uRunStep) || (spend < nBurnFactor)){
		return std::make_tuple (false, 0, string("mul error\n"));
	}
	return std::make_tuple (true, spend, string("VmScript Sucess\n"));

}