|
|
@ -14,6 +14,7 @@ |
|
|
|
******************************************************************************/ |
|
|
|
|
|
|
|
#include "CCGateways.h" |
|
|
|
#include "key_io.h" |
|
|
|
|
|
|
|
/*
|
|
|
|
prevent duplicate bindtxid via mempool scan |
|
|
@ -147,7 +148,7 @@ |
|
|
|
*/ |
|
|
|
// start of consensus code
|
|
|
|
|
|
|
|
CScript EncodeGatewaysBindOpRet(uint8_t funcid,uint256 tokenid,std::string coin,int64_t totalsupply,uint256 oracletxid,uint8_t M,uint8_t N,std::vector<CPubKey> gatewaypubkeys,uint8_t taddr,uint8_t prefix,uint8_t prefix2) |
|
|
|
CScript EncodeGatewaysBindOpRet(uint8_t funcid,uint256 tokenid,std::string coin,int64_t totalsupply,uint256 oracletxid,uint8_t M,uint8_t N,std::vector<CPubKey> gatewaypubkeys,uint8_t taddr,uint8_t prefix,uint8_t prefix2,uint8_t wiftype) |
|
|
|
{ |
|
|
|
CScript opret; uint8_t evalcode = EVAL_GATEWAYS; struct CCcontract_info *cp,C; CPubKey gatewayspk; |
|
|
|
std::vector<CPubKey> pubkeys; |
|
|
@ -155,11 +156,11 @@ CScript EncodeGatewaysBindOpRet(uint8_t funcid,uint256 tokenid,std::string coin, |
|
|
|
cp = CCinit(&C,EVAL_GATEWAYS); |
|
|
|
gatewayspk = GetUnspendable(cp,0); |
|
|
|
pubkeys.push_back(gatewayspk); |
|
|
|
opret << OP_RETURN << E_MARSHAL(ss << evalcode << funcid << coin << totalsupply << oracletxid << M << N << gatewaypubkeys << taddr << prefix << prefix2); |
|
|
|
opret << OP_RETURN << E_MARSHAL(ss << evalcode << funcid << coin << totalsupply << oracletxid << M << N << gatewaypubkeys << taddr << prefix << prefix2 << wiftype); |
|
|
|
return(EncodeTokenOpRet(tokenid,pubkeys,opret)); |
|
|
|
} |
|
|
|
|
|
|
|
uint8_t DecodeGatewaysBindOpRet(char *depositaddr,const CScript &scriptPubKey,uint256 &tokenid,std::string &coin,int64_t &totalsupply,uint256 &oracletxid,uint8_t &M,uint8_t &N,std::vector<CPubKey> &gatewaypubkeys,uint8_t &taddr,uint8_t &prefix,uint8_t &prefix2) |
|
|
|
uint8_t DecodeGatewaysBindOpRet(char *depositaddr,const CScript &scriptPubKey,uint256 &tokenid,std::string &coin,int64_t &totalsupply,uint256 &oracletxid,uint8_t &M,uint8_t &N,std::vector<CPubKey> &gatewaypubkeys,uint8_t &taddr,uint8_t &prefix,uint8_t &prefix2,uint8_t wiftype) |
|
|
|
{ |
|
|
|
std::vector<uint8_t> vopret; uint8_t *script,e,f,tokenevalcode; |
|
|
|
std::vector<uint8_t> vOpretExtra; std::vector<CPubKey> pubkeys; |
|
|
@ -171,7 +172,7 @@ uint8_t DecodeGatewaysBindOpRet(char *depositaddr,const CScript &scriptPubKey,ui |
|
|
|
else GetOpReturnData(scriptPubKey, vopret); |
|
|
|
script = (uint8_t *)vopret.data(); |
|
|
|
depositaddr[0] = 0; |
|
|
|
if ( vopret.size() > 2 && E_UNMARSHAL(vopret,ss >> e; ss >> f; ss >> coin; ss >> totalsupply; ss >> oracletxid; ss >> M; ss >> N; ss >> gatewaypubkeys; ss >> taddr; ss >> prefix; ss >> prefix2;) != 0 ) |
|
|
|
if ( vopret.size() > 2 && E_UNMARSHAL(vopret,ss >> e; ss >> f; ss >> coin; ss >> totalsupply; ss >> oracletxid; ss >> M; ss >> N; ss >> gatewaypubkeys; ss >> taddr; ss >> prefix; ss >> prefix2; ss >> wiftype) != 0 ) |
|
|
|
{ |
|
|
|
if ( prefix == 60 ) |
|
|
|
{ |
|
|
@ -181,6 +182,11 @@ uint8_t DecodeGatewaysBindOpRet(char *depositaddr,const CScript &scriptPubKey,ui |
|
|
|
//LogPrint("gatewayscc","f.%c M.%d of N.%d size.%d -> %s\n",f,M,N,(int32_t)gatewaypubkeys.size(),depositaddr);
|
|
|
|
} else Getscriptaddress(depositaddr,CScript() << ParseHex(HexStr(gatewaypubkeys[0])) << OP_CHECKSIG); |
|
|
|
} |
|
|
|
else if (prefix == 28 && prefix2 == 50) |
|
|
|
{ |
|
|
|
if ( N > 1 ) strcpy(depositaddr,CCustomBitcoinAddress(CScriptID(GetScriptForMultisig(M,gatewaypubkeys)),taddr,prefix,prefix2).ToString().c_str()); |
|
|
|
else GetCustomscriptaddress(depositaddr,CScript() << ParseHex(HexStr(gatewaypubkeys[0])) << OP_CHECKSIG,taddr,prefix,prefix2); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
LogPrint("gatewayscc","need to generate non-KMD addresses prefix.%d\n",prefix); |
|
|
@ -446,7 +452,7 @@ uint256 GatewaysReverseScan(uint256 &txid,int32_t height,uint256 reforacletxid,u |
|
|
|
} |
|
|
|
} //else LogPrint("gatewayscc","height.%d vs search ht.%d\n",(int32_t)merkleht,(int32_t)height);
|
|
|
|
batontxid = bhash; |
|
|
|
//LogPrint("gatewayscc","new hash %s\n",uint256_str(str,batontxid));
|
|
|
|
// LogPrint("gatewayscc","new hash %s\n",uint256_str(str,batontxid));
|
|
|
|
} else break; |
|
|
|
} |
|
|
|
LogPrint("gatewayscc","end of loop\n"); |
|
|
@ -479,7 +485,7 @@ uint256 BitcoinGetProofMerkleRoot(const std::vector<uint8_t> &proofData, std::ve |
|
|
|
return merkleBlock.txn.ExtractMatches(txids); |
|
|
|
} |
|
|
|
|
|
|
|
int64_t GatewaysVerify(char *refdepositaddr,uint256 oracletxid,int32_t claimvout,std::string refcoin,uint256 cointxid,const std::string deposithex,std::vector<uint8_t>proof,uint256 merkleroot,CPubKey destpub) |
|
|
|
int64_t GatewaysVerify(char *refdepositaddr,uint256 oracletxid,int32_t claimvout,std::string refcoin,uint256 cointxid,const std::string deposithex,std::vector<uint8_t>proof,uint256 merkleroot,CPubKey destpub,uint8_t taddr,uint8_t prefix,uint8_t prefix2) |
|
|
|
{ |
|
|
|
std::vector<uint256> txids; uint256 proofroot,hashBlock,txid = zeroid; CTransaction tx; std::string name,description,format; |
|
|
|
char destaddr[64],destpubaddr[64],claimaddr[64],str[65],str2[65]; int32_t i,numvouts; int64_t nValue = 0; |
|
|
@ -507,13 +513,13 @@ int64_t GatewaysVerify(char *refdepositaddr,uint256 oracletxid,int32_t claimvout |
|
|
|
} |
|
|
|
if ( DecodeHexTx(tx,deposithex) != 0 ) |
|
|
|
{ |
|
|
|
Getscriptaddress(claimaddr,tx.vout[claimvout].scriptPubKey); |
|
|
|
Getscriptaddress(destpubaddr,CScript() << ParseHex(HexStr(destpub)) << OP_CHECKSIG); |
|
|
|
GetCustomscriptaddress(claimaddr,tx.vout[claimvout].scriptPubKey,taddr,prefix,prefix2); |
|
|
|
GetCustomscriptaddress(destpubaddr,CScript() << ParseHex(HexStr(destpub)) << OP_CHECKSIG,taddr,prefix,prefix2); |
|
|
|
if ( strcmp(claimaddr,destpubaddr) == 0 ) |
|
|
|
{ |
|
|
|
for (i=0; i<numvouts; i++) |
|
|
|
{ |
|
|
|
Getscriptaddress(destaddr,tx.vout[i].scriptPubKey); |
|
|
|
GetCustomscriptaddress(destaddr,tx.vout[i].scriptPubKey,taddr,prefix,prefix2); |
|
|
|
if ( strcmp(refdepositaddr,destaddr) == 0 ) |
|
|
|
{ |
|
|
|
txid = tx.GetHash(); |
|
|
@ -521,13 +527,13 @@ int64_t GatewaysVerify(char *refdepositaddr,uint256 oracletxid,int32_t claimvout |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
if ( txid == cointxid ) |
|
|
|
{ |
|
|
|
LogPrint("gatewayscc","verified proof for cointxid in merkleroot\n"); |
|
|
|
return(nValue); |
|
|
|
} else LogPrint("gatewayscc","(%s) != (%s) or txid %s mismatch.%d or script mismatch\n",refdepositaddr,destaddr,uint256_str(str,txid),txid != cointxid); |
|
|
|
} else LogPrint("gatewayscc","claimaddr.(%s) != destpubaddr.(%s)\n",claimaddr,destpubaddr); |
|
|
|
} |
|
|
|
if ( txid == cointxid ) |
|
|
|
{ |
|
|
|
LogPrint("gatewayscc","verified proof for cointxid in merkleroot\n"); |
|
|
|
return(nValue); |
|
|
|
} else LogPrint("gatewayscc","(%s) != (%s) or txid %s mismatch.%d or script mismatch\n",refdepositaddr,destaddr,uint256_str(str,txid),txid != cointxid); |
|
|
|
} |
|
|
|
return(0); |
|
|
|
} |
|
|
|
|
|
|
@ -549,7 +555,7 @@ int64_t GatewaysDepositval(CTransaction tx,CPubKey mypk) |
|
|
|
int32_t GatewaysBindExists(struct CCcontract_info *cp,CPubKey gatewayspk,uint256 reftokenid) |
|
|
|
{ |
|
|
|
char markeraddr[64],depositaddr[64]; std::string coin; int32_t numvouts; int64_t totalsupply; uint256 tokenid,oracletxid,hashBlock; |
|
|
|
uint8_t M,N,taddr,prefix,prefix2; std::vector<CPubKey> pubkeys; CTransaction tx; |
|
|
|
uint8_t M,N,taddr,prefix,prefix2,wiftype; std::vector<CPubKey> pubkeys; CTransaction tx; |
|
|
|
std::vector<std::pair<CAddressIndexKey, CAmount> > addressIndex; |
|
|
|
|
|
|
|
_GetCCaddress(markeraddr,EVAL_GATEWAYS,gatewayspk); |
|
|
@ -558,7 +564,7 @@ int32_t GatewaysBindExists(struct CCcontract_info *cp,CPubKey gatewayspk,uint256 |
|
|
|
{ |
|
|
|
if ( myGetTransaction(it->first.txhash,tx,hashBlock) != 0 && (numvouts= tx.vout.size()) > 0 && DecodeGatewaysOpRet(tx.vout[numvouts-1].scriptPubKey)=='B' ) |
|
|
|
{ |
|
|
|
if ( DecodeGatewaysBindOpRet(depositaddr,tx.vout[numvouts-1].scriptPubKey,tokenid,coin,totalsupply,oracletxid,M,N,pubkeys,taddr,prefix,prefix2) == 'B' ) |
|
|
|
if ( DecodeGatewaysBindOpRet(depositaddr,tx.vout[numvouts-1].scriptPubKey,tokenid,coin,totalsupply,oracletxid,M,N,pubkeys,taddr,prefix,prefix2,wiftype) == 'B' ) |
|
|
|
{ |
|
|
|
if ( tokenid == reftokenid ) |
|
|
|
{ |
|
|
@ -574,7 +580,7 @@ int32_t GatewaysBindExists(struct CCcontract_info *cp,CPubKey gatewayspk,uint256 |
|
|
|
const uint256 &hash = txmempool.GetHash(); |
|
|
|
|
|
|
|
if ((numvouts=txmempool.vout.size()) > 0 && DecodeGatewaysOpRet(tx.vout[numvouts-1].scriptPubKey)=='B') |
|
|
|
if (DecodeGatewaysBindOpRet(depositaddr,tx.vout[numvouts-1].scriptPubKey,tokenid,coin,totalsupply,oracletxid,M,N,pubkeys,taddr,prefix,prefix2) == 'B' && |
|
|
|
if (DecodeGatewaysBindOpRet(depositaddr,tx.vout[numvouts-1].scriptPubKey,tokenid,coin,totalsupply,oracletxid,M,N,pubkeys,taddr,prefix,prefix2,wiftype) == 'B' && |
|
|
|
tokenid == reftokenid) |
|
|
|
return(1); |
|
|
|
} |
|
|
@ -584,7 +590,7 @@ int32_t GatewaysBindExists(struct CCcontract_info *cp,CPubKey gatewayspk,uint256 |
|
|
|
|
|
|
|
bool GatewaysValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &tx, uint32_t nIn) |
|
|
|
{ |
|
|
|
int32_t numvins,numvouts,preventCCvins,preventCCvouts,i,numblocks,height,claimvout; bool retval; uint8_t funcid,hash[32],K,M,N,taddr,prefix,prefix2; |
|
|
|
int32_t numvins,numvouts,preventCCvins,preventCCvouts,i,numblocks,height,claimvout; bool retval; uint8_t funcid,hash[32],K,M,N,taddr,prefix,prefix2,wiftype; |
|
|
|
char str[65],destaddr[64],depositaddr[65],validationError[512]; |
|
|
|
std::vector<uint256> txids; std::vector<CPubKey> pubkeys,publishers,tmppublishers; std::vector<uint8_t> proof; int64_t fullsupply,totalsupply,amount,tmpamount; |
|
|
|
uint256 hashblock,txid,bindtxid,deposittxid,withdrawtxid,completetxid,tokenid,tmptokenid,oracletxid,bindtokenid,cointxid,tmptxid,merkleroot,mhash; CTransaction bindtx,tmptx; |
|
|
@ -615,7 +621,7 @@ bool GatewaysValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction & |
|
|
|
//vin.1: CC input of tokens
|
|
|
|
//vout.0: CC vout of gateways tokens to gateways tokens CC address
|
|
|
|
//vout.1: CC vout txfee marker
|
|
|
|
//vout.n-1: opreturn - 'B' tokenid coin totalsupply oracletxid M N pubkeys taddr prefix prefix2
|
|
|
|
//vout.n-1: opreturn - 'B' tokenid coin totalsupply oracletxid M N pubkeys taddr prefix prefix2 wiftype
|
|
|
|
return eval->Invalid("unexpected GatewaysValidate for gatewaysbind!"); |
|
|
|
break; |
|
|
|
case 'D': |
|
|
@ -644,7 +650,7 @@ bool GatewaysValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction & |
|
|
|
return eval->Invalid("vout.0 is CC for gatewaysClaim!"); |
|
|
|
else if (myGetTransaction(bindtxid,tmptx,hashblock) == 0) |
|
|
|
return eval->Invalid("invalid gatewaysbind txid!"); |
|
|
|
else if ((numvouts=tmptx.vout.size()) < 1 || DecodeGatewaysBindOpRet(depositaddr,tmptx.vout[numvouts-1].scriptPubKey,tokenid,tmprefcoin,totalsupply,oracletxid,M,N,pubkeys,taddr,prefix,prefix2) != 'B') |
|
|
|
else if ((numvouts=tmptx.vout.size()) < 1 || DecodeGatewaysBindOpRet(depositaddr,tmptx.vout[numvouts-1].scriptPubKey,tokenid,tmprefcoin,totalsupply,oracletxid,M,N,pubkeys,taddr,prefix,prefix2,wiftype) != 'B') |
|
|
|
return eval->Invalid("invalid gatewaysbind OP_RETURN data!"); |
|
|
|
else if (tmprefcoin!=refcoin) |
|
|
|
return eval->Invalid("refcoin different than in bind tx"); |
|
|
@ -718,7 +724,7 @@ bool GatewaysValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction & |
|
|
|
sprintf(validationError,"couldnt find merkleroot for ht.%d %s oracle.%s m.%d vs n.%d\n",height,tmprefcoin.c_str(),uint256_str(str,oracletxid),m,N); |
|
|
|
return eval->Invalid(validationError); |
|
|
|
} |
|
|
|
else if (GatewaysVerify(depositaddr,oracletxid,claimvout,tmprefcoin,cointxid,hex,proof,merkleroot,pubkey)!=amount) |
|
|
|
else if (GatewaysVerify(depositaddr,oracletxid,claimvout,tmprefcoin,cointxid,hex,proof,merkleroot,pubkey,taddr,prefix,prefix2)!=amount) |
|
|
|
return eval->Invalid("external deposit not verified\n"); |
|
|
|
} |
|
|
|
break; |
|
|
@ -764,7 +770,7 @@ bool GatewaysValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction & |
|
|
|
return eval->Invalid("gatewayswithdraw tx is not yet confirmed(notarised)!"); |
|
|
|
else if (myGetTransaction(bindtxid,tmptx,hashblock) == 0) |
|
|
|
return eval->Invalid("invalid gatewaysbind txid!"); |
|
|
|
else if ((numvouts=tmptx.vout.size()) < 1 || DecodeGatewaysBindOpRet(depositaddr,tmptx.vout[numvouts-1].scriptPubKey,tokenid,tmprefcoin,totalsupply,oracletxid,M,N,pubkeys,taddr,prefix,prefix2) != 'B') |
|
|
|
else if ((numvouts=tmptx.vout.size()) < 1 || DecodeGatewaysBindOpRet(depositaddr,tmptx.vout[numvouts-1].scriptPubKey,tokenid,tmprefcoin,totalsupply,oracletxid,M,N,pubkeys,taddr,prefix,prefix2,wiftype) != 'B') |
|
|
|
return eval->Invalid("invalid gatewaysbind OP_RETURN data!"); |
|
|
|
else if (tmprefcoin!=refcoin) |
|
|
|
return eval->Invalid("refcoin different than in bind tx"); |
|
|
@ -808,7 +814,7 @@ bool GatewaysValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction & |
|
|
|
return eval->Invalid("gatewayswithdraw tx is not yet confirmed(notarised)!"); |
|
|
|
else if (myGetTransaction(bindtxid,tmptx,hashblock) == 0) |
|
|
|
return eval->Invalid("invalid gatewaysbind txid!"); |
|
|
|
else if ((numvouts=tmptx.vout.size()) < 1 || DecodeGatewaysBindOpRet(depositaddr,tmptx.vout[numvouts-1].scriptPubKey,tokenid,tmprefcoin,totalsupply,oracletxid,M,N,pubkeys,taddr,prefix,prefix2) != 'B') |
|
|
|
else if ((numvouts=tmptx.vout.size()) < 1 || DecodeGatewaysBindOpRet(depositaddr,tmptx.vout[numvouts-1].scriptPubKey,tokenid,tmprefcoin,totalsupply,oracletxid,M,N,pubkeys,taddr,prefix,prefix2,wiftype) != 'B') |
|
|
|
return eval->Invalid("invalid gatewaysbind OP_RETURN data!"); |
|
|
|
else if (tmprefcoin!=refcoin) |
|
|
|
return eval->Invalid("refcoin different than in bind tx"); |
|
|
@ -846,7 +852,7 @@ bool GatewaysValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction & |
|
|
|
return eval->Invalid("gatewayswithdraw tx is not yet confirmed(notarised)!"); |
|
|
|
else if (myGetTransaction(bindtxid,tmptx,hashblock) == 0) |
|
|
|
return eval->Invalid("invalid gatewaysbind txid!"); |
|
|
|
else if ((numvouts=tmptx.vout.size()) < 1 || DecodeGatewaysBindOpRet(depositaddr,tmptx.vout[numvouts-1].scriptPubKey,tokenid,tmprefcoin,totalsupply,oracletxid,M,N,pubkeys,taddr,prefix,prefix2) != 'B') |
|
|
|
else if ((numvouts=tmptx.vout.size()) < 1 || DecodeGatewaysBindOpRet(depositaddr,tmptx.vout[numvouts-1].scriptPubKey,tokenid,tmprefcoin,totalsupply,oracletxid,M,N,pubkeys,taddr,prefix,prefix2,wiftype) != 'B') |
|
|
|
return eval->Invalid("invalid gatewaysbind OP_RETURN data!"); |
|
|
|
else if (tmprefcoin!=refcoin) |
|
|
|
return eval->Invalid("refcoin different than in bind tx"); |
|
|
@ -874,13 +880,13 @@ bool GatewaysValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction & |
|
|
|
int64_t AddGatewaysInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey pk,uint256 bindtxid,int64_t total,int32_t maxinputs) |
|
|
|
{ |
|
|
|
char coinaddr[64],depositaddr[64]; int64_t threshold,nValue,price,totalinputs = 0,totalsupply,amount; |
|
|
|
CTransaction vintx,bindtx; int32_t vout,numvouts,n = 0; uint8_t M,N,evalcode,funcid,taddr,prefix,prefix2; std::vector<CPubKey> pubkeys; |
|
|
|
CTransaction vintx,bindtx; int32_t vout,numvouts,n = 0; uint8_t M,N,evalcode,funcid,taddr,prefix,prefix2,wiftype; std::vector<CPubKey> pubkeys; |
|
|
|
std::vector<std::pair<CAddressUnspentKey, CAddressUnspentValue> > unspentOutputs; std::string refcoin,tmprefcoin; CPubKey withdrawpub,destpub; |
|
|
|
uint256 tokenid,txid,oracletxid,tmpbindtxid,tmptokenid,deposittxid,hashBlock; |
|
|
|
|
|
|
|
if ( GetTransaction(bindtxid,bindtx,hashBlock,false) != 0 ) |
|
|
|
{ |
|
|
|
if ((numvouts=bindtx.vout.size())!=0 && DecodeGatewaysBindOpRet(depositaddr,bindtx.vout[numvouts-1].scriptPubKey,tokenid,refcoin,totalsupply,oracletxid,M,N,pubkeys,taddr,prefix,prefix2) == 'B') |
|
|
|
if ((numvouts=bindtx.vout.size())!=0 && DecodeGatewaysBindOpRet(depositaddr,bindtx.vout[numvouts-1].scriptPubKey,tokenid,refcoin,totalsupply,oracletxid,M,N,pubkeys,taddr,prefix,prefix2,wiftype) == 'B') |
|
|
|
{ |
|
|
|
GetTokensCCaddress(cp,coinaddr,pk); |
|
|
|
SetCCunspents(unspentOutputs,coinaddr); |
|
|
@ -933,10 +939,10 @@ int64_t AddGatewaysInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CP |
|
|
|
return(0); |
|
|
|
} |
|
|
|
|
|
|
|
std::string GatewaysBind(uint64_t txfee,std::string coin,uint256 tokenid,int64_t totalsupply,uint256 oracletxid,uint8_t M,uint8_t N,std::vector<CPubKey> pubkeys) |
|
|
|
std::string GatewaysBind(uint64_t txfee,std::string coin,uint256 tokenid,int64_t totalsupply,uint256 oracletxid,uint8_t M,uint8_t N,std::vector<CPubKey> pubkeys,uint8_t p1,uint8_t p2,uint8_t p3,uint8_t p4) |
|
|
|
{ |
|
|
|
CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); |
|
|
|
CTransaction oracletx; uint8_t taddr,prefix,prefix2; CPubKey mypk,gatewayspk; CScript opret; uint256 hashBlock; |
|
|
|
CTransaction oracletx; uint8_t taddr,prefix,prefix2,wiftype; CPubKey mypk,gatewayspk; CScript opret; uint256 hashBlock; |
|
|
|
struct CCcontract_info *cp,*cpTokens,C,CTokens; std::string name,description,format; int32_t i,numvouts; int64_t fullsupply; |
|
|
|
char destaddr[64],coinaddr[64],myTokenCCaddr[64],str[65],*fstr; |
|
|
|
|
|
|
@ -944,16 +950,18 @@ std::string GatewaysBind(uint64_t txfee,std::string coin,uint256 tokenid,int64_t |
|
|
|
cpTokens = CCinit(&CTokens,EVAL_TOKENS); |
|
|
|
if (coin=="KMD") |
|
|
|
{ |
|
|
|
taddr = 0; |
|
|
|
prefix = 60; |
|
|
|
prefix2 = 85; |
|
|
|
wiftype = 188; |
|
|
|
taddr = 0; |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
LogPrint("gatewayscc","set taddr, prefix, prefix2 for %s\n",coin.c_str()); |
|
|
|
taddr = 0; |
|
|
|
prefix = 60; |
|
|
|
prefix2 = 85; |
|
|
|
prefix = p1; |
|
|
|
prefix2 = p2; |
|
|
|
wiftype = p3; |
|
|
|
taddr = p4; |
|
|
|
LogPrint("gatewayscc","set prefix %d, prefix2 %d, wiftype %d for %s\n",prefix,prefix2,wiftype,coin.c_str()); |
|
|
|
} |
|
|
|
if ( N == 0 || N > 15 || M > N ) |
|
|
|
{ |
|
|
@ -1030,7 +1038,7 @@ std::string GatewaysBind(uint64_t txfee,std::string coin,uint256 tokenid,int64_t |
|
|
|
{ |
|
|
|
mtx.vout.push_back(MakeTokensCC1vout(cp->evalcode,totalsupply,gatewayspk)); |
|
|
|
mtx.vout.push_back(MakeCC1vout(cp->evalcode,txfee,gatewayspk)); |
|
|
|
return(FinalizeCCTx(0,cp,mtx,mypk,txfee,EncodeGatewaysBindOpRet('B',tokenid,coin,totalsupply,oracletxid,M,N,pubkeys,taddr,prefix,prefix2))); |
|
|
|
return(FinalizeCCTx(0,cp,mtx,mypk,txfee,EncodeGatewaysBindOpRet('B',tokenid,coin,totalsupply,oracletxid,M,N,pubkeys,taddr,prefix,prefix2,wiftype))); |
|
|
|
} |
|
|
|
} |
|
|
|
CCerror = strprintf("cant find enough inputs"); |
|
|
@ -1042,7 +1050,7 @@ std::string GatewaysDeposit(uint64_t txfee,uint256 bindtxid,int32_t height,std:: |
|
|
|
{ |
|
|
|
CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); |
|
|
|
CTransaction bindtx; CPubKey mypk; uint256 oracletxid,merkleroot,mhash,hashBlock,tokenid,txid; |
|
|
|
int64_t totalsupply; int32_t i,m,n,numvouts; uint8_t M,N,taddr,prefix,prefix2; std::string coin; struct CCcontract_info *cp,C; |
|
|
|
int64_t totalsupply; int32_t i,m,n,numvouts; uint8_t M,N,taddr,prefix,prefix2,wiftype; std::string coin; struct CCcontract_info *cp,C; |
|
|
|
std::vector<CPubKey> pubkeys,publishers; std::vector<uint256>txids; char str[67],depositaddr[64],txidaddr[64]; |
|
|
|
|
|
|
|
cp = CCinit(&C,EVAL_GATEWAYS); |
|
|
@ -1056,9 +1064,9 @@ std::string GatewaysDeposit(uint64_t txfee,uint256 bindtxid,int32_t height,std:: |
|
|
|
LogPrint("gatewayscc","%s\n", CCerror.c_str() ); |
|
|
|
return(""); |
|
|
|
} |
|
|
|
if ( DecodeGatewaysBindOpRet(depositaddr,bindtx.vout[numvouts-1].scriptPubKey,tokenid,coin,totalsupply,oracletxid,M,N,pubkeys,taddr,prefix,prefix2) != 'B' || refcoin != coin ) |
|
|
|
if ( DecodeGatewaysBindOpRet(depositaddr,bindtx.vout[numvouts-1].scriptPubKey,tokenid,coin,totalsupply,oracletxid,M,N,pubkeys,taddr,prefix,prefix2,wiftype) != 'B' || refcoin != coin ) |
|
|
|
{ |
|
|
|
CCerror = strprintf("invalid coin - bindtxid %s coin.%n",uint256_str(str,bindtxid),coin.c_str()); |
|
|
|
CCerror = strprintf("invalid coin - bindtxid %s coin.%s",uint256_str(str,bindtxid),coin.c_str()); |
|
|
|
LogPrint("gatewayscc","%s\n", CCerror.c_str() ); |
|
|
|
return(""); |
|
|
|
} |
|
|
@ -1099,7 +1107,7 @@ std::string GatewaysDeposit(uint64_t txfee,uint256 bindtxid,int32_t height,std:: |
|
|
|
LogPrint("gatewayscc","%s\n", CCerror.c_str() ); |
|
|
|
return(""); |
|
|
|
} |
|
|
|
if ( GatewaysVerify(depositaddr,oracletxid,claimvout,coin,cointxid,deposithex,proof,merkleroot,destpub) != amount ) |
|
|
|
if ( GatewaysVerify(depositaddr,oracletxid,claimvout,coin,cointxid,deposithex,proof,merkleroot,destpub,taddr,prefix,prefix2) != amount ) |
|
|
|
{ |
|
|
|
CCerror = strprintf("deposittxid didnt validate"); |
|
|
|
LogPrint("gatewayscc","%s\n", CCerror.c_str() ); |
|
|
@ -1119,7 +1127,7 @@ std::string GatewaysDeposit(uint64_t txfee,uint256 bindtxid,int32_t height,std:: |
|
|
|
std::string GatewaysClaim(uint64_t txfee,uint256 bindtxid,std::string refcoin,uint256 deposittxid,CPubKey destpub,int64_t amount) |
|
|
|
{ |
|
|
|
CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); |
|
|
|
CTransaction tx; CPubKey mypk,gatewayspk,tmpdestpub; struct CCcontract_info *cp,C; uint8_t M,N,taddr,prefix,prefix2; |
|
|
|
CTransaction tx; CPubKey mypk,gatewayspk,tmpdestpub; struct CCcontract_info *cp,C; uint8_t M,N,taddr,prefix,prefix2,wiftype; |
|
|
|
std::string coin, deposithex; std::vector<CPubKey> msigpubkeys,publishers; int64_t totalsupply,depositamount,tmpamount,inputs,CCchange=0; |
|
|
|
int32_t numvouts,claimvout,height; std::vector<uint8_t> proof; |
|
|
|
uint256 hashBlock,tokenid,oracletxid,tmptxid,cointxid; char str[65],depositaddr[64],coinaddr[64],destaddr[64]; std::vector<uint256> txids; |
|
|
@ -1135,7 +1143,7 @@ std::string GatewaysClaim(uint64_t txfee,uint256 bindtxid,std::string refcoin,ui |
|
|
|
LogPrint("gatewayscc","%s\n", CCerror.c_str() ); |
|
|
|
return(""); |
|
|
|
} |
|
|
|
if ( DecodeGatewaysBindOpRet(depositaddr,tx.vout[numvouts-1].scriptPubKey,tokenid,coin,totalsupply,oracletxid,M,N,msigpubkeys,taddr,prefix,prefix2) != 'B' || coin != refcoin ) |
|
|
|
if ( DecodeGatewaysBindOpRet(depositaddr,tx.vout[numvouts-1].scriptPubKey,tokenid,coin,totalsupply,oracletxid,M,N,msigpubkeys,taddr,prefix,prefix2,wiftype) != 'B' || coin != refcoin ) |
|
|
|
{ |
|
|
|
CCerror = strprintf("invalid coin - bindtxid %s coin.%s",uint256_str(str,bindtxid),coin.c_str()); |
|
|
|
LogPrint("gatewayscc","%s\n", CCerror.c_str() ); |
|
|
@ -1197,7 +1205,7 @@ std::string GatewaysWithdraw(uint64_t txfee,uint256 bindtxid,std::string refcoin |
|
|
|
{ |
|
|
|
CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); |
|
|
|
CTransaction tx; CPubKey mypk,gatewayspk,signerpk; uint256 txid,tokenid,hashBlock,oracletxid,tmptokenid,tmpbindtxid,withdrawtxid; int32_t vout,numvouts; |
|
|
|
int64_t nValue,totalsupply,inputs,CCchange=0,tmpamount; uint8_t funcid,K,M,N,taddr,prefix,prefix2; std::string coin,hex; |
|
|
|
int64_t nValue,totalsupply,inputs,CCchange=0,tmpamount; uint8_t funcid,K,M,N,taddr,prefix,prefix2,wiftype; std::string coin,hex; |
|
|
|
std::vector<CPubKey> msigpubkeys; char depositaddr[64],str[65],coinaddr[64]; struct CCcontract_info *cp,C,*cpTokens,CTokens; |
|
|
|
std::vector<std::pair<CAddressUnspentKey, CAddressUnspentValue> > unspentOutputs; |
|
|
|
|
|
|
@ -1214,7 +1222,7 @@ std::string GatewaysWithdraw(uint64_t txfee,uint256 bindtxid,std::string refcoin |
|
|
|
LogPrint("gatewayscc","%s\n", CCerror.c_str() ); |
|
|
|
return(""); |
|
|
|
} |
|
|
|
if( DecodeGatewaysBindOpRet(depositaddr,tx.vout[numvouts-1].scriptPubKey,tokenid,coin,totalsupply,oracletxid,M,N,msigpubkeys,taddr,prefix,prefix2) != 'B' || coin != refcoin ) |
|
|
|
if( DecodeGatewaysBindOpRet(depositaddr,tx.vout[numvouts-1].scriptPubKey,tokenid,coin,totalsupply,oracletxid,M,N,msigpubkeys,taddr,prefix,prefix2,wiftype) != 'B' || coin != refcoin ) |
|
|
|
{ |
|
|
|
CCerror = strprintf("invalid bindtxid %s coin.%s",uint256_str(str,bindtxid),coin.c_str()); |
|
|
|
LogPrint("gatewayscc","%s\n", CCerror.c_str() ); |
|
|
@ -1283,7 +1291,7 @@ std::string GatewaysPartialSign(uint64_t txfee,uint256 lasttxid,std::string refc |
|
|
|
CPubKey mypk,withdrawpub,signerpk,gatewayspk; struct CCcontract_info *cp,C; CTransaction tx,tmptx; |
|
|
|
std::vector<std::pair<CAddressUnspentKey, CAddressUnspentValue> > unspentOutputs; char funcid,str[65],depositaddr[64]; |
|
|
|
int32_t numvouts; uint256 withdrawtxid,hashBlock,bindtxid,tokenid,oracletxid,tmptokenid; std::string coin,tmphex; int64_t amount,totalsupply; |
|
|
|
uint8_t K=0,M,N,taddr,prefix,prefix2; std::vector<CPubKey> pubkeys; |
|
|
|
uint8_t K=0,M,N,taddr,prefix,prefix2,wiftype; std::vector<CPubKey> pubkeys; |
|
|
|
|
|
|
|
cp = CCinit(&C,EVAL_GATEWAYS); |
|
|
|
if ( txfee == 0 ) |
|
|
@ -1318,7 +1326,7 @@ std::string GatewaysPartialSign(uint64_t txfee,uint256 lasttxid,std::string refc |
|
|
|
LogPrint("gatewayscc","%s\n", CCerror.c_str() ); |
|
|
|
return(""); |
|
|
|
} |
|
|
|
else if (DecodeGatewaysBindOpRet(depositaddr,tmptx.vout[numvouts-1].scriptPubKey,tokenid,coin,totalsupply,oracletxid,M,N,pubkeys,taddr,prefix,prefix2) != 'B' |
|
|
|
else if (DecodeGatewaysBindOpRet(depositaddr,tmptx.vout[numvouts-1].scriptPubKey,tokenid,coin,totalsupply,oracletxid,M,N,pubkeys,taddr,prefix,prefix2,wiftype) != 'B' |
|
|
|
|| refcoin!=coin || tokenid!=tmptokenid) |
|
|
|
{ |
|
|
|
CCerror = strprintf("invalid bind tx %s",uint256_str(str,bindtxid)); |
|
|
@ -1359,7 +1367,7 @@ std::string GatewaysPartialSign(uint64_t txfee,uint256 lasttxid,std::string refc |
|
|
|
LogPrint("gatewayscc","%s\n", CCerror.c_str() ); |
|
|
|
return(""); |
|
|
|
} |
|
|
|
else if (DecodeGatewaysBindOpRet(depositaddr,tmptx.vout[numvouts-1].scriptPubKey,tokenid,coin,totalsupply,oracletxid,M,N,pubkeys,taddr,prefix,prefix2) != 'B' |
|
|
|
else if (DecodeGatewaysBindOpRet(depositaddr,tmptx.vout[numvouts-1].scriptPubKey,tokenid,coin,totalsupply,oracletxid,M,N,pubkeys,taddr,prefix,prefix2,wiftype) != 'B' |
|
|
|
|| refcoin!=coin || tokenid!=tmptokenid) |
|
|
|
{ |
|
|
|
CCerror = strprintf("invalid bind tx %s",uint256_str(str,bindtxid)); |
|
|
@ -1383,7 +1391,7 @@ std::string GatewaysCompleteSigning(uint64_t txfee,uint256 lasttxid,std::string |
|
|
|
CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); |
|
|
|
CPubKey mypk,gatewayspk,signerpk,withdrawpub; struct CCcontract_info *cp,C; char funcid,str[65],depositaddr[64]; int64_t amount,totalsupply; |
|
|
|
std::string coin,tmphex; CTransaction tx,tmptx; uint256 withdrawtxid,hashBlock,tokenid,tmptokenid,bindtxid,oracletxid; int32_t numvouts; |
|
|
|
uint8_t K=0,M,N,taddr,prefix,prefix2; std::vector<CPubKey> pubkeys; |
|
|
|
uint8_t K=0,M,N,taddr,prefix,prefix2,wiftype; std::vector<CPubKey> pubkeys; |
|
|
|
|
|
|
|
cp = CCinit(&C,EVAL_GATEWAYS); |
|
|
|
mypk = pubkey2pk(Mypubkey()); |
|
|
@ -1418,7 +1426,7 @@ std::string GatewaysCompleteSigning(uint64_t txfee,uint256 lasttxid,std::string |
|
|
|
LogPrint("gatewayscc","%s\n", CCerror.c_str() ); |
|
|
|
return(""); |
|
|
|
} |
|
|
|
else if (DecodeGatewaysBindOpRet(depositaddr,tmptx.vout[numvouts-1].scriptPubKey,tokenid,coin,totalsupply,oracletxid,M,N,pubkeys,taddr,prefix,prefix2) != 'B' |
|
|
|
else if (DecodeGatewaysBindOpRet(depositaddr,tmptx.vout[numvouts-1].scriptPubKey,tokenid,coin,totalsupply,oracletxid,M,N,pubkeys,taddr,prefix,prefix2,wiftype) != 'B' |
|
|
|
|| refcoin!=coin || tokenid!=tmptokenid) |
|
|
|
{ |
|
|
|
CCerror = strprintf("invalid bind tx %s",uint256_str(str,bindtxid)); |
|
|
@ -1458,7 +1466,7 @@ std::string GatewaysCompleteSigning(uint64_t txfee,uint256 lasttxid,std::string |
|
|
|
LogPrint("gatewayscc","%s\n", CCerror.c_str() ); |
|
|
|
return(""); |
|
|
|
} |
|
|
|
else if (DecodeGatewaysBindOpRet(depositaddr,tmptx.vout[numvouts-1].scriptPubKey,tokenid,coin,totalsupply,oracletxid,M,N,pubkeys,taddr,prefix,prefix2) != 'B' |
|
|
|
else if (DecodeGatewaysBindOpRet(depositaddr,tmptx.vout[numvouts-1].scriptPubKey,tokenid,coin,totalsupply,oracletxid,M,N,pubkeys,taddr,prefix,prefix2,wiftype) != 'B' |
|
|
|
|| refcoin!=coin || tokenid!=tmptokenid) |
|
|
|
{ |
|
|
|
CCerror = strprintf("invalid bind tx %s",uint256_str(str,bindtxid)); |
|
|
@ -1482,7 +1490,7 @@ std::string GatewaysMarkDone(uint64_t txfee,uint256 completetxid,std::string ref |
|
|
|
CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); |
|
|
|
CPubKey mypk; struct CCcontract_info *cp,C; char str[65],depositaddr[64]; CTransaction tx; int32_t numvouts; |
|
|
|
uint256 withdrawtxid,bindtxid,oracletxid,tokenid,tmptokenid,hashBlock; std::string coin,hex; |
|
|
|
uint8_t K,M,N,taddr,prefix,prefix2; std::vector<CPubKey> pubkeys; int64_t amount,totalsupply; CPubKey withdrawpub; |
|
|
|
uint8_t K,M,N,taddr,prefix,prefix2,wiftype; std::vector<CPubKey> pubkeys; int64_t amount,totalsupply; CPubKey withdrawpub; |
|
|
|
|
|
|
|
cp = CCinit(&C,EVAL_GATEWAYS); |
|
|
|
mypk = pubkey2pk(Mypubkey()); |
|
|
@ -1524,7 +1532,7 @@ std::string GatewaysMarkDone(uint64_t txfee,uint256 completetxid,std::string ref |
|
|
|
LogPrint("gatewayscc","%s\n", CCerror.c_str() ); |
|
|
|
return(""); |
|
|
|
} |
|
|
|
else if (DecodeGatewaysBindOpRet(depositaddr,tx.vout[numvouts-1].scriptPubKey,tokenid,coin,totalsupply,oracletxid,M,N,pubkeys,taddr,prefix,prefix2) != 'B' |
|
|
|
else if (DecodeGatewaysBindOpRet(depositaddr,tx.vout[numvouts-1].scriptPubKey,tokenid,coin,totalsupply,oracletxid,M,N,pubkeys,taddr,prefix,prefix2,wiftype) != 'B' |
|
|
|
|| refcoin!=coin || tokenid!=tmptokenid) |
|
|
|
{ |
|
|
|
CCerror = strprintf("invalid bind tx %s",uint256_str(str,bindtxid)); |
|
|
@ -1546,7 +1554,7 @@ UniValue GatewaysPendingDeposits(uint256 bindtxid,std::string refcoin) |
|
|
|
{ |
|
|
|
UniValue result(UniValue::VOBJ),pending(UniValue::VARR); CTransaction tx; std::string coin,hex,pub; |
|
|
|
CPubKey mypk,gatewayspk,destpub; std::vector<CPubKey> pubkeys,publishers; std::vector<uint256> txids; |
|
|
|
uint256 tmpbindtxid,hashBlock,txid,tokenid,oracletxid,cointxid; uint8_t M,N,taddr,prefix,prefix2; |
|
|
|
uint256 tmpbindtxid,hashBlock,txid,tokenid,oracletxid,cointxid; uint8_t M,N,taddr,prefix,prefix2,wiftype; |
|
|
|
char depositaddr[65],coinaddr[65],str[65],destaddr[65],txidaddr[65]; std::vector<uint8_t> proof; |
|
|
|
int32_t numvouts,vout,claimvout,height; int64_t totalsupply,nValue,amount; struct CCcontract_info *cp,C; |
|
|
|
std::vector<std::pair<CAddressUnspentKey, CAddressUnspentValue> > unspentOutputs; |
|
|
@ -1561,7 +1569,7 @@ UniValue GatewaysPendingDeposits(uint256 bindtxid,std::string refcoin) |
|
|
|
LogPrint("gatewayscc","%s\n", CCerror.c_str() ); |
|
|
|
return(""); |
|
|
|
} |
|
|
|
if ( DecodeGatewaysBindOpRet(depositaddr,tx.vout[numvouts-1].scriptPubKey,tokenid,coin,totalsupply,oracletxid,M,N,pubkeys,taddr,prefix,prefix2) != 'B' || refcoin != coin) |
|
|
|
if ( DecodeGatewaysBindOpRet(depositaddr,tx.vout[numvouts-1].scriptPubKey,tokenid,coin,totalsupply,oracletxid,M,N,pubkeys,taddr,prefix,prefix2,wiftype) != 'B' || refcoin != coin) |
|
|
|
{ |
|
|
|
CCerror = strprintf("invalid bindtxid %s coin.%s",uint256_str(str,bindtxid),coin.c_str()); |
|
|
|
LogPrint("gatewayscc","%s\n", CCerror.c_str() ); |
|
|
@ -1583,6 +1591,7 @@ UniValue GatewaysPendingDeposits(uint256 bindtxid,std::string refcoin) |
|
|
|
CCtxidaddr(txidaddr,txid); |
|
|
|
obj.push_back(Pair("deposittxidaddr",txidaddr)); |
|
|
|
_GetCCaddress(destaddr,EVAL_TOKENS,destpub); |
|
|
|
obj.push_back(Pair("depositaddr",depositaddr)); |
|
|
|
obj.push_back(Pair("tokens_destination_address",destaddr)); |
|
|
|
pub=HexStr(destpub); |
|
|
|
obj.push_back(Pair("claim_pubkey",pub)); |
|
|
@ -1599,7 +1608,7 @@ UniValue GatewaysPendingDeposits(uint256 bindtxid,std::string refcoin) |
|
|
|
UniValue GatewaysPendingWithdraws(uint256 bindtxid,std::string refcoin) |
|
|
|
{ |
|
|
|
UniValue result(UniValue::VOBJ),pending(UniValue::VARR); CTransaction tx; std::string coin,hex; CPubKey mypk,gatewayspk,withdrawpub,signerpk; |
|
|
|
std::vector<CPubKey> msigpubkeys; uint256 hashBlock,tokenid,txid,tmpbindtxid,tmptokenid,oracletxid,withdrawtxid; uint8_t K,M,N,taddr,prefix,prefix2; |
|
|
|
std::vector<CPubKey> msigpubkeys; uint256 hashBlock,tokenid,txid,tmpbindtxid,tmptokenid,oracletxid,withdrawtxid; uint8_t K,M,N,taddr,prefix,prefix2,wiftype; |
|
|
|
char funcid,depositaddr[65],coinaddr[65],tokensaddr[65],destaddr[65],str[65],withaddr[65],numstr[32],signeraddr[65],txidaddr[65]; |
|
|
|
int32_t i,n,numvouts,vout,queueflag; int64_t totalsupply,amount,nValue; struct CCcontract_info *cp,C; |
|
|
|
std::vector<std::pair<CAddressUnspentKey, CAddressUnspentValue> > unspentOutputs; |
|
|
@ -1615,7 +1624,7 @@ UniValue GatewaysPendingWithdraws(uint256 bindtxid,std::string refcoin) |
|
|
|
LogPrint("gatewayscc","%s\n", CCerror.c_str() ); |
|
|
|
return(""); |
|
|
|
} |
|
|
|
if ( DecodeGatewaysBindOpRet(depositaddr,tx.vout[numvouts-1].scriptPubKey,tokenid,coin,totalsupply,oracletxid,M,N,msigpubkeys,taddr,prefix,prefix2) != 'B' || refcoin != coin ) |
|
|
|
if ( DecodeGatewaysBindOpRet(depositaddr,tx.vout[numvouts-1].scriptPubKey,tokenid,coin,totalsupply,oracletxid,M,N,msigpubkeys,taddr,prefix,prefix2,wiftype) != 'B' || refcoin != coin ) |
|
|
|
{ |
|
|
|
CCerror = strprintf("invalid bindtxid %s coin.%s",uint256_str(str,bindtxid),coin.c_str()); |
|
|
|
LogPrint("gatewayscc","%s\n", CCerror.c_str() ); |
|
|
@ -1651,12 +1660,12 @@ UniValue GatewaysPendingWithdraws(uint256 bindtxid,std::string refcoin) |
|
|
|
continue; |
|
|
|
} |
|
|
|
Getscriptaddress(destaddr,tx.vout[1].scriptPubKey); |
|
|
|
Getscriptaddress(withaddr,CScript() << ParseHex(HexStr(withdrawpub)) << OP_CHECKSIG); |
|
|
|
GetCustomscriptaddress(withaddr,CScript() << ParseHex(HexStr(withdrawpub)) << OP_CHECKSIG,taddr,prefix,prefix2); |
|
|
|
if ( strcmp(destaddr,tokensaddr) == 0 ) |
|
|
|
{ |
|
|
|
UniValue obj(UniValue::VOBJ); |
|
|
|
obj.push_back(Pair("withdrawtxid",uint256_str(str,tx.GetHash()))); |
|
|
|
CCtxidaddr(txidaddr,tx.GetHash()); |
|
|
|
CCCustomtxidaddr(txidaddr,tx.GetHash(),taddr,prefix,prefix2); |
|
|
|
obj.push_back(Pair("withdrawtxidaddr",txidaddr)); |
|
|
|
obj.push_back(Pair("withdrawaddr",withaddr)); |
|
|
|
sprintf(numstr,"%.8f",(double)tx.vout[1].nValue/COIN); |
|
|
@ -1665,7 +1674,7 @@ UniValue GatewaysPendingWithdraws(uint256 bindtxid,std::string refcoin) |
|
|
|
if ( queueflag != 0 ) |
|
|
|
{ |
|
|
|
obj.push_back(Pair("depositaddr",depositaddr)); |
|
|
|
Getscriptaddress(signeraddr,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG); |
|
|
|
GetCustomscriptaddress(signeraddr,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG,taddr,prefix,prefix2); |
|
|
|
obj.push_back(Pair("signeraddr",signeraddr)); |
|
|
|
} |
|
|
|
if (N>1) |
|
|
@ -1688,7 +1697,7 @@ UniValue GatewaysProcessedWithdraws(uint256 bindtxid,std::string refcoin) |
|
|
|
{ |
|
|
|
UniValue result(UniValue::VOBJ),processed(UniValue::VARR); CTransaction tx; std::string coin,hex; |
|
|
|
CPubKey mypk,gatewayspk,withdrawpub; std::vector<CPubKey> msigpubkeys; |
|
|
|
uint256 withdrawtxid,hashBlock,txid,tokenid,tmptokenid,oracletxid; uint8_t K,M,N,taddr,prefix,prefix2; |
|
|
|
uint256 withdrawtxid,hashBlock,txid,tokenid,tmptokenid,oracletxid; uint8_t K,M,N,taddr,prefix,prefix2,wiftype; |
|
|
|
char depositaddr[65],coinaddr[65],str[65],numstr[32],withaddr[65],txidaddr[65]; |
|
|
|
int32_t i,n,numvouts,vout,queueflag; int64_t totalsupply,nValue,amount; struct CCcontract_info *cp,C; |
|
|
|
std::vector<std::pair<CAddressUnspentKey, CAddressUnspentValue> > unspentOutputs; |
|
|
@ -1703,7 +1712,7 @@ UniValue GatewaysProcessedWithdraws(uint256 bindtxid,std::string refcoin) |
|
|
|
LogPrint("gatewayscc","%s\n", CCerror.c_str() ); |
|
|
|
return(""); |
|
|
|
} |
|
|
|
if ( DecodeGatewaysBindOpRet(depositaddr,tx.vout[numvouts-1].scriptPubKey,tokenid,coin,totalsupply,oracletxid,M,N,msigpubkeys,taddr,prefix,prefix2) != 'B' || refcoin != coin) |
|
|
|
if ( DecodeGatewaysBindOpRet(depositaddr,tx.vout[numvouts-1].scriptPubKey,tokenid,coin,totalsupply,oracletxid,M,N,msigpubkeys,taddr,prefix,prefix2,wiftype) != 'B' || refcoin != coin) |
|
|
|
{ |
|
|
|
CCerror = strprintf("invalid bindtxid %s coin.%s",uint256_str(str,bindtxid),coin.c_str()); |
|
|
|
LogPrint("gatewayscc","%s\n", CCerror.c_str() ); |
|
|
@ -1732,9 +1741,9 @@ UniValue GatewaysProcessedWithdraws(uint256 bindtxid,std::string refcoin) |
|
|
|
UniValue obj(UniValue::VOBJ); |
|
|
|
obj.push_back(Pair("completesigningtxid",uint256_str(str,txid))); |
|
|
|
obj.push_back(Pair("withdrawtxid",uint256_str(str,withdrawtxid))); |
|
|
|
CCtxidaddr(txidaddr,withdrawtxid); |
|
|
|
CCCustomtxidaddr(txidaddr,withdrawtxid,taddr,prefix,prefix2); |
|
|
|
obj.push_back(Pair("withdrawtxidaddr",txidaddr)); |
|
|
|
Getscriptaddress(withaddr,CScript() << ParseHex(HexStr(withdrawpub)) << OP_CHECKSIG); |
|
|
|
GetCustomscriptaddress(withaddr,CScript() << ParseHex(HexStr(withdrawpub)) << OP_CHECKSIG,taddr,prefix,prefix2); |
|
|
|
obj.push_back(Pair("withdrawaddr",withaddr)); |
|
|
|
obj.push_back(Pair("confirmed_or_notarized",komodo_txnotarizedconfirmed(txid))); |
|
|
|
sprintf(numstr,"%.8f",(double)tx.vout[1].nValue/COIN); |
|
|
@ -1752,7 +1761,7 @@ UniValue GatewaysProcessedWithdraws(uint256 bindtxid,std::string refcoin) |
|
|
|
|
|
|
|
UniValue GatewaysList() |
|
|
|
{ |
|
|
|
UniValue result(UniValue::VARR); std::vector<std::pair<CAddressIndexKey, CAmount> > addressIndex; struct CCcontract_info *cp,C; uint256 txid,hashBlock,oracletxid,tokenid; CTransaction vintx; std::string coin; int64_t totalsupply; char str[65],depositaddr[64]; uint8_t M,N,taddr,prefix,prefix2; std::vector<CPubKey> pubkeys; |
|
|
|
UniValue result(UniValue::VARR); std::vector<std::pair<CAddressIndexKey, CAmount> > addressIndex; struct CCcontract_info *cp,C; uint256 txid,hashBlock,oracletxid,tokenid; CTransaction vintx; std::string coin; int64_t totalsupply; char str[65],depositaddr[64]; uint8_t M,N,taddr,prefix,prefix2,wiftype; std::vector<CPubKey> pubkeys; |
|
|
|
cp = CCinit(&C,EVAL_GATEWAYS); |
|
|
|
SetCCtxids(addressIndex,cp->unspendableCCaddr); |
|
|
|
for (std::vector<std::pair<CAddressIndexKey, CAmount> >::const_iterator it=addressIndex.begin(); it!=addressIndex.end(); it++) |
|
|
@ -1760,7 +1769,7 @@ UniValue GatewaysList() |
|
|
|
txid = it->first.txhash; |
|
|
|
if ( GetTransaction(txid,vintx,hashBlock,false) != 0 ) |
|
|
|
{ |
|
|
|
if ( vintx.vout.size() > 0 && DecodeGatewaysBindOpRet(depositaddr,vintx.vout[vintx.vout.size()-1].scriptPubKey,tokenid,coin,totalsupply,oracletxid,M,N,pubkeys,taddr,prefix,prefix2) != 0 ) |
|
|
|
if ( vintx.vout.size() > 0 && DecodeGatewaysBindOpRet(depositaddr,vintx.vout[vintx.vout.size()-1].scriptPubKey,tokenid,coin,totalsupply,oracletxid,M,N,pubkeys,taddr,prefix,prefix2,wiftype) != 0 ) |
|
|
|
{ |
|
|
|
result.push_back(uint256_str(str,txid)); |
|
|
|
} |
|
|
@ -1769,11 +1778,60 @@ UniValue GatewaysList() |
|
|
|
return(result); |
|
|
|
} |
|
|
|
|
|
|
|
UniValue GatewaysExternalAddress(uint256 bindtxid,CPubKey pubkey) |
|
|
|
{ |
|
|
|
UniValue result(UniValue::VOBJ); struct CCcontract_info *cp,C; uint256 txid,hashBlock,oracletxid,tokenid; CTransaction tx; |
|
|
|
std::string coin; int64_t numvouts,totalsupply; char str[65],addr[65],depositaddr[65]; uint8_t M,N,taddr,prefix,prefix2,wiftype; std::vector<CPubKey> msigpubkeys; |
|
|
|
|
|
|
|
cp = CCinit(&C,EVAL_GATEWAYS); |
|
|
|
if ( GetTransaction(bindtxid,tx,hashBlock,false) == 0 || (numvouts= tx.vout.size()) <= 0 ) |
|
|
|
{ |
|
|
|
CCerror = strprintf("cant find bindtxid %s",uint256_str(str,bindtxid)); |
|
|
|
LogPrint("gatewayscc","%s\n", CCerror.c_str() ); |
|
|
|
return(""); |
|
|
|
} |
|
|
|
if ( DecodeGatewaysBindOpRet(depositaddr,tx.vout[numvouts-1].scriptPubKey,tokenid,coin,totalsupply,oracletxid,M,N,msigpubkeys,taddr,prefix,prefix2,wiftype) != 'B') |
|
|
|
{ |
|
|
|
CCerror = strprintf("invalid bindtxid %s coin.%s",uint256_str(str,bindtxid),coin.c_str()); |
|
|
|
LogPrint("gatewayscc","%s\n", CCerror.c_str() ); |
|
|
|
return(""); |
|
|
|
} |
|
|
|
GetCustomscriptaddress(addr,CScript() << ParseHex(HexStr(pubkey)) << OP_CHECKSIG,taddr,prefix,prefix2); |
|
|
|
result.push_back(Pair("result","success")); |
|
|
|
result.push_back(Pair("address",addr)); |
|
|
|
return(result); |
|
|
|
} |
|
|
|
|
|
|
|
UniValue GatewaysDumpPrivKey(uint256 bindtxid,CKey key) |
|
|
|
{ |
|
|
|
UniValue result(UniValue::VOBJ); struct CCcontract_info *cp,C; uint256 txid,hashBlock,oracletxid,tokenid; CTransaction tx; |
|
|
|
std::string coin,priv; int64_t numvouts,totalsupply; char str[65],addr[65],depositaddr[65]; uint8_t M,N,taddr,prefix,prefix2,wiftype; std::vector<CPubKey> msigpubkeys; |
|
|
|
|
|
|
|
cp = CCinit(&C,EVAL_GATEWAYS); |
|
|
|
if ( GetTransaction(bindtxid,tx,hashBlock,false) == 0 || (numvouts= tx.vout.size()) <= 0 ) |
|
|
|
{ |
|
|
|
CCerror = strprintf("cant find bindtxid %s",uint256_str(str,bindtxid)); |
|
|
|
LogPrint("gatewayscc","%s\n", CCerror.c_str() ); |
|
|
|
return(""); |
|
|
|
} |
|
|
|
if ( DecodeGatewaysBindOpRet(depositaddr,tx.vout[numvouts-1].scriptPubKey,tokenid,coin,totalsupply,oracletxid,M,N,msigpubkeys,taddr,prefix,prefix2,wiftype) != 'B') |
|
|
|
{ |
|
|
|
CCerror = strprintf("invalid bindtxid %s coin.%s",uint256_str(str,bindtxid),coin.c_str()); |
|
|
|
LogPrint("gatewayscc","%s\n", CCerror.c_str() ); |
|
|
|
return(""); |
|
|
|
} |
|
|
|
|
|
|
|
priv=EncodeCustomSecret(key,wiftype); |
|
|
|
result.push_back(Pair("result","success")); |
|
|
|
result.push_back(Pair("address",priv.c_str())); |
|
|
|
return(result); |
|
|
|
} |
|
|
|
|
|
|
|
UniValue GatewaysInfo(uint256 bindtxid) |
|
|
|
{ |
|
|
|
CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); |
|
|
|
UniValue result(UniValue::VOBJ),a(UniValue::VARR); std::string coin; char str[67],numstr[65],depositaddr[64],gatewaystokens[64]; |
|
|
|
uint8_t M,N; std::vector<CPubKey> pubkeys; uint8_t taddr,prefix,prefix2; uint256 tokenid,oracletxid,hashBlock; CTransaction tx; |
|
|
|
uint8_t M,N; std::vector<CPubKey> pubkeys; uint8_t taddr,prefix,prefix2,wiftype; uint256 tokenid,oracletxid,hashBlock; CTransaction tx; |
|
|
|
CPubKey Gatewayspk; struct CCcontract_info *cp,C; int32_t i; int64_t numvouts,totalsupply,remaining; std::vector<CPubKey> msigpubkeys; |
|
|
|
|
|
|
|
cp = CCinit(&C,EVAL_GATEWAYS); |
|
|
@ -1785,7 +1843,7 @@ UniValue GatewaysInfo(uint256 bindtxid) |
|
|
|
LogPrint("gatewayscc","%s\n", CCerror.c_str() ); |
|
|
|
return(""); |
|
|
|
} |
|
|
|
if ( DecodeGatewaysBindOpRet(depositaddr,tx.vout[numvouts-1].scriptPubKey,tokenid,coin,totalsupply,oracletxid,M,N,msigpubkeys,taddr,prefix,prefix2) != 'B') |
|
|
|
if ( DecodeGatewaysBindOpRet(depositaddr,tx.vout[numvouts-1].scriptPubKey,tokenid,coin,totalsupply,oracletxid,M,N,msigpubkeys,taddr,prefix,prefix2,wiftype) != 'B') |
|
|
|
{ |
|
|
|
CCerror = strprintf("invalid bindtxid %s coin.%s",uint256_str(str,bindtxid),coin.c_str()); |
|
|
|
LogPrint("gatewayscc","%s\n", CCerror.c_str() ); |
|
|
@ -1796,7 +1854,7 @@ UniValue GatewaysInfo(uint256 bindtxid) |
|
|
|
result.push_back(Pair("result","success")); |
|
|
|
result.push_back(Pair("name","Gateways")); |
|
|
|
depositaddr[0] = 0; |
|
|
|
if ( tx.vout.size() > 0 && DecodeGatewaysBindOpRet(depositaddr,tx.vout[tx.vout.size()-1].scriptPubKey,tokenid,coin,totalsupply,oracletxid,M,N,pubkeys,taddr,prefix,prefix2) != 0 && M <= N && N > 0 ) |
|
|
|
if ( tx.vout.size() > 0 && DecodeGatewaysBindOpRet(depositaddr,tx.vout[tx.vout.size()-1].scriptPubKey,tokenid,coin,totalsupply,oracletxid,M,N,pubkeys,taddr,prefix,prefix2,wiftype) != 0 && M <= N && N > 0 ) |
|
|
|
{ |
|
|
|
if ( N > 1 ) |
|
|
|
{ |
|
|
|