| 31 | } |
| 32 | |
| 33 | extern bool ProcessAssetFee(CBaseTx &tx, CCacheWrapper &cw, CAccount *pSrcAccount, |
| 34 | const string &action, vector<CReceipt> &receipts, string &errMsg) { |
| 35 | |
| 36 | uint64_t assetFee = 0; |
| 37 | if (action == ASSET_ACTION_ISSUE) { |
| 38 | if (!cw.sysParamCache.GetParam(ASSET_ISSUE_FEE, assetFee)) { |
| 39 | errMsg = "read param ASSET_ISSUE_FEE failed"; |
| 40 | return false; |
| 41 | } |
| 42 | } else { |
| 43 | assert(action == ASSET_ACTION_UPDATE); |
| 44 | assetFee = ASSET_UPDATE_FEE; |
| 45 | // if (!cw.sysParamCache.GetParam(ASSET_UPDATE_FEE, assetFee)) { |
| 46 | // errMsg = "read param ASSET_UPDATE_FEE failed"; |
| 47 | // return false; |
| 48 | // } |
| 49 | } |
| 50 | |
| 51 | uint64_t assetRiskFeeRatio; |
| 52 | if(!cw.sysParamCache.GetParam(SysParamType::ASSET_RISK_FEE_RATIO, assetRiskFeeRatio)) { |
| 53 | errMsg = "get assetRiskFeeRatio failed"; |
| 54 | return false; |
| 55 | } |
| 56 | |
| 57 | auto freeAmount = pSrcAccount->GetToken(SYMB::WICC).free_amount; |
| 58 | if (freeAmount < assetFee) { |
| 59 | errMsg = strprintf( |
| 60 | "account=%s balance=%llu is insufficient for %s asset fee=%llu", |
| 61 | pSrcAccount->regid.ToString(), freeAmount, assetFee, action); |
| 62 | return false; |
| 63 | } |
| 64 | |
| 65 | uint64_t riskFee = assetFee * assetRiskFeeRatio / RATIO_BOOST; |
| 66 | uint64_t minerTotalFee = assetFee - riskFee; |
| 67 | |
| 68 | auto spFcoinAccount = tx.GetAccount(cw, SysCfg().GetFcoinGenesisRegId()); |
| 69 | if (!spFcoinAccount) { |
| 70 | errMsg = "get fcoin account failed"; |
| 71 | return false; |
| 72 | } |
| 73 | |
| 74 | ReceiptType code = (action == ASSET_ACTION_ISSUE) ? ReceiptType::ASSET_ISSUED_FEE_TO_RESERVE : |
| 75 | ReceiptType::ASSET_UPDATED_FEE_TO_RESERVE; |
| 76 | |
| 77 | if (!pSrcAccount->OperateBalance(SYMB::WICC, BalanceOpType::SUB_FREE, riskFee, code, receipts, spFcoinAccount.get())) { |
| 78 | errMsg = strprintf( |
| 79 | "account=%s balance=%llu is insufficient for asset fee=%llu to risk reserve", |
| 80 | pSrcAccount->regid.ToString(), pSrcAccount->GetToken(SYMB::WICC).free_amount, riskFee); |
| 81 | return false; |
| 82 | } |
| 83 | |
| 84 | VoteDelegateVector delegates; |
| 85 | if (!cw.delegateCache.GetActiveDelegates(delegates)) { |
| 86 | errMsg = "GetActiveDelegates failed"; |
| 87 | return false; |
| 88 | } |
| 89 | assert(delegates.size() != 0 ); |
| 90 |
no test coverage detected