MCPcopy Create free account
hub / github.com/WaykiChain/WaykiChain / ComputeCDPInterest

Function ComputeCDPInterest

src/rpc/core/rpccommons.cpp:832–852  ·  view source on GitHub ↗

* Interest Ratio Formula: ( a / Log10(b + N) ) * * ==> ratio = a / Log10 (b+N) */

Source from the content-addressed store, hash-verified

830 * ==> ratio = a / Log10 (b+N)
831 */
832static uint64_t ComputeCDPInterest(CSysParamDBCache &sysParamCache, const CUserCDP &cdp, uint32_t tipHeight) {
833 if (cdp.total_owed_scoins == 0 || cdp.block_height > tipHeight) {
834 return 0;
835 }
836
837 const auto& coinPair = cdp.GetCoinPair();
838
839 list<CCdpInterestParamChange> changes;
840 if (!sysParamCache.GetCdpInterestParamChanges(coinPair, cdp.block_height, tipHeight, changes)) {
841 throw JSONRPCError(RPC_INTERNAL_ERROR, strprintf("get cdp interest param changes error! coinPiar=%s",
842 coinPair.ToString()));
843 }
844
845 uint64_t interest = 0;
846 for (auto &change : changes) {
847 interest += ::ComputeCDPInterest(cdp.total_owed_scoins, change.begin_height, change.end_height,
848 change.param_a, change.param_b);
849 }
850
851 return interest;
852}
853
854Object RPC_PARAM::CdpToJson(const CUserCDP &cdp, uint32_t tipHeight) {
855

Callers 1

CdpToJsonMethod · 0.70

Calls 4

JSONRPCErrorFunction · 0.85
GetCoinPairMethod · 0.80
ToStringMethod · 0.45

Tested by

no test coverage detected