gatewayswithdraw roc

This commit is contained in:
jl777
2018-09-12 02:30:51 -11:00
parent 02df0dce6f
commit 3f4351c9fb
2 changed files with 23 additions and 13 deletions

View File

@@ -17,6 +17,10 @@
/* /*
prevent duplicate bindtxid and cointxid via mempool scan prevent duplicate bindtxid and cointxid via mempool scan
wait for notarization for oraclefeed and validation of gatewaysdeposit
gatewayswithdraw
validation
string oracles string oracles
*/ */
@@ -682,6 +686,11 @@ std::string GatewaysWithdraw(uint64_t txfee,uint256 bindtxid,std::string refcoin
txfee = 10000; txfee = 10000;
mypk = pubkey2pk(Mypubkey()); mypk = pubkey2pk(Mypubkey());
gatewayspk = GetUnspendable(cp,0); gatewayspk = GetUnspendable(cp,0);
_GetCCaddress(coinaddr,EVAL_ASSETS,gatewayspk);
CCaddr2set(assetscp,EVAL_ASSETS,gatewayspk,cp->CCpriv,coinaddr);
Myprivkey(mypriv);
_GetCCaddress(coinaddr,EVAL_GATEWAYS,mypk);
CCaddr3set(assetscp,EVAL_GATEWAYS,mypk,mypriv,coinaddr);
if ( GetTransaction(bindtxid,tx,hashBlock,false) == 0 || (numvouts= tx.vout.size()) <= 0 ) if ( GetTransaction(bindtxid,tx,hashBlock,false) == 0 || (numvouts= tx.vout.size()) <= 0 )
{ {
fprintf(stderr,"cant find bindtxid %s\n",uint256_str(str,bindtxid)); fprintf(stderr,"cant find bindtxid %s\n",uint256_str(str,bindtxid));
@@ -692,16 +701,16 @@ std::string GatewaysWithdraw(uint64_t txfee,uint256 bindtxid,std::string refcoin
fprintf(stderr,"invalid bindtxid %s coin.%s\n",uint256_str(str,bindtxid),coin.c_str()); fprintf(stderr,"invalid bindtxid %s coin.%s\n",uint256_str(str,bindtxid),coin.c_str());
return(""); return("");
} }
if ( AddNormalinputs(mtx,mypk,2*txfee,1) > 0 ) if ( AddNormalinputs(mtx,mypk,2*txfee,3) > 0 )
{ {
if ( (inputs= AddAssetInputs(assetscp,mtx,mypk,assetid,amount,60)) > 0 ) if ( (inputs= AddAssetInputs(assetscp,mtx,mypk,assetid,amount,60)) > 0 )
{ {
if ( inputs > amount ) if ( inputs > amount )
CCchange = (inputs - amount); CCchange = (inputs - amount);
mtx.vout.push_back(MakeCC1vout(EVAL_ASSETS,amount,gatewayspk)); mtx.vout.push_back(MakeCC1vout(EVAL_ASSETS,amount,gatewayspk));
mtx.vout.push_back(CTxOut(txfee,CScript() << withdrawpub << OP_CHECKSIG));
if ( CCchange != 0 ) if ( CCchange != 0 )
mtx.vout.push_back(MakeCC1vout(EVAL_ASSETS,CCchange,mypk)); mtx.vout.push_back(MakeCC1vout(EVAL_ASSETS,CCchange,mypk));
mtx.vout.push_back(CTxOut(txfee,CScript() << ParseHex(HexStr(withdrawpub)) << OP_CHECKSIG));
return(FinalizeCCTx(0,assetscp,mtx,mypk,txfee,EncodeAssetOpRet('t',assetid,zeroid,0,Mypubkey()))); return(FinalizeCCTx(0,assetscp,mtx,mypk,txfee,EncodeAssetOpRet('t',assetid,zeroid,0,Mypubkey())));
} }
} }

View File

@@ -5462,13 +5462,6 @@ UniValue gatewaysdeposit(const UniValue& params, bool fHelp)
amount = atof((char *)params[8].get_str().c_str()) * COIN; amount = atof((char *)params[8].get_str().c_str()) * COIN;
if ( amount <= 0 || claimvout < 0 ) if ( amount <= 0 || claimvout < 0 )
throw runtime_error("invalid param: amount, numpks or claimvout\n"); throw runtime_error("invalid param: amount, numpks or claimvout\n");
/*for (i=0; i<numpks; i++)
{
if ( params.size() < 10+i+1 )
throw runtime_error("not enough parameters for numpks oraclepubkeys\n");
pubkey = ParseHex(params[10+i].get_str().c_str());
pubkeys.push_back(pubkey2pk(pubkey));
}*/
hex = GatewaysDeposit(0,bindtxid,height,coin,cointxid,claimvout,deposithex,proof,pubkey2pk(destpub),amount); hex = GatewaysDeposit(0,bindtxid,height,coin,cointxid,claimvout,deposithex,proof,pubkey2pk(destpub),amount);
if ( hex.size() > 0 ) if ( hex.size() > 0 )
{ {
@@ -5482,7 +5475,7 @@ UniValue gatewaysclaim(const UniValue& params, bool fHelp)
{ {
UniValue result(UniValue::VOBJ); std::string hex,coin; uint256 bindtxid,deposittxid; std::vector<uint8_t>destpub; int64_t amount; UniValue result(UniValue::VOBJ); std::string hex,coin; uint256 bindtxid,deposittxid; std::vector<uint8_t>destpub; int64_t amount;
if ( fHelp || params.size() != 5 ) if ( fHelp || params.size() != 5 )
throw runtime_error("gatewaysclaim bindtxid coin deposittxid redeemscript amount\n"); throw runtime_error("gatewaysclaim bindtxid coin deposittxid destpub amount\n");
if ( ensure_CCrequirements() < 0 ) if ( ensure_CCrequirements() < 0 )
throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n");
bindtxid = Parseuint256((char *)params[0].get_str().c_str()); bindtxid = Parseuint256((char *)params[0].get_str().c_str());
@@ -5501,8 +5494,16 @@ UniValue gatewaysclaim(const UniValue& params, bool fHelp)
UniValue gatewayswithdraw(const UniValue& params, bool fHelp) UniValue gatewayswithdraw(const UniValue& params, bool fHelp)
{ {
UniValue result(UniValue::VOBJ); std::string hex; UniValue result(UniValue::VOBJ); uint256 bindtxid; int64_t amount; std::string hex,coin; std::vector<uint8_t> withdrawpub;
// std::string GatewaysWithdraw(uint64_t txfee,uint256 bindtxid,std::string refcoin,std::vector<uint8_t> withdrawpub,int64_t amount) if ( fHelp || params.size() != 5 )
throw runtime_error("gatewayswithdraw bindtxid coin withdrawpub amount\n");
if ( ensure_CCrequirements() < 0 )
throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n");
bindtxid = Parseuint256((char *)params[0].get_str().c_str());
coin = params[1].get_str();
withdrawpub = ParseHex(params[2].get_str());
amount = atof((char *)params[3].get_str().c_str()) * COIN;
hex = GatewaysWithdraw(0,bindtxid,coin,withdrawpub,amount);
if ( hex.size() > 0 ) if ( hex.size() > 0 )
{ {
result.push_back(Pair("result", "success")); result.push_back(Pair("result", "success"));