From 3f4351c9fb692cde3729cc280bc6b30ca754d176 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 12 Sep 2018 02:30:51 -1100 Subject: [PATCH] gatewayswithdraw roc --- src/cc/gateways.cpp | 15 ++++++++++++--- src/wallet/rpcwallet.cpp | 21 +++++++++++---------- 2 files changed, 23 insertions(+), 13 deletions(-) diff --git a/src/cc/gateways.cpp b/src/cc/gateways.cpp index 507e594ad..c773674db 100644 --- a/src/cc/gateways.cpp +++ b/src/cc/gateways.cpp @@ -17,7 +17,11 @@ /* prevent duplicate bindtxid and cointxid via mempool scan - + wait for notarization for oraclefeed and validation of gatewaysdeposit + gatewayswithdraw + + validation + string oracles */ @@ -682,6 +686,11 @@ std::string GatewaysWithdraw(uint64_t txfee,uint256 bindtxid,std::string refcoin txfee = 10000; mypk = pubkey2pk(Mypubkey()); 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 ) { 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()); 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 > amount ) CCchange = (inputs - amount); mtx.vout.push_back(MakeCC1vout(EVAL_ASSETS,amount,gatewayspk)); + mtx.vout.push_back(CTxOut(txfee,CScript() << withdrawpub << OP_CHECKSIG)); if ( CCchange != 0 ) 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()))); } } diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 4fb3f8beb..aa29b7c46 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -5462,13 +5462,6 @@ UniValue gatewaysdeposit(const UniValue& params, bool fHelp) amount = atof((char *)params[8].get_str().c_str()) * COIN; if ( amount <= 0 || claimvout < 0 ) throw runtime_error("invalid param: amount, numpks or claimvout\n"); - /*for (i=0; i 0 ) { @@ -5482,7 +5475,7 @@ UniValue gatewaysclaim(const UniValue& params, bool fHelp) { UniValue result(UniValue::VOBJ); std::string hex,coin; uint256 bindtxid,deposittxid; std::vectordestpub; int64_t amount; 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 ) 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()); @@ -5501,8 +5494,16 @@ UniValue gatewaysclaim(const UniValue& params, bool fHelp) UniValue gatewayswithdraw(const UniValue& params, bool fHelp) { - UniValue result(UniValue::VOBJ); std::string hex; - // std::string GatewaysWithdraw(uint64_t txfee,uint256 bindtxid,std::string refcoin,std::vector withdrawpub,int64_t amount) + UniValue result(UniValue::VOBJ); uint256 bindtxid; int64_t amount; std::string hex,coin; std::vector withdrawpub; + 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 ) { result.push_back(Pair("result", "success"));