forked from noise23/gamecredits
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add Komodo validation code thanks to jl777
- Loading branch information
1 parent
ca77990
commit e65fe30
Showing
6 changed files
with
1,409 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
/****************************************************************************** | ||
* Copyright © 2014-2018 The SuperNET Developers. * | ||
* * | ||
* See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * | ||
* the top-level directory of this distribution for the individual copyright * | ||
* holder information and the developer policies on copyright and licensing. * | ||
* * | ||
* Unless otherwise agreed in a custom licensing agreement, no part of the * | ||
* SuperNET software, including this file may be copied, modified, propagated * | ||
* or distributed except according to the terms contained in the LICENSE file * | ||
* * | ||
* Removal or modification of this copyright notice is prohibited. * | ||
* * | ||
******************************************************************************/ | ||
|
||
|
||
#ifndef komodo_rpcblockchain_h | ||
#define komodo_rpcblockchain_h | ||
|
||
|
||
int32_t komodo_MoMdata(int32_t *notarized_htp,uint256 *MoMp,uint256 *kmdtxidp,int32_t height,uint256 *MoMoMp,int32_t *MoMoMoffsetp,int32_t *MoMoMdepthp,int32_t *kmdstartip,int32_t *kmdendip); | ||
uint256 komodo_calcMoM(int32_t height,int32_t MoMdepth); | ||
extern char ASSETCHAINS_SYMBOL[65]; | ||
|
||
int32_t komodo_MoM(int32_t *notarized_heightp,uint256 *MoMp,uint256 *kmdtxidp,int32_t nHeight,uint256 *MoMoMp,int32_t *MoMoMoffsetp,int32_t *MoMoMdepthp,int32_t *kmdstartip,int32_t *kmdendip) | ||
{ | ||
int32_t depth,notarized_ht; uint256 MoM,kmdtxid; | ||
depth = komodo_MoMdata(¬arized_ht,&MoM,&kmdtxid,nHeight,MoMoMp,MoMoMoffsetp,MoMoMdepthp,kmdstartip,kmdendip); | ||
memset(MoMp,0,sizeof(*MoMp)); | ||
memset(kmdtxidp,0,sizeof(*kmdtxidp)); | ||
*notarized_heightp = 0; | ||
if ( depth > 0 && notarized_ht > 0 && nHeight > notarized_ht-depth && nHeight <= notarized_ht ) | ||
{ | ||
*MoMp = MoM; | ||
*notarized_heightp = notarized_ht; | ||
*kmdtxidp = kmdtxid; | ||
} | ||
return(depth); | ||
} | ||
|
||
UniValue calc_MoM(const JSONRPCRequest& request) | ||
{ | ||
int32_t height,MoMdepth; uint256 MoM; UniValue ret(UniValue::VOBJ); UniValue a(UniValue::VARR); | ||
if ( request.params.size() != 2 ) | ||
throw std::runtime_error("calc_MoM height MoMdepth\n"); | ||
LOCK(cs_main); | ||
height = atoi(request.params[0].get_str().c_str()); | ||
MoMdepth = atoi(request.params[1].get_str().c_str()); | ||
if ( height <= 0 || MoMdepth <= 0 || MoMdepth >= height ) | ||
throw std::runtime_error("calc_MoM illegal height or MoMdepth\n"); | ||
//fprintf(stderr,"height_MoM height.%d\n",height); | ||
MoM = komodo_calcMoM(height,MoMdepth); | ||
ret.push_back(Pair("coin",(char *)(ASSETCHAINS_SYMBOL[0] == 0 ? "KMD" : ASSETCHAINS_SYMBOL))); | ||
ret.push_back(Pair("height",height)); | ||
ret.push_back(Pair("MoMdepth",MoMdepth)); | ||
ret.push_back(Pair("MoM",MoM.GetHex())); | ||
return ret; | ||
} | ||
|
||
UniValue height_MoM(const JSONRPCRequest& request) | ||
{ | ||
int32_t height,depth,notarized_height,MoMoMdepth,MoMoMoffset,kmdstarti,kmdendi; uint256 MoM,MoMoM,kmdtxid; uint32_t timestamp = 0; UniValue ret(UniValue::VOBJ); UniValue a(UniValue::VARR); | ||
if ( request.params.size() != 1 ) | ||
throw std::runtime_error("height_MoM height\n"); | ||
LOCK(cs_main); | ||
height = atoi(request.params[0].get_str().c_str()); | ||
if ( height <= 0 ) | ||
{ | ||
if ( chainActive.Tip() == 0 ) | ||
{ | ||
ret.push_back(Pair("error",(char *)"no active chain yet")); | ||
return(ret); | ||
} | ||
height = chainActive.Tip()->nHeight; | ||
} | ||
//fprintf(stderr,"height_MoM height.%d\n",height); | ||
depth = komodo_MoM(¬arized_height,&MoM,&kmdtxid,height,&MoMoM,&MoMoMoffset,&MoMoMdepth,&kmdstarti,&kmdendi); | ||
ret.push_back(Pair("coin",(char *)(ASSETCHAINS_SYMBOL[0] == 0 ? "KMD" : ASSETCHAINS_SYMBOL))); | ||
ret.push_back(Pair("height",height)); | ||
ret.push_back(Pair("timestamp",(uint64_t)timestamp)); | ||
if ( depth > 0 ) | ||
{ | ||
ret.push_back(Pair("depth",depth)); | ||
ret.push_back(Pair("notarized_height",notarized_height)); | ||
ret.push_back(Pair("MoM",MoM.GetHex())); | ||
ret.push_back(Pair("kmdtxid",kmdtxid.GetHex())); | ||
if ( ASSETCHAINS_SYMBOL[0] != 0 ) | ||
{ | ||
ret.push_back(Pair("MoMoM",MoMoM.GetHex())); | ||
ret.push_back(Pair("MoMoMoffset",MoMoMoffset)); | ||
ret.push_back(Pair("MoMoMdepth",MoMoMdepth)); | ||
ret.push_back(Pair("kmdstarti",kmdstarti)); | ||
ret.push_back(Pair("kmdendi",kmdendi)); | ||
} | ||
} else ret.push_back(Pair("error",(char *)"no MoM for height")); | ||
|
||
return ret; | ||
} | ||
|
||
#endif /* komodo_rpcblockchain_h */ |
Oops, something went wrong.