Browse Source

Test

pull/4/head
jl777 6 years ago
parent
commit
62f0cedd3c
  1. 73
      src/cc/dapps/oraclefeed.c
  2. 18
      src/cc/gateways.cpp

73
src/cc/dapps/oraclefeed.c

@ -430,6 +430,78 @@ int32_t get_KMDheader(bits256 *blockhashp,bits256 *merklerootp,int32_t prevheigh
return(0);
}
cJSON *get_gatewayspending(char *acname,char *oraclestxidstr,char *coin)
{
cJSON *retjson; char *retstr; int32_t height=0;
if ( (retjson= get_komodocli(&retstr,acname,"gatewayspending",oraclestxidstr,coin,"")) != 0 )
{
return(retjson);
}
else if ( retstr != 0 )
{
fprintf(stderr,"get_gatewayspending.(%s) error.(%s)\n",acname,retstr);
free(retstr);
}
return(0);
}
cJSON *get_rawmempool(char *acname)
{
cJSON *retjson; char *retstr; int32_t height=0;
if ( (retjson= get_komodocli(&retstr,acname,"getrawmempool","","","")) != 0 )
{
return(retjson);
}
else if ( retstr != 0 )
{
fprintf(stderr,"get_rawmempool.(%s) error.(%s)\n",acname,retstr);
free(retstr);
}
return(0);
}
void update_gatewayspending(char *acname,char *oraclestxidstr,char *coin)
{
// check queue to prevent duplicate
// check KMD chain and mempool for txidaddr
// if txidaddr exists properly, spend the marker (txid.2)
// create withdraw tx and sign it
// if enough sigs, sendrawtransaction and when it confirms spend marker (txid.2)
// if not enough sigs, post partially signed to acname with marker2
// monitor marker2, for the partially signed withdraws
cJSON *retjson,*pending; char *coinstr,*txidaddr; int32_t i,n;
if ( (retjson= get_gatewayspending(acname,oraclestxidstr,coin)) != 0 )
{
if ( jint(retjson,"queueflag") != 0 && (coinstr= jstr(retjson,"coin")) != 0 && strcmp(coinstr,coin) == 0 )
{
if ( (pending= jarray(&n,retjson,"pending")) != 0 )
{
for (i=0; i<n; i++)
{
item = jitem(pending,i);
/*{
"txid": "10ec8f4dad6903df6b249b361b879ac77b0617caad7629b97e10f29fa7e99a9b",
"txidaddr": "RMbite4TGugVmkGmu76ytPHDEQZQGSUjxz",
"withdrawaddr": "RNJmgYaFF5DbnrNUX6pMYz9rcnDKC2tuAc",
"amount": "1.00000000"
}*/
if ( (txidaddr= jstr(item,"txidaddr")) != 0 )
{
if ( gateways_txidexists(txidaddr) == 0 )
{
// ./komodo-cli z_sendmany "pubkeyaddr" '[{"address":"RFpxgqff7FDHFuHa3jSX5NzqqWCcELz8ha","amount":0.0001},{"address":"RHV2As4rox97BuE3LK96vMeNY8VsGRTmBj","amount":7.6999}]'
}
else
{
// spend acname txid.2
}
}
}
}
free_json(retjson);
}
}
int32_t get_oracledata(int32_t prevheight,char *hexstr,int32_t maxsize,char *format)
{
int32_t i; uint32_t height; uint64_t price; bits256 blockhash,merkleroot;
@ -528,6 +600,7 @@ int32_t main(int32_t argc,char **argv)
prevheight = height;
acheight = get_KMDheight(acname);
printf("ht.%d <- %s\n",height,hexstr);
update_gatewayspending(acname,oraclestr,"KMD");
}
free_json(clijson2);
}

18
src/cc/gateways.cpp

@ -138,13 +138,6 @@ int32_t GatewaysAddQueue(std::string coin,uint256 txid,CScript scriptPubKey,int6
char destaddr[64],str[65];
Getscriptaddress(destaddr,scriptPubKey);
fprintf(stderr,"GatewaysAddQueue: %s %s %s %.8f\n",coin.c_str(),uint256_str(str,txid),destaddr,(double)nValue/COIN);
// check queue to prevent duplicate
// check KMD chain and mempool for txidaddr
// if txidaddr exists properly, spend the marker (txid.2)
// create withdraw tx and sign it
// if enough sigs, sendrawtransaction and when it confirms spend marker (txid.2)
/// if not enough sigs, post partially signed to acname with marker2
/// monitor marker2, for the partially signed withdraws
}
// start of consensus code
@ -772,7 +765,7 @@ std::string GatewaysWithdraw(uint64_t txfee,uint256 bindtxid,std::string refcoin
UniValue GatewaysPendingWithdraws(uint256 bindtxid,std::string refcoin)
{
UniValue result(UniValue::VOBJ),pending(UniValue::VARR),obj(UniValue::VOBJ); CTransaction tx; std::string coin; CPubKey mypk,gatewayspk; std::vector<CPubKey> msigpubkeys; uint256 hashBlock,assetid,txid,oracletxid; uint8_t M,N,taddr,prefix,prefix2; char depositaddr[64],withmarker[64],coinaddr[64],destaddr[64],str[65],withaddr[64],numstr[32],txidaddr[64]; int32_t i,n,numvouts,vout,numqueued,queueflag; int64_t totalsupply; struct CCcontract_info *cp,C;
UniValue result(UniValue::VOBJ),pending(UniValue::VARR),obj(UniValue::VOBJ); CTransaction tx; std::string coin; CPubKey mypk,gatewayspk; std::vector<CPubKey> msigpubkeys; uint256 hashBlock,assetid,txid,oracletxid; uint8_t M,N,taddr,prefix,prefix2; char depositaddr[64],withmarker[64],coinaddr[64],destaddr[64],str[65],withaddr[64],numstr[32],txidaddr[64],signeraddr[64]; int32_t i,n,numvouts,vout,numqueued,queueflag; int64_t totalsupply; struct CCcontract_info *cp,C;
std::vector<std::pair<CAddressUnspentKey, CAddressUnspentValue> > unspentOutputs;
cp = CCinit(&C,EVAL_GATEWAYS);
mypk = pubkey2pk(Mypubkey());
@ -816,8 +809,13 @@ UniValue GatewaysPendingWithdraws(uint256 bindtxid,std::string refcoin)
sprintf(numstr,"%.8f",(double)tx.vout[0].nValue/COIN);
obj.push_back(Pair("amount",numstr));
pending.push_back(obj);
//if ( queueflag != 0 )
// numqueued += GatewaysAddQueue(refcoin,txid,tx.vout[1].scriptPubKey,tx.vout[0].nValue);
if ( queueflag != 0 )
{
obj.push_back(Pair("depositaddr",depositaddr));
Getscriptaddress(signeraddr,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG);
obj.push_back(Pair("signeraddr",signeraddr));
// numqueued += GatewaysAddQueue(refcoin,txid,tx.vout[1].scriptPubKey,tx.vout[0].nValue);
}
}
}
}

Loading…
Cancel
Save