From 3f4351c9fb692cde3729cc280bc6b30ca754d176 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 12 Sep 2018 02:30:51 -1100 Subject: [PATCH 01/32] 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")); From f978cd481657be744d9d75ccce1459ef1caacb36 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 12 Sep 2018 02:32:09 -1100 Subject: [PATCH 02/32] Fix --- src/cc/gateways.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/gateways.cpp b/src/cc/gateways.cpp index c773674db..09ae1dd7b 100644 --- a/src/cc/gateways.cpp +++ b/src/cc/gateways.cpp @@ -679,7 +679,7 @@ std::string GatewaysClaim(uint64_t txfee,uint256 bindtxid,std::string refcoin,ui std::string GatewaysWithdraw(uint64_t txfee,uint256 bindtxid,std::string refcoin,std::vector withdrawpub,int64_t amount) { - CMutableTransaction mtx; CTransaction tx; CPubKey mypk,gatewayspk; struct CCcontract_info *cp,C,*assetscp,C2; uint256 assetid,hashBlock,oracletxid; int32_t numvouts; int64_t totalsupply,inputs,CCchange=0; uint8_t M,N,taddr,prefix,prefix2; std::string coin; std::vector msigpubkeys; char depositaddr[64],str[65]; + CMutableTransaction mtx; CTransaction tx; CPubKey mypk,gatewayspk; struct CCcontract_info *cp,C,*assetscp,C2; uint256 assetid,hashBlock,oracletxid; int32_t numvouts; int64_t totalsupply,inputs,CCchange=0; uint8_t M,N,taddr,prefix,prefix2,mypriv[32]; std::string coin; std::vector msigpubkeys; char depositaddr[64],str[65],coinaddr[64]; cp = CCinit(&C,EVAL_GATEWAYS); assetscp = CCinit(&C2,EVAL_ASSETS); if ( txfee == 0 ) From 9d860bd978950e681db874d6870011acd326e81b Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 12 Sep 2018 02:36:00 -1100 Subject: [PATCH 03/32] Fix --- src/cc/gateways.cpp | 6 ++++++ src/wallet/rpcwallet.cpp | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/cc/gateways.cpp b/src/cc/gateways.cpp index 09ae1dd7b..9cfe9c4c9 100644 --- a/src/cc/gateways.cpp +++ b/src/cc/gateways.cpp @@ -116,6 +116,12 @@ string oracles gatewaysclaim bindtxid coin deposittxid destpub amount ./c gatewaysclaim e6c99f79d4afb216aa8063658b4222edb773dd24bb0f8e91bd4ef341f3e47e5e KMD 9d80ea79a65aaa0d464f8b762356fa01047e16e9793505a22ca04559f81a6eb6 0223d114dededb04f253816d6ad0ce78dd08c617c94ce3c53bf50dc74a5157bef8 7.6999 + + now the asset is in the pubkey's asset address! + it can be used, traded freely and any node who has the asset can do a gatewayswithdraw + + gatewayswithdraw bindtxid coin withdrawpub amount + ./c gatewayswithdraw e6c99f79d4afb216aa8063658b4222edb773dd24bb0f8e91bd4ef341f3e47e5e KMD 03b7621b44118017a16043f19b30cc8a4cfe068ac4e42417bae16ba460c80f3828 1 */ // start of consensus code diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index aa29b7c46..df2edee04 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -5495,7 +5495,7 @@ UniValue gatewaysclaim(const UniValue& params, bool fHelp) UniValue gatewayswithdraw(const UniValue& params, bool fHelp) { UniValue result(UniValue::VOBJ); uint256 bindtxid; int64_t amount; std::string hex,coin; std::vector withdrawpub; - if ( fHelp || params.size() != 5 ) + if ( fHelp || params.size() != 4 ) 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"); From 5955955d188f063f9375f2ee4a054ad9f233bd89 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 12 Sep 2018 03:49:09 -1100 Subject: [PATCH 04/32] gatewayspending --- src/cc/CCGateways.h | 1 + src/cc/gateways.cpp | 98 +++++++++++++++++++++++++++++++++++++--- src/rpcserver.cpp | 1 + src/rpcserver.h | 1 + src/wallet/rpcwallet.cpp | 12 +++++ 5 files changed, 107 insertions(+), 6 deletions(-) diff --git a/src/cc/CCGateways.h b/src/cc/CCGateways.h index b7c653ef3..e7ab74601 100644 --- a/src/cc/CCGateways.h +++ b/src/cc/CCGateways.h @@ -25,6 +25,7 @@ std::string GatewaysBind(uint64_t txfee,std::string coin,uint256 tokenid,int64_t std::string GatewaysDeposit(uint64_t txfee,uint256 bindtxid,int32_t height,std::string refcoin,uint256 cointxid,int32_t claimvout,std::string deposithex,std::vectorproof,CPubKey destpub,int64_t amount); std::string GatewaysClaim(uint64_t txfee,uint256 bindtxid,std::string refcoin,uint256 deposittxid,CPubKey destpub,int64_t amount); std::string GatewaysWithdraw(uint64_t txfee,uint256 bindtxid,std::string refcoin,std::vector withdrawpub,int64_t amount); +UniValue GatewaysPendingWithdraws(std::string refcoin,uint256 bindtxid); // CCcustom UniValue GatewaysInfo(uint256 bindtxid); diff --git a/src/cc/gateways.cpp b/src/cc/gateways.cpp index 9cfe9c4c9..df51e57bc 100644 --- a/src/cc/gateways.cpp +++ b/src/cc/gateways.cpp @@ -16,7 +16,7 @@ #include "CCGateways.h" /* - prevent duplicate bindtxid and cointxid via mempool scan + prevent duplicate bindtxid via mempool scan wait for notarization for oraclefeed and validation of gatewaysdeposit gatewayswithdraw @@ -122,8 +122,19 @@ string oracles gatewayswithdraw bindtxid coin withdrawpub amount ./c gatewayswithdraw e6c99f79d4afb216aa8063658b4222edb773dd24bb0f8e91bd4ef341f3e47e5e KMD 03b7621b44118017a16043f19b30cc8a4cfe068ac4e42417bae16ba460c80f3828 1 + ef3cc452da006eb2edda6b6ed3d3347664be51260f3e91f59ec44ec9701367f0 + + Now there is a withdraw pending, so it needs to be processed by the signing nodes on the KMD side */ + +int32_t GatewaysAddQueue(std::string coin,uint256 txid,CScript scriptPubKey,int64_t nValue) +{ + 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); +} + // start of consensus code CScript EncodeGatewaysBindOpRet(uint8_t funcid,std::string coin,uint256 tokenid,int64_t totalsupply,uint256 oracletxid,uint8_t M,uint8_t N,std::vector pubkeys,uint8_t taddr,uint8_t prefix,uint8_t prefix2) @@ -318,18 +329,40 @@ int32_t GatewaysBindExists(struct CCcontract_info *cp,CPubKey gatewayspk,uint256 return(0); } +static int32_t myIs_coinaddr_inmempoolvout(char *coinaddr) +{ + int32_t i,n; char destaddr[64]; + BOOST_FOREACH(const CTxMemPoolEntry &e,mempool.mapTx) + { + const CTransaction &tx = e.GetTx(); + if ( (n= tx.vout.size()) > 0 ) + { + const uint256 &txid = tx.GetHash(); + for (i=0; i > addressIndex; CCtxidaddr(txidaddr,cointxid); - fprintf(stderr," txidaddr.(%s) need to scan mempool also\n",txidaddr); SetCCtxids(addressIndex,txidaddr); for (std::vector >::const_iterator it=addressIndex.begin(); it!=addressIndex.end(); it++) { return(-1); } - return(0); + return(myIs_coinaddr_inmempoolvout(txidaddr)); } UniValue GatewaysInfo(uint256 bindtxid) @@ -707,7 +740,7 @@ 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,3) > 0 ) + if ( AddNormalinputs(mtx,mypk,3*txfee,3) > 0 ) { if ( (inputs= AddAssetInputs(assetscp,mtx,mypk,assetid,amount,60)) > 0 ) { @@ -715,6 +748,7 @@ std::string GatewaysWithdraw(uint64_t txfee,uint256 bindtxid,std::string refcoin CCchange = (inputs - amount); mtx.vout.push_back(MakeCC1vout(EVAL_ASSETS,amount,gatewayspk)); mtx.vout.push_back(CTxOut(txfee,CScript() << withdrawpub << OP_CHECKSIG)); + mtx.vout.push_back(CTxOut(txfee,CScript() << ParseHex(HexStr(gatewayspk)) << OP_CHECKSIG)); if ( CCchange != 0 ) mtx.vout.push_back(MakeCC1vout(EVAL_ASSETS,CCchange,mypk)); return(FinalizeCCTx(0,assetscp,mtx,mypk,txfee,EncodeAssetOpRet('t',assetid,zeroid,0,Mypubkey()))); @@ -724,6 +758,58 @@ std::string GatewaysWithdraw(uint64_t txfee,uint256 bindtxid,std::string refcoin return(""); } -// withdrawtxid used on external chain to create baton address, its existence in mempool (along with the withdraw) proof that the withdraw is pending - +UniValue GatewaysPendingWithdraws(std::string refcoin,uint256 bindtxid) +{ + UniValue result(UniValue::VOBJ),pending(UniValue:VARR),obj(UniValue:VOBJ); CTransaction tx; std::string coin; CPubKey mypk,gatewayspk; std::vector 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]; int32_t i,n,numvouts,vout,numqueued,(i=0; i > unspentOutputs; + cp = CCinit(&C,EVAL_GATEWAYS); + mypk = pubkey2pk(Mypubkey()); + gatewayspk = GetUnspendable(cp,0); + _GetCCaddress(coinaddr,EVAL_ASSETS,gatewayspk); + if ( GetTransaction(bindtxid,tx,hashBlock,false) == 0 || (numvouts= tx.vout.size()) <= 0 ) + { + fprintf(stderr,"cant find bindtxid %s\n",uint256_str(str,bindtxid)); + return(result); + } + if ( DecodeGatewaysBindOpRet(depositaddr,tx.vout[numvouts-1].scriptPubKey,coin,assetid,totalsupply,oracletxid,M,N,msigpubkeys,taddr,prefix,prefix2) != 'B' || coin != refcoin ) + { + fprintf(stderr,"invalid bindtxid %s coin.%s\n",uint256_str(str,bindtxid),coin.c_str()); + return(result); + } + n = msigpubkeys.size(); + queueflag = 0; + for (i=0; i >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++) + { + txid = it->first.txhash; + vout = (int32_t)it->first.index; + if ( GetTransaction(txid,tx,hashBlock,false) != 0 ) + { + Getscriptaddress(destaddr,tx.vout[0].scriptPubKey); + Getscriptaddress(withaddr,tx.vout[1].scriptPubKey); + if ( strcmp(destaddr,coinaddr) == 0 ) + { + obj.push_back("txid",uint256_str(str,txid)); + obj.push_back("withdrawaddr",withaddr); + sprintf(numstr,"%.8f",(double)tx.vout[0].nValue/COIN); + obj.push_back("amount",numstr); + pending.push_back(obj); + if ( queueflag != 0 ) + numqueued += GatewaysAddQueue(refcoin,txid,tx.vout[1].scriptPubKey,tx.vout[0].nValue); + } + } + } + result.push_back(Pair("coin",refcoin)); + result.push_back(Pair("pending",pending)); + result.push_back(Pair("queueflag",queueflag)); + return(result); +} diff --git a/src/rpcserver.cpp b/src/rpcserver.cpp index ee1d51568..49b7d529c 100644 --- a/src/rpcserver.cpp +++ b/src/rpcserver.cpp @@ -417,6 +417,7 @@ static const CRPCCommand vRPCCommands[] = { "gateways", "gatewaysdeposit", &gatewaysdeposit, true }, { "gateways", "gatewaysclaim", &gatewaysclaim, true }, { "gateways", "gatewayswithdraw", &gatewayswithdraw, true }, + { "gateways", "gatewayspending", &gatewayspending, true }, /* dice */ { "dice", "dicelist", &dicelist, true }, diff --git a/src/rpcserver.h b/src/rpcserver.h index 0061956ba..bb3266881 100644 --- a/src/rpcserver.h +++ b/src/rpcserver.h @@ -242,6 +242,7 @@ extern UniValue gatewaysbind(const UniValue& params, bool fHelp); extern UniValue gatewaysdeposit(const UniValue& params, bool fHelp); extern UniValue gatewaysclaim(const UniValue& params, bool fHelp); extern UniValue gatewayswithdraw(const UniValue& params, bool fHelp); +extern UniValue gatewayspending(const UniValue& params, bool fHelp); extern UniValue channelsinfo(const UniValue& params, bool fHelp); extern UniValue channelsbind(const UniValue& params, bool fHelp); extern UniValue channelsopen(const UniValue& params, bool fHelp); diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index df2edee04..eee5e0594 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -5512,6 +5512,18 @@ UniValue gatewayswithdraw(const UniValue& params, bool fHelp) return(result); } +UniValue gatewayspending(const UniValue& params, bool fHelp) +{ + uint256 bindtxid; std::string coin; + if ( fHelp || params.size() != 2 ) + throw runtime_error("gatewayspending bindtxid coin\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(); + return(GatewaysPendingWithdraws(bindtxid,coin)); +} + UniValue oracleslist(const UniValue& params, bool fHelp) { if ( fHelp || params.size() > 0 ) From d8c4018c888417270709c702b11ae36a3c6be2d2 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 12 Sep 2018 03:50:16 -1100 Subject: [PATCH 05/32] : --- src/cc/gateways.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/gateways.cpp b/src/cc/gateways.cpp index df51e57bc..0e5c067d0 100644 --- a/src/cc/gateways.cpp +++ b/src/cc/gateways.cpp @@ -760,7 +760,7 @@ std::string GatewaysWithdraw(uint64_t txfee,uint256 bindtxid,std::string refcoin UniValue GatewaysPendingWithdraws(std::string refcoin,uint256 bindtxid) { - UniValue result(UniValue::VOBJ),pending(UniValue:VARR),obj(UniValue:VOBJ); CTransaction tx; std::string coin; CPubKey mypk,gatewayspk; std::vector 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]; int32_t i,n,numvouts,vout,numqueued,(i=0; i 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]; int32_t i,n,numvouts,vout,numqueued,(i=0; i > unspentOutputs; cp = CCinit(&C,EVAL_GATEWAYS); mypk = pubkey2pk(Mypubkey()); From 4f61de87de1c75e57bceba6b3495acb18127e834 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 12 Sep 2018 03:51:22 -1100 Subject: [PATCH 06/32] Test --- src/cc/gateways.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/cc/gateways.cpp b/src/cc/gateways.cpp index 0e5c067d0..09aea55cf 100644 --- a/src/cc/gateways.cpp +++ b/src/cc/gateways.cpp @@ -797,10 +797,10 @@ UniValue GatewaysPendingWithdraws(std::string refcoin,uint256 bindtxid) Getscriptaddress(withaddr,tx.vout[1].scriptPubKey); if ( strcmp(destaddr,coinaddr) == 0 ) { - obj.push_back("txid",uint256_str(str,txid)); - obj.push_back("withdrawaddr",withaddr); + obj.push_back(Pair("txid",uint256_str(str,txid))); + obj.push_back(Pair("withdrawaddr",withaddr)); sprintf(numstr,"%.8f",(double)tx.vout[0].nValue/COIN); - obj.push_back("amount",numstr); + 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); From 339c931241bbc3be8ce345b8c598276e87d2350d Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 12 Sep 2018 03:52:15 -1100 Subject: [PATCH 07/32] Test --- src/cc/gateways.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/gateways.cpp b/src/cc/gateways.cpp index 09aea55cf..647c4445a 100644 --- a/src/cc/gateways.cpp +++ b/src/cc/gateways.cpp @@ -760,7 +760,7 @@ std::string GatewaysWithdraw(uint64_t txfee,uint256 bindtxid,std::string refcoin UniValue GatewaysPendingWithdraws(std::string refcoin,uint256 bindtxid) { - UniValue result(UniValue::VOBJ),pending(UniValue:VARR),obj(UniValue::VOBJ); CTransaction tx; std::string coin; CPubKey mypk,gatewayspk; std::vector 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]; int32_t i,n,numvouts,vout,numqueued,(i=0; i 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]; int32_t i,n,numvouts,vout,numqueued,queueflag; int64_t totalsupply; struct CCcontract_info *cp,C; std::vector > unspentOutputs; cp = CCinit(&C,EVAL_GATEWAYS); mypk = pubkey2pk(Mypubkey()); From d808ad8e74d8ed8ce08a93d44746968b04b74ce6 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 12 Sep 2018 03:54:53 -1100 Subject: [PATCH 08/32] Test --- src/cc/gateways.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/cc/gateways.cpp b/src/cc/gateways.cpp index 647c4445a..58289d61c 100644 --- a/src/cc/gateways.cpp +++ b/src/cc/gateways.cpp @@ -131,7 +131,7 @@ string oracles int32_t GatewaysAddQueue(std::string coin,uint256 txid,CScript scriptPubKey,int64_t nValue) { char destaddr[64],str[65]; - GetScriptAddress(destaddr,scriptPubKey); + Getscriptaddress(destaddr,scriptPubKey); fprintf(stderr,"GatewaysAddQueue: %s %s %s %.8f\n",coin.c_str(),uint256_str(str,txid),destaddr,(double)nValue/COIN); } @@ -340,10 +340,10 @@ static int32_t myIs_coinaddr_inmempoolvout(char *coinaddr) const uint256 &txid = tx.GetHash(); for (i=0; i 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]; 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 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]; int32_t i,n,numvouts,vout,numqueued,queueflag; int64_t totalsupply; struct CCcontract_info *cp,C; std::vector > unspentOutputs; cp = CCinit(&C,EVAL_GATEWAYS); mypk = pubkey2pk(Mypubkey()); From e3cd34a4d1d263f0a24c886397cf62e92806fc9e Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 12 Sep 2018 03:58:04 -1100 Subject: [PATCH 09/32] Test --- src/cc/CCGateways.h | 2 +- src/cc/gateways.cpp | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/cc/CCGateways.h b/src/cc/CCGateways.h index e7ab74601..f0c094080 100644 --- a/src/cc/CCGateways.h +++ b/src/cc/CCGateways.h @@ -25,7 +25,7 @@ std::string GatewaysBind(uint64_t txfee,std::string coin,uint256 tokenid,int64_t std::string GatewaysDeposit(uint64_t txfee,uint256 bindtxid,int32_t height,std::string refcoin,uint256 cointxid,int32_t claimvout,std::string deposithex,std::vectorproof,CPubKey destpub,int64_t amount); std::string GatewaysClaim(uint64_t txfee,uint256 bindtxid,std::string refcoin,uint256 deposittxid,CPubKey destpub,int64_t amount); std::string GatewaysWithdraw(uint64_t txfee,uint256 bindtxid,std::string refcoin,std::vector withdrawpub,int64_t amount); -UniValue GatewaysPendingWithdraws(std::string refcoin,uint256 bindtxid); +UniValue GatewaysPendingWithdraws(uint256 bindtxid,std::string refcoin); // CCcustom UniValue GatewaysInfo(uint256 bindtxid); diff --git a/src/cc/gateways.cpp b/src/cc/gateways.cpp index 58289d61c..6450b3c90 100644 --- a/src/cc/gateways.cpp +++ b/src/cc/gateways.cpp @@ -125,6 +125,12 @@ string oracles ef3cc452da006eb2edda6b6ed3d3347664be51260f3e91f59ec44ec9701367f0 Now there is a withdraw pending, so it needs to be processed by the signing nodes on the KMD side + + gatewayspending bindtxid coin + gatewayspending will display all pending withdraws and if it is done on one of the msigpubkeys, then it will queue it for processing + ./c gatewayspending e6c99f79d4afb216aa8063658b4222edb773dd24bb0f8e91bd4ef341f3e47e5e KMD + + */ @@ -758,7 +764,7 @@ std::string GatewaysWithdraw(uint64_t txfee,uint256 bindtxid,std::string refcoin return(""); } -UniValue GatewaysPendingWithdraws(std::string refcoin,uint256 bindtxid) +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 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]; int32_t i,n,numvouts,vout,numqueued,queueflag; int64_t totalsupply; struct CCcontract_info *cp,C; std::vector > unspentOutputs; From 2d16b4dbe69acf0411bc3311b3fc328aa3bc1c6b Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 12 Sep 2018 05:13:00 -1100 Subject: [PATCH 10/32] Test --- src/cc/gateways.cpp | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/cc/gateways.cpp b/src/cc/gateways.cpp index 6450b3c90..7f639d4ba 100644 --- a/src/cc/gateways.cpp +++ b/src/cc/gateways.cpp @@ -130,7 +130,6 @@ string oracles gatewayspending will display all pending withdraws and if it is done on one of the msigpubkeys, then it will queue it for processing ./c gatewayspending e6c99f79d4afb216aa8063658b4222edb773dd24bb0f8e91bd4ef341f3e47e5e KMD - */ @@ -139,6 +138,13 @@ 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 @@ -766,7 +772,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 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]; 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 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; std::vector > unspentOutputs; cp = CCinit(&C,EVAL_GATEWAYS); mypk = pubkey2pk(Mypubkey()); @@ -804,12 +810,14 @@ UniValue GatewaysPendingWithdraws(uint256 bindtxid,std::string refcoin) if ( strcmp(destaddr,coinaddr) == 0 ) { obj.push_back(Pair("txid",uint256_str(str,txid))); + CCtxidaddr(txidaddr,txid); + obj.push_back(Pair("txidaddr",txidaddr)); obj.push_back(Pair("withdrawaddr",withaddr)); 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 ) + // numqueued += GatewaysAddQueue(refcoin,txid,tx.vout[1].scriptPubKey,tx.vout[0].nValue); } } } From 62f0cedd3c5e359805e772e0a240e8bb7f707bd1 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 12 Sep 2018 06:00:40 -1100 Subject: [PATCH 11/32] Test --- src/cc/dapps/oraclefeed.c | 73 +++++++++++++++++++++++++++++++++++++++ src/cc/gateways.cpp | 18 +++++----- 2 files changed, 81 insertions(+), 10 deletions(-) diff --git a/src/cc/dapps/oraclefeed.c b/src/cc/dapps/oraclefeed.c index bd044ab62..9eaa40964 100644 --- a/src/cc/dapps/oraclefeed.c +++ b/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 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 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 > 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); + } } } } From f602ac985c26f10fbcd2d7aa7e9b9f1aa0db37a4 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 12 Sep 2018 06:06:02 -1100 Subject: [PATCH 12/32] Test --- src/cc/gateways.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/gateways.cpp b/src/cc/gateways.cpp index efb1847cb..3f9ee501e 100644 --- a/src/cc/gateways.cpp +++ b/src/cc/gateways.cpp @@ -808,7 +808,6 @@ UniValue GatewaysPendingWithdraws(uint256 bindtxid,std::string refcoin) obj.push_back(Pair("withdrawaddr",withaddr)); sprintf(numstr,"%.8f",(double)tx.vout[0].nValue/COIN); obj.push_back(Pair("amount",numstr)); - pending.push_back(obj); if ( queueflag != 0 ) { obj.push_back(Pair("depositaddr",depositaddr)); @@ -816,6 +815,7 @@ UniValue GatewaysPendingWithdraws(uint256 bindtxid,std::string refcoin) obj.push_back(Pair("signeraddr",signeraddr)); // numqueued += GatewaysAddQueue(refcoin,txid,tx.vout[1].scriptPubKey,tx.vout[0].nValue); } + pending.push_back(obj); } } } From e5c8c5c8e850d8dc94e3ee3f3181258e5bcbda36 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 12 Sep 2018 07:34:50 -1100 Subject: [PATCH 13/32] Process deposits in oraclefeed.c --- src/cc/dapps/oraclefeed.c | 170 ++++++++++++++++++++++++++++++++++---- 1 file changed, 155 insertions(+), 15 deletions(-) diff --git a/src/cc/dapps/oraclefeed.c b/src/cc/dapps/oraclefeed.c index 9eaa40964..e367539a1 100644 --- a/src/cc/dapps/oraclefeed.c +++ b/src/cc/dapps/oraclefeed.c @@ -351,6 +351,29 @@ bits256 komodobroadcast(char *acname,cJSON *hexjson) return(txid); } +bits256 sendtoaddress(char *acname,char *destaddr,int64_t satoshis) +{ + char numstr[32],*retstr,str[65]; cJSON *retjson; bits256 txid; + memset(txid.bytes,0,sizeof(txid)); + sprintf(numstr,"%.8f",(double)satoshis/SATOSHIDEN); + if ( (retjson= get_komodocli(&retstr,acname,"sendrawtransaction",destaddr,numstr,"")) != 0 ) + { + fprintf(stderr,"unexpected sendrawtransaction json.(%s)\n",jprint(retjson,0)); + free_json(retjson); + } + else if ( retstr != 0 ) + { + if ( strlen(retstr) >= 64 ) + { + retstr[64] = 0; + decode_hex(txid.bytes,32,retstr); + } + fprintf(stderr,"sendtoaddress %s %.8f txid.(%s)\n",destaddr,(double)satoshis/SATOSHIDEN,bits256_str(str,txid)); + free(retstr); + } + return(txid); +} + int32_t get_KMDheight(char *acname) { cJSON *retjson; char *retstr; int32_t height=0; @@ -432,7 +455,7 @@ int32_t get_KMDheader(bits256 *blockhashp,bits256 *merklerootp,int32_t prevheigh cJSON *get_gatewayspending(char *acname,char *oraclestxidstr,char *coin) { - cJSON *retjson; char *retstr; int32_t height=0; + cJSON *retjson; char *retstr; if ( (retjson= get_komodocli(&retstr,acname,"gatewayspending",oraclestxidstr,coin,"")) != 0 ) { return(retjson); @@ -447,7 +470,7 @@ cJSON *get_gatewayspending(char *acname,char *oraclestxidstr,char *coin) cJSON *get_rawmempool(char *acname) { - cJSON *retjson; char *retstr; int32_t height=0; + cJSON *retjson; char *retstr; if ( (retjson= get_komodocli(&retstr,acname,"getrawmempool","","","")) != 0 ) { return(retjson); @@ -460,16 +483,112 @@ cJSON *get_rawmempool(char *acname) return(0); } +cJSON *get_addressutxos(char *acname,char *coinaddr) +{ + //kcli getaddressutxos "{\"addresses\":[\"RMbite4TGugVmkGmu76ytPHDEQZQGSUjxz\"]}" + cJSON *retjson; char *retstr,jsonbuf[256]; + sprintf(jsonbuf,"{\"addresses\":[\"%s\"]}",coinaddr); + if ( (retjson= get_komodocli(&retstr,acname,"getaddressutxos",jsonbuf,"","")) != 0 ) + { + return(retjson); + } + else if ( retstr != 0 ) + { + fprintf(stderr,"get_addressutxos.(%s) error.(%s)\n",acname,retstr); + free(retstr); + } + return(0); +} + +cJSON *get_rawtransaction(char *acname,bits256 txid) +{ + //kcli getaddressutxos "{\"addresses\":[\"RMbite4TGugVmkGmu76ytPHDEQZQGSUjxz\"]}" + cJSON *retjson; char *retstr,str[65]; + sprintf(jsonbuf,"{\"addresses\":[\"%s\"]}",coinaddr); + if ( (retjson= get_komodocli(&retstr,acname,"getrawtransaction",bits256_str(str,txid),"1","")) != 0 ) + { + return(retjson); + } + else if ( retstr != 0 ) + { + fprintf(stderr,"get_rawtransaction.(%s) error.(%s)\n",acname,retstr); + free(retstr); + } + return(0); +} + +int32_t tx_has_voutaddress(char *acname,bits256 txid,char *coinaddr) +{ + cJSON *txobj,*vouts,*vout,*sobj,*addresses; char str[65]; int32_t i,j,n,numvouts,retval = 0; + if ( (txobj= get_rawtransaction(acname,txid)) != 0 ) + { + if ( (vouts= jarray(&numvouts,txobj,"vout")) != 0 ) + { + for (i=0; i 0 ) + { + num = 1; + break; + } + } + } + free_json(array); + } else return(-1); + } + return(num); +} + 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 + /// 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; + cJSON *retjson,*pending; char *coinstr,*txidaddr,*signeraddr,*srcaddr,*withdrawaddr; int32_t i,n,retval,processed = 0; bits256 txid,withtxid; int64_t satoshis; if ( (retjson= get_gatewayspending(acname,oraclestxidstr,coin)) != 0 ) { if ( jint(retjson,"queueflag") != 0 && (coinstr= jstr(retjson,"coin")) != 0 && strcmp(coinstr,coin) == 0 ) @@ -478,23 +597,44 @@ void update_gatewayspending(char *acname,char *oraclestxidstr,char *coin) { for (i=0; i","amount":0.0001},{"address":"","amount":}]' + txid = sendtoaddress(acname,txidaddr,10000); + if ( bits256_nonz(txid) != 0 && coinaddrexists(acname,txidaddr) > 0 ) + { + withtxid = sendtoaddress(strcmp("KMD",coin)==0?"":coin,withdrawaddr,withdrawamount); + if ( bits256_nonz(withtxid) != 0 ) + { + fprintf(stderr,"withdraw %s %s %s %.8f processed\n",coin,bits256_str(str,withtxid),withaddr,(double)satoshis/SATOSHIDEN); + // spend txid.2 + processed++; + } + else + { + fprintf(stderr,"ERROR withdraw %s %s %s %.8f processed\n",coin,bits256_str(str,withtxid),withaddr,(double)satoshis/SATOSHIDEN); + } + } } - else + else if ( retval > 0 ) { - // spend acname txid.2 + fprintf(stderr,"already did withdraw %s %s %s %.8f processed\n",coin,bits256_str(str,withtxid),withaddr,(double)satoshis/SATOSHIDEN); + // spend txid.2 } + } } } } @@ -561,7 +701,7 @@ oraclesdata 17a841a919c284cea8a676f34e793da002e606f19a9258a3190bed12d5aaa3ff 034 int32_t main(int32_t argc,char **argv) { - cJSON *clijson,*clijson2,*regjson,*item; int32_t acheight,i,n,height,prevheight = 0; char *format,*acname,*oraclestr,*pkstr,*pubstr,*retstr,*retstr2,hexstr[4096]; uint64_t price; bits256 txid; + cJSON *clijson,*clijson2,*regjson,*item; int32_t acheight,i,retval,n,height,prevheight = 0; char *format,*acname,*oraclestr,*pkstr,*pubstr,*retstr,*retstr2,hexstr[4096]; uint64_t price; bits256 txid; if ( argc != 5 ) { printf("usage: oraclefeed $ACNAME $ORACLETXID $MYPUBKEY $FORMAT\nPowered by CoinDesk (%s) %.8f\n","https://www.coindesk.com/price/",dstr(get_btcusd())); From 3efac93c2636b2b6b64223e60837aa929b4bbfc8 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 12 Sep 2018 07:37:43 -1100 Subject: [PATCH 14/32] Test --- src/cc/dapps/oraclefeed.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/cc/dapps/oraclefeed.c b/src/cc/dapps/oraclefeed.c index e367539a1..28b1519a0 100644 --- a/src/cc/dapps/oraclefeed.c +++ b/src/cc/dapps/oraclefeed.c @@ -473,6 +473,7 @@ cJSON *get_rawmempool(char *acname) cJSON *retjson; char *retstr; if ( (retjson= get_komodocli(&retstr,acname,"getrawmempool","","","")) != 0 ) { + printf("mempool.(%s)\n",jprint(retjson,0)); return(retjson); } else if ( retstr != 0 ) @@ -490,6 +491,7 @@ cJSON *get_addressutxos(char *acname,char *coinaddr) sprintf(jsonbuf,"{\"addresses\":[\"%s\"]}",coinaddr); if ( (retjson= get_komodocli(&retstr,acname,"getaddressutxos",jsonbuf,"","")) != 0 ) { + printf("addressutxos.(%s)\n",jprint(retjson,0)); return(retjson); } else if ( retstr != 0 ) @@ -502,9 +504,7 @@ cJSON *get_addressutxos(char *acname,char *coinaddr) cJSON *get_rawtransaction(char *acname,bits256 txid) { - //kcli getaddressutxos "{\"addresses\":[\"RMbite4TGugVmkGmu76ytPHDEQZQGSUjxz\"]}" cJSON *retjson; char *retstr,str[65]; - sprintf(jsonbuf,"{\"addresses\":[\"%s\"]}",coinaddr); if ( (retjson= get_komodocli(&retstr,acname,"getrawtransaction",bits256_str(str,txid),"1","")) != 0 ) { return(retjson); @@ -588,7 +588,7 @@ void update_gatewayspending(char *acname,char *oraclestxidstr,char *coin) /// 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,*signeraddr,*srcaddr,*withdrawaddr; int32_t i,n,retval,processed = 0; bits256 txid,withtxid; int64_t satoshis; + cJSON *retjson,*pending,*item; char *coinstr,*txidaddr,*signeraddr,*srcaddr,*withdrawaddr; int32_t i,n,retval,processed = 0; bits256 txid,withtxid; int64_t satoshis; if ( (retjson= get_gatewayspending(acname,oraclestxidstr,coin)) != 0 ) { if ( jint(retjson,"queueflag") != 0 && (coinstr= jstr(retjson,"coin")) != 0 && strcmp(coinstr,coin) == 0 ) From 2c37b55deba34c2c0a671f93fe4f84c21e79a7c0 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 12 Sep 2018 07:39:22 -1100 Subject: [PATCH 15/32] Test --- src/cc/dapps/oraclefeed.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/cc/dapps/oraclefeed.c b/src/cc/dapps/oraclefeed.c index 28b1519a0..7c0dd953b 100644 --- a/src/cc/dapps/oraclefeed.c +++ b/src/cc/dapps/oraclefeed.c @@ -519,7 +519,7 @@ cJSON *get_rawtransaction(char *acname,bits256 txid) int32_t tx_has_voutaddress(char *acname,bits256 txid,char *coinaddr) { - cJSON *txobj,*vouts,*vout,*sobj,*addresses; char str[65]; int32_t i,j,n,numvouts,retval = 0; + cJSON *txobj,*vouts,*vout,*sobj,*addresses; char *addr,str[65]; int32_t i,j,n,numvouts,retval = 0; if ( (txobj= get_rawtransaction(acname,txid)) != 0 ) { if ( (vouts= jarray(&numvouts,txobj,"vout")) != 0 ) @@ -588,7 +588,7 @@ void update_gatewayspending(char *acname,char *oraclestxidstr,char *coin) /// 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,*item; char *coinstr,*txidaddr,*signeraddr,*srcaddr,*withdrawaddr; int32_t i,n,retval,processed = 0; bits256 txid,withtxid; int64_t satoshis; + cJSON *retjson,*pending,*item; char str[65],*coinstr,*txidaddr,*signeraddr,*srcaddr,*withdrawaddr; int32_t i,n,retval,processed = 0; bits256 txid,withtxid; int64_t satoshis; if ( (retjson= get_gatewayspending(acname,oraclestxidstr,coin)) != 0 ) { if ( jint(retjson,"queueflag") != 0 && (coinstr= jstr(retjson,"coin")) != 0 && strcmp(coinstr,coin) == 0 ) @@ -616,10 +616,10 @@ void update_gatewayspending(char *acname,char *oraclestxidstr,char *coin) txid = sendtoaddress(acname,txidaddr,10000); if ( bits256_nonz(txid) != 0 && coinaddrexists(acname,txidaddr) > 0 ) { - withtxid = sendtoaddress(strcmp("KMD",coin)==0?"":coin,withdrawaddr,withdrawamount); + withtxid = sendtoaddress(strcmp("KMD",coin)==0?"":coin,withdrawaddr,satoshis); if ( bits256_nonz(withtxid) != 0 ) { - fprintf(stderr,"withdraw %s %s %s %.8f processed\n",coin,bits256_str(str,withtxid),withaddr,(double)satoshis/SATOSHIDEN); + fprintf(stderr,"withdraw %s %s %s %.8f processed\n",coin,bits256_str(str,withtxid),withdrawaddr,(double)satoshis/SATOSHIDEN); // spend txid.2 processed++; } From 5135f3f49fa6a5c4595d0a45ad24ee42fd0bf691 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 12 Sep 2018 07:40:20 -1100 Subject: [PATCH 16/32] Test --- src/cc/dapps/oraclefeed.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/cc/dapps/oraclefeed.c b/src/cc/dapps/oraclefeed.c index 7c0dd953b..b944182dc 100644 --- a/src/cc/dapps/oraclefeed.c +++ b/src/cc/dapps/oraclefeed.c @@ -458,6 +458,7 @@ cJSON *get_gatewayspending(char *acname,char *oraclestxidstr,char *coin) cJSON *retjson; char *retstr; if ( (retjson= get_komodocli(&retstr,acname,"gatewayspending",oraclestxidstr,coin,"")) != 0 ) { + printf("pending.(%s)\n",jprint(retjson,0)); return(retjson); } else if ( retstr != 0 ) @@ -625,7 +626,7 @@ void update_gatewayspending(char *acname,char *oraclestxidstr,char *coin) } else { - fprintf(stderr,"ERROR withdraw %s %s %s %.8f processed\n",coin,bits256_str(str,withtxid),withaddr,(double)satoshis/SATOSHIDEN); + fprintf(stderr,"ERROR withdraw %s %s %s %.8f processed\n",coin,bits256_str(str,withtxid),withdrawaddr,(double)satoshis/SATOSHIDEN); } } } From 2e1bceb4468e1bb2dd983ab104be39d0fe150f36 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 12 Sep 2018 07:42:54 -1100 Subject: [PATCH 17/32] Test --- src/cc/dapps/oraclefeed.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/cc/dapps/oraclefeed.c b/src/cc/dapps/oraclefeed.c index b944182dc..0a63c1530 100644 --- a/src/cc/dapps/oraclefeed.c +++ b/src/cc/dapps/oraclefeed.c @@ -518,6 +518,12 @@ cJSON *get_rawtransaction(char *acname,bits256 txid) return(0); } +void gatewaystxid2(char *acname,bits256 txid) +{ + char str[65]; + printf("spend %s %s/v2 as marker\n",acname,bits256_str(str,txid)); +} + int32_t tx_has_voutaddress(char *acname,bits256 txid,char *coinaddr) { cJSON *txobj,*vouts,*vout,*sobj,*addresses; char *addr,str[65]; int32_t i,j,n,numvouts,retval = 0; @@ -621,7 +627,7 @@ void update_gatewayspending(char *acname,char *oraclestxidstr,char *coin) if ( bits256_nonz(withtxid) != 0 ) { fprintf(stderr,"withdraw %s %s %s %.8f processed\n",coin,bits256_str(str,withtxid),withdrawaddr,(double)satoshis/SATOSHIDEN); - // spend txid.2 + gatewaystxid2(acname,txid); processed++; } else @@ -632,8 +638,8 @@ void update_gatewayspending(char *acname,char *oraclestxidstr,char *coin) } else if ( retval > 0 ) { - fprintf(stderr,"already did withdraw %s %s %s %.8f processed\n",coin,bits256_str(str,withtxid),withaddr,(double)satoshis/SATOSHIDEN); - // spend txid.2 + fprintf(stderr,"already did withdraw %s %s %s %.8f processed\n",coin,bits256_str(str,withtxid),withdrawaddr,(double)satoshis/SATOSHIDEN); + gatewaystxid2(acname,txid); } } } From 847837949cb28117433de474f7977be510636e13 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 12 Sep 2018 07:46:44 -1100 Subject: [PATCH 18/32] Test --- src/cc/dapps/oraclefeed.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/cc/dapps/oraclefeed.c b/src/cc/dapps/oraclefeed.c index 0a63c1530..dc0be07ef 100644 --- a/src/cc/dapps/oraclefeed.c +++ b/src/cc/dapps/oraclefeed.c @@ -702,22 +702,21 @@ oraclesdata 17a841a919c284cea8a676f34e793da002e606f19a9258a3190bed12d5aaa3ff 034 */ -//#define ORACLETXID "4895f631316a649e216153aee7a574bd281686265dc4e8d37597f72353facac3" -//#define MYPUBKEY "02ebc786cb83de8dc3922ab83c21f3f8a2f3216940c3bf9da43ce39e2a3a882c92" -//#define ACNAME "ORCL" +// ./a.out AT5 1f1aefcca2bdea8196cfd77337fb21de22d200ddea977c2f9e8742c55829d808 02ebc786cb83de8dc3922ab83c21f3f8a2f3216940c3bf9da43ce39e2a3a882c92 Ihh e6c99f79d4afb216aa8063658b4222edb773dd24bb0f8e91bd4ef341f3e47e5e int32_t main(int32_t argc,char **argv) { - cJSON *clijson,*clijson2,*regjson,*item; int32_t acheight,i,retval,n,height,prevheight = 0; char *format,*acname,*oraclestr,*pkstr,*pubstr,*retstr,*retstr2,hexstr[4096]; uint64_t price; bits256 txid; - if ( argc != 5 ) + cJSON *clijson,*clijson2,*regjson,*item; int32_t acheight,i,retval,n,height,prevheight = 0; char *format,*acname,*oraclestr,*bindtxidstr,*pkstr,*pubstr,*retstr,*retstr2,hexstr[4096]; uint64_t price; bits256 txid; + if ( argc != 6 ) { - printf("usage: oraclefeed $ACNAME $ORACLETXID $MYPUBKEY $FORMAT\nPowered by CoinDesk (%s) %.8f\n","https://www.coindesk.com/price/",dstr(get_btcusd())); + printf("usage: oraclefeed $ACNAME $ORACLETXID $MYPUBKEY $FORMAT $BINDTXID\nPowered by CoinDesk (%s) %.8f\n","https://www.coindesk.com/price/",dstr(get_btcusd())); return(-1); } acname = argv[1]; oraclestr = argv[2]; pkstr = argv[3]; format = argv[4]; + bindtxidstr = argv[5]; if ( strncmp(format,"Ihh",3) != 0 && format[0] != 'L' ) { printf("only formats of L and Ihh are supported now\n"); @@ -747,7 +746,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"); + update_gatewayspending(acname,bindtxidstr,"KMD"); } free_json(clijson2); } From 2468e05229e417837b601b99b7879b00f73b724d Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 12 Sep 2018 07:50:26 -1100 Subject: [PATCH 19/32] Test --- src/cc/dapps/oraclefeed.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/cc/dapps/oraclefeed.c b/src/cc/dapps/oraclefeed.c index dc0be07ef..3437d3e52 100644 --- a/src/cc/dapps/oraclefeed.c +++ b/src/cc/dapps/oraclefeed.c @@ -598,8 +598,10 @@ void update_gatewayspending(char *acname,char *oraclestxidstr,char *coin) cJSON *retjson,*pending,*item; char str[65],*coinstr,*txidaddr,*signeraddr,*srcaddr,*withdrawaddr; int32_t i,n,retval,processed = 0; bits256 txid,withtxid; int64_t satoshis; if ( (retjson= get_gatewayspending(acname,oraclestxidstr,coin)) != 0 ) { + //pending.({"coin":"KMD","pending":[{"txid":"10ec8f4dad6903df6b249b361b879ac77b0617caad7629b97e10f29fa7e99a9b","txidaddr":"RMbite4TGugVmkGmu76ytPHDEQZQGSUjxz","withdrawaddr":"RNJmgYaFF5DbnrNUX6pMYz9rcnDKC2tuAc","amount":"1.00000000","depositaddr":"RHV2As4rox97BuE3LK96vMeNY8VsGRTmBj","signeraddr":"RHV2As4rox97BuE3LK96vMeNY8VsGRTmBj"}],"queueflag":1}) if ( jint(retjson,"queueflag") != 0 && (coinstr= jstr(retjson,"coin")) != 0 && strcmp(coinstr,coin) == 0 ) { + printf("check pending\n"); if ( (pending= jarray(&n,retjson,"pending")) != 0 ) { for (i=0; i Date: Wed, 12 Sep 2018 07:54:17 -1100 Subject: [PATCH 20/32] Test --- src/cc/dapps/oraclefeed.c | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) diff --git a/src/cc/dapps/oraclefeed.c b/src/cc/dapps/oraclefeed.c index 3437d3e52..ee67812b4 100644 --- a/src/cc/dapps/oraclefeed.c +++ b/src/cc/dapps/oraclefeed.c @@ -595,13 +595,11 @@ void update_gatewayspending(char *acname,char *oraclestxidstr,char *coin) /// 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,*item; char str[65],*coinstr,*txidaddr,*signeraddr,*srcaddr,*withdrawaddr; int32_t i,n,retval,processed = 0; bits256 txid,withtxid; int64_t satoshis; + cJSON *retjson,*pending,*item; char str[65],*coinstr,*txidaddr,*signeraddr,*withdrawaddr; int32_t i,n,retval,processed = 0; bits256 txid,withtxid; int64_t satoshis; if ( (retjson= get_gatewayspending(acname,oraclestxidstr,coin)) != 0 ) { - //pending.({"coin":"KMD","pending":[{"txid":"10ec8f4dad6903df6b249b361b879ac77b0617caad7629b97e10f29fa7e99a9b","txidaddr":"RMbite4TGugVmkGmu76ytPHDEQZQGSUjxz","withdrawaddr":"RNJmgYaFF5DbnrNUX6pMYz9rcnDKC2tuAc","amount":"1.00000000","depositaddr":"RHV2As4rox97BuE3LK96vMeNY8VsGRTmBj","signeraddr":"RHV2As4rox97BuE3LK96vMeNY8VsGRTmBj"}],"queueflag":1}) if ( jint(retjson,"queueflag") != 0 && (coinstr= jstr(retjson,"coin")) != 0 && strcmp(coinstr,coin) == 0 ) { - printf("check pending\n"); if ( (pending= jarray(&n,retjson,"pending")) != 0 ) { for (i=0; i","amount":0.0001},{"address":"","amount":}]' txid = sendtoaddress(acname,txidaddr,10000); @@ -637,7 +627,7 @@ void update_gatewayspending(char *acname,char *oraclestxidstr,char *coin) { fprintf(stderr,"ERROR withdraw %s %s %s %.8f processed\n",coin,bits256_str(str,withtxid),withdrawaddr,(double)satoshis/SATOSHIDEN); } - } + } else fprintf(stderr,"error sending txidaddr.%s -> %s exists.%d\n",txidaddr,bits256_str(str,txid),coinaddrexists(acname,txidaddr)); } else if ( retval > 0 ) { From e4207d456f42d3000e7c6a7203886aa72470fb1c Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 12 Sep 2018 07:56:22 -1100 Subject: [PATCH 21/32] Test --- src/cc/dapps/oraclefeed.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/dapps/oraclefeed.c b/src/cc/dapps/oraclefeed.c index ee67812b4..01c3a3c7f 100644 --- a/src/cc/dapps/oraclefeed.c +++ b/src/cc/dapps/oraclefeed.c @@ -489,7 +489,7 @@ cJSON *get_addressutxos(char *acname,char *coinaddr) { //kcli getaddressutxos "{\"addresses\":[\"RMbite4TGugVmkGmu76ytPHDEQZQGSUjxz\"]}" cJSON *retjson; char *retstr,jsonbuf[256]; - sprintf(jsonbuf,"{\"addresses\":[\"%s\"]}",coinaddr); + sprintf(jsonbuf,"{\\\"addresses\\\":[\\\"%s\\\"]}",coinaddr); if ( (retjson= get_komodocli(&retstr,acname,"getaddressutxos",jsonbuf,"","")) != 0 ) { printf("addressutxos.(%s)\n",jprint(retjson,0)); From b2a18a1ad9fdb5d22dbdfa3088c71589e7835d30 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 12 Sep 2018 08:00:43 -1100 Subject: [PATCH 22/32] Test --- src/cc/dapps/oraclefeed.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/cc/dapps/oraclefeed.c b/src/cc/dapps/oraclefeed.c index 01c3a3c7f..038efcafb 100644 --- a/src/cc/dapps/oraclefeed.c +++ b/src/cc/dapps/oraclefeed.c @@ -506,7 +506,7 @@ cJSON *get_addressutxos(char *acname,char *coinaddr) cJSON *get_rawtransaction(char *acname,bits256 txid) { cJSON *retjson; char *retstr,str[65]; - if ( (retjson= get_komodocli(&retstr,acname,"getrawtransaction",bits256_str(str,txid),"1","")) != 0 ) + if ( (retjson= get_komodocli(&retstr,acname,"getrawtransaction",bits256_str(str,txid),"true","")) != 0 ) { return(retjson); } @@ -529,6 +529,7 @@ int32_t tx_has_voutaddress(char *acname,bits256 txid,char *coinaddr) cJSON *txobj,*vouts,*vout,*sobj,*addresses; char *addr,str[65]; int32_t i,j,n,numvouts,retval = 0; if ( (txobj= get_rawtransaction(acname,txid)) != 0 ) { + printf("rawtx.(%s)\n",jprint(txobj,0)); if ( (vouts= jarray(&numvouts,txobj,"vout")) != 0 ) { for (i=0; i %s exists.%d\n",txidaddr,bits256_str(str,txid),coinaddrexists(acname,txidaddr)); + } else fprintf(stderr,"error sending %s txidaddr.%s -> %s exists.%d\n",acname,txidaddr,bits256_str(str,txid),coinaddrexists(acname,txidaddr)); } else if ( retval > 0 ) { From 32cfe054ca028d91b396dfd8b0384aa8b08bbd6c Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 12 Sep 2018 08:02:50 -1100 Subject: [PATCH 23/32] Test --- src/cc/dapps/oraclefeed.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/cc/dapps/oraclefeed.c b/src/cc/dapps/oraclefeed.c index 038efcafb..ca30d1940 100644 --- a/src/cc/dapps/oraclefeed.c +++ b/src/cc/dapps/oraclefeed.c @@ -310,7 +310,8 @@ uint64_t get_btcusd() cJSON *get_komodocli(char **retstrp,char *acname,char *method,char *arg0,char *arg1,char *arg2) { - long fsize; cJSON *retjson = 0; char cmdstr[32768],*jsonstr,*fname = "/tmp/komodocli"; + long fsize; cJSON *retjson = 0; char cmdstr[32768],*jsonstr,fname[256]; + sprintf(fname,"/tmp/oraclefeed.%s",method); if ( acname[0] != 0 ) sprintf(cmdstr,"./komodo-cli -ac_name=%s %s %s %s %s > %s\n",acname,method,arg0,arg1,arg2,fname); else sprintf(cmdstr,"./komodo-cli %s %s %s %s > %s\n",method,arg0,arg1,arg2,fname); @@ -487,7 +488,6 @@ cJSON *get_rawmempool(char *acname) cJSON *get_addressutxos(char *acname,char *coinaddr) { - //kcli getaddressutxos "{\"addresses\":[\"RMbite4TGugVmkGmu76ytPHDEQZQGSUjxz\"]}" cJSON *retjson; char *retstr,jsonbuf[256]; sprintf(jsonbuf,"{\\\"addresses\\\":[\\\"%s\\\"]}",coinaddr); if ( (retjson= get_komodocli(&retstr,acname,"getaddressutxos",jsonbuf,"","")) != 0 ) @@ -506,7 +506,7 @@ cJSON *get_addressutxos(char *acname,char *coinaddr) cJSON *get_rawtransaction(char *acname,bits256 txid) { cJSON *retjson; char *retstr,str[65]; - if ( (retjson= get_komodocli(&retstr,acname,"getrawtransaction",bits256_str(str,txid),"true","")) != 0 ) + if ( (retjson= get_komodocli(&retstr,acname,"getrawtransaction",bits256_str(str,txid),"1","")) != 0 ) { return(retjson); } From cfdf7b6b5e5e19706e503f0ada5e4e123523f78c Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 12 Sep 2018 08:06:01 -1100 Subject: [PATCH 24/32] Test --- src/cc/dapps/oraclefeed.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/cc/dapps/oraclefeed.c b/src/cc/dapps/oraclefeed.c index ca30d1940..79038d6ea 100644 --- a/src/cc/dapps/oraclefeed.c +++ b/src/cc/dapps/oraclefeed.c @@ -357,7 +357,7 @@ bits256 sendtoaddress(char *acname,char *destaddr,int64_t satoshis) char numstr[32],*retstr,str[65]; cJSON *retjson; bits256 txid; memset(txid.bytes,0,sizeof(txid)); sprintf(numstr,"%.8f",(double)satoshis/SATOSHIDEN); - if ( (retjson= get_komodocli(&retstr,acname,"sendrawtransaction",destaddr,numstr,"")) != 0 ) + if ( (retjson= get_komodocli(&retstr,acname,"sendtoaddress",destaddr,numstr,"")) != 0 ) { fprintf(stderr,"unexpected sendrawtransaction json.(%s)\n",jprint(retjson,0)); free_json(retjson); @@ -529,7 +529,6 @@ int32_t tx_has_voutaddress(char *acname,bits256 txid,char *coinaddr) cJSON *txobj,*vouts,*vout,*sobj,*addresses; char *addr,str[65]; int32_t i,j,n,numvouts,retval = 0; if ( (txobj= get_rawtransaction(acname,txid)) != 0 ) { - printf("rawtx.(%s)\n",jprint(txobj,0)); if ( (vouts= jarray(&numvouts,txobj,"vout")) != 0 ) { for (i=0; i Date: Wed, 12 Sep 2018 08:10:51 -1100 Subject: [PATCH 25/32] Test --- src/cc/dapps/oraclefeed.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/cc/dapps/oraclefeed.c b/src/cc/dapps/oraclefeed.c index 79038d6ea..af516e285 100644 --- a/src/cc/dapps/oraclefeed.c +++ b/src/cc/dapps/oraclefeed.c @@ -345,7 +345,7 @@ bits256 komodobroadcast(char *acname,cJSON *hexjson) retstr[64] = 0; decode_hex(txid.bytes,32,retstr); } - fprintf(stderr,"txid.(%s)\n",bits256_str(str,txid)); + fprintf(stderr,"broadcast %s txid.(%s)\n",acname,bits256_str(str,txid)); free(retstr); } } @@ -475,7 +475,7 @@ cJSON *get_rawmempool(char *acname) cJSON *retjson; char *retstr; if ( (retjson= get_komodocli(&retstr,acname,"getrawmempool","","","")) != 0 ) { - printf("mempool.(%s)\n",jprint(retjson,0)); + //printf("mempool.(%s)\n",jprint(retjson,0)); return(retjson); } else if ( retstr != 0 ) @@ -610,7 +610,7 @@ void update_gatewayspending(char *acname,char *oraclestxidstr,char *coin) //process item.0 {"txid":"10ec8f4dad6903df6b249b361b879ac77b0617caad7629b97e10f29fa7e99a9b","txidaddr":"RMbite4TGugVmkGmu76ytPHDEQZQGSUjxz","withdrawaddr":"RNJmgYaFF5DbnrNUX6pMYz9rcnDKC2tuAc","amount":"1.00000000","depositaddr":"RHV2As4rox97BuE3LK96vMeNY8VsGRTmBj","signeraddr":"RHV2As4rox97BuE3LK96vMeNY8VsGRTmBj"} if ( (txidaddr= jstr(item,"txidaddr")) != 0 && (withdrawaddr= jstr(item,"withdrawaddr")) != 0 && (signeraddr= jstr(item,"signeraddr")) != 0 ) { - if ( (retval= coinaddrexists(acname,txidaddr)) == 0 && (satoshis= jdouble(item,"amount")*SATOSHIDEN) != 0 ) + if ( (satoshis= jdouble(item,"amount")*SATOSHIDEN) != 0 && (retval= coinaddrexists(acname,txidaddr)) == 0 ) { // this is less errors but more expensive: ./komodo-cli z_sendmany "signeraddr" '[{"address":"","amount":0.0001},{"address":"","amount":}]' txid = sendtoaddress(acname,txidaddr,10000); @@ -631,7 +631,7 @@ void update_gatewayspending(char *acname,char *oraclestxidstr,char *coin) } else if ( retval > 0 ) { - fprintf(stderr,"already did withdraw %s %s %s %.8f processed\n",coin,bits256_str(str,withtxid),withdrawaddr,(double)satoshis/SATOSHIDEN); + fprintf(stderr,"already did withdraw %s %s %.8f processed\n",coin,withdrawaddr,(double)satoshis/SATOSHIDEN); gatewaystxid2(acname,txid); } } From 7f131476cac7ea475cd3b845c846ed1af3e7fa19 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 12 Sep 2018 08:12:42 -1100 Subject: [PATCH 26/32] Test --- src/cc/dapps/oraclefeed.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/cc/dapps/oraclefeed.c b/src/cc/dapps/oraclefeed.c index af516e285..64d4b191f 100644 --- a/src/cc/dapps/oraclefeed.c +++ b/src/cc/dapps/oraclefeed.c @@ -492,7 +492,7 @@ cJSON *get_addressutxos(char *acname,char *coinaddr) sprintf(jsonbuf,"{\\\"addresses\\\":[\\\"%s\\\"]}",coinaddr); if ( (retjson= get_komodocli(&retstr,acname,"getaddressutxos",jsonbuf,"","")) != 0 ) { - printf("addressutxos.(%s)\n",jprint(retjson,0)); + //printf("addressutxos.(%s)\n",jprint(retjson,0)); return(retjson); } else if ( retstr != 0 ) @@ -595,7 +595,7 @@ void update_gatewayspending(char *acname,char *oraclestxidstr,char *coin) /// 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,*item; char str[65],*coinstr,*txidaddr,*signeraddr,*withdrawaddr; int32_t i,n,retval,processed = 0; bits256 txid,withtxid; int64_t satoshis; + cJSON *retjson,*pending,*item; char str[65],*coinstr,*txidaddr,*signeraddr,*withdrawaddr; int32_t i,n,retval,processed = 0; bits256 txid,withtxid,origtxid; int64_t satoshis; if ( (retjson= get_gatewayspending(acname,oraclestxidstr,coin)) != 0 ) { if ( jint(retjson,"queueflag") != 0 && (coinstr= jstr(retjson,"coin")) != 0 && strcmp(coinstr,coin) == 0 ) @@ -607,6 +607,7 @@ void update_gatewayspending(char *acname,char *oraclestxidstr,char *coin) if ( processed != 0 ) // avoid out of utxo conditions break; item = jitem(pending,i); + origtxid = jbits256(item,"txid"); //process item.0 {"txid":"10ec8f4dad6903df6b249b361b879ac77b0617caad7629b97e10f29fa7e99a9b","txidaddr":"RMbite4TGugVmkGmu76ytPHDEQZQGSUjxz","withdrawaddr":"RNJmgYaFF5DbnrNUX6pMYz9rcnDKC2tuAc","amount":"1.00000000","depositaddr":"RHV2As4rox97BuE3LK96vMeNY8VsGRTmBj","signeraddr":"RHV2As4rox97BuE3LK96vMeNY8VsGRTmBj"} if ( (txidaddr= jstr(item,"txidaddr")) != 0 && (withdrawaddr= jstr(item,"withdrawaddr")) != 0 && (signeraddr= jstr(item,"signeraddr")) != 0 ) { @@ -620,7 +621,7 @@ void update_gatewayspending(char *acname,char *oraclestxidstr,char *coin) if ( bits256_nonz(withtxid) != 0 ) { fprintf(stderr,"withdraw %s %s %s %.8f processed\n",coin,bits256_str(str,withtxid),withdrawaddr,(double)satoshis/SATOSHIDEN); - gatewaystxid2(acname,txid); + gatewaystxid2(acname,origtxid); processed++; } else @@ -632,7 +633,7 @@ void update_gatewayspending(char *acname,char *oraclestxidstr,char *coin) else if ( retval > 0 ) { fprintf(stderr,"already did withdraw %s %s %.8f processed\n",coin,withdrawaddr,(double)satoshis/SATOSHIDEN); - gatewaystxid2(acname,txid); + gatewaystxid2(acname,origtxid); } } } From 40542921b714071d65d71ead9bef6952291077c6 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 12 Sep 2018 08:13:09 -1100 Subject: [PATCH 27/32] Test --- src/cc/gateways.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/cc/gateways.cpp b/src/cc/gateways.cpp index 3f9ee501e..969018312 100644 --- a/src/cc/gateways.cpp +++ b/src/cc/gateways.cpp @@ -18,7 +18,6 @@ /* prevent duplicate bindtxid via mempool scan wait for notarization for oraclefeed and validation of gatewaysdeposit - gatewayswithdraw validation From 11ce33e84f06f9b3963f35d891fda9bf39d6bff0 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 12 Sep 2018 08:27:40 -1100 Subject: [PATCH 28/32] Test --- src/cc/dapps/oraclefeed.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/cc/dapps/oraclefeed.c b/src/cc/dapps/oraclefeed.c index 64d4b191f..37da19101 100644 --- a/src/cc/dapps/oraclefeed.c +++ b/src/cc/dapps/oraclefeed.c @@ -518,10 +518,20 @@ cJSON *get_rawtransaction(char *acname,bits256 txid) return(0); } -void gatewaystxid2(char *acname,bits256 txid) +void gatewaysmarkdone(char *acname,bits256 txid) { - char str[65]; + char str[65],*retstr; cJSON *retjson; printf("spend %s %s/v2 as marker\n",acname,bits256_str(str,txid)); + if ( (retjson= get_komodocli(&retstr,acname,"gatewaysmarkdone",bits256_str(str,txid),"","")) != 0 ) + { + komodobroadcast(acname,retjson); + free_json(retjson); + } + else if ( retstr != 0 ) + { + printf("error parsing gatewaysmarkdone.(%s)\n",retstr); + free(retstr); + } } int32_t tx_has_voutaddress(char *acname,bits256 txid,char *coinaddr) @@ -543,7 +553,7 @@ int32_t tx_has_voutaddress(char *acname,bits256 txid,char *coinaddr) addr = jstri(addresses,j); if ( strcmp(addr,coinaddr) == 0 ) { - fprintf(stderr,"found %s in %s v%d\n",coinaddr,bits256_str(str,txid),i); + //fprintf(stderr,"found %s in %s v%d\n",coinaddr,bits256_str(str,txid),i); retval = 1; } } @@ -617,6 +627,7 @@ void update_gatewayspending(char *acname,char *oraclestxidstr,char *coin) txid = sendtoaddress(acname,txidaddr,10000); if ( bits256_nonz(txid) != 0 && coinaddrexists(acname,txidaddr) > 0 ) { + // the actual withdraw withtxid = sendtoaddress(strcmp("KMD",coin)==0?"":coin,withdrawaddr,satoshis); if ( bits256_nonz(withtxid) != 0 ) { From 6bde696a3136716adaaa2a1eb69e15fbf5ad2ed6 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 12 Sep 2018 08:36:01 -1100 Subject: [PATCH 29/32] Gatewaysmarkdone --- src/cc/CCGateways.h | 1 + src/cc/dapps/oraclefeed.c | 4 ++-- src/cc/gateways.cpp | 11 +++++++++++ src/rpcserver.cpp | 1 + src/rpcserver.h | 1 + src/wallet/rpcwallet.cpp | 17 +++++++++++++++++ 6 files changed, 33 insertions(+), 2 deletions(-) diff --git a/src/cc/CCGateways.h b/src/cc/CCGateways.h index f0c094080..1d7bef9d5 100644 --- a/src/cc/CCGateways.h +++ b/src/cc/CCGateways.h @@ -26,6 +26,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); std::string GatewaysWithdraw(uint64_t txfee,uint256 bindtxid,std::string refcoin,std::vector withdrawpub,int64_t amount); UniValue GatewaysPendingWithdraws(uint256 bindtxid,std::string refcoin); +std::string GatewaysMarkdone(uint64_t txfee,uint256 withdrawtxid); // CCcustom UniValue GatewaysInfo(uint256 bindtxid); diff --git a/src/cc/dapps/oraclefeed.c b/src/cc/dapps/oraclefeed.c index 37da19101..fa67989bf 100644 --- a/src/cc/dapps/oraclefeed.c +++ b/src/cc/dapps/oraclefeed.c @@ -632,7 +632,7 @@ void update_gatewayspending(char *acname,char *oraclestxidstr,char *coin) if ( bits256_nonz(withtxid) != 0 ) { fprintf(stderr,"withdraw %s %s %s %.8f processed\n",coin,bits256_str(str,withtxid),withdrawaddr,(double)satoshis/SATOSHIDEN); - gatewaystxid2(acname,origtxid); + gatewaysmarkdone(acname,origtxid); processed++; } else @@ -644,7 +644,7 @@ void update_gatewayspending(char *acname,char *oraclestxidstr,char *coin) else if ( retval > 0 ) { fprintf(stderr,"already did withdraw %s %s %.8f processed\n",coin,withdrawaddr,(double)satoshis/SATOSHIDEN); - gatewaystxid2(acname,origtxid); + gatewaysmarkdone(acname,origtxid); } } } diff --git a/src/cc/gateways.cpp b/src/cc/gateways.cpp index 969018312..b366db6ba 100644 --- a/src/cc/gateways.cpp +++ b/src/cc/gateways.cpp @@ -762,6 +762,17 @@ std::string GatewaysWithdraw(uint64_t txfee,uint256 bindtxid,std::string refcoin return(""); } +std::string GatewaysMarkdone(uint64_t txfee,uint256 withdrawtxid) +{ + CMutableTransaction mtx; CScript opret; + cp = CCinit(&C,EVAL_GATEWAYS); + if ( txfee == 0 ) + txfee = 10000; + mypk = pubkey2pk(Mypubkey()); + mtx.vin.push_back(CTxIn(withdrawtxid,2,CScript())); + return(FinalizeCCTx(0,cp,mtx,mypk,txfee,opret)); +} + 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 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; diff --git a/src/rpcserver.cpp b/src/rpcserver.cpp index 49b7d529c..c4c8d378b 100644 --- a/src/rpcserver.cpp +++ b/src/rpcserver.cpp @@ -418,6 +418,7 @@ static const CRPCCommand vRPCCommands[] = { "gateways", "gatewaysclaim", &gatewaysclaim, true }, { "gateways", "gatewayswithdraw", &gatewayswithdraw, true }, { "gateways", "gatewayspending", &gatewayspending, true }, + { "gateways", "gatewaysmarkdone", &gatewaysmarkdone, true }, /* dice */ { "dice", "dicelist", &dicelist, true }, diff --git a/src/rpcserver.h b/src/rpcserver.h index bb3266881..a697ee4ee 100644 --- a/src/rpcserver.h +++ b/src/rpcserver.h @@ -243,6 +243,7 @@ extern UniValue gatewaysdeposit(const UniValue& params, bool fHelp); extern UniValue gatewaysclaim(const UniValue& params, bool fHelp); extern UniValue gatewayswithdraw(const UniValue& params, bool fHelp); extern UniValue gatewayspending(const UniValue& params, bool fHelp); +extern UniValue gatewaysmarkdone(const UniValue& params, bool fHelp); extern UniValue channelsinfo(const UniValue& params, bool fHelp); extern UniValue channelsbind(const UniValue& params, bool fHelp); extern UniValue channelsopen(const UniValue& params, bool fHelp); diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index eee5e0594..d3825388c 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -5512,6 +5512,23 @@ UniValue gatewayswithdraw(const UniValue& params, bool fHelp) return(result); } +UniValue gatewaysmarkdone(const UniValue& params, bool fHelp) +{ + UniValue result(UniValue::VOBJ); uint256 withdrawtxid; std::string hex; + if ( fHelp || params.size() != 1 ) + throw runtime_error("gatewaysmarkdone withdrawtxid\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"); + withdrawtxid = Parseuint256((char *)params[0].get_str().c_str()); + hex = GatewaysMarkdone(0,withdrawtxid); + if ( hex.size() > 0 ) + { + result.push_back(Pair("result", "success")); + result.push_back(Pair("hex", hex)); + } else ERR_RESULT("couldnt gatewaysmarkdone"); + return(result); +} + UniValue gatewayspending(const UniValue& params, bool fHelp) { uint256 bindtxid; std::string coin; From b31844cbb55ca6bb10906eff5b769190b6df1db3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 12 Sep 2018 08:37:02 -1100 Subject: [PATCH 30/32] Test --- src/cc/gateways.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/gateways.cpp b/src/cc/gateways.cpp index b366db6ba..7590e9cfc 100644 --- a/src/cc/gateways.cpp +++ b/src/cc/gateways.cpp @@ -764,7 +764,7 @@ std::string GatewaysWithdraw(uint64_t txfee,uint256 bindtxid,std::string refcoin std::string GatewaysMarkdone(uint64_t txfee,uint256 withdrawtxid) { - CMutableTransaction mtx; CScript opret; + CMutableTransaction mtx; CScript opret; CPubKey mypk; struct CCcontract_info *cp,C; cp = CCinit(&C,EVAL_GATEWAYS); if ( txfee == 0 ) txfee = 10000; From 9f72c41af3300ea18252ff5dc94498e5b599a7c8 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 12 Sep 2018 08:51:23 -1100 Subject: [PATCH 31/32] Test --- src/cc/gateways.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/cc/gateways.cpp b/src/cc/gateways.cpp index 7590e9cfc..f21ee7c03 100644 --- a/src/cc/gateways.cpp +++ b/src/cc/gateways.cpp @@ -767,9 +767,10 @@ std::string GatewaysMarkdone(uint64_t txfee,uint256 withdrawtxid) CMutableTransaction mtx; CScript opret; CPubKey mypk; struct CCcontract_info *cp,C; cp = CCinit(&C,EVAL_GATEWAYS); if ( txfee == 0 ) - txfee = 10000; + txfee = 5000; mypk = pubkey2pk(Mypubkey()); mtx.vin.push_back(CTxIn(withdrawtxid,2,CScript())); + mtx.vout.push_back(CTxOut(5000,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG)); return(FinalizeCCTx(0,cp,mtx,mypk,txfee,opret)); } From b9de8352c77b33ceca80e2b5709d5271a0d9b59b Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 12 Sep 2018 08:54:22 -1100 Subject: [PATCH 32/32] Verify gatewaysmarkdone --- src/cc/dapps/oraclefeed.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/dapps/oraclefeed.c b/src/cc/dapps/oraclefeed.c index fa67989bf..8af31c2e4 100644 --- a/src/cc/dapps/oraclefeed.c +++ b/src/cc/dapps/oraclefeed.c @@ -459,7 +459,7 @@ cJSON *get_gatewayspending(char *acname,char *oraclestxidstr,char *coin) cJSON *retjson; char *retstr; if ( (retjson= get_komodocli(&retstr,acname,"gatewayspending",oraclestxidstr,coin,"")) != 0 ) { - printf("pending.(%s)\n",jprint(retjson,0)); + //printf("pending.(%s)\n",jprint(retjson,0)); return(retjson); } else if ( retstr != 0 )