From 9648870fdcdc1383567e3dac268059447b794a82 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 17 Sep 2018 03:16:04 -1100 Subject: [PATCH 01/48] Sync gateways --- src/cc/gateways.cpp | 100 +++++++++++++++++--------------------------- 1 file changed, 39 insertions(+), 61 deletions(-) diff --git a/src/cc/gateways.cpp b/src/cc/gateways.cpp index df5c24e7c..23b600930 100644 --- a/src/cc/gateways.cpp +++ b/src/cc/gateways.cpp @@ -21,7 +21,7 @@ debug multisig and do partial signing validation -string oracles + string oracles */ /* @@ -58,7 +58,7 @@ string oracles 5. Now a gatewaysbind can bind an external coin to an asset, along with the oracle for the merkleroots. the txid from the bind is used in most of the other gateways CC calls usage: - ./c tokencreate KMD 1000000 KMD_equivalent_token_for_gatewaysCC + ./c tokencreate KMD 1000000 KMD_equivalent_token_for_gatewaysCC a7398a8748354dd0a3f8d07d70e65294928ecc3674674bb2d9483011ccaa9a7a transfer to gateways pubkey: 03ea9c062b9652d8eff34879b504eda0717895d27597aaeb60347d65eed96ccb40 RDMqGyREkP1Gwub1Nr5Ye8a325LGZsWBCb @@ -94,7 +94,7 @@ string oracles "remaining": "1000000.00000000", "issued": "0.00000000" } - + To make a gateway deposit, send the funds to the "deposit" address, along with any amount to the same pubkey address you want to get the assetized KMD to appear in. 0223d114dededb04f253816d6ad0ce78dd08c617c94ce3c53bf50dc74a5157bef8 pubkey for RFpxgqff7FDHFuHa3jSX5NzqqWCcELz8ha @@ -106,16 +106,16 @@ string oracles ./komodo-cli getrawtransaction bc41a00e429db741c3199f17546a48012fd3b7eea45dfc6bc2f5228278133009 010000000149964cdcd17fe9b1cae4d0f3b5f5db301d9b4f54099fdf4d34498df281757094010000006a4730440220594f3a630dd73c123f44621aa8bb9968ab86734833453dd479af6d79ae6f584202207bb5e35f13b337ccc8a88d9a006c8c5ddb016c0a6f4f2dc44357a8128623d85d01210223154bf53cd3a75e64d86697070d6437c8f0010a09c1df35b659e31ce3d79b5dffffffff0310270000000000001976a91447d2e323a14b0c3be08698aa46a9b91489b189d688ac701de52d000000001976a91459fdba29ea85c65ad90f6d38f7a6646476b26b1688acb0a86a00000000001976a914f9a9daf5519dae38b8b61d945f075da895df441d88ace18d965b - + gatewaysdeposit bindtxid height coin cointxid claimvout deposithex proof destpub amount -./komodo-cli -ac_name=AT5 gatewaysdeposit e6c99f79d4afb216aa8063658b4222edb773dd24bb0f8e91bd4ef341f3e47e5e 1003776 KMD bc41a00e429db741c3199f17546a48012fd3b7eea45dfc6bc2f5228278133009 0 010000000149964cdcd17fe9b1cae4d0f3b5f5db301d9b4f54099fdf4d34498df281757094010000006a4730440220594f3a630dd73c123f44621aa8bb9968ab86734833453dd479af6d79ae6f584202207bb5e35f13b337ccc8a88d9a006c8c5ddb016c0a6f4f2dc44357a8128623d85d01210223154bf53cd3a75e64d86697070d6437c8f0010a09c1df35b659e31ce3d79b5dffffffff0310270000000000001976a91447d2e323a14b0c3be08698aa46a9b91489b189d688ac701de52d000000001976a91459fdba29ea85c65ad90f6d38f7a6646476b26b1688acb0a86a00000000001976a914f9a9daf5519dae38b8b61d945f075da895df441d88ace18d965b 04000000232524ea04b54489eb222f8b3f566ed35504e3050488a63f0ab7b1c2030000007f91615f04835822bf6984a56482aeeb11d03814352eca9afc0a20192fdcae900000000000000000000000000000000000000000000000000000000000000000268e965ba608071d0800038e16762900000000000000000000000000000000000000000042008dd6fd4005016b4292b05df6dfd316c458c53e28fb2befb96e4870a40c6c04e733d75d8a7a18cce34fe326005efdc403bfa4644e30eeafdaeff34419edc591299e6cc5933cb2eeecbab5c4dfe97cd413b75215999a3dd02b540373581e81d8512bff1640590a6b4da4aaa9b8adc0102c38ca0022daed997b53ed192ba326e212fba5e505ce29e3ad149cef7f48d0e00948a1acd81731d84008760759211eb4abbc7b037939a7964182edb59cf9065357e864188ee5fc7316e8796963036bb99eeb9f06c95d64f78749ecec7181c12eb5d83a3b9b1c1e8a0aae9a20ce04a250b28216620bfc99bb81a6de4db80b93a5aea916de97c1a272e26644abdd683f19c5e3174a2e4513ed767d8f11a4c3074295f697839c5d9139676a813451cc7da38f68cbae5d990a79075f98903233ca04fe1b4b099e433585e5adcc45d41d54a9c648179297359c75950a5e574f13f70b728bbbf552770256315cd0a00139d6ab6934cb5ed70a4fc01a92611b096dd0028f17f4cc687b75f37dca530aa47a18321c50528dbd9272eabb3e13a87021a05918a6d2627e2caba6d7cf1a9f0b831ea3337b9a6af92746d83140078d60c72b6beacf91c9e68a34cee209e08670be1d17ff8d80b7a2285b1325461a2e33f2ee675593f1900e066a5d212615cd8da18749b0e684eee73edcc9031709be715b889c6d015cf4bd4ad5ab7e21bd3492c208930a54d353ef36a437f507ead38855633c1b88d060d9e4221ca8ce2f698e8a6ae0d41e9ace3cbd401f1e0f07650e9c126d4ef20278c8be6e85c7637513643f8d02d7ad64c09da11c16429d60e5160c345844b8158ece62794e8ad280d4e4664150e74978609ece431e51a9f9e1ce8aa49c16f36c7fd12b71acc42d893e18476b8b1e144a8175519612efc93e0aecc61f3b21212c958b0e2331d76aaa62faf11a58fe2bd91ab9ab01b906406c9bbc02df2a106e67182aae0a20b538bf19f09c57f9de5e198ba254580fb1b11e22ad526550093420cb7c68628d4c3ad329c8acc6e219093d277810ed016b6099b7e3781de412a22dacedaa2acf29e8062debcd85c7b9529a20b2782a2470763ac27cf89611a527d43ac89b8063ffb93b6ed993425194f8ee821a8493a563072c896f9584f95db28e3f2fc5fb4a6f3c39d615cd563641717cd50afb73ed3989cbf504b2043882993ce9575f56402534173b1396fbc13df80920b46788ae340ad5a91f25177cc74aa69024d76f56166199d2e4d50a053555256c4e3137ea1cee1130e916a88b6ee5cf2c85652fb8824d5dacfa485e3ef6190591ac0c2fcacc4fc7deb65aca4b0b89b76e35a46b0627e2e967cc63a5d606a984c8e63eabb98fde3e69114340ae524c974cb936e57690e98a7a74533f6f7d1d0496976496b54d14a8163efb32b70dfbb79d80a3022c4f53571c08bf044270565716b435084376714b224ab23e9817c05af8223723afc0577af5c8fc28f71036ca82528aaa4ca9bcd18a50e25d2a528f183d3a2074d968d170876d8dce434c5937261b55173ab87e03d5632ca0834fdc5387c15ab3a17d75c0f274004f289ff1bf7d14e97fdf4172eb49adfb418cc2f4794806ae7c0111c97df4d65d38679ec93fea3ef738ed565e8906a8fe1861cafe3938c772fedcfab40159938e06ef414fd299f2355c6d3369bc1bd3c4db64ce205f0a1b70a40030f505b736e28230de82e97776b5ee7b10708bb3020d28cec7a8e124549ec80c547ac4e7b52bf397c72bcfce30820554ab8fb4d1f73b209bc32a0e7e878843cdbf5f01222728ccea7e6ab7cb5e3fee3234f5b85d1985f91492f6ceaa6454a658dab5074f163ce26ed753137fa61c940679de13bd7b212cd3cf2b334f5201cecbc7473342bd7a239e09169bccd56d03000000037a9068df0625e548e71263c8361b4e904c998378f6b9e32729c3f19b10ad752e093013788222f5c26bfc5da4eeb7d32f01486a54179f19c341b79d420ea041bc8878d22fad4692b2d609c3cf190903874d3682a714c7483518c9392e07c25035010b 0223d114dededb04f253816d6ad0ce78dd08c617c94ce3c53bf50dc74a5157bef8 7.6999 + ./komodo-cli -ac_name=AT5 gatewaysdeposit e6c99f79d4afb216aa8063658b4222edb773dd24bb0f8e91bd4ef341f3e47e5e 1003776 KMD bc41a00e429db741c3199f17546a48012fd3b7eea45dfc6bc2f5228278133009 0 010000000149964cdcd17fe9b1cae4d0f3b5f5db301d9b4f54099fdf4d34498df281757094010000006a4730440220594f3a630dd73c123f44621aa8bb9968ab86734833453dd479af6d79ae6f584202207bb5e35f13b337ccc8a88d9a006c8c5ddb016c0a6f4f2dc44357a8128623d85d01210223154bf53cd3a75e64d86697070d6437c8f0010a09c1df35b659e31ce3d79b5dffffffff0310270000000000001976a91447d2e323a14b0c3be08698aa46a9b91489b189d688ac701de52d000000001976a91459fdba29ea85c65ad90f6d38f7a6646476b26b1688acb0a86a00000000001976a914f9a9daf5519dae38b8b61d945f075da895df441d88ace18d965b 04000000232524ea04b54489eb222f8b3f566ed35504e3050488a63f0ab7b1c2030000007f91615f04835822bf6984a56482aeeb11d03814352eca9afc0a20192fdcae900000000000000000000000000000000000000000000000000000000000000000268e965ba608071d0800038e16762900000000000000000000000000000000000000000042008dd6fd4005016b4292b05df6dfd316c458c53e28fb2befb96e4870a40c6c04e733d75d8a7a18cce34fe326005efdc403bfa4644e30eeafdaeff34419edc591299e6cc5933cb2eeecbab5c4dfe97cd413b75215999a3dd02b540373581e81d8512bff1640590a6b4da4aaa9b8adc0102c38ca0022daed997b53ed192ba326e212fba5e505ce29e3ad149cef7f48d0e00948a1acd81731d84008760759211eb4abbc7b037939a7964182edb59cf9065357e864188ee5fc7316e8796963036bb99eeb9f06c95d64f78749ecec7181c12eb5d83a3b9b1c1e8a0aae9a20ce04a250b28216620bfc99bb81a6de4db80b93a5aea916de97c1a272e26644abdd683f19c5e3174a2e4513ed767d8f11a4c3074295f697839c5d9139676a813451cc7da38f68cbae5d990a79075f98903233ca04fe1b4b099e433585e5adcc45d41d54a9c648179297359c75950a5e574f13f70b728bbbf552770256315cd0a00139d6ab6934cb5ed70a4fc01a92611b096dd0028f17f4cc687b75f37dca530aa47a18321c50528dbd9272eabb3e13a87021a05918a6d2627e2caba6d7cf1a9f0b831ea3337b9a6af92746d83140078d60c72b6beacf91c9e68a34cee209e08670be1d17ff8d80b7a2285b1325461a2e33f2ee675593f1900e066a5d212615cd8da18749b0e684eee73edcc9031709be715b889c6d015cf4bd4ad5ab7e21bd3492c208930a54d353ef36a437f507ead38855633c1b88d060d9e4221ca8ce2f698e8a6ae0d41e9ace3cbd401f1e0f07650e9c126d4ef20278c8be6e85c7637513643f8d02d7ad64c09da11c16429d60e5160c345844b8158ece62794e8ad280d4e4664150e74978609ece431e51a9f9e1ce8aa49c16f36c7fd12b71acc42d893e18476b8b1e144a8175519612efc93e0aecc61f3b21212c958b0e2331d76aaa62faf11a58fe2bd91ab9ab01b906406c9bbc02df2a106e67182aae0a20b538bf19f09c57f9de5e198ba254580fb1b11e22ad526550093420cb7c68628d4c3ad329c8acc6e219093d277810ed016b6099b7e3781de412a22dacedaa2acf29e8062debcd85c7b9529a20b2782a2470763ac27cf89611a527d43ac89b8063ffb93b6ed993425194f8ee821a8493a563072c896f9584f95db28e3f2fc5fb4a6f3c39d615cd563641717cd50afb73ed3989cbf504b2043882993ce9575f56402534173b1396fbc13df80920b46788ae340ad5a91f25177cc74aa69024d76f56166199d2e4d50a053555256c4e3137ea1cee1130e916a88b6ee5cf2c85652fb8824d5dacfa485e3ef6190591ac0c2fcacc4fc7deb65aca4b0b89b76e35a46b0627e2e967cc63a5d606a984c8e63eabb98fde3e69114340ae524c974cb936e57690e98a7a74533f6f7d1d0496976496b54d14a8163efb32b70dfbb79d80a3022c4f53571c08bf044270565716b435084376714b224ab23e9817c05af8223723afc0577af5c8fc28f71036ca82528aaa4ca9bcd18a50e25d2a528f183d3a2074d968d170876d8dce434c5937261b55173ab87e03d5632ca0834fdc5387c15ab3a17d75c0f274004f289ff1bf7d14e97fdf4172eb49adfb418cc2f4794806ae7c0111c97df4d65d38679ec93fea3ef738ed565e8906a8fe1861cafe3938c772fedcfab40159938e06ef414fd299f2355c6d3369bc1bd3c4db64ce205f0a1b70a40030f505b736e28230de82e97776b5ee7b10708bb3020d28cec7a8e124549ec80c547ac4e7b52bf397c72bcfce30820554ab8fb4d1f73b209bc32a0e7e878843cdbf5f01222728ccea7e6ab7cb5e3fee3234f5b85d1985f91492f6ceaa6454a658dab5074f163ce26ed753137fa61c940679de13bd7b212cd3cf2b334f5201cecbc7473342bd7a239e09169bccd56d03000000037a9068df0625e548e71263c8361b4e904c998378f6b9e32729c3f19b10ad752e093013788222f5c26bfc5da4eeb7d32f01486a54179f19c341b79d420ea041bc8878d22fad4692b2d609c3cf190903874d3682a714c7483518c9392e07c25035010b 0223d114dededb04f253816d6ad0ce78dd08c617c94ce3c53bf50dc74a5157bef8 7.6999 -> 9d80ea79a65aaa0d464f8b762356fa01047e16e9793505a22ca04559f81a6eb6 to get the merkleroots onchain, from the multisig signers nodes run the oraclefeed program with acname oracletxid pubkey Ihh ./oraclefeed AT5 1f1aefcca2bdea8196cfd77337fb21de22d200ddea977c2f9e8742c55829d808 02ebc786cb83de8dc3922ab83c21f3f8a2f3216940c3bf9da43ce39e2a3a882c92 Ihh gatewaysclaim bindtxid coin deposittxid destpub amount -./c gatewaysclaim e6c99f79d4afb216aa8063658b4222edb773dd24bb0f8e91bd4ef341f3e47e5e KMD 9d80ea79a65aaa0d464f8b762356fa01047e16e9793505a22ca04559f81a6eb6 0223d114dededb04f253816d6ad0ce78dd08c617c94ce3c53bf50dc74a5157bef8 7.6999 + ./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 @@ -126,11 +126,11 @@ string oracles Now there is a withdraw pending, so it needs to be processed by the signing nodes on the KMD side - gatewayspending bindtxid coin + 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 -*/ + */ int32_t GatewaysAddQueue(std::string coin,uint256 txid,CScript scriptPubKey,int64_t nValue) @@ -283,32 +283,32 @@ bool GatewaysValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction & // helper functions for rpc calls in rpcwallet.cpp /*int64_t AddGatewaysInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey pk,int64_t total,int32_t maxinputs) -{ - char coinaddr[64]; int64_t nValue,price,totalinputs = 0; uint256 txid,hashBlock; std::vector origpubkey; CTransaction vintx; int32_t vout,n = 0; - std::vector > unspentOutputs; - GetCCaddress(cp,coinaddr,pk); - SetCCunspents(unspentOutputs,coinaddr); - for (std::vector >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++) - { - txid = it->first.txhash; - vout = (int32_t)it->first.index; - // no need to prevent dup - if ( GetTransaction(txid,vintx,hashBlock,false) != 0 ) - { - if ( (nValue= IsGatewaysvout(cp,vintx,vout)) > 10000 && myIsutxo_spentinmempool(txid,vout) == 0 ) - { - if ( total != 0 && maxinputs != 0 ) - mtx.vin.push_back(CTxIn(txid,vout,CScript())); - nValue = it->second.satoshis; - totalinputs += nValue; - n++; - if ( (total > 0 && totalinputs >= total) || (maxinputs > 0 && n >= maxinputs) ) - break; - } - } - } - return(totalinputs); -}*/ + { + char coinaddr[64]; int64_t nValue,price,totalinputs = 0; uint256 txid,hashBlock; std::vector origpubkey; CTransaction vintx; int32_t vout,n = 0; + std::vector > unspentOutputs; + GetCCaddress(cp,coinaddr,pk); + SetCCunspents(unspentOutputs,coinaddr); + for (std::vector >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++) + { + txid = it->first.txhash; + vout = (int32_t)it->first.index; + // no need to prevent dup + if ( GetTransaction(txid,vintx,hashBlock,false) != 0 ) + { + if ( (nValue= IsGatewaysvout(cp,vintx,vout)) > 10000 && myIsutxo_spentinmempool(txid,vout) == 0 ) + { + if ( total != 0 && maxinputs != 0 ) + mtx.vin.push_back(CTxIn(txid,vout,CScript())); + nValue = it->second.satoshis; + totalinputs += nValue; + n++; + if ( (total > 0 && totalinputs >= total) || (maxinputs > 0 && n >= maxinputs) ) + break; + } + } + } + return(totalinputs); + }*/ int32_t GatewaysBindExists(struct CCcontract_info *cp,CPubKey gatewayspk,uint256 reftokenid) // dont forget to check mempool! { @@ -521,7 +521,7 @@ uint256 GatewaysReverseScan(uint256 &txid,int32_t height,uint256 reforacletxid,u if ( oracle_format(&hash,&merkleht,0,'I',(uint8_t *)data.data(),0,(int32_t)data.size()) == sizeof(int32_t) && merkleht == height ) { if ( oracle_format(&hash,&val,0,'h',(uint8_t *)data.data(),sizeof(int32_t),(int32_t)data.size()) == sizeof(hash) && - oracle_format(&mhash,&val,0,'h',(uint8_t *)data.data(),(int32_t)(sizeof(int32_t)+sizeof(uint256)),(int32_t)data.size()) == sizeof(hash) && mhash != zeroid ) + oracle_format(&mhash,&val,0,'h',(uint8_t *)data.data(),(int32_t)(sizeof(int32_t)+sizeof(uint256)),(int32_t)data.size()) == sizeof(hash) && mhash != zeroid ) { txid = batontxid; return(mhash); @@ -837,23 +837,7 @@ UniValue GatewaysPendingWithdraws(uint256 bindtxid,std::string refcoin) return(result); } -std::string GatewaysMultisigUpdate(struct CCcontract_info *cp,int32_t &complete,int32_t &partialtx,CPubKey mypk,int32_t ith,uint256 withdrawtxid,uint8_t M,uint8_t N,char *unspentstr) -{ - CMutableTransaction mtx; cJSON *unspents; std::string hex,rawtx; CScript opret; uint64_t txfee = 10000; - complete = partialtx = 0; - { - // iterate txidaddr, extract signatures! - // iterate for sigs depth and find the deepest - // if not already a signer, add signature and post to next - // if first one, then create a rawtx and sign it, ie. depth 1 - // if fully signed, broadcast - - return(FinalizeCCTx(0,cp,mtx,mypk,txfee,opret)); - } - return(hex); -} - -UniValue GatewaysMultisig(uint64_t txfee,std::string refcoin,uint256 bindtxid,uint256 withdrawtxid,char *unspentstr) +std::string GatewaysMultisig(uint64_t txfee,std::string refcoin,uint256 bindtxid,uint256 withdrawtxid,char *txidaddr) { UniValue result(UniValue::VOBJ); std::string coin,hex; char str[67],numstr[65],depositaddr[64],gatewaysassets[64]; uint8_t M,N; std::vector pubkeys; uint8_t taddr,prefix,prefix2; uint256 tokenid,oracletxid,hashBlock; CTransaction tx; CPubKey Gatewayspk,mypk; struct CCcontract_info *cp,C; int32_t i,n,complete,partialtx; int64_t totalsupply; cp = CCinit(&C,EVAL_GATEWAYS); @@ -868,22 +852,16 @@ UniValue GatewaysMultisig(uint64_t txfee,std::string refcoin,uint256 bindtxid,ui depositaddr[0] = 0; if ( tx.vout.size() > 0 && DecodeGatewaysBindOpRet(depositaddr,tx.vout[tx.vout.size()-1].scriptPubKey,coin,tokenid,totalsupply,oracletxid,M,N,pubkeys,taddr,prefix,prefix2) != 0 && M <= N && N > 1 && coin == refcoin ) { + // need a decentralized way to add signatures to msig tx n = pubkeys.size(); for (i=0; i send tx to refcoin withdraw complete - // partialtx:1 -> send partialsig to txidaddr, satoshis 10000 + ith pubkey + 1 - result.push_back(Pair("result","success")); - result.push_back(Pair("coin",refcoin)); - result.push_back(Pair("complete",complete)); - result.push_back(Pair("partialtx",partialtx)); - result.push_back(Pair("hex",hex)); - return(result); + return(hex); } From 403b69675c0691138de17e0fe1c9fd219c099bca Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 18 Sep 2018 03:48:44 -1100 Subject: [PATCH 02/48] 1of2 CC --- src/cc/prices.cpp | 55 ++++++++++++++++++++++++---------------- src/wallet/rpcwallet.cpp | 5 ++++ 2 files changed, 38 insertions(+), 22 deletions(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index 1465c6ee6..40a777bcf 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -28,15 +28,31 @@ Funds work like with dice, ie. there is a Prices plan that traders bet against. - PricesOpen -> oracletxid start with 'L' price, leverage, amount - funds are locked into global CC address + PricesFunding oracletxid, priceaveraging, maxleverage, funding, longtoken, shorttoken, N [pubkeys] + + PricesBet -> oracletxid start with 'L', leverage, funding, direction + funds are locked into global CC address it can be closed at anytime by the trader for cash settlement the house account can close it if rekt Implementation Notes: In order to eliminate the need for worrying about sybil attacks, each prices plan would be able to specific pubkey(s?) for whitelisted publishers. It would be possible to have a non-whitelisted plan that would use 50% correlation between publishers. - delta neutral balancing of risk exposure + delta neutral balancing of riskexposure: fabs(long exposure - short exposure) + bet +B at leverage L + absval(sum(+BLi) - sum(-Bli)) + + validate: update riskexposure and it needs to be <= funds + + PricesProfits: limit withdraw to funds in excess of riskexposure + PricesFinish: payout (if winning) and update riskexposure + need long/short exposure assets + + exposure tokens + funding -> 1of2 CC global CC address and dealer address + pricebet -> user funds to 1of2 address. exposuretoken to exposure address + pricewin -> winnings from dealer funds, exposure token back to 1of2 address + priceloss -> exposuretoken back to 1of2 address + */ @@ -211,34 +227,29 @@ UniValue PricesList() return(result); } -std::string PricesCreateFunding(uint64_t txfee,char *planstr,int64_t funds,int64_t minbet,int64_t maxbet,int64_t maxodds,int64_t timeoutblocks) +// PricesFunding oracletxid, priceaveraging, maxleverage, funding, longtoken, shorttoken, N [pubkeys] + +std::string PricesCreateFunding(uint64_t txfee,uint256 oracletxid,uint64_t mode,uint256 longtoken,uint256 shorttoken,int32_t maxleverage,int64_t funding,CPubKey pubkeys) { - CMutableTransaction mtx; uint256 zero; CScript fundingPubKey; CPubKey mypk,pricepk; int64_t a,b,c,d; uint64_t sbits; struct CCcontract_info *cp,C; - if ( funds < 0 || minbet < 0 || maxbet < 0 || maxodds < 1 || maxodds > 9999 || timeoutblocks < 0 || timeoutblocks > 1440 ) + CMutableTransaction mtx; CPubKey mypk,pricespk; struct CCcontract_info *cp,C; + if ( funding < 100*COIN || maxleverage <= 0 || maxleverage > 10000 ) { CCerror = "invalid parameter error"; fprintf(stderr,"%s\n", CCerror.c_str() ); return(""); } - if ( funds < 100*COIN ) + cp = CCinit(&C,EVAL_REWARDS); + if ( txfee == 0 ) + txfee = 10000; + mypk = pubkey2pk(Mypubkey()); + pricespk = GetUnspendable(cp,0); + // verify long and short assets + if ( AddNormalinputs(mtx,mypk,funding+3*txfee,60) > 0 ) { - CCerror = "price plan needs at least 100 coins"; - fprintf(stderr,"%s\n", CCerror.c_str() ); - return(""); - } - memset(&zero,0,sizeof(zero)); - if ( (cp= Pricesinit(fundingPubKey,zero,&C,planstr,txfee,mypk,pricepk,sbits,a,b,c,d)) == 0 ) - { - CCerror = "Priceinit error in create funding"; - fprintf(stderr,"%s\n", CCerror.c_str() ); - return(""); - } - if ( AddNormalinputs(mtx,mypk,funds+3*txfee,60) > 0 ) - { - mtx.vout.push_back(MakeCC1vout(cp->evalcode,funds,pricepk)); + mtx.vout.push_back(MakeCC1vout(cp->evalcode,funding,pricepk)); mtx.vout.push_back(CTxOut(txfee,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG)); mtx.vout.push_back(CTxOut(txfee,CScript() << ParseHex(HexStr(pricepk)) << OP_CHECKSIG)); - return(FinalizeCCTx(0,cp,mtx,mypk,txfee,EncodePricesFundingOpRet('F',sbits,minbet,maxbet,maxodds,timeoutblocks))); + return(FinalizeCCTx(0,cp,mtx,mypk,txfee,EncodePricesFundingOpRet('F',oracletxid,longtoken,shorttoken,funding,mode,maxleverage,pubkeys))); } CCerror = "cant find enough inputs"; fprintf(stderr,"%s\n", CCerror.c_str() ); diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 57c9fabc1..48e1d75f3 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4934,7 +4934,12 @@ UniValue pricesaddress(const UniValue& params, bool fHelp) 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"); if ( params.size() == 1 ) + { pubkey = ParseHex(params[0].get_str().c_str()); + char destaddr[64]; + GetCCaddress1of2(cp,destaddr,pubkey2pk(pubkey),pubkey2pk(pubkey)); + fprintf(stderr,"1of2 CC %s\n",destaddr); + } return(CCaddress(cp,(char *)"Prices",pubkey)); } From 08d66385b3d1802aee063ab3696846ec7f4575e9 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 18 Sep 2018 04:13:43 -1100 Subject: [PATCH 03/48] Test --- src/cc/prices.cpp | 8 ++++---- src/wallet/rpcwallet.cpp | 3 +++ 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index 40a777bcf..1db14d1b9 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -48,10 +48,10 @@ PricesFinish: payout (if winning) and update riskexposure need long/short exposure assets - exposure tokens + funding -> 1of2 CC global CC address and dealer address - pricebet -> user funds to 1of2 address. exposuretoken to exposure address - pricewin -> winnings from dealer funds, exposure token back to 1of2 address - priceloss -> exposuretoken back to 1of2 address + funding -> 1of2 CC global CC address and dealer address, exposure tokens to global 1of2 assets CC address + pricebet -> user funds and exposure token to 1of2 address. + pricewin -> winnings from dealer funds, exposure token back to global address + priceloss -> exposuretoken back to global address */ diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 48e1d75f3..44965db73 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4939,6 +4939,9 @@ UniValue pricesaddress(const UniValue& params, bool fHelp) char destaddr[64]; GetCCaddress1of2(cp,destaddr,pubkey2pk(pubkey),pubkey2pk(pubkey)); fprintf(stderr,"1of2 CC %s\n",destaddr); + cp->evalcode = EVAL_ASSETS; + GetCCaddress1of2(cp,destaddr,pubkey2pk(pubkey),pubkey2pk(pubkey)); + fprintf(stderr,"1of2 assets CC %s\n",destaddr); } return(CCaddress(cp,(char *)"Prices",pubkey)); } From f44cd67e8298122cf4dea84cff3685696553fb74 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 19 Sep 2018 21:04:47 -1100 Subject: [PATCH 04/48] Prices stub --- src/cc/CCPrices.h | 9 +- src/cc/CCassets.h | 2 +- src/cc/CCassetsCore.cpp | 48 ++++- src/cc/CCassetstx.cpp | 4 +- src/cc/CCinclude.h | 4 +- src/cc/CCtx.cpp | 5 +- src/cc/assets.cpp | 4 +- src/cc/gateways.cpp | 26 ++- src/cc/prices.cpp | 401 ++++++++++++++++++++++++--------------- src/komodo_utils.h | 5 + src/rpcserver.cpp | 9 +- src/rpcserver.h | 7 + src/wallet/rpcwallet.cpp | 208 ++++++++++++++++++-- 13 files changed, 536 insertions(+), 196 deletions(-) diff --git a/src/cc/CCPrices.h b/src/cc/CCPrices.h index 8b09e9267..d35823838 100644 --- a/src/cc/CCPrices.h +++ b/src/cc/CCPrices.h @@ -22,6 +22,13 @@ bool PricesValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx); // CCcustom -UniValue PricesInfo(); +UniValue PricesList(); +UniValue PricesInfo(uint256 fundingtxid); +UniValue PricesStatus(uint64_t txfee,uint256 fundingtxid,uint256 bettxid); +std::string PricesCreateFunding(uint64_t txfee,uint256 bettoken,uint256 oracletxid,uint64_t margin,uint64_t mode,uint256 longtoken,uint256 shorttoken,int32_t maxleverage,int64_t funding,std::vector pubkeys); +std::string PricesAddFunding(uint64_t txfee,uint256 bettoken,uint256 fundingtxid,int64_t amount); +std::string PricesBet(uint64_t txfee,uint256 bettoken,uint256 fundingtxid,int64_t amount,int32_t leverage); +std::string PricesFinish(uint64_t txfee,uint256 bettoken,uint256 fundingtxid,uint256 bettxid); + #endif diff --git a/src/cc/CCassets.h b/src/cc/CCassets.h index 9a0f2a0ea..afb3579cf 100644 --- a/src/cc/CCassets.h +++ b/src/cc/CCassets.h @@ -33,7 +33,7 @@ bool AssetsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx CScript EncodeAssetCreateOpRet(uint8_t funcid,std::vector origpubkey,std::string name,std::string description); CScript EncodeAssetOpRet(uint8_t funcid,uint256 assetid,uint256 assetid2,int64_t price,std::vector origpubkey); bool DecodeAssetCreateOpRet(const CScript &scriptPubKey,std::vector &origpubkey,std::string &name,std::string &description); -uint8_t DecodeAssetOpRet(const CScript &scriptPubKey,uint256 &assetid,uint256 &assetid2,int64_t &price,std::vector &origpubkey); +uint8_t DecodeAssetOpRet(const CScript &scriptPubKey,uint256 &assetid,uint256 &assetid2,int64_t &price,std::vector &origpubkey,uint256 &bettxid,int32_t &leverage); bool SetAssetOrigpubkey(std::vector &origpubkey,int64_t &price,const CTransaction &tx); int64_t IsAssetvout(int64_t &price,std::vector &origpubkey,const CTransaction& tx,int32_t v,uint256 refassetid); bool ValidateBidRemainder(int64_t remaining_price,int64_t remaining_nValue,int64_t orig_nValue,int64_t received_nValue,int64_t paidprice,int64_t totalprice); diff --git a/src/cc/CCassetsCore.cpp b/src/cc/CCassetsCore.cpp index 55a4ccdcb..cd2e267e1 100644 --- a/src/cc/CCassetsCore.cpp +++ b/src/cc/CCassetsCore.cpp @@ -274,7 +274,29 @@ bool DecodeAssetCreateOpRet(const CScript &scriptPubKey,std::vector &or return(0); } -uint8_t DecodeAssetOpRet(const CScript &scriptPubKey,uint256 &assetid,uint256 &assetid2,int64_t &price,std::vector &origpubkey) +CScript EncodeAssetOpRetExtra(uint8_t funcid,uint256 assetid,uint256 assetid2,uint256 bettxid,int32_t leverage) +{ + CScript opret; uint8_t evalcode = EVAL_ASSETS; + assetid = revuint256(assetid); + assetid2 = revuint256(assetid2); + opret << OP_RETURN << E_MARSHAL(ss << evalcode << funcid << assetid << assetid2 << bettxid << leverage); + return(opret); +} + +uint8_t DecodeAssetOpRetExtra(CScript scriptPubKey,uint256 &assetid,uint256 &assetid2,uint256 &bettxid,int32_t leverage) +{ + std::vector vopret; uint8_t funcid=0,e,f; + GetOpReturnData(scriptPubKey, vopret); + if ( E_UNMARSHAL(vopret,ss >> e; ss >> f; ss >> assetid; ss >> assetid2; ss >> bettxid; ss >> leverage) != 0 ) + { + assetid = revuint256(assetid); + assetid2 = revuint256(assetid2); + return(funcid); + } + return(0); +} + +uint8_t DecodeAssetOpRet(const CScript &scriptPubKey,uint256 &assetid,uint256 &assetid2,int64_t &price,std::vector &origpubkey,uint256 &bettxid,int32_t &leverage) { std::vector vopret; uint8_t funcid=0,*script,e,f; GetOpReturnData(scriptPubKey, vopret); @@ -297,6 +319,14 @@ uint8_t DecodeAssetOpRet(const CScript &scriptPubKey,uint256 &assetid,uint256 &a return(funcid); } break; + case 'T': + if ( E_UNMARSHAL(vopret,ss >> e; ss >> f; ss >> assetid; ss >> assetid2; ss >> bettxid; ss >> leverage) != 0 ) + { + assetid = revuint256(assetid); + assetid2 = revuint256(assetid2); + return(funcid); + } + break; case 's': case 'b': case 'S': case 'B': if ( E_UNMARSHAL(vopret,ss >> e; ss >> f; ss >> assetid; ss >> price; ss >> origpubkey) != 0 ) { @@ -325,17 +355,17 @@ uint8_t DecodeAssetOpRet(const CScript &scriptPubKey,uint256 &assetid,uint256 &a bool SetAssetOrigpubkey(std::vector &origpubkey,int64_t &price,const CTransaction &tx) { - uint256 assetid,assetid2; - if ( tx.vout.size() > 0 && DecodeAssetOpRet(tx.vout[tx.vout.size()-1].scriptPubKey,assetid,assetid2,price,origpubkey) != 0 ) + uint256 assetid,assetid2,bettxid; int32_t leverage; + if ( tx.vout.size() > 0 && DecodeAssetOpRet(tx.vout[tx.vout.size()-1].scriptPubKey,assetid,assetid2,price,origpubkey,bettxid,leverage) != 0 ) return(true); else return(false); } bool GetAssetorigaddrs(struct CCcontract_info *cp,char *CCaddr,char *destaddr,const CTransaction& tx) { - uint256 assetid,assetid2; int64_t price,nValue=0; int32_t n; uint8_t funcid; std::vector origpubkey; CScript script; + uint256 assetid,assetid2,bettxid; int32_t leverage; int64_t price,nValue=0; int32_t n; uint8_t funcid; std::vector origpubkey; CScript script; n = tx.vout.size(); - if ( n == 0 || (funcid= DecodeAssetOpRet(tx.vout[n-1].scriptPubKey,assetid,assetid2,price,origpubkey)) == 0 ) + if ( n == 0 || (funcid= DecodeAssetOpRet(tx.vout[n-1].scriptPubKey,assetid,assetid2,price,origpubkey,bettxid,leverage)) == 0 ) return(false); if ( GetCCaddress(cp,CCaddr,pubkey2pk(origpubkey)) != 0 && Getscriptaddress(destaddr,CScript() << origpubkey << OP_CHECKSIG) != 0 ) return(true); @@ -344,7 +374,7 @@ bool GetAssetorigaddrs(struct CCcontract_info *cp,char *CCaddr,char *destaddr,co int64_t IsAssetvout(int64_t &price,std::vector &origpubkey,const CTransaction& tx,int32_t v,uint256 refassetid) { - uint256 assetid,assetid2; int64_t nValue=0; int32_t n; uint8_t funcid; + uint256 assetid,assetid2,bettxid; int64_t nValue=0; int32_t n,leverage; uint8_t funcid; if ( tx.vout[v].scriptPubKey.IsPayToCryptoCondition() != 0 ) // maybe check address too? { n = tx.vout.size(); @@ -352,7 +382,7 @@ int64_t IsAssetvout(int64_t &price,std::vector &origpubkey,const CTrans //fprintf(stderr,"CC vout v.%d of n.%d %.8f\n",v,n,(double)nValue/COIN); if ( v >= n-1 ) return(0); - if ( (funcid= DecodeAssetOpRet(tx.vout[n-1].scriptPubKey,assetid,assetid2,price,origpubkey)) == 0 ) + if ( (funcid= DecodeAssetOpRet(tx.vout[n-1].scriptPubKey,assetid,assetid2,price,origpubkey,bettxid,leverage)) == 0 ) { fprintf(stderr,"null decodeopret v.%d\n",v); return(0); @@ -414,7 +444,7 @@ int64_t AssetValidateCCvin(struct CCcontract_info *cp,Eval* eval,char *CCaddr,ch int64_t AssetValidateBuyvin(struct CCcontract_info *cp,Eval* eval,int64_t &tmpprice,std::vector &tmporigpubkey,char *CCaddr,char *origaddr,const CTransaction &tx,uint256 refassetid) { - CTransaction vinTx; int64_t nValue; uint256 assetid,assetid2; uint8_t funcid; + CTransaction vinTx; int64_t nValue; int32_t leverage; uint256 assetid,assetid2,bettxid; uint8_t funcid; CCaddr[0] = origaddr[0] = 0; if ( (nValue= AssetValidateCCvin(cp,eval,CCaddr,origaddr,tx,1,vinTx)) == 0 ) return(0); @@ -423,7 +453,7 @@ int64_t AssetValidateBuyvin(struct CCcontract_info *cp,Eval* eval,int64_t &tmppr else { //fprintf(stderr,"have %.8f checking assetid origaddr.(%s)\n",(double)nValue/COIN,origaddr); - if ( vinTx.vout.size() > 0 && (funcid= DecodeAssetOpRet(vinTx.vout[vinTx.vout.size()-1].scriptPubKey,assetid,assetid2,tmpprice,tmporigpubkey)) != 'b' && funcid != 'B' ) + if ( vinTx.vout.size() > 0 && (funcid= DecodeAssetOpRet(vinTx.vout[vinTx.vout.size()-1].scriptPubKey,assetid,assetid2,tmpprice,tmporigpubkey,bettxid,leverage)) != 'b' && funcid != 'B' ) return eval->Invalid("invalid opreturn for buyvin"); else if ( refassetid != assetid ) return eval->Invalid("invalid assetid for buyvin"); diff --git a/src/cc/CCassetstx.cpp b/src/cc/CCassetstx.cpp index cbf40d603..63d1a1089 100644 --- a/src/cc/CCassetstx.cpp +++ b/src/cc/CCassetstx.cpp @@ -106,7 +106,7 @@ UniValue AssetList() UniValue AssetOrders(uint256 refassetid) { static uint256 zero; - int64_t price; uint256 txid,hashBlock,assetid,assetid2; std::vector origpubkey; CTransaction vintx; UniValue result(UniValue::VARR); std::vector > unspentOutputs; uint8_t funcid; char numstr[32],funcidstr[16],origaddr[64],assetidstr[65]; struct CCcontract_info *cp,C; + int64_t price; uint256 txid,hashBlock,assetid,assetid2,bettxid; std::vector origpubkey; CTransaction vintx; UniValue result(UniValue::VARR); std::vector > unspentOutputs; int32_t leverage; uint8_t funcid; char numstr[32],funcidstr[16],origaddr[64],assetidstr[65]; struct CCcontract_info *cp,C; cp = CCinit(&C,EVAL_ASSETS); SetCCunspents(unspentOutputs,(char *)cp->unspendableCCaddr); for (std::vector >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++) @@ -114,7 +114,7 @@ UniValue AssetOrders(uint256 refassetid) txid = it->first.txhash; if ( GetTransaction(txid,vintx,hashBlock,false) != 0 ) { - if ( vintx.vout.size() > 0 && (funcid= DecodeAssetOpRet(vintx.vout[vintx.vout.size()-1].scriptPubKey,assetid,assetid2,price,origpubkey)) != 0 ) + if ( vintx.vout.size() > 0 && (funcid= DecodeAssetOpRet(vintx.vout[vintx.vout.size()-1].scriptPubKey,assetid,assetid2,price,origpubkey,bettxid,leverage)) != 0 ) { if ( refassetid != zero && assetid != refassetid ) { diff --git a/src/cc/CCinclude.h b/src/cc/CCinclude.h index 4beb722a1..4059191a7 100644 --- a/src/cc/CCinclude.h +++ b/src/cc/CCinclude.h @@ -110,10 +110,12 @@ uint256 OraclesBatontxid(uint256 oracletxid,CPubKey pk); int64_t AddAssetInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey pk,uint256 assetid,int64_t total,int32_t maxinputs); bool DecodeHexTx(CTransaction& tx, const std::string& strHexTx); bool DecodeAssetCreateOpRet(const CScript &scriptPubKey,std::vector &origpubkey,std::string &name,std::string &description); -uint8_t DecodeAssetOpRet(const CScript &scriptPubKey,uint256 &assetid,uint256 &assetid2,int64_t &price,std::vector &origpubkey); +uint8_t DecodeAssetOpRet(const CScript &scriptPubKey,uint256 &assetid,uint256 &assetid2,int64_t &price,std::vector &origpubkey,uint256 &bettxid,int32_t &leverage); uint8_t DecodeOraclesData(const CScript &scriptPubKey,uint256 &oracletxid,uint256 &batontxid,CPubKey &pk,std::vector &data); int32_t oracle_format(uint256 *hashp,int64_t *valp,char *str,uint8_t fmt,uint8_t *data,int32_t offset,int32_t datalen); CScript EncodeAssetOpRet(uint8_t funcid,uint256 assetid,uint256 assetid2,int64_t price,std::vector origpubkey); +CScript EncodeAssetOpRetExtra(uint8_t funcid,uint256 assetid,uint256 assetid2,uint256 bettxid,int32_t leverage); +uint8_t DecodeAssetOpRetExtra(CScript scriptPubKey,uint256 &assetid,uint256 &assetid2,uint256 &bettxid,int32_t leverage); // CCcustom CPubKey GetUnspendable(struct CCcontract_info *cp,uint8_t *unspendablepriv); diff --git a/src/cc/CCtx.cpp b/src/cc/CCtx.cpp index 50bb9616f..b26ca7cfd 100644 --- a/src/cc/CCtx.cpp +++ b/src/cc/CCtx.cpp @@ -250,14 +250,15 @@ int64_t CCfullsupply(uint256 tokenid) int64_t CCtoken_balance(char *coinaddr,uint256 tokenid) { - int64_t price,sum = 0; int32_t numvouts; CTransaction tx; uint256 assetid,assetid2,txid,hashBlock; std::vector origpubkey; std::vector > unspentOutputs; + int64_t price,sum = 0; int32_t numvouts; CTransaction tx; uint256 assetid,assetid2,txid,bettxid,hashBlock; std::vector origpubkey; int32_t leverage; + std::vector > unspentOutputs; SetCCunspents(unspentOutputs,coinaddr); for (std::vector >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++) { txid = it->first.txhash; if ( GetTransaction(txid,tx,hashBlock,false) != 0 && (numvouts= tx.vout.size()) > 0 ) { - if ( DecodeAssetOpRet(tx.vout[numvouts-1].scriptPubKey,assetid,assetid2,price,origpubkey) != 0 && assetid == tokenid ) + if ( DecodeAssetOpRet(tx.vout[numvouts-1].scriptPubKey,assetid,assetid2,price,origpubkey,bettxid,leverage) != 0 && assetid == tokenid ) { sum += it->second.satoshis; } diff --git a/src/cc/assets.cpp b/src/cc/assets.cpp index e5a5af4e0..bf979a1e0 100644 --- a/src/cc/assets.cpp +++ b/src/cc/assets.cpp @@ -132,12 +132,12 @@ bool AssetsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx) { static uint256 zero; - CTxDestination address; CTransaction vinTx,createTx; uint256 hashBlock,assetid,assetid2; int32_t i,starti,numvins,numvouts,preventCCvins,preventCCvouts; int64_t remaining_price,nValue,assetoshis,outputs,inputs,tmpprice,totalunits,ignore; std::vector origpubkey,tmporigpubkey,ignorepubkey; uint8_t funcid; char destaddr[64],origaddr[64],CCaddr[64]; + CTxDestination address; CTransaction vinTx,createTx; uint256 bettxid,hashBlock,assetid,assetid2; int32_t i,starti,leverage,numvins,numvouts,preventCCvins,preventCCvouts; int64_t remaining_price,nValue,assetoshis,outputs,inputs,tmpprice,totalunits,ignore; std::vector origpubkey,tmporigpubkey,ignorepubkey; uint8_t funcid; char destaddr[64],origaddr[64],CCaddr[64]; numvins = tx.vin.size(); numvouts = tx.vout.size(); outputs = inputs = 0; preventCCvins = preventCCvouts = -1; - if ( (funcid= DecodeAssetOpRet(tx.vout[numvouts-1].scriptPubKey,assetid,assetid2,remaining_price,origpubkey)) == 0 ) + if ( (funcid= DecodeAssetOpRet(tx.vout[numvouts-1].scriptPubKey,assetid,assetid2,remaining_price,origpubkey,bettxid,leverage)) == 0 ) return eval->Invalid("Invalid opreturn payload"); fprintf(stderr,"AssetValidate (%c)\n",funcid); if ( funcid != 'o' && funcid != 'x' && eval->GetTxUnconfirmed(assetid,createTx,hashBlock) == 0 ) diff --git a/src/cc/gateways.cpp b/src/cc/gateways.cpp index 23b600930..9146a864b 100644 --- a/src/cc/gateways.cpp +++ b/src/cc/gateways.cpp @@ -130,6 +130,11 @@ 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 + + Implementation Issues: + When thinking about validation, it is clear that we cant use EVAL_ASSETS for the locked coins as there wont be any enforcement of the gateways locking. This means we need a way to transfer assets into gateways outputs and back. It seems a tokenconvert rpc will be needed and hopefully that will be enough to make it all work properly. + + */ @@ -433,19 +438,24 @@ std::string GatewaysBind(uint64_t txfee,std::string coin,uint256 tokenid,int64_t { CMutableTransaction mtx; CTransaction oracletx; uint8_t taddr,prefix,prefix2; CPubKey mypk,gatewayspk; CScript opret; uint256 hashBlock; struct CCcontract_info *cp,C; std::string name,description,format; int32_t i,numvouts; int64_t fullsupply; char destaddr[64],coinaddr[64],str[65],*fstr; cp = CCinit(&C,EVAL_GATEWAYS); + if ( strcmp((char *)"KMD",coin.c_str()) == 0 ) + { + taddr = 0; + prefix = 60; + prefix2 = 85; + } + else + { + fprintf(stderr,"set taddr, prefix, prefix2 for %s\n",coin.c_str()); + taddr = 0; + prefix = 60; + prefix2 = 85; + } if ( N == 0 || N > 15 || M > N ) { fprintf(stderr,"illegal M.%d or N.%d\n",M,N); return(""); } - if ( strcmp((char *)"KMD",coin.c_str()) != 0 ) - { - fprintf(stderr,"only KMD supported for now\n"); - return(""); - } - taddr = 0; - prefix = 60; - prefix2 = 85; if ( pubkeys.size() != N ) { fprintf(stderr,"M.%d N.%d but pubkeys[%d]\n",M,N,(int32_t)pubkeys.size()); diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index 1db14d1b9..49e87127a 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -28,7 +28,7 @@ Funds work like with dice, ie. there is a Prices plan that traders bet against. - PricesFunding oracletxid, priceaveraging, maxleverage, funding, longtoken, shorttoken, N [pubkeys] + PricesFunding oracletxid, margin, priceaveraging, maxleverage, funding, longtoken, shorttoken, N [pubkeys] PricesBet -> oracletxid start with 'L', leverage, funding, direction funds are locked into global CC address @@ -53,58 +53,35 @@ pricewin -> winnings from dealer funds, exposure token back to global address priceloss -> exposuretoken back to global address + exposure address, funds address */ // start of consensus code -int64_t IsPricesvout(struct CCcontract_info *cp,const CTransaction& tx,int32_t v) +int64_t PricesOraclePrice(int64_t &rektprice,uint64_t mode,uint256 oracletxid,std::vectorpubkeys,int32_t dir,int64_t amount,int32_t leverage) { - char destaddr[64]; - if ( tx.vout[v].scriptPubKey.IsPayToCryptoCondition() != 0 ) - { - if ( Getscriptaddress(destaddr,tx.vout[v].scriptPubKey) > 0 && strcmp(destaddr,cp->unspendableCCaddr) == 0 ) - return(tx.vout[v].nValue); - } - return(0); + int64_t price; + // howto ensure price when block it confirms it not known + // get price from oracle + current chaintip + // normalize leveraged amount + if ( dir > 0 ) + rektprice = price * leverage / (leverage-1); + else rektprice = price * (leverage-1) / leverage; + return(price); } -bool PricesExactAmounts(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx,int32_t minage,uint64_t txfee) +CScript EncodePricesFundingOpRet(uint8_t funcid,CPubKey planpk,uint256 oracletxid,uint256 longtoken,uint256 shorttoken,int32_t millimargin,uint64_t mode,int32_t maxleverage,std::vector pubkeys) { - static uint256 zerohash; - CTransaction vinTx; uint256 hashBlock,activehash; int32_t i,numvins,numvouts; int64_t inputs=0,outputs=0,assetoshis; - numvins = tx.vin.size(); - numvouts = tx.vout.size(); - for (i=0; iismyvin)(tx.vin[i].scriptSig) != 0 ) - { - //fprintf(stderr,"vini.%d check mempool\n",i); - if ( eval->GetTxUnconfirmed(tx.vin[i].prevout.hash,vinTx,hashBlock) == 0 ) - return eval->Invalid("cant find vinTx"); - else - { - //fprintf(stderr,"vini.%d check hash and vout\n",i); - if ( hashBlock == zerohash ) - return eval->Invalid("cant Prices from mempool"); - if ( (assetoshis= IsPricesvout(cp,vinTx,tx.vin[i].prevout.n)) != 0 ) - inputs += assetoshis; - } - } - } - for (i=0; iInvalid("mismatched inputs != outputs + txfee"); - } - else return(true); + CScript opret; + fprintf(stderr,"implement EncodePricesFundingOpRet\n"); + return(opret); +} + +uint8_t DecodePricesFundingOpRet(CScript scriptPubKey,CPubKey &planpk,uint256 &oracletxid,uint256 &longtoken,uint256 &shorttoken,int32_t &millimargin,uint64_t &mode,int32_t &maxleverage,std::vector &pubkeys,uint256 &bettoken) +{ + fprintf(stderr,"implement DecodePricesFundingOpRet\n"); + return(0); } bool PricesValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx) @@ -148,20 +125,20 @@ bool PricesValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx // helper functions for rpc calls in rpcwallet.cpp -int64_t AddPricesInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey pk,int64_t total,int32_t maxinputs) +int64_t AddTokensInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,char *destaddr,uint256 tolenid,int64_t total,int32_t maxinputs) { - char coinaddr[64]; int64_t nValue,price,totalinputs = 0; uint256 txid,hashBlock; std::vector origpubkey; CTransaction vintx; int32_t vout,n = 0; + int64_t nValue,price,totalinputs = 0; uint256 txid,hashBlock; std::vector origpubkey; CTransaction vintx; int32_t vout,n = 0; std::vector > unspentOutputs; - GetCCaddress(cp,coinaddr,pk); - SetCCunspents(unspentOutputs,coinaddr); + SetCCunspents(unspentOutputs,destaddr); for (std::vector >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++) { txid = it->first.txhash; vout = (int32_t)it->first.index; - // no need to prevent dup - if ( GetTransaction(txid,vintx,hashBlock,false) != 0 ) + // need to prevent dup + if ( GetTransaction(txid,vintx,hashBlock,false) != 0 && vout < tx.vout.size() ) { - if ( (nValue= IsPricesvout(cp,vintx,vout)) > 1000000 && myIsutxo_spentinmempool(txid,vout) == 0 ) + // need to verify assetid + if ( (nValue= vintx.vout[vout].nValue)) > 10000 && myIsutxo_spentinmempool(txid,vout) == 0 ) { if ( total != 0 && maxinputs != 0 ) mtx.vin.push_back(CTxIn(txid,vout,CScript())); @@ -176,49 +153,18 @@ int64_t AddPricesInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPub return(totalinputs); } -#ifdef later -UniValue PricesInfo(uint256 pricesid) -{ - UniValue result(UniValue::VOBJ); CPubKey pricepk; uint256 hashBlock,oracletxid; CTransaction vintx; int64_t minbet,maxbet,maxodds; uint64_t funding; char numstr[65]; struct CCcontract_info *cp,C; - if ( GetTransaction(pricesid,vintx,hashBlock,false) == 0 ) - { - fprintf(stderr,"cant find fundingtxid\n"); - ERR_RESULT("cant find fundingtxid"); - return(result); - } - if ( vintx.vout.size() > 0 && DecodePricesFundingOpRet(vintx.vout[vintx.vout.size()-1].scriptPubKey,oracletxid,minbet,maxbet,maxodds) == 0 ) - { - fprintf(stderr,"fundingtxid isnt price creation txid\n"); - ERR_RESULT("fundingtxid isnt price creation txid"); - return(result); - } - result.push_back(Pair("result","success")); - result.push_back(Pair("pricesid",uint256_str(str,pricesid))); - result.push_back(Pair("oracletxid",uint256_str(str,oracletxid))); - sprintf(numstr,"%.8f",(double)minbet/COIN); - result.push_back(Pair("minbet",numstr)); - sprintf(numstr,"%.8f",(double)maxbet/COIN); - result.push_back(Pair("maxbet",numstr)); - result.push_back(Pair("maxodds",maxodds)); - cp = CCinit(&C,EVAL_PRICES); - pricepk = GetUnspendable(cp,0); - funding = PricePlanFunds(cp,pricepk,pricesid); - sprintf(numstr,"%.8f",(double)funding/COIN); - result.push_back(Pair("funding",numstr)); - return(result); -} - UniValue PricesList() { - UniValue result(UniValue::VARR); std::vector > addressIndex; struct CCcontract_info *cp,C; uint256 txid,hashBlock,oracletxid; CTransaction vintx; int64_t minbet,maxbet,maxodds; char str[65]; + UniValue result(UniValue::VARR); std::vector > addressIndex; struct CCcontract_info *cp,C; uint64_t mode; int32_t margin,maxleverage; std::vectorpubkeys; uint256 txid,hashBlock,oracletxid,longtoken,shorttoken,bettoken; CPubKey planpk,pricespk; char str[65]; CTransaction vintx; cp = CCinit(&C,EVAL_PRICES); + pricespk = GetUnspendable(cp,0); SetCCtxids(addressIndex,cp->normaladdr); for (std::vector >::const_iterator it=addressIndex.begin(); it!=addressIndex.end(); it++) { txid = it->first.txhash; if ( GetTransaction(txid,vintx,hashBlock,false) != 0 ) { - if ( vintx.vout.size() > 0 && DecodePricesFundingOpRet(vintx.vout[vintx.vout.size()-1].scriptPubKey,oracletxid,minbet,maxbet,maxodds) != 0 ) + if ( vintx.vout.size() > 0 && DecodePricesFundingOpRet(vintx.vout[vintx.vout.size()-1].scriptPubKey,planpk,oracletxid,longtoken,shorttoken,margin,mode,maxleverage,pubkeys,bettoken) == 'F' ) { result.push_back(uint256_str(str,txid)); } @@ -227,54 +173,165 @@ UniValue PricesList() return(result); } -// PricesFunding oracletxid, priceaveraging, maxleverage, funding, longtoken, shorttoken, N [pubkeys] - -std::string PricesCreateFunding(uint64_t txfee,uint256 oracletxid,uint64_t mode,uint256 longtoken,uint256 shorttoken,int32_t maxleverage,int64_t funding,CPubKey pubkeys) +// longtoken satoshis limits long exposure +// shorttoken satoshis limits short exposure +// both must be in the 1of2 CC address with its total supply +// bettoken +std::string PricesCreateFunding(uint64_t txfee,uint256 bettoken,uint256 oracletxid,uint64_t margin,uint64_t mode,uint256 longtoken,uint256 shorttoken,int32_t maxleverage,int64_t funding,std::vector pubkeys) { - CMutableTransaction mtx; CPubKey mypk,pricespk; struct CCcontract_info *cp,C; + CMutableTransaction mtx; CTransaction oracletx; int64_t fullsupply,inputs,CCchange=0; uint256 hashBlock; char str[65],coinaddr[64],houseaddr[64]; CPubKey mypk,pricespk; int32_t i,N,numvouts; struct CCcontract_info *cp,C,*assetscp,C2; if ( funding < 100*COIN || maxleverage <= 0 || maxleverage > 10000 ) { CCerror = "invalid parameter error"; fprintf(stderr,"%s\n", CCerror.c_str() ); return(""); } - cp = CCinit(&C,EVAL_REWARDS); + cp = CCinit(&C,EVAL_PRICES); + assetscp = CCinit(&C2,EVAL_ASSETS); if ( txfee == 0 ) txfee = 10000; mypk = pubkey2pk(Mypubkey()); pricespk = GetUnspendable(cp,0); - // verify long and short assets - if ( AddNormalinputs(mtx,mypk,funding+3*txfee,60) > 0 ) + if ( (N= (int32_t)pubkeys.size()) || N > 15 ) { - mtx.vout.push_back(MakeCC1vout(cp->evalcode,funding,pricepk)); - mtx.vout.push_back(CTxOut(txfee,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG)); - mtx.vout.push_back(CTxOut(txfee,CScript() << ParseHex(HexStr(pricepk)) << OP_CHECKSIG)); - return(FinalizeCCTx(0,cp,mtx,mypk,txfee,EncodePricesFundingOpRet('F',oracletxid,longtoken,shorttoken,funding,mode,maxleverage,pubkeys))); + fprintf(stderr,"too many pubkeys N.%d\n",N); + return(""); + } + for (i=0; i 0 ) + { + mtx.vout.push_back(CTxOut(txfee,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG)); + mtx.vout.push_back(CTxOut(txfee,CScript() << ParseHex(HexStr(pricespk)) << OP_CHECKSIG)); + return(FinalizeCCTx(0,cp,mtx,mypk,txfee,EncodePricesFundingOpRet('F',mypk,oracletxid,longtoken,shorttoken,margin,mode,maxleverage,pubkeys,bettoken))); + } + else + { + CCerror = "cant find enough inputs"; + fprintf(stderr,"%s\n", CCerror.c_str() ); } - CCerror = "cant find enough inputs"; - fprintf(stderr,"%s\n", CCerror.c_str() ); return(""); } -std::string PricesAddfunding(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t amount) +UniValue PricesInfo(uint256 fundingtxid) { - CMutableTransaction mtx; CScript fundingPubKey,scriptPubKey; CPubKey mypk,pricepk; struct CCcontract_info *cp,C; int64_t minbet,maxbet,maxodds; - if ( amount < 0 ) + UniValue result(UniValue::VOBJ),a(UniValue::VARR); CPubKey pricespk,planpk; uint256 hashBlock,oracletxid,longtoken,shorttoken,bettoken; CTransaction vintx; int64_t balance,supply,exposure; uint64_t funding,mode; int32_t i,margin,maxleverage; char numstr[65],houseaddr[64],exposureaddr[64]; struct CCcontract_info *cp,C,*assetscp,C2; + cp = CCinit(&C,EVAL_PRICES); + assetscp = CCinit(&C2,EVAL_ASSETS); + pricespk = GetUnspendable(cp,0); + if ( GetTransaction(fundingtxid,vintx,hashBlock,false) == 0 ) + { + fprintf(stderr,"cant find fundingtxid\n"); + ERR_RESULT("cant find fundingtxid"); + return(result); + } + if ( vintx.vout.size() > 0 && DecodePricesFundingOpRet(vintx.vout[vintx.vout.size()-1].scriptPubKey,planpk,oracletxid,longtoken,shorttoken,margin,mode,maxleverage,pubkeys,bettoken) == 'F' ) + { + result.push_back(Pair("result","success")); + result.push_back(Pair("fundingtxid",uint256_str(str,fundingtxid))); + result.push_back(Pair("bettoken",uint256_str(str,bettoken))); + result.push_back(Pair("oracletxid",uint256_str(str,oracletxid))); + sprintf(numstr,"%.3f",(double)margin/1000); + result.push_back(Pair("profitmargin",numstr)); + result.push_back(Pair("maxleverage",maxleverage)); + result.push_back(Pair("mode",(int64_t)mode)); + for (i=0; i 0 ) + fprintf(stderr,"cant find fundingtxid\n"); + ERR_RESULT("cant find fundingtxid"); + return(result); + } + if ( tx.vout.size() > 0 && DecodePricesFundingOpRet(tx.vout[tx.vout.size()-1].scriptPubKey,planpk,oracletxid,longtoken,shorttoken,margin,mode,maxleverage,pubkeys,bettoken) == 'F' && bettoken == refbettoken ) + { + GetCCaddress1of2(houseaddr,assetscp,pricespk,planpk); + if ( AddNormalinputs(mtx,mypk,2*txfee,3) > 0 ) { - mtx.vout.push_back(MakeCC1vout(cp->evalcode,amount,pricepk)); - mtx.vout.push_back(CTxOut(txfee,fundingPubKey)); - return(FinalizeCCTx(0,cp,mtx,mypk,txfee,EncodePricesOpRet('E',sbits,fundingtxid,hentropy,zeroid))); + if ( (inputs= AddBetAssetInputs(assetscp,mtx,myaddr,bettoken,amount,60)) >= amount ) + { + mtx.vout.push_back(MakeCC1of2vout(assetscp->evalcode,amount,pricespk,planpk)); + mtx.vout.push_back(CTxOut(txfee,CScript() << ParseHex(HexStr(planpk)) << OP_CHECKSIG)); + if ( inputs > amount+txfee ) + CCchange = (inputs - amount); + mtx.vout.push_back(MakeCCvout(assetscp->evalcode,CCchange,mypk)); + // add addr2 + return(FinalizeCCTx(0,cp,mtx,mypk,txfee,EncodeAssetOpRet('t',bettoken,zeroid,0,Mypubkey()))); + } + else + { + CCerror = "cant find enough bet inputs"; + fprintf(stderr,"%s\n", CCerror.c_str() ); + } } else { @@ -282,66 +339,106 @@ std::string PricesAddfunding(uint64_t txfee,char *planstr,uint256 fundingtxid,in fprintf(stderr,"%s\n", CCerror.c_str() ); } } - else - { - CCerror = "only fund creator can add more funds (entropy)"; - fprintf(stderr,"%s\n", CCerror.c_str() ); - } return(""); } -std::string PricesBet(uint64_t txfee,uint256 pricesid,int64_t bet,int32_t odds) +std::string PricesBet(uint64_t txfee,uint256 refbettoken,uint256 fundingtxid,int64_t amount,int32_t leverage) { - CMutableTransaction mtx; CScript fundingPubKey; CPubKey mypk,pricepk; int64_t funding,minbet,maxbet,maxodds; struct CCcontract_info *cp,C; - if ( bet < 0 ) + CMutableTransaction mtx; struct CCcontract_info *cp,C,*asssetcp,C2; CPubKey pricespk,planpk,mypk; uint256 hashBlock,oracletxid,longtoken,shorttoken,tokenid,bettoken; CTransaction tx; int64_t balance,supply,exposure,inputs,inputs2,longexposure,netexposure,shortexposure,CCchange = 0,CCchange2 = 0; uint64_t funding,mode; int32_t dir,margin,maxleverage; char houseaddr[64],myaddr[64],exposureaddr[64]; + if ( amount < 0 ) { - CCerror = "bet must be positive"; - fprintf(stderr,"%s\n", CCerror.c_str() ); + amount = -amount; + dir = -1; + } else dir = 1; + cp = CCinit(&C,EVAL_PRICES); + assetscp = CCinit(&C2,EVAL_ASSETS); + if ( txfee == 0 ) + txfee = 10000; + mypk = pubkey2pk(Mypubkey()); + pricespk = GetUnspendable(cp,0); + GetCCaddress(myaddr,assetscp,mypk); + if ( GetTransaction(fundingtxid,tx,hashBlock,false) == 0 ) + { + fprintf(stderr,"cant find fundingtxid\n"); + ERR_RESULT("cant find fundingtxid"); return(""); } - if ( odds < 1 || odds > 9999 ) + if ( tx.vout.size() > 0 && DecodePricesFundingOpRet(tx.vout[tx.vout.size()-1].scriptPubKey,planpk,oracletxid,longtoken,shorttoken,margin,mode,maxleverage,pubkeys,bettoken) == 'F' && bettoken == refbettoken ) { - CCerror = "odds must be between 1 and 9999"; - fprintf(stderr,"%s\n", CCerror.c_str() ); - return(""); - } - if ( (cp= Pricesinit(fundingPubKey,pricesid,&C,txfee,mypk,pricepk,minbet,maxbet,maxodds)) == 0 ) - return(""); - if ( bet < minbet || bet > maxbet || odds > maxodds ) - { - CCerror = strprintf("Price plan %s illegal bet %.8f: minbet %.8f maxbet %.8f or odds %d vs max.%d\n",planstr,(double)bet/COIN,(double)minbet/COIN,(double)maxbet/COIN,(int32_t)odds,(int32_t)maxodds); - fprintf(stderr,"%s\n", CCerror.c_str() ); - return(""); - } - if ( (funding= PricesPlanFunds(cp,pricepk,pricesid)) >= 2*bet*odds+txfee ) - { - if ( myIsutxo_spentinmempool(entropytxid,0) != 0 ) + if ( leverage > maxleverage || leverage < 1 ) { - CCerror = "entropy txid is spent"; - fprintf(stderr,"%s\n", CCerror.c_str() ); + fprintf(stderr,"illegal leverage\n"); return(""); } - if ( AddNormalinputs(mtx,mypk,bet+2*txfee+odds,60) > 0 ) + GetCCaddress1of2(houseaddr,assetscp,pricespk,planpk); + GetCCaddress1of2(exposureaddr,assetscp,pricespk,pricespk); + if ( dir < 0 ) + tokenid = shorttoken; + else tokenid = longtoken; + exposure = leverage * amount; + longexposure = CCtoken_balance(exposureaddr,longtoken); + shortexposure = CCtoken_balance(exposureaddr,shorttoken); + netexposure = (longexposure - shortexposure + exposure*dir); + if ( netexposure < 0 ) + netexposure = -netexposure; + balance = CCtoken_balance(myaddr,bettoken) / COIN; + if ( balance < netexposure*9/10 ) // 10% extra room for dynamically closed bets in wrong direction { - mtx.vout.push_back(MakeCC1vout(cp->evalcode,entropyval,pricepk)); - mtx.vout.push_back(MakeCC1vout(cp->evalcode,bet,pricepk)); - mtx.vout.push_back(CTxOut(txfee+odds,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG)); - return(FinalizeCCTx(0,cp,mtx,mypk,txfee,EncodePricesOpRet('B',pricesid))); - } else fprintf(stderr,"cant find enough normal inputs for %.8f, plan funding %.8f\n",(double)bet/COIN,(double)funding/COIN); + fprintf(stderr,"balance %lld < 90% netexposure %lld, refuse bet\n",(long long)balance,(long long)netexposure); + return(""); + } + if ( AddNormalinputs(mtx,mypk,txfee,3) > 0 ) + { + if ( (inputs= AddTokensInputs(assetscp,mtx,houseaddr,tokenid,exposure,30)) >= exposure ) + { + if ( (inputs2= AddTokensInputs(assetscp,mtx,myaddr,bettoken,amount,30)) >= amount ) + { + mtx.vout.push_back(MakeCC1of2vout(assetscp->evalcode,amount,pricespk,planpk)); + mtx.vout.push_back(MakeCC1of2vout(assetscp->evalcode,exposure,pricespk,pricespk)); + if ( inputs > exposure+txfee ) + CCchange = (inputs - exposure); + if ( inputs2 > amount+txfee ) + CCchange2 = (inputs2 - amount); + mtx.vout.push_back(MakeCC1of2vout(assetscp->evalcode,CCchange,pricespk,planpk)); + mtx.vout.push_back(MakeCCvout(assetscp->evalcode,CCchange2,mypk)); + // add addr2 and addr3 + return(FinalizeCCTx(mask,assetscp,mtx,mypk,txfee,EncodeAssetOpRetExtra('T',tokenid,bettoken,bettxid,dir*leverage))); + } + else + { + fprintf(stderr,"cant find enough bettoken inputs\n"); + return(""); + } + } + else + { + fprintf(stderr,"cant find enough exposure inputs\n"); + return(""); + } + } + else + { + CCerror = "cant find enough inputsB"; + fprintf(stderr,"%s\n", CCerror.c_str() ); + } } - if ( entropyval == 0 && funding != 0 ) - CCerror = "cant find price entropy inputs"; - else CCerror = "cant find price input"; - fprintf(stderr,"%s\n", CCerror.c_str() ); return(""); } -std::string PricesBetFinish(int32_t *resultp,uint64_t txfee,uint256 pricesid,uint256 bettxid) +UniValue PricesStatus(uint64_t txfee,uint256 refbettoken,uint256 fundingtxid,uint256 bettxid) +{ + UniValue result(UniValue::VOBJ); + // get height of bettxid + // get price and rekt + // get current height and price + // what about if rekt in the past? + return(result); +} + +std::string PricesFinish(uint64_t txfee,uint256 refbettoken,uint256 fundingtxid,uint256 bettxid) { - *resultp = -1; - CCerror = "couldnt find bettx or entropytx"; - fprintf(stderr,"%s\n", CCerror.c_str() ); return(""); } -#endif + + diff --git a/src/komodo_utils.h b/src/komodo_utils.h index d98418c82..2441da83d 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1628,6 +1628,11 @@ void komodo_args(char *argv0) { int32_t komodo_baseid(char *origbase); extern int COINBASE_MATURITY; + if ( strcmp(ASSETCHAINS_SYMBOL,"KMD") == 0 ) + { + fprintf(stderr,"cant have assetchain named KMD\n"); + exit(0); + } if ( (port= komodo_userpass(ASSETCHAINS_USERPASS,ASSETCHAINS_SYMBOL)) != 0 ) ASSETCHAINS_RPCPORT = port; else komodo_configfile(ASSETCHAINS_SYMBOL,ASSETCHAINS_P2PPORT + 1); diff --git a/src/rpcserver.cpp b/src/rpcserver.cpp index d268ed7fa..77e53f7a1 100644 --- a/src/rpcserver.cpp +++ b/src/rpcserver.cpp @@ -398,7 +398,14 @@ static const CRPCCommand vRPCCommands[] = { "oracles", "oraclessamples", &oraclessamples, true }, /* Prices */ - { "prices", "pricesaddress", &pricesaddress, true }, + { "prices", "pricesaddress", &pricesaddress, true }, + { "prices", "priceslist", &priceslist, true }, + { "prices", "pricesinfo", &pricesinfo, true }, + { "prices", "pricescreate", &pricescreate, true }, + { "prices", "pricesaddfunding", &pricesaddfunding, true }, + { "prices", "pricesbet", &pricesbet, true }, + { "prices", "pricesstatus", &pricesstatus, true }, + { "prices", "pricesfinish", &pricesfinish, true }, /* Pegs */ { "pegs", "pegsaddress", &pegsaddress, true }, diff --git a/src/rpcserver.h b/src/rpcserver.h index 1ebff82ef..e0c87756f 100644 --- a/src/rpcserver.h +++ b/src/rpcserver.h @@ -232,6 +232,13 @@ extern UniValue oraclessubscribe(const UniValue& params, bool fHelp); extern UniValue oraclesdata(const UniValue& params, bool fHelp); extern UniValue oraclessamples(const UniValue& params, bool fHelp); extern UniValue pricesaddress(const UniValue& params, bool fHelp); +extern UniValue priceslist(const UniValue& params, bool fHelp); +extern UniValue pricesinfo(const UniValue& params, bool fHelp); +extern UniValue pricescreate(const UniValue& params, bool fHelp); +extern UniValue pricesaddfunding(const UniValue& params, bool fHelp); +extern UniValue pricesbet(const UniValue& params, bool fHelp); +extern UniValue pricesstatus(const UniValue& params, bool fHelp); +extern UniValue pricesfinish(const UniValue& params, bool fHelp); extern UniValue pegsaddress(const UniValue& params, bool fHelp); extern UniValue triggersaddress(const UniValue& params, bool fHelp); extern UniValue paymentsaddress(const UniValue& params, bool fHelp); diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 44965db73..397c4f3c3 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4896,7 +4896,7 @@ UniValue CCaddress(struct CCcontract_info *cp,char *name,std::vector destpubkey; CPubKey pk,pk2; char destaddr[64]; + UniValue result(UniValue::VOBJ); struct CCcontract_info *cp,C; std::vector destpubkey; CPubKey pk,pk2; char destaddr[64]; cp = CCinit(&C,EVAL_CHANNELS); if ( fHelp || params.size() != 1 ) throw runtime_error("channelsaddress destpubkey\n"); @@ -4927,23 +4927,25 @@ UniValue oraclesaddress(const UniValue& params, bool fHelp) UniValue pricesaddress(const UniValue& params, bool fHelp) { - struct CCcontract_info *cp,C; std::vector pubkey; + UniValue result(UniValue::VOBJ); struct CCcontract_info *cp,C,*assetscp,C2; std::vector pubkey; CPubKey mypk,pricespk; char myaddr[64],houseaddr[64],exposureaddr[64]; cp = CCinit(&C,EVAL_PRICES); + assetscp = CCinit(&C2,EVAL_PRICES); if ( fHelp || params.size() > 1 ) throw runtime_error("pricesaddress [pubkey]\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"); if ( params.size() == 1 ) - { pubkey = ParseHex(params[0].get_str().c_str()); - char destaddr[64]; - GetCCaddress1of2(cp,destaddr,pubkey2pk(pubkey),pubkey2pk(pubkey)); - fprintf(stderr,"1of2 CC %s\n",destaddr); - cp->evalcode = EVAL_ASSETS; - GetCCaddress1of2(cp,destaddr,pubkey2pk(pubkey),pubkey2pk(pubkey)); - fprintf(stderr,"1of2 assets CC %s\n",destaddr); - } - return(CCaddress(cp,(char *)"Prices",pubkey)); + result = CCaddress(cp,(char *)"Prices",pubkey); + mypk = pubkey2pk(Mypubkey()); + pricespk = GetUnspendable(cp,0); + GetCCaddress(myaddr,assetscp,mypk); + GetCCaddress1of2(houseaddr,assetscp,pricespk,planpk); + GetCCaddress1of2(exposureaddr,assetscp,pricespk,pricespk); + result.push_back(Pair("myaddr",myaddr)); // for holding my asssets + result.push_back(Pair("houseaddr",houseaddr)); // globally accessible house assets + result.push_back(Pair("exposureaddr",exposureaddr)); // tracking of exposure + return(result); } UniValue pegsaddress(const UniValue& params, bool fHelp) @@ -5121,7 +5123,8 @@ UniValue channelsopen(const UniValue& params, bool fHelp) throw runtime_error("channelsopen destpubkey numpayments payment\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"); - LOCK(cs_main); + const CKeyStore& keystore = *pwalletMain; + LOCK2(cs_main, pwalletMain->cs_wallet); destpub = ParseHex(params[0].get_str().c_str()); numpayments = atoi(params[1].get_str().c_str()); payment = atol(params[2].get_str().c_str()); @@ -5142,7 +5145,8 @@ UniValue channelsstop(const UniValue& params, bool fHelp) throw runtime_error("channelsstop destpubkey origtxid\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"); - LOCK(cs_main); + const CKeyStore& keystore = *pwalletMain; + LOCK2(cs_main, pwalletMain->cs_wallet); destpub = ParseHex(params[0].get_str().c_str()); origtxid = Parseuint256((char *)params[1].get_str().c_str()); hex = ChannelStop(0,pubkey2pk(destpub),origtxid); @@ -5162,7 +5166,8 @@ UniValue channelspayment(const UniValue& params, bool fHelp) throw runtime_error("channelspayment prevtxid origtxid n 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"); - LOCK(cs_main); + const CKeyStore& keystore = *pwalletMain; + LOCK2(cs_main, pwalletMain->cs_wallet); prevtxid = Parseuint256((char *)params[0].get_str().c_str()); origtxid = Parseuint256((char *)params[1].get_str().c_str()); n = atoi((char *)params[2].get_str().c_str()); @@ -5184,7 +5189,8 @@ UniValue channelscollect(const UniValue& params, bool fHelp) throw runtime_error("channelscollect paytxid origtxid n 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"); - LOCK(cs_main); + const CKeyStore& keystore = *pwalletMain; + LOCK2(cs_main, pwalletMain->cs_wallet); paytxid = Parseuint256((char *)params[0].get_str().c_str()); origtxid = Parseuint256((char *)params[1].get_str().c_str()); n = atoi((char *)params[2].get_str().c_str()); @@ -5206,7 +5212,8 @@ UniValue channelsrefund(const UniValue& params, bool fHelp) throw runtime_error("channelsrefund stoptxid origtxid\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"); - LOCK(cs_main); + const CKeyStore& keystore = *pwalletMain; + LOCK2(cs_main, pwalletMain->cs_wallet); stoptxid = Parseuint256((char *)params[0].get_str().c_str()); origtxid = Parseuint256((char *)params[1].get_str().c_str()); hex = ChannelRefund(0,stoptxid,origtxid); @@ -5428,6 +5435,8 @@ UniValue gatewaysbind(const UniValue& params, bool fHelp) throw runtime_error("gatewaysbind tokenid oracletxid coin tokensupply M N pubkey(s)\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"); + const CKeyStore& keystore = *pwalletMain; + LOCK2(cs_main, pwalletMain->cs_wallet); tokenid = Parseuint256((char *)params[0].get_str().c_str()); oracletxid = Parseuint256((char *)params[1].get_str().c_str()); coin = params[2].get_str(); @@ -5459,6 +5468,8 @@ UniValue gatewaysdeposit(const UniValue& params, bool fHelp) throw runtime_error("gatewaysdeposit bindtxid height coin cointxid claimvout deposithex proof 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"); + const CKeyStore& keystore = *pwalletMain; + LOCK2(cs_main, pwalletMain->cs_wallet); bindtxid = Parseuint256((char *)params[0].get_str().c_str()); height = atoi((char *)params[1].get_str().c_str()); coin = params[2].get_str(); @@ -5486,6 +5497,8 @@ UniValue gatewaysclaim(const UniValue& params, bool fHelp) 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"); + const CKeyStore& keystore = *pwalletMain; + LOCK2(cs_main, pwalletMain->cs_wallet); bindtxid = Parseuint256((char *)params[0].get_str().c_str()); coin = params[1].get_str(); deposittxid = Parseuint256((char *)params[2].get_str().c_str()); @@ -5507,6 +5520,8 @@ UniValue gatewayswithdraw(const UniValue& params, bool fHelp) 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"); + const CKeyStore& keystore = *pwalletMain; + LOCK2(cs_main, pwalletMain->cs_wallet); bindtxid = Parseuint256((char *)params[0].get_str().c_str()); coin = params[1].get_str(); withdrawpub = ParseHex(params[2].get_str()); @@ -5527,6 +5542,8 @@ UniValue gatewaysmarkdone(const UniValue& params, bool fHelp) throw runtime_error("gatewaysmarkdone withdrawtxid coin cointxid\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"); + const CKeyStore& keystore = *pwalletMain; + LOCK2(cs_main, pwalletMain->cs_wallet); withdrawtxid = Parseuint256((char *)params[0].get_str().c_str()); coin = params[1].get_str(); cointxid = Parseuint256((char *)params[2].get_str().c_str()); @@ -5558,6 +5575,8 @@ UniValue gatewaysmultisig(const UniValue& params, bool fHelp) throw runtime_error("gatewaysmultisig bindtxid coin withtxid txidaddr\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"); + const CKeyStore& keystore = *pwalletMain; + LOCK2(cs_main, pwalletMain->cs_wallet); bindtxid = Parseuint256((char *)params[0].get_str().c_str()); coin = params[1].get_str(); withtxid = Parseuint256((char *)params[2].get_str().c_str()); @@ -5598,6 +5617,8 @@ UniValue oraclesregister(const UniValue& params, bool fHelp) throw runtime_error("oraclesregister oracletxid datafee\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"); + const CKeyStore& keystore = *pwalletMain; + LOCK2(cs_main, pwalletMain->cs_wallet); txid = Parseuint256((char *)params[0].get_str().c_str()); datafee = atol((char *)params[1].get_str().c_str()); hex = OracleRegister(0,txid,datafee); @@ -5616,6 +5637,8 @@ UniValue oraclessubscribe(const UniValue& params, bool fHelp) throw runtime_error("oraclessubscribe oracletxid publisher 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"); + const CKeyStore& keystore = *pwalletMain; + LOCK2(cs_main, pwalletMain->cs_wallet); txid = Parseuint256((char *)params[0].get_str().c_str()); pubkey = ParseHex(params[1].get_str().c_str()); amount = atof((char *)params[2].get_str().c_str()) * COIN; @@ -5648,6 +5671,8 @@ UniValue oraclesdata(const UniValue& params, bool fHelp) throw runtime_error("oraclesdata oracletxid hexstr\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"); + const CKeyStore& keystore = *pwalletMain; + LOCK2(cs_main, pwalletMain->cs_wallet); txid = Parseuint256((char *)params[0].get_str().c_str()); data = ParseHex(params[1].get_str().c_str()); hex = OracleData(0,txid,data); @@ -5784,6 +5809,156 @@ UniValue faucetget(const UniValue& params, bool fHelp) return(result); } +UniValue priceslist(const UniValue& params, bool fHelp) +{ + if ( fHelp || params.size() > 0 ) + throw runtime_error("priceslist\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"); + return(PricesList()); +} + +UniValue pricesinfo(const UniValue& params, bool fHelp) +{ + uint256 fundingtxid; + if ( fHelp || params.size() != 1 ) + throw runtime_error("pricesinfo fundingtxid\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"); + fundingtxid = Parseuint256((char *)params[0].get_str().c_str()); + return(PricesInfo(fundingtxid)); +} + +UniValue pricescreate(const UniValue& params, bool fHelp) +{ + UniValue result(UniValue::VOBJ); uint64_t margin,mode; int32_t i,n,margin,maxleverage; std::string hex; uint256 oracletxid,longtoken,shorttoken,bettoken; std::vector pubkeys; std::vectorpubkey; + if ( fHelp || params.size() < 8 ) + throw runtime_error("pricescreate bettoken oracletxid margin mode longtoken shorttoken maxleverage funding N [pubkeys]\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"); + const CKeyStore& keystore = *pwalletMain; + LOCK2(cs_main, pwalletMain->cs_wallet); + bettoken = Parseuint256((char *)params[0].get_str().c_str()); + oracletxid = Parseuint256((char *)params[1].get_str().c_str()); + margin = atof(params[2].get_str().c_str()) * 1000; + mode = atol(params[3].get_str().c_str()); + longtoken = Parseuint256((char *)params[4].get_str().c_str()); + shorttoken = Parseuint256((char *)params[5].get_str().c_str()); + maxleverage = atol(params[6].get_str().c_str()); + funding = atof(params[7].get_str().c_str()) * COIN; + n = atoi(params[8].get_str().c_str()); + if ( n > 0 ) + { + for (i=0; i 0 ) + { + result.push_back(Pair("result", "success")); + result.push_back(Pair("hex", hex)); + } + else + { + ERR_RESULT("couldnt create prices funding transaction"); + } + return(result); +} + +UniValue pricesaddfunding(const UniValue& params, bool fHelp) +{ + UniValue result(UniValue::VOBJ); std::string hex; uint256 fundingtxid,bettoken; int64_t amount; + if ( fHelp || params.size() != 3 ) + throw runtime_error("pricesaddfunding fundingtxid bettoken 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"); + const CKeyStore& keystore = *pwalletMain; + LOCK2(cs_main, pwalletMain->cs_wallet); + fundingtxid = Parseuint256((char *)params[0].get_str().c_str()); + bettoken = Parseuint256((char *)params[1].get_str().c_str()); + amount = atof(params[2].get_str().c_str()) * COIN; + hex = PricesAddFunding(0,bettoken,fundingtxid,amount); + if ( hex.size() > 0 ) + { + result.push_back(Pair("result", "success")); + result.push_back(Pair("hex", hex)); + } + else + { + ERR_RESULT("couldnt create pricesaddfunding transaction"); + } + return(result); +} + +UniValue pricesbet(const UniValue& params, bool fHelp) +{ + UniValue result(UniValue::VOBJ); std::string hex; uint256 fundingtxid,bettoken; int64_t amount; int32_t leverage; + if ( fHelp || params.size() != 4 ) + throw runtime_error("pricesbet fundingtxid bettoken amount leverage\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"); + const CKeyStore& keystore = *pwalletMain; + LOCK2(cs_main, pwalletMain->cs_wallet); + fundingtxid = Parseuint256((char *)params[0].get_str().c_str()); + bettoken = Parseuint256((char *)params[1].get_str().c_str()); + amount = atof(params[2].get_str().c_str()) * COIN; + leverage = atoi(params[3].get_str().c_str()); + hex = PricesBet(0,bettoken,fundingtxid,amount,leverage); + if ( hex.size() > 0 ) + { + result.push_back(Pair("result", "success")); + result.push_back(Pair("hex", hex)); + } + else + { + ERR_RESULT("couldnt create pricesbet transaction"); + } + return(result); +} + +UniValue pricesstatus(const UniValue& params, bool fHelp) +{ + uint256 fundingtxid,bettxid,bettoken; + if ( fHelp || params.size() != 3 ) + throw runtime_error("pricesstatus fundingtxid bettoken bettxid\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"); + fundingtxid = Parseuint256((char *)params[0].get_str().c_str()); + bettoken = Parseuint256((char *)params[1].get_str().c_str()); + bettxid = Parseuint256((char *)params[2].get_str().c_str()); + return(PricesStatus(0,bettoken,fundingtxid,bettxid)); +} + +UniValue pricesfinish(const UniValue& params, bool fHelp) +{ + UniValue result(UniValue::VOBJ); uint256 fundingtxid,bettxid,bettoken; std::string hex; + if ( fHelp || params.size() != 3 ) + throw runtime_error("pricesfinish fundingtxid bettoken bettxid\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"); + const CKeyStore& keystore = *pwalletMain; + LOCK2(cs_main, pwalletMain->cs_wallet); + fundingtxid = Parseuint256((char *)params[0].get_str().c_str()); + bettoken = Parseuint256((char *)params[1].get_str().c_str()); + bettxid = Parseuint256((char *)params[2].get_str().c_str()); + hex = PricesFinish(0,bettoken,fundingtxid,bettxid); + if ( hex.size() > 0 ) + { + result.push_back(Pair("result", "success")); + result.push_back(Pair("hex", hex)); + } + else + { + ERR_RESULT("couldnt create pricesfinish transaction"); + } + return(result); +} + UniValue dicefund(const UniValue& params, bool fHelp) { UniValue result(UniValue::VOBJ); int64_t funds,minbet,maxbet,maxodds,timeoutblocks; std::string hex; char *name; @@ -5955,7 +6130,6 @@ UniValue dicestatus(const UniValue& params, bool fHelp) UniValue dicelist(const UniValue& params, bool fHelp) { - uint256 tokenid; if ( fHelp || params.size() > 0 ) throw runtime_error("dicelist\n"); if ( ensure_CCrequirements() < 0 ) From bfd7858525db2e8b929d099b2406c940714afff2 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 19 Sep 2018 21:09:27 -1100 Subject: [PATCH 05/48] Syntax --- src/cc/prices.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index 49e87127a..0c530d0aa 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -71,7 +71,7 @@ int64_t PricesOraclePrice(int64_t &rektprice,uint64_t mode,uint256 oracletxid,st return(price); } -CScript EncodePricesFundingOpRet(uint8_t funcid,CPubKey planpk,uint256 oracletxid,uint256 longtoken,uint256 shorttoken,int32_t millimargin,uint64_t mode,int32_t maxleverage,std::vector pubkeys) +CScript EncodePricesFundingOpRet(uint8_t funcid,CPubKey planpk,uint256 oracletxid,uint256 longtoken,uint256 shorttoken,int32_t millimargin,uint64_t mode,int32_t maxleverage,std::vector pubkeys,uint256 bettoken) { CScript opret; fprintf(stderr,"implement EncodePricesFundingOpRet\n"); @@ -104,12 +104,12 @@ bool PricesValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx } } //fprintf(stderr,"check amounts\n"); - if ( PricesExactAmounts(cp,eval,tx,1,10000) == false ) + //if ( PricesExactAmounts(cp,eval,tx,1,10000) == false ) { fprintf(stderr,"Pricesget invalid amount\n"); return false; } - else + //else { txid = tx.GetHash(); memcpy(hash,&txid,sizeof(hash)); @@ -135,10 +135,10 @@ int64_t AddTokensInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,char txid = it->first.txhash; vout = (int32_t)it->first.index; // need to prevent dup - if ( GetTransaction(txid,vintx,hashBlock,false) != 0 && vout < tx.vout.size() ) + if ( GetTransaction(txid,vintx,hashBlock,false) != 0 && vout < vintx.vout.size() ) { // need to verify assetid - if ( (nValue= vintx.vout[vout].nValue)) > 10000 && myIsutxo_spentinmempool(txid,vout) == 0 ) + if ( (nValue= vintx.vout[vout].nValue) > 10000 && myIsutxo_spentinmempool(txid,vout) == 0 ) { if ( total != 0 && maxinputs != 0 ) mtx.vin.push_back(CTxIn(txid,vout,CScript())); @@ -208,7 +208,7 @@ std::string PricesCreateFunding(uint64_t txfee,uint256 bettoken,uint256 oracletx } if ( GetCCaddress1of2(houseaddr,cp,pricespk,mypk) == 0 ) { - fprintf(stderr,"PricesCreateFunding (%s) cant create globaladdr\n",uint256_str(str,tokenid)); + fprintf(stderr,"PricesCreateFunding cant create globaladdr\n"); return(""); } if ( CCtoken_balance(houseaddr,longtoken) != CCfullsupply(longtoken) ) From 5efdb4f325c5ae29da5fa7cc17e36142ae548b34 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 19 Sep 2018 21:10:58 -1100 Subject: [PATCH 06/48] N --- src/cc/prices.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index 0c530d0aa..eb47c33db 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -206,7 +206,7 @@ std::string PricesCreateFunding(uint64_t txfee,uint256 bettoken,uint256 oracletx return(""); } } - if ( GetCCaddress1of2(houseaddr,cp,pricespk,mypk) == 0 ) + if ( GetCCaddress1of2(cp,houseaddr,pricespk,mypk) == 0 ) { fprintf(stderr,"PricesCreateFunding cant create globaladdr\n"); return(""); @@ -266,8 +266,8 @@ UniValue PricesInfo(uint256 fundingtxid) for (i=0; i 0 && DecodePricesFundingOpRet(tx.vout[tx.vout.size()-1].scriptPubKey,planpk,oracletxid,longtoken,shorttoken,margin,mode,maxleverage,pubkeys,bettoken) == 'F' && bettoken == refbettoken ) { - GetCCaddress1of2(houseaddr,assetscp,pricespk,planpk); + GetCCaddress1of2(assetscp,houseaddr,pricespk,planpk); if ( AddNormalinputs(mtx,mypk,2*txfee,3) > 0 ) { if ( (inputs= AddBetAssetInputs(assetscp,mtx,myaddr,bettoken,amount,60)) >= amount ) @@ -370,8 +370,8 @@ std::string PricesBet(uint64_t txfee,uint256 refbettoken,uint256 fundingtxid,int fprintf(stderr,"illegal leverage\n"); return(""); } - GetCCaddress1of2(houseaddr,assetscp,pricespk,planpk); - GetCCaddress1of2(exposureaddr,assetscp,pricespk,pricespk); + GetCCaddress1of2(assetscp,houseaddr,pricespk,planpk); + GetCCaddress1of2(assetscp,exposureaddr,pricespk,pricespk); if ( dir < 0 ) tokenid = shorttoken; else tokenid = longtoken; From 816acd6719d67bb5a299e2fd9de22aacfe95dd7b Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 19 Sep 2018 21:14:25 -1100 Subject: [PATCH 07/48] Test --- src/cc/prices.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index eb47c33db..935986920 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -243,7 +243,7 @@ std::string PricesCreateFunding(uint64_t txfee,uint256 bettoken,uint256 oracletx UniValue PricesInfo(uint256 fundingtxid) { - UniValue result(UniValue::VOBJ),a(UniValue::VARR); CPubKey pricespk,planpk; uint256 hashBlock,oracletxid,longtoken,shorttoken,bettoken; CTransaction vintx; int64_t balance,supply,exposure; uint64_t funding,mode; int32_t i,margin,maxleverage; char numstr[65],houseaddr[64],exposureaddr[64]; struct CCcontract_info *cp,C,*assetscp,C2; + UniValue result(UniValue::VOBJ),a(UniValue::VARR); CPubKey pricespk,planpk; uint256 hashBlock,oracletxid,longtoken,shorttoken,bettoken; CTransaction vintx; int64_t balance,supply,exposure; uint64_t funding,mode; int32_t i,margin,maxleverage; char numstr[65],houseaddr[64],exposureaddr[64],str[65]; std::vectorpubkeys; struct CCcontract_info *cp,C,*assetscp,C2; cp = CCinit(&C,EVAL_PRICES); assetscp = CCinit(&C2,EVAL_ASSETS); pricespk = GetUnspendable(cp,0); @@ -292,7 +292,7 @@ UniValue PricesInfo(uint256 fundingtxid) std::string PricesAddfunding(uint64_t txfee,uint256 refbettoken,uint256 fundingtxid,int64_t amount) { - CMutableTransaction mtx; struct CCcontract_info *cp,C,*assetscp,C2; CPubKey pricespk,planpk,mypk; uint256 hashBlock,oracletxid,longtoken,shorttoken,bettoken; CTransaction tx; int64_t balance,supply,exposure,inputs,CCchange = 0; uint64_t funding,mode; int32_t margin,maxleverage; char houseaddr[64],myaddr[64]; + CMutableTransaction mtx; struct CCcontract_info *cp,C,*assetscp,C2; CPubKey pricespk,planpk,mypk; uint256 hashBlock,oracletxid,longtoken,shorttoken,bettoken; CTransaction tx; int64_t balance,supply,exposure,inputs,CCchange = 0; uint64_t funding,mode; int32_t margin,maxleverage; char houseaddr[64],myaddr[64]; std::vectorpubkeys; if ( amount < 10000 ) { CCerror = "amount must be positive"; @@ -305,7 +305,7 @@ std::string PricesAddfunding(uint64_t txfee,uint256 refbettoken,uint256 fundingt txfee = 10000; mypk = pubkey2pk(Mypubkey()); pricespk = GetUnspendable(cp,0); - GetCCaddress(myaddr,assetscp,mypk); + GetCCaddress(assetscp,myaddr,mypk); if ( GetTransaction(fundingtxid,tx,hashBlock,false) == 0 ) { fprintf(stderr,"cant find fundingtxid\n"); @@ -344,7 +344,7 @@ std::string PricesAddfunding(uint64_t txfee,uint256 refbettoken,uint256 fundingt std::string PricesBet(uint64_t txfee,uint256 refbettoken,uint256 fundingtxid,int64_t amount,int32_t leverage) { - CMutableTransaction mtx; struct CCcontract_info *cp,C,*asssetcp,C2; CPubKey pricespk,planpk,mypk; uint256 hashBlock,oracletxid,longtoken,shorttoken,tokenid,bettoken; CTransaction tx; int64_t balance,supply,exposure,inputs,inputs2,longexposure,netexposure,shortexposure,CCchange = 0,CCchange2 = 0; uint64_t funding,mode; int32_t dir,margin,maxleverage; char houseaddr[64],myaddr[64],exposureaddr[64]; + CMutableTransaction mtx; struct CCcontract_info *cp,C,*asssetcp,C2; CPubKey pricespk,planpk,mypk; uint256 hashBlock,oracletxid,longtoken,shorttoken,tokenid,bettoken; CTransaction tx; int64_t balance,supply,exposure,inputs,inputs2,longexposure,netexposure,shortexposure,CCchange = 0,CCchange2 = 0; uint64_t funding,mode; int32_t dir,margin,maxleverage; char houseaddr[64],myaddr[64],exposureaddr[64]; std::vectorpubkeys; if ( amount < 0 ) { amount = -amount; @@ -356,7 +356,7 @@ std::string PricesBet(uint64_t txfee,uint256 refbettoken,uint256 fundingtxid,int txfee = 10000; mypk = pubkey2pk(Mypubkey()); pricespk = GetUnspendable(cp,0); - GetCCaddress(myaddr,assetscp,mypk); + GetCCaddress(assetscp,myaddr,mypk); if ( GetTransaction(fundingtxid,tx,hashBlock,false) == 0 ) { fprintf(stderr,"cant find fundingtxid\n"); From f6b969d4b419f8563bd13ad685da517528a2518e Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 19 Sep 2018 21:17:06 -1100 Subject: [PATCH 08/48] Test --- src/cc/prices.cpp | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index 935986920..174c824f3 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -309,15 +309,14 @@ std::string PricesAddfunding(uint64_t txfee,uint256 refbettoken,uint256 fundingt if ( GetTransaction(fundingtxid,tx,hashBlock,false) == 0 ) { fprintf(stderr,"cant find fundingtxid\n"); - ERR_RESULT("cant find fundingtxid"); - return(result); + return(""); } if ( tx.vout.size() > 0 && DecodePricesFundingOpRet(tx.vout[tx.vout.size()-1].scriptPubKey,planpk,oracletxid,longtoken,shorttoken,margin,mode,maxleverage,pubkeys,bettoken) == 'F' && bettoken == refbettoken ) { GetCCaddress1of2(assetscp,houseaddr,pricespk,planpk); if ( AddNormalinputs(mtx,mypk,2*txfee,3) > 0 ) { - if ( (inputs= AddBetAssetInputs(assetscp,mtx,myaddr,bettoken,amount,60)) >= amount ) + if ( (inputs= AddTokensInputs(assetscp,mtx,myaddr,bettoken,amount,60)) >= amount ) { mtx.vout.push_back(MakeCC1of2vout(assetscp->evalcode,amount,pricespk,planpk)); mtx.vout.push_back(CTxOut(txfee,CScript() << ParseHex(HexStr(planpk)) << OP_CHECKSIG)); @@ -344,7 +343,7 @@ std::string PricesAddfunding(uint64_t txfee,uint256 refbettoken,uint256 fundingt std::string PricesBet(uint64_t txfee,uint256 refbettoken,uint256 fundingtxid,int64_t amount,int32_t leverage) { - CMutableTransaction mtx; struct CCcontract_info *cp,C,*asssetcp,C2; CPubKey pricespk,planpk,mypk; uint256 hashBlock,oracletxid,longtoken,shorttoken,tokenid,bettoken; CTransaction tx; int64_t balance,supply,exposure,inputs,inputs2,longexposure,netexposure,shortexposure,CCchange = 0,CCchange2 = 0; uint64_t funding,mode; int32_t dir,margin,maxleverage; char houseaddr[64],myaddr[64],exposureaddr[64]; std::vectorpubkeys; + CMutableTransaction mtx; struct CCcontract_info *cp,C,*assetscp,C2; CPubKey pricespk,planpk,mypk; uint256 hashBlock,oracletxid,longtoken,shorttoken,tokenid,bettoken; CTransaction tx; int64_t balance,supply,exposure,inputs,inputs2,longexposure,netexposure,shortexposure,CCchange = 0,CCchange2 = 0; uint64_t funding,mode; int32_t dir,margin,maxleverage; char houseaddr[64],myaddr[64],exposureaddr[64]; std::vectorpubkeys; if ( amount < 0 ) { amount = -amount; @@ -360,7 +359,6 @@ std::string PricesBet(uint64_t txfee,uint256 refbettoken,uint256 fundingtxid,int if ( GetTransaction(fundingtxid,tx,hashBlock,false) == 0 ) { fprintf(stderr,"cant find fundingtxid\n"); - ERR_RESULT("cant find fundingtxid"); return(""); } if ( tx.vout.size() > 0 && DecodePricesFundingOpRet(tx.vout[tx.vout.size()-1].scriptPubKey,planpk,oracletxid,longtoken,shorttoken,margin,mode,maxleverage,pubkeys,bettoken) == 'F' && bettoken == refbettoken ) @@ -384,7 +382,7 @@ std::string PricesBet(uint64_t txfee,uint256 refbettoken,uint256 fundingtxid,int balance = CCtoken_balance(myaddr,bettoken) / COIN; if ( balance < netexposure*9/10 ) // 10% extra room for dynamically closed bets in wrong direction { - fprintf(stderr,"balance %lld < 90% netexposure %lld, refuse bet\n",(long long)balance,(long long)netexposure); + fprintf(stderr,"balance %lld < 90%% netexposure %lld, refuse bet\n",(long long)balance,(long long)netexposure); return(""); } if ( AddNormalinputs(mtx,mypk,txfee,3) > 0 ) @@ -402,7 +400,7 @@ std::string PricesBet(uint64_t txfee,uint256 refbettoken,uint256 fundingtxid,int mtx.vout.push_back(MakeCC1of2vout(assetscp->evalcode,CCchange,pricespk,planpk)); mtx.vout.push_back(MakeCCvout(assetscp->evalcode,CCchange2,mypk)); // add addr2 and addr3 - return(FinalizeCCTx(mask,assetscp,mtx,mypk,txfee,EncodeAssetOpRetExtra('T',tokenid,bettoken,bettxid,dir*leverage))); + return(FinalizeCCTx(0,assetscp,mtx,mypk,txfee,EncodeAssetOpRetExtra('T',tokenid,bettoken,zeroid,dir*leverage))); } else { From feb11ae0389b15cc5650ebb0c65b1e9f0b21783a Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 19 Sep 2018 21:18:15 -1100 Subject: [PATCH 09/48] std::vectorpubkeys; --- src/cc/prices.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index 174c824f3..d1ec9167a 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -322,7 +322,7 @@ std::string PricesAddfunding(uint64_t txfee,uint256 refbettoken,uint256 fundingt mtx.vout.push_back(CTxOut(txfee,CScript() << ParseHex(HexStr(planpk)) << OP_CHECKSIG)); if ( inputs > amount+txfee ) CCchange = (inputs - amount); - mtx.vout.push_back(MakeCCvout(assetscp->evalcode,CCchange,mypk)); + mtx.vout.push_back(MakeCC1vout(assetscp->evalcode,CCchange,mypk)); // add addr2 return(FinalizeCCTx(0,cp,mtx,mypk,txfee,EncodeAssetOpRet('t',bettoken,zeroid,0,Mypubkey()))); } @@ -398,7 +398,7 @@ std::string PricesBet(uint64_t txfee,uint256 refbettoken,uint256 fundingtxid,int if ( inputs2 > amount+txfee ) CCchange2 = (inputs2 - amount); mtx.vout.push_back(MakeCC1of2vout(assetscp->evalcode,CCchange,pricespk,planpk)); - mtx.vout.push_back(MakeCCvout(assetscp->evalcode,CCchange2,mypk)); + mtx.vout.push_back(MakeCC1vout(assetscp->evalcode,CCchange2,mypk)); // add addr2 and addr3 return(FinalizeCCTx(0,assetscp,mtx,mypk,txfee,EncodeAssetOpRetExtra('T',tokenid,bettoken,zeroid,dir*leverage))); } From 06c4e87ff978dfd04b1c1e88e465a5fce9292d31 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 19 Sep 2018 21:29:11 -1100 Subject: [PATCH 10/48] CCprices.h --- src/wallet/rpcwallet.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 397c4f3c3..68c13b2b3 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4858,6 +4858,7 @@ int32_t ensure_CCrequirements() #include "../cc/CCchannels.h" #include "../cc/CCOracles.h" #include "../cc/CCGateways.h" +#include "../cc/CCPrices.h" UniValue CCaddress(struct CCcontract_info *cp,char *name,std::vector &pubkey) { From a51c08d1a193e609280e440e67cc6a27107c8dd6 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 19 Sep 2018 21:32:22 -1100 Subject: [PATCH 11/48] Test --- src/cc/CCPrices.h | 2 +- src/wallet/rpcwallet.cpp | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/cc/CCPrices.h b/src/cc/CCPrices.h index d35823838..f375ee10a 100644 --- a/src/cc/CCPrices.h +++ b/src/cc/CCPrices.h @@ -24,7 +24,7 @@ bool PricesValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx // CCcustom UniValue PricesList(); UniValue PricesInfo(uint256 fundingtxid); -UniValue PricesStatus(uint64_t txfee,uint256 fundingtxid,uint256 bettxid); +UniValue PricesStatus(uint64_t txfee,uint256 refbettoken,uint256 fundingtxid,uint256 bettxid); std::string PricesCreateFunding(uint64_t txfee,uint256 bettoken,uint256 oracletxid,uint64_t margin,uint64_t mode,uint256 longtoken,uint256 shorttoken,int32_t maxleverage,int64_t funding,std::vector pubkeys); std::string PricesAddFunding(uint64_t txfee,uint256 bettoken,uint256 fundingtxid,int64_t amount); std::string PricesBet(uint64_t txfee,uint256 bettoken,uint256 fundingtxid,int64_t amount,int32_t leverage); diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 68c13b2b3..c1dd1c3fb 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4928,7 +4928,7 @@ UniValue oraclesaddress(const UniValue& params, bool fHelp) UniValue pricesaddress(const UniValue& params, bool fHelp) { - UniValue result(UniValue::VOBJ); struct CCcontract_info *cp,C,*assetscp,C2; std::vector pubkey; CPubKey mypk,pricespk; char myaddr[64],houseaddr[64],exposureaddr[64]; + UniValue result(UniValue::VOBJ); struct CCcontract_info *cp,C,*assetscp,C2; std::vector pubkey; CPubKey mypk,planpk,pricespk; char myaddr[64],houseaddr[64],exposureaddr[64]; cp = CCinit(&C,EVAL_PRICES); assetscp = CCinit(&C2,EVAL_PRICES); if ( fHelp || params.size() > 1 ) @@ -4940,9 +4940,9 @@ UniValue pricesaddress(const UniValue& params, bool fHelp) result = CCaddress(cp,(char *)"Prices",pubkey); mypk = pubkey2pk(Mypubkey()); pricespk = GetUnspendable(cp,0); - GetCCaddress(myaddr,assetscp,mypk); - GetCCaddress1of2(houseaddr,assetscp,pricespk,planpk); - GetCCaddress1of2(exposureaddr,assetscp,pricespk,pricespk); + GetCCaddress(assetscp,myaddr,mypk); + GetCCaddress1of2(assetscp,houseaddr,pricespk,planpk); + GetCCaddress1of2(assetscp,exposureaddr,pricespk,pricespk); result.push_back(Pair("myaddr",myaddr)); // for holding my asssets result.push_back(Pair("houseaddr",houseaddr)); // globally accessible house assets result.push_back(Pair("exposureaddr",exposureaddr)); // tracking of exposure @@ -5832,7 +5832,7 @@ UniValue pricesinfo(const UniValue& params, bool fHelp) UniValue pricescreate(const UniValue& params, bool fHelp) { - UniValue result(UniValue::VOBJ); uint64_t margin,mode; int32_t i,n,margin,maxleverage; std::string hex; uint256 oracletxid,longtoken,shorttoken,bettoken; std::vector pubkeys; std::vectorpubkey; + UniValue result(UniValue::VOBJ); uint64_t mode; int64_t funding; int32_t i,n,margin,maxleverage; std::string hex; uint256 oracletxid,longtoken,shorttoken,bettoken; std::vector pubkeys; std::vectorpubkey; if ( fHelp || params.size() < 8 ) throw runtime_error("pricescreate bettoken oracletxid margin mode longtoken shorttoken maxleverage funding N [pubkeys]\n"); if ( ensure_CCrequirements() < 0 ) From 7d6f7d7ea5d7dee6e25e4abe65ac89607cf71230 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 19 Sep 2018 21:34:25 -1100 Subject: [PATCH 12/48] PricesAddFunding --- src/cc/prices.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index d1ec9167a..e8755b53e 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -290,7 +290,7 @@ UniValue PricesInfo(uint256 fundingtxid) return(result); } -std::string PricesAddfunding(uint64_t txfee,uint256 refbettoken,uint256 fundingtxid,int64_t amount) +std::string PricesAddFunding(uint64_t txfee,uint256 refbettoken,uint256 fundingtxid,int64_t amount) { CMutableTransaction mtx; struct CCcontract_info *cp,C,*assetscp,C2; CPubKey pricespk,planpk,mypk; uint256 hashBlock,oracletxid,longtoken,shorttoken,bettoken; CTransaction tx; int64_t balance,supply,exposure,inputs,CCchange = 0; uint64_t funding,mode; int32_t margin,maxleverage; char houseaddr[64],myaddr[64]; std::vectorpubkeys; if ( amount < 10000 ) From 541e5e92491cef6df3c6b5b2e87673ae31a96aa2 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 19 Sep 2018 21:51:56 -1100 Subject: [PATCH 13/48] Token convert --- src/cc/CCassets.h | 2 ++ src/cc/CCassetstx.cpp | 27 +++++++++++++++++++++++++++ src/cc/gateways.cpp | 2 +- src/rpcserver.cpp | 1 + src/rpcserver.h | 1 + src/wallet/rpcwallet.cpp | 36 ++++++++++++++++++++++++++++++++++++ 6 files changed, 68 insertions(+), 1 deletion(-) diff --git a/src/cc/CCassets.h b/src/cc/CCassets.h index afb3579cf..0fb4ae6f7 100644 --- a/src/cc/CCassets.h +++ b/src/cc/CCassets.h @@ -54,6 +54,8 @@ UniValue AssetInfo(uint256 tokenid); UniValue AssetList(); std::string CreateAsset(int64_t txfee,int64_t assetsupply,std::string name,std::string description); std::string AssetTransfer(int64_t txfee,uint256 assetid,std::vector destpubkey,int64_t total); +std::string AssetConvert(int64_t txfee,uint256 assetid,std::vector destpubkey,int64_t total,int32_t evalcode); + std::string CreateBuyOffer(int64_t txfee,int64_t bidamount,uint256 assetid,int64_t pricetotal); std::string CancelBuyOffer(int64_t txfee,uint256 assetid,uint256 bidtxid); std::string FillBuyOffer(int64_t txfee,uint256 assetid,uint256 bidtxid,int64_t fillamount); diff --git a/src/cc/CCassetstx.cpp b/src/cc/CCassetstx.cpp index 63d1a1089..2ce13a1ff 100644 --- a/src/cc/CCassetstx.cpp +++ b/src/cc/CCassetstx.cpp @@ -243,6 +243,33 @@ std::string AssetTransfer(int64_t txfee,uint256 assetid,std::vector des return(""); } +std::string AssetConvert(int64_t txfee,uint256 assetid,std::vector destpubkey,int64_t total,int32_t evalcode) +{ + CMutableTransaction mtx; CPubKey mypk; int64_t CCchange=0,inputs=0; struct CCcontract_info *cp,C; + if ( total < 0 ) + { + fprintf(stderr,"negative total %lld\n",(long long)total); + return(""); + } + cp = CCinit(&C,EVAL_ASSETS); + if ( txfee == 0 ) + txfee = 10000; + mypk = pubkey2pk(Mypubkey()); + if ( AddNormalinputs(mtx,mypk,txfee,1) > 0 ) + { + if ( (inputs= AddAssetInputs(cp,mtx,mypk,assetid,total,60)) > 0 ) + { + if ( inputs > total ) + CCchange = (inputs - total); + mtx.vout.push_back(MakeCC1vout(evalcode,total,pubkey2pk(destpubkey))); + if ( CCchange != 0 ) + mtx.vout.push_back(MakeCC1vout(EVAL_ASSETS,CCchange,mypk)); + return(FinalizeCCTx(0,cp,mtx,mypk,txfee,EncodeAssetOpRet('t',assetid,zeroid,0,Mypubkey()))); + } else fprintf(stderr,"not enough CC asset inputs for %.8f\n",(double)total/COIN); + } + return(""); +} + std::string CreateBuyOffer(int64_t txfee,int64_t bidamount,uint256 assetid,int64_t pricetotal) { CMutableTransaction mtx; CPubKey mypk; struct CCcontract_info *cp,C; uint256 hashBlock; CTransaction vintx; std::vector origpubkey; std::string name,description; diff --git a/src/cc/gateways.cpp b/src/cc/gateways.cpp index 9146a864b..3acc69027 100644 --- a/src/cc/gateways.cpp +++ b/src/cc/gateways.cpp @@ -474,7 +474,7 @@ std::string GatewaysBind(uint64_t txfee,std::string coin,uint256 tokenid,int64_t txfee = 10000; mypk = pubkey2pk(Mypubkey()); gatewayspk = GetUnspendable(cp,0); - if ( _GetCCaddress(destaddr,EVAL_ASSETS,gatewayspk) == 0 ) + if ( _GetCCaddress(destaddr,EVAL_GATEWAYS,gatewayspk) == 0 ) { fprintf(stderr,"Gateway bind.%s (%s) cant create globaladdr\n",coin.c_str(),uint256_str(str,tokenid)); return(""); diff --git a/src/rpcserver.cpp b/src/rpcserver.cpp index 77e53f7a1..8934ae717 100644 --- a/src/rpcserver.cpp +++ b/src/rpcserver.cpp @@ -454,6 +454,7 @@ static const CRPCCommand vRPCCommands[] = { "tokens", "tokencancelask", &tokencancelask, true }, { "tokens", "tokenfillask", &tokenfillask, true }, //{ "tokens", "tokenfillswap", &tokenfillswap, true }, + { "tokens", "tokenconvert", &tokenconvert, true }, /* Address index */ { "addressindex", "getaddressmempool", &getaddressmempool, true }, diff --git a/src/rpcserver.h b/src/rpcserver.h index e0c87756f..f4c502d63 100644 --- a/src/rpcserver.h +++ b/src/rpcserver.h @@ -221,6 +221,7 @@ extern UniValue tokenfillbid(const UniValue& params, bool fHelp); extern UniValue tokenask(const UniValue& params, bool fHelp); extern UniValue tokencancelask(const UniValue& params, bool fHelp); extern UniValue tokenfillask(const UniValue& params, bool fHelp); +extern UniValue tokenconvert(const UniValue& params, bool fHelp); extern UniValue mofnaddress(const UniValue& params, bool fHelp); extern UniValue channelsaddress(const UniValue& params, bool fHelp); extern UniValue oraclesaddress(const UniValue& params, bool fHelp); diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index c1dd1c3fb..e8fff8904 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -6279,6 +6279,42 @@ UniValue tokentransfer(const UniValue& params, bool fHelp) return(result); } +UniValue tokenconvert(const UniValue& params, bool fHelp) +{ + UniValue result(UniValue::VOBJ); std::string hex; int32_t evalcode; int64_t amount; uint256 tokenid; + if ( fHelp || params.size() != 3 ) + throw runtime_error("tokenconvert evalcode tokenid pubkey 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"); + const CKeyStore& keystore = *pwalletMain; + LOCK2(cs_main, pwalletMain->cs_wallet); + evalcode = atoi(params[0].get_str().c_str()); + tokenid = Parseuint256((char *)params[1].get_str().c_str()); + std::vector pubkey(ParseHex(params[2].get_str().c_str())); + amount = atol(params[3].get_str().c_str()); + if ( tokenid == zeroid ) + { + ERR_RESULT("invalid tokenid"); + return(result); + } + if ( amount <= 0 ) + { + ERR_RESULT("amount must be positive"); + return(result); + } + hex = AssetConvert(0,tokenid,pubkey,amount,evalcode); + if (amount > 0) { + if ( hex.size() > 0 ) + { + result.push_back(Pair("result", "success")); + result.push_back(Pair("hex", hex)); + } else ERR_RESULT("couldnt convert tokens"); + } else { + ERR_RESULT("amount must be positive"); + } + return(result); +} + UniValue tokenbid(const UniValue& params, bool fHelp) { UniValue result(UniValue::VOBJ); int64_t bidamount,numtokens; std::string hex; double price; uint256 tokenid; From 009f09069b4433b53a8e559be2fed6f3435793cb Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 19 Sep 2018 22:08:09 -1100 Subject: [PATCH 14/48] Remove dualmode for gateways --- src/cc/gateways.cpp | 39 ++++++++++++++------------------------- 1 file changed, 14 insertions(+), 25 deletions(-) diff --git a/src/cc/gateways.cpp b/src/cc/gateways.cpp index 3acc69027..8e9a04c62 100644 --- a/src/cc/gateways.cpp +++ b/src/cc/gateways.cpp @@ -134,6 +134,7 @@ Implementation Issues: When thinking about validation, it is clear that we cant use EVAL_ASSETS for the locked coins as there wont be any enforcement of the gateways locking. This means we need a way to transfer assets into gateways outputs and back. It seems a tokenconvert rpc will be needed and hopefully that will be enough to make it all work properly. + Care must be taken so that tokens are not lost and can be converted back */ @@ -382,7 +383,7 @@ UniValue GatewaysInfo(uint256 bindtxid) result.push_back(Pair("name","Gateways")); cp = CCinit(&C,EVAL_GATEWAYS); Gatewayspk = GetUnspendable(cp,0); - _GetCCaddress(gatewaysassets,EVAL_ASSETS,Gatewayspk); + _GetCCaddress(gatewaysassets,EVAL_GATEWAYS,Gatewayspk); if ( GetTransaction(bindtxid,tx,hashBlock,false) != 0 ) { depositaddr[0] = 0; @@ -681,18 +682,12 @@ 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; CTransaction tx; CPubKey mypk,gatewayspk; struct CCcontract_info *cp,C,*assetscp,C2; uint8_t M,N,taddr,prefix,prefix2,mypriv[32]; std::string coin; std::vector msigpubkeys; int64_t totalsupply,depositamount,inputs,CCchange=0; int32_t numvouts; uint256 hashBlock,assetid,oracletxid; char str[65],depositaddr[64],coinaddr[64]; + CMutableTransaction mtx; CTransaction tx; CPubKey mypk,gatewayspk; struct CCcontract_info *cp,C; uint8_t M,N,taddr,prefix,prefix2; std::string coin; std::vector msigpubkeys; int64_t totalsupply,depositamount,inputs,CCchange=0; int32_t numvouts; uint256 hashBlock,assetid,oracletxid; char str[65],depositaddr[64],coinaddr[64]; cp = CCinit(&C,EVAL_GATEWAYS); - assetscp = CCinit(&C2,EVAL_ASSETS); if ( txfee == 0 ) 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)); @@ -716,15 +711,15 @@ std::string GatewaysClaim(uint64_t txfee,uint256 bindtxid,std::string refcoin,ui //fprintf(stderr,"depositaddr.(%s) vs %s\n",depositaddr,cp->unspendableaddr2); if ( AddNormalinputs(mtx,mypk,txfee,1) > 0 ) { - if ( (inputs= AddAssetInputs(assetscp,mtx,gatewayspk,assetid,amount,60)) > 0 ) + if ( (inputs= AddGatewaysInputs(cp,mtx,gatewayspk,assetid,amount,60)) > 0 ) { if ( inputs > amount ) CCchange = (inputs - amount); mtx.vin.push_back(CTxIn(deposittxid,0,CScript())); // triggers EVAL_GATEWAYS validation - mtx.vout.push_back(MakeCC1vout(EVAL_ASSETS,amount,mypk)); + mtx.vout.push_back(MakeCC1vout(EVAL_ASSETS,amount,mypk)); // transfer back to normal token if ( CCchange != 0 ) - mtx.vout.push_back(MakeCC1vout(EVAL_ASSETS,CCchange,gatewayspk)); - return(FinalizeCCTx(0,assetscp,mtx,mypk,txfee,EncodeAssetOpRet('t',assetid,zeroid,0,Mypubkey()))); + mtx.vout.push_back(MakeCC1vout(EVAL_GATEWAYS,CCchange,gatewayspk)); + return(FinalizeCCTx(0,cp,mtx,mypk,txfee,EncodeAssetOpRet('t',assetid,zeroid,0,Mypubkey()))); } } fprintf(stderr,"cant find enough inputs or mismatched total\n"); @@ -733,18 +728,12 @@ 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,mypriv[32]; std::string coin; std::vector msigpubkeys; char depositaddr[64],str[65],coinaddr[64]; + CMutableTransaction mtx; CTransaction tx; CPubKey mypk,gatewayspk; struct CCcontract_info *cp,C; 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],coinaddr[64]; cp = CCinit(&C,EVAL_GATEWAYS); - assetscp = CCinit(&C2,EVAL_ASSETS); if ( txfee == 0 ) 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)); @@ -757,16 +746,16 @@ std::string GatewaysWithdraw(uint64_t txfee,uint256 bindtxid,std::string refcoin } if ( AddNormalinputs(mtx,mypk,3*txfee,3) > 0 ) { - if ( (inputs= AddAssetInputs(assetscp,mtx,mypk,assetid,amount,60)) > 0 ) + if ( (inputs= AddGatewaysInputs(cp,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(MakeCC1vout(EVAL_GATEWAYS,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()))); + mtx.vout.push_back(MakeCC1vout(EVAL_GATEWAYS,CCchange,mypk)); + return(FinalizeCCTx(0,cp,mtx,mypk,txfee,EncodeAssetOpRet('t',assetid,zeroid,0,Mypubkey()))); } } fprintf(stderr,"cant find enough inputs or mismatched total\n"); @@ -793,7 +782,7 @@ UniValue GatewaysPendingWithdraws(uint256 bindtxid,std::string refcoin) cp = CCinit(&C,EVAL_GATEWAYS); mypk = pubkey2pk(Mypubkey()); gatewayspk = GetUnspendable(cp,0); - _GetCCaddress(coinaddr,EVAL_ASSETS,gatewayspk); + _GetCCaddress(coinaddr,EVAL_GATEWAYS,gatewayspk); if ( GetTransaction(bindtxid,tx,hashBlock,false) == 0 || (numvouts= tx.vout.size()) <= 0 ) { fprintf(stderr,"cant find bindtxid %s\n",uint256_str(str,bindtxid)); @@ -856,7 +845,7 @@ std::string GatewaysMultisig(uint64_t txfee,std::string refcoin,uint256 bindtxid complete = partialtx = 0; mypk = pubkey2pk(Mypubkey()); Gatewayspk = GetUnspendable(cp,0); - _GetCCaddress(gatewaysassets,EVAL_ASSETS,Gatewayspk); + _GetCCaddress(gatewaysassets,EVAL_GATEWAYS,Gatewayspk); if ( GetTransaction(bindtxid,tx,hashBlock,false) != 0 ) { depositaddr[0] = 0; From 9eece428bb7b48b53e3139301cc1e90a5783cb17 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 19 Sep 2018 22:15:50 -1100 Subject: [PATCH 15/48] Test --- src/cc/gateways.cpp | 62 +++++++++++++++++++++++++-------------------- 1 file changed, 35 insertions(+), 27 deletions(-) diff --git a/src/cc/gateways.cpp b/src/cc/gateways.cpp index 8e9a04c62..effc02ea8 100644 --- a/src/cc/gateways.cpp +++ b/src/cc/gateways.cpp @@ -288,33 +288,41 @@ bool GatewaysValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction & // helper functions for rpc calls in rpcwallet.cpp -/*int64_t AddGatewaysInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey pk,int64_t total,int32_t maxinputs) - { - char coinaddr[64]; int64_t nValue,price,totalinputs = 0; uint256 txid,hashBlock; std::vector origpubkey; CTransaction vintx; int32_t vout,n = 0; - std::vector > unspentOutputs; - GetCCaddress(cp,coinaddr,pk); - SetCCunspents(unspentOutputs,coinaddr); - for (std::vector >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++) - { - txid = it->first.txhash; - vout = (int32_t)it->first.index; - // no need to prevent dup - if ( GetTransaction(txid,vintx,hashBlock,false) != 0 ) - { - if ( (nValue= IsGatewaysvout(cp,vintx,vout)) > 10000 && myIsutxo_spentinmempool(txid,vout) == 0 ) - { - if ( total != 0 && maxinputs != 0 ) - mtx.vin.push_back(CTxIn(txid,vout,CScript())); - nValue = it->second.satoshis; - totalinputs += nValue; - n++; - if ( (total > 0 && totalinputs >= total) || (maxinputs > 0 && n >= maxinputs) ) - break; - } - } - } - return(totalinputs); - }*/ +int64_t AddGatewaysInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey pk,uint256 assetid,int64_t total,int32_t maxinputs) +{ + char coinaddr[64],destaddr[64]; int64_t nValue,price,totalinputs = 0; uint256 txid,hashBlock; std::vector origpubkey; CTransaction vintx; int32_t j,vout,n = 0; + std::vector > unspentOutputs; + GetCCaddress(cp,coinaddr,pk); + SetCCunspents(unspentOutputs,coinaddr); + for (std::vector >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++) + { + txid = it->first.txhash; + vout = (int32_t)it->first.index; + for (j=0; junspendableCCaddr) != 0 && strcmp(destaddr,cp->unspendableaddr2) != 0 ) + continue; + // check for gatewaysassset + if ( (nValue= IsAssetvout(price,origpubkey,vintx,vout,assetid)) > 0 && myIsutxo_spentinmempool(txid,vout) == 0 ) + { + if ( total != 0 && maxinputs != 0 ) + mtx.vin.push_back(CTxIn(txid,vout,CScript())); + nValue = it->second.satoshis; + totalinputs += nValue; + n++; + if ( (total > 0 && totalinputs >= total) || (maxinputs > 0 && n >= maxinputs) ) + break; + } + } + } + return(totalinputs); +} int32_t GatewaysBindExists(struct CCcontract_info *cp,CPubKey gatewayspk,uint256 reftokenid) // dont forget to check mempool! { From 1605948a06c64a9aac9e5da3553c9cdb6e814c58 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 19 Sep 2018 22:18:51 -1100 Subject: [PATCH 16/48] Test --- src/cc/gateways.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/gateways.cpp b/src/cc/gateways.cpp index effc02ea8..1d57e8bc4 100644 --- a/src/cc/gateways.cpp +++ b/src/cc/gateways.cpp @@ -308,8 +308,8 @@ int64_t AddGatewaysInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CP Getscriptaddress(destaddr,vintx.vout[vout].scriptPubKey); if ( strcmp(destaddr,coinaddr) != 0 && strcmp(destaddr,cp->unspendableCCaddr) != 0 && strcmp(destaddr,cp->unspendableaddr2) != 0 ) continue; - // check for gatewaysassset - if ( (nValue= IsAssetvout(price,origpubkey,vintx,vout,assetid)) > 0 && myIsutxo_spentinmempool(txid,vout) == 0 ) + // check for gatewaysassset assetid and 't' + if ( (nValue= vintx.vout[vout].nValue) > 0 && myIsutxo_spentinmempool(txid,vout) == 0 ) { if ( total != 0 && maxinputs != 0 ) mtx.vin.push_back(CTxIn(txid,vout,CScript())); From dceeaa3dc59dfe04d87896f85cf4c0ba276f46b5 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 19 Sep 2018 22:35:08 -1100 Subject: [PATCH 17/48] Test --- src/cc/gateways.cpp | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/src/cc/gateways.cpp b/src/cc/gateways.cpp index 1d57e8bc4..69594583a 100644 --- a/src/cc/gateways.cpp +++ b/src/cc/gateways.cpp @@ -288,9 +288,9 @@ bool GatewaysValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction & // helper functions for rpc calls in rpcwallet.cpp -int64_t AddGatewaysInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey pk,uint256 assetid,int64_t total,int32_t maxinputs) +int64_t AddGatewaysInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey pk,uint256 refassetid,int64_t total,int32_t maxinputs) { - char coinaddr[64],destaddr[64]; int64_t nValue,price,totalinputs = 0; uint256 txid,hashBlock; std::vector origpubkey; CTransaction vintx; int32_t j,vout,n = 0; + char coinaddr[64],destaddr[64]; int64_t nValue,price,totalinputs = 0; uint256 txid,hashBlock; std::vector origpubkey; std::vector vopret; CTransaction vintx; int32_t j,vout,n = 0; uint8_t evalcode,funcid; std::vector > unspentOutputs; GetCCaddress(cp,coinaddr,pk); SetCCunspents(unspentOutputs,coinaddr); @@ -308,16 +308,20 @@ int64_t AddGatewaysInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CP Getscriptaddress(destaddr,vintx.vout[vout].scriptPubKey); if ( strcmp(destaddr,coinaddr) != 0 && strcmp(destaddr,cp->unspendableCCaddr) != 0 && strcmp(destaddr,cp->unspendableaddr2) != 0 ) continue; - // check for gatewaysassset assetid and 't' - if ( (nValue= vintx.vout[vout].nValue) > 0 && myIsutxo_spentinmempool(txid,vout) == 0 ) + GetOpReturnData(vintx.vout[vintx.vout.size()-1].scriptPubKey, vopret); + if ( E_UNMARSHAL(vopret,ss >> evalcode; ss >> funcid; ss >> assetid) != 0 ) { - if ( total != 0 && maxinputs != 0 ) - mtx.vin.push_back(CTxIn(txid,vout,CScript())); - nValue = it->second.satoshis; - totalinputs += nValue; - n++; - if ( (total > 0 && totalinputs >= total) || (maxinputs > 0 && n >= maxinputs) ) - break; + assetid = revuint256(assetid); + if ( evalcode == cp->evalcode && assetid == refassetid && funcid == 't' && (nValue= vintx.vout[vout].nValue) > 0 && myIsutxo_spentinmempool(txid,vout) == 0 ) + { + if ( total != 0 && maxinputs != 0 ) + mtx.vin.push_back(CTxIn(txid,vout,CScript())); + nValue = it->second.satoshis; + totalinputs += nValue; + n++; + if ( (total > 0 && totalinputs >= total) || (maxinputs > 0 && n >= maxinputs) ) + break; + } } } } From 2884a3f64add9fec0150167aa54a92d213a4b2b3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 19 Sep 2018 22:35:50 -1100 Subject: [PATCH 18/48] 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 69594583a..5c06a7c54 100644 --- a/src/cc/gateways.cpp +++ b/src/cc/gateways.cpp @@ -290,7 +290,7 @@ bool GatewaysValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction & int64_t AddGatewaysInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey pk,uint256 refassetid,int64_t total,int32_t maxinputs) { - char coinaddr[64],destaddr[64]; int64_t nValue,price,totalinputs = 0; uint256 txid,hashBlock; std::vector origpubkey; std::vector vopret; CTransaction vintx; int32_t j,vout,n = 0; uint8_t evalcode,funcid; + char coinaddr[64],destaddr[64]; int64_t nValue,price,totalinputs = 0; uint256 assetid,txid,hashBlock; std::vector origpubkey; std::vector vopret; CTransaction vintx; int32_t j,vout,n = 0; uint8_t evalcode,funcid; std::vector > unspentOutputs; GetCCaddress(cp,coinaddr,pk); SetCCunspents(unspentOutputs,coinaddr); From ff3116ce3cd816007fba72e1ea8a4bd3c270eef0 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 20 Sep 2018 02:55:45 -1100 Subject: [PATCH 19/48] Chance for AssetConvert to validate --- src/cc/CCassetsCore.cpp | 3 ++- src/cc/CCassetstx.cpp | 3 +-- src/cc/assets.cpp | 1 - src/cc/gateways.cpp | 6 +++++- 4 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/cc/CCassetsCore.cpp b/src/cc/CCassetsCore.cpp index cd2e267e1..e2bcf01ff 100644 --- a/src/cc/CCassetsCore.cpp +++ b/src/cc/CCassetsCore.cpp @@ -490,8 +490,9 @@ bool AssetExactAmounts(struct CCcontract_info *cp,int64_t &inputs,int32_t starti fprintf(stderr,"i.%d starti.%d numvins.%d\n",i,starti,numvins); return eval->Invalid("always should find vin, but didnt"); } - else if ( (assetoshis= IsAssetvout(tmpprice,tmporigpubkey,vinTx,tx.vin[i].prevout.n,assetid)) != 0 ) + else if ( (assetoshis= IsAssetvout(tmpprice,tmporigpubkey,vinTx,tx.vin[i].prevout.n,assetid)) != 0 || vinTx.vout[i].scriptPubKey.IsPayToCryptoCondition() != 0 ) { + assetoshis = vinTx.vout[i].nValue; fprintf(stderr,"vin%d %llu, ",i,(long long)assetoshis); inputs += assetoshis; } diff --git a/src/cc/CCassetstx.cpp b/src/cc/CCassetstx.cpp index 2ce13a1ff..70a2c76ee 100644 --- a/src/cc/CCassetstx.cpp +++ b/src/cc/CCassetstx.cpp @@ -261,9 +261,8 @@ std::string AssetConvert(int64_t txfee,uint256 assetid,std::vector dest { if ( inputs > total ) CCchange = (inputs - total); + mtx.vout.push_back(MakeCC1vout(EVAL_ASSETS,CCchange,mypk)); mtx.vout.push_back(MakeCC1vout(evalcode,total,pubkey2pk(destpubkey))); - if ( CCchange != 0 ) - mtx.vout.push_back(MakeCC1vout(EVAL_ASSETS,CCchange,mypk)); return(FinalizeCCTx(0,cp,mtx,mypk,txfee,EncodeAssetOpRet('t',assetid,zeroid,0,Mypubkey()))); } else fprintf(stderr,"not enough CC asset inputs for %.8f\n",(double)total/COIN); } diff --git a/src/cc/assets.cpp b/src/cc/assets.cpp index bf979a1e0..fa6d87500 100644 --- a/src/cc/assets.cpp +++ b/src/cc/assets.cpp @@ -167,7 +167,6 @@ bool AssetsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx //vout.n-1: opreturn [EVAL_ASSETS] ['c'] [{"":""}] return eval->Invalid("unexpected AssetValidate for createasset"); break; - case 't': // transfer //vin.0: normal input //vin.1 .. vin.n-1: valid CC outputs diff --git a/src/cc/gateways.cpp b/src/cc/gateways.cpp index 5c06a7c54..976cd1971 100644 --- a/src/cc/gateways.cpp +++ b/src/cc/gateways.cpp @@ -134,7 +134,11 @@ Implementation Issues: When thinking about validation, it is clear that we cant use EVAL_ASSETS for the locked coins as there wont be any enforcement of the gateways locking. This means we need a way to transfer assets into gateways outputs and back. It seems a tokenconvert rpc will be needed and hopefully that will be enough to make it all work properly. - Care must be taken so that tokens are not lost and can be converted back + Care must be taken so that tokens are not lost and can be converted back. + + This changes the usage to require tokenconvert before doing the bind and also tokenconvert before doing a withdraw. EVAL_GATEWAYS has evalcode of 251 + + The gatewaysclaim automatically converts the deposit amount of tokens back to EVAL_ASSETS. */ From 627cd0f5590ff1f66bfabb4f756ce7b36677896e Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 20 Sep 2018 03:45:37 -1100 Subject: [PATCH 20/48] Assets 't' exemption --- src/cc/CCassets.h | 2 +- src/cc/CCassetsCore.cpp | 71 +++++++++++++++++------------------------ src/cc/CCinclude.h | 4 +-- src/cc/CCtx.cpp | 4 +-- src/cc/assets.cpp | 4 +-- 5 files changed, 35 insertions(+), 50 deletions(-) diff --git a/src/cc/CCassets.h b/src/cc/CCassets.h index 0fb4ae6f7..4d4f30b3b 100644 --- a/src/cc/CCassets.h +++ b/src/cc/CCassets.h @@ -33,7 +33,7 @@ bool AssetsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx CScript EncodeAssetCreateOpRet(uint8_t funcid,std::vector origpubkey,std::string name,std::string description); CScript EncodeAssetOpRet(uint8_t funcid,uint256 assetid,uint256 assetid2,int64_t price,std::vector origpubkey); bool DecodeAssetCreateOpRet(const CScript &scriptPubKey,std::vector &origpubkey,std::string &name,std::string &description); -uint8_t DecodeAssetOpRet(const CScript &scriptPubKey,uint256 &assetid,uint256 &assetid2,int64_t &price,std::vector &origpubkey,uint256 &bettxid,int32_t &leverage); +uint8_t DecodeAssetOpRet(const CScript &scriptPubKey,uint256 &assetid,uint256 &assetid2,int64_t &price,std::vector &origpubkey); bool SetAssetOrigpubkey(std::vector &origpubkey,int64_t &price,const CTransaction &tx); int64_t IsAssetvout(int64_t &price,std::vector &origpubkey,const CTransaction& tx,int32_t v,uint256 refassetid); bool ValidateBidRemainder(int64_t remaining_price,int64_t remaining_nValue,int64_t orig_nValue,int64_t received_nValue,int64_t paidprice,int64_t totalprice); diff --git a/src/cc/CCassetsCore.cpp b/src/cc/CCassetsCore.cpp index e2bcf01ff..f53633813 100644 --- a/src/cc/CCassetsCore.cpp +++ b/src/cc/CCassetsCore.cpp @@ -274,29 +274,7 @@ bool DecodeAssetCreateOpRet(const CScript &scriptPubKey,std::vector &or return(0); } -CScript EncodeAssetOpRetExtra(uint8_t funcid,uint256 assetid,uint256 assetid2,uint256 bettxid,int32_t leverage) -{ - CScript opret; uint8_t evalcode = EVAL_ASSETS; - assetid = revuint256(assetid); - assetid2 = revuint256(assetid2); - opret << OP_RETURN << E_MARSHAL(ss << evalcode << funcid << assetid << assetid2 << bettxid << leverage); - return(opret); -} - -uint8_t DecodeAssetOpRetExtra(CScript scriptPubKey,uint256 &assetid,uint256 &assetid2,uint256 &bettxid,int32_t leverage) -{ - std::vector vopret; uint8_t funcid=0,e,f; - GetOpReturnData(scriptPubKey, vopret); - if ( E_UNMARSHAL(vopret,ss >> e; ss >> f; ss >> assetid; ss >> assetid2; ss >> bettxid; ss >> leverage) != 0 ) - { - assetid = revuint256(assetid); - assetid2 = revuint256(assetid2); - return(funcid); - } - return(0); -} - -uint8_t DecodeAssetOpRet(const CScript &scriptPubKey,uint256 &assetid,uint256 &assetid2,int64_t &price,std::vector &origpubkey,uint256 &bettxid,int32_t &leverage) +uint8_t DecodeAssetOpRet(const CScript &scriptPubKey,uint256 &assetid,uint256 &assetid2,int64_t &price,std::vector &origpubkey) { std::vector vopret; uint8_t funcid=0,*script,e,f; GetOpReturnData(scriptPubKey, vopret); @@ -319,14 +297,6 @@ uint8_t DecodeAssetOpRet(const CScript &scriptPubKey,uint256 &assetid,uint256 &a return(funcid); } break; - case 'T': - if ( E_UNMARSHAL(vopret,ss >> e; ss >> f; ss >> assetid; ss >> assetid2; ss >> bettxid; ss >> leverage) != 0 ) - { - assetid = revuint256(assetid); - assetid2 = revuint256(assetid2); - return(funcid); - } - break; case 's': case 'b': case 'S': case 'B': if ( E_UNMARSHAL(vopret,ss >> e; ss >> f; ss >> assetid; ss >> price; ss >> origpubkey) != 0 ) { @@ -355,17 +325,17 @@ uint8_t DecodeAssetOpRet(const CScript &scriptPubKey,uint256 &assetid,uint256 &a bool SetAssetOrigpubkey(std::vector &origpubkey,int64_t &price,const CTransaction &tx) { - uint256 assetid,assetid2,bettxid; int32_t leverage; - if ( tx.vout.size() > 0 && DecodeAssetOpRet(tx.vout[tx.vout.size()-1].scriptPubKey,assetid,assetid2,price,origpubkey,bettxid,leverage) != 0 ) + uint256 assetid,assetid2; + if ( tx.vout.size() > 0 && DecodeAssetOpRet(tx.vout[tx.vout.size()-1].scriptPubKey,assetid,assetid2,price,origpubkey) != 0 ) return(true); else return(false); } bool GetAssetorigaddrs(struct CCcontract_info *cp,char *CCaddr,char *destaddr,const CTransaction& tx) { - uint256 assetid,assetid2,bettxid; int32_t leverage; int64_t price,nValue=0; int32_t n; uint8_t funcid; std::vector origpubkey; CScript script; + uint256 assetid,assetid2; int64_t price,nValue=0; int32_t n; uint8_t funcid; std::vector origpubkey; CScript script; n = tx.vout.size(); - if ( n == 0 || (funcid= DecodeAssetOpRet(tx.vout[n-1].scriptPubKey,assetid,assetid2,price,origpubkey,bettxid,leverage)) == 0 ) + if ( n == 0 || (funcid= DecodeAssetOpRet(tx.vout[n-1].scriptPubKey,assetid,assetid2,price,origpubkey)) == 0 ) return(false); if ( GetCCaddress(cp,CCaddr,pubkey2pk(origpubkey)) != 0 && Getscriptaddress(destaddr,CScript() << origpubkey << OP_CHECKSIG) != 0 ) return(true); @@ -374,7 +344,7 @@ bool GetAssetorigaddrs(struct CCcontract_info *cp,char *CCaddr,char *destaddr,co int64_t IsAssetvout(int64_t &price,std::vector &origpubkey,const CTransaction& tx,int32_t v,uint256 refassetid) { - uint256 assetid,assetid2,bettxid; int64_t nValue=0; int32_t n,leverage; uint8_t funcid; + uint256 assetid,assetid2; int64_t nValue=0; int32_t n; uint8_t funcid; if ( tx.vout[v].scriptPubKey.IsPayToCryptoCondition() != 0 ) // maybe check address too? { n = tx.vout.size(); @@ -382,7 +352,7 @@ int64_t IsAssetvout(int64_t &price,std::vector &origpubkey,const CTrans //fprintf(stderr,"CC vout v.%d of n.%d %.8f\n",v,n,(double)nValue/COIN); if ( v >= n-1 ) return(0); - if ( (funcid= DecodeAssetOpRet(tx.vout[n-1].scriptPubKey,assetid,assetid2,price,origpubkey,bettxid,leverage)) == 0 ) + if ( (funcid= DecodeAssetOpRet(tx.vout[n-1].scriptPubKey,assetid,assetid2,price,origpubkey)) == 0 ) { fprintf(stderr,"null decodeopret v.%d\n",v); return(0); @@ -444,7 +414,7 @@ int64_t AssetValidateCCvin(struct CCcontract_info *cp,Eval* eval,char *CCaddr,ch int64_t AssetValidateBuyvin(struct CCcontract_info *cp,Eval* eval,int64_t &tmpprice,std::vector &tmporigpubkey,char *CCaddr,char *origaddr,const CTransaction &tx,uint256 refassetid) { - CTransaction vinTx; int64_t nValue; int32_t leverage; uint256 assetid,assetid2,bettxid; uint8_t funcid; + CTransaction vinTx; int64_t nValue; uint256 assetid,assetid2; uint8_t funcid; CCaddr[0] = origaddr[0] = 0; if ( (nValue= AssetValidateCCvin(cp,eval,CCaddr,origaddr,tx,1,vinTx)) == 0 ) return(0); @@ -453,7 +423,7 @@ int64_t AssetValidateBuyvin(struct CCcontract_info *cp,Eval* eval,int64_t &tmppr else { //fprintf(stderr,"have %.8f checking assetid origaddr.(%s)\n",(double)nValue/COIN,origaddr); - if ( vinTx.vout.size() > 0 && (funcid= DecodeAssetOpRet(vinTx.vout[vinTx.vout.size()-1].scriptPubKey,assetid,assetid2,tmpprice,tmporigpubkey,bettxid,leverage)) != 'b' && funcid != 'B' ) + if ( vinTx.vout.size() > 0 && (funcid= DecodeAssetOpRet(vinTx.vout[vinTx.vout.size()-1].scriptPubKey,assetid,assetid2,tmpprice,tmporigpubkey)) != 'b' && funcid != 'B' ) return eval->Invalid("invalid opreturn for buyvin"); else if ( refassetid != assetid ) return eval->Invalid("invalid assetid for buyvin"); @@ -477,7 +447,7 @@ int64_t AssetValidateSellvin(struct CCcontract_info *cp,Eval* eval,int64_t &tmpp bool AssetExactAmounts(struct CCcontract_info *cp,int64_t &inputs,int32_t starti,int64_t &outputs,Eval* eval,const CTransaction &tx,uint256 assetid) { - CTransaction vinTx; uint256 hashBlock; int32_t i,numvins,numvouts; int64_t assetoshis; std::vector tmporigpubkey; int64_t tmpprice; + CTransaction vinTx; uint256 hashBlock,id,id2; int32_t i,flag,numvins,numvouts; int64_t assetoshis; std::vector tmporigpubkey; int64_t tmpprice; numvins = tx.vin.size(); numvouts = tx.vout.size(); inputs = outputs = 0; @@ -490,14 +460,25 @@ bool AssetExactAmounts(struct CCcontract_info *cp,int64_t &inputs,int32_t starti fprintf(stderr,"i.%d starti.%d numvins.%d\n",i,starti,numvins); return eval->Invalid("always should find vin, but didnt"); } - else if ( (assetoshis= IsAssetvout(tmpprice,tmporigpubkey,vinTx,tx.vin[i].prevout.n,assetid)) != 0 || vinTx.vout[i].scriptPubKey.IsPayToCryptoCondition() != 0 ) + else if ( (assetoshis= IsAssetvout(tmpprice,tmporigpubkey,vinTx,tx.vin[i].prevout.n,assetid)) != 0 ) { - assetoshis = vinTx.vout[i].nValue; fprintf(stderr,"vin%d %llu, ",i,(long long)assetoshis); inputs += assetoshis; } + else + { + if ( vinTx.vout[i].scriptPubKey.IsPayToCryptoCondition() != 0 && DecodeAssetOpRet(vinTx.vout[vinTx.vout.size()-1].scriptPubKey,id,id2,tmpprice,tmporigpubkey) == 't' && id == asssetid ) + { + assetoshis = vinTx.vout[i].nValue; + fprintf(stderr,"vin%d %llu special case, ",(long long)assetoshi); + inputs += assetoshis; + } + } } } + if ( DecodeAssetOpRet(tx.vout[tx.vout.size()-1].scriptPubKey,id,id2,tmpprice,tmporigpubkey) == 't' && id == asssetid ) + flag = 1; + else flag = 0; for (i=0; i &origpubkey,std::string &name,std::string &description); -uint8_t DecodeAssetOpRet(const CScript &scriptPubKey,uint256 &assetid,uint256 &assetid2,int64_t &price,std::vector &origpubkey,uint256 &bettxid,int32_t &leverage); +uint8_t DecodeAssetOpRet(const CScript &scriptPubKey,uint256 &assetid,uint256 &assetid2,int64_t &price,std::vector &origpubkey); uint8_t DecodeOraclesData(const CScript &scriptPubKey,uint256 &oracletxid,uint256 &batontxid,CPubKey &pk,std::vector &data); int32_t oracle_format(uint256 *hashp,int64_t *valp,char *str,uint8_t fmt,uint8_t *data,int32_t offset,int32_t datalen); CScript EncodeAssetOpRet(uint8_t funcid,uint256 assetid,uint256 assetid2,int64_t price,std::vector origpubkey); -CScript EncodeAssetOpRetExtra(uint8_t funcid,uint256 assetid,uint256 assetid2,uint256 bettxid,int32_t leverage); -uint8_t DecodeAssetOpRetExtra(CScript scriptPubKey,uint256 &assetid,uint256 &assetid2,uint256 &bettxid,int32_t leverage); // CCcustom CPubKey GetUnspendable(struct CCcontract_info *cp,uint8_t *unspendablepriv); diff --git a/src/cc/CCtx.cpp b/src/cc/CCtx.cpp index b26ca7cfd..d651537cf 100644 --- a/src/cc/CCtx.cpp +++ b/src/cc/CCtx.cpp @@ -250,7 +250,7 @@ int64_t CCfullsupply(uint256 tokenid) int64_t CCtoken_balance(char *coinaddr,uint256 tokenid) { - int64_t price,sum = 0; int32_t numvouts; CTransaction tx; uint256 assetid,assetid2,txid,bettxid,hashBlock; std::vector origpubkey; int32_t leverage; + int64_t price,sum = 0; int32_t numvouts; CTransaction tx; uint256 assetid,assetid2,txid,hashBlock; std::vector origpubkey; std::vector > unspentOutputs; SetCCunspents(unspentOutputs,coinaddr); for (std::vector >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++) @@ -258,7 +258,7 @@ int64_t CCtoken_balance(char *coinaddr,uint256 tokenid) txid = it->first.txhash; if ( GetTransaction(txid,tx,hashBlock,false) != 0 && (numvouts= tx.vout.size()) > 0 ) { - if ( DecodeAssetOpRet(tx.vout[numvouts-1].scriptPubKey,assetid,assetid2,price,origpubkey,bettxid,leverage) != 0 && assetid == tokenid ) + if ( DecodeAssetOpRet(tx.vout[numvouts-1].scriptPubKey,assetid,assetid2,price,origpubkey) != 0 && assetid == tokenid ) { sum += it->second.satoshis; } diff --git a/src/cc/assets.cpp b/src/cc/assets.cpp index fa6d87500..1ddbdc4f8 100644 --- a/src/cc/assets.cpp +++ b/src/cc/assets.cpp @@ -132,12 +132,12 @@ bool AssetsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx) { static uint256 zero; - CTxDestination address; CTransaction vinTx,createTx; uint256 bettxid,hashBlock,assetid,assetid2; int32_t i,starti,leverage,numvins,numvouts,preventCCvins,preventCCvouts; int64_t remaining_price,nValue,assetoshis,outputs,inputs,tmpprice,totalunits,ignore; std::vector origpubkey,tmporigpubkey,ignorepubkey; uint8_t funcid; char destaddr[64],origaddr[64],CCaddr[64]; + CTxDestination address; CTransaction vinTx,createTx; uint256 hashBlock,assetid,assetid2; int32_t i,starti,numvins,numvouts,preventCCvins,preventCCvouts; int64_t remaining_price,nValue,assetoshis,outputs,inputs,tmpprice,totalunits,ignore; std::vector origpubkey,tmporigpubkey,ignorepubkey; uint8_t funcid; char destaddr[64],origaddr[64],CCaddr[64]; numvins = tx.vin.size(); numvouts = tx.vout.size(); outputs = inputs = 0; preventCCvins = preventCCvouts = -1; - if ( (funcid= DecodeAssetOpRet(tx.vout[numvouts-1].scriptPubKey,assetid,assetid2,remaining_price,origpubkey,bettxid,leverage)) == 0 ) + if ( (funcid= DecodeAssetOpRet(tx.vout[numvouts-1].scriptPubKey,assetid,assetid2,remaining_price,origpubkey)) == 0 ) return eval->Invalid("Invalid opreturn payload"); fprintf(stderr,"AssetValidate (%c)\n",funcid); if ( funcid != 'o' && funcid != 'x' && eval->GetTxUnconfirmed(assetid,createTx,hashBlock) == 0 ) From 4ab5f2f1d74883315ac93f1489166185aec4044c Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 20 Sep 2018 03:46:55 -1100 Subject: [PATCH 21/48] Test --- src/cc/CCassetsCore.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/cc/CCassetsCore.cpp b/src/cc/CCassetsCore.cpp index f53633813..fadbe15ae 100644 --- a/src/cc/CCassetsCore.cpp +++ b/src/cc/CCassetsCore.cpp @@ -467,16 +467,16 @@ bool AssetExactAmounts(struct CCcontract_info *cp,int64_t &inputs,int32_t starti } else { - if ( vinTx.vout[i].scriptPubKey.IsPayToCryptoCondition() != 0 && DecodeAssetOpRet(vinTx.vout[vinTx.vout.size()-1].scriptPubKey,id,id2,tmpprice,tmporigpubkey) == 't' && id == asssetid ) + if ( vinTx.vout[i].scriptPubKey.IsPayToCryptoCondition() != 0 && DecodeAssetOpRet(vinTx.vout[vinTx.vout.size()-1].scriptPubKey,id,id2,tmpprice,tmporigpubkey) == 't' && id == assetid ) { assetoshis = vinTx.vout[i].nValue; - fprintf(stderr,"vin%d %llu special case, ",(long long)assetoshi); + fprintf(stderr,"vin%d %llu special case, ",(long long)assetoshis); inputs += assetoshis; } } } } - if ( DecodeAssetOpRet(tx.vout[tx.vout.size()-1].scriptPubKey,id,id2,tmpprice,tmporigpubkey) == 't' && id == asssetid ) + if ( DecodeAssetOpRet(tx.vout[tx.vout.size()-1].scriptPubKey,id,id2,tmpprice,tmporigpubkey) == 't' && id == assetid ) flag = 1; else flag = 0; for (i=0; i Date: Thu, 20 Sep 2018 03:47:39 -1100 Subject: [PATCH 22/48] Test --- src/cc/CCassetsCore.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/CCassetsCore.cpp b/src/cc/CCassetsCore.cpp index fadbe15ae..3a9226a27 100644 --- a/src/cc/CCassetsCore.cpp +++ b/src/cc/CCassetsCore.cpp @@ -470,7 +470,7 @@ bool AssetExactAmounts(struct CCcontract_info *cp,int64_t &inputs,int32_t starti if ( vinTx.vout[i].scriptPubKey.IsPayToCryptoCondition() != 0 && DecodeAssetOpRet(vinTx.vout[vinTx.vout.size()-1].scriptPubKey,id,id2,tmpprice,tmporigpubkey) == 't' && id == assetid ) { assetoshis = vinTx.vout[i].nValue; - fprintf(stderr,"vin%d %llu special case, ",(long long)assetoshis); + fprintf(stderr,"vin%d %llu special case, ",i,(long long)assetoshis); inputs += assetoshis; } } @@ -489,7 +489,7 @@ bool AssetExactAmounts(struct CCcontract_info *cp,int64_t &inputs,int32_t starti else if ( flag != 0 && tx.vout[i].scriptPubKey.IsPayToCryptoCondition() != 0 ) { assetoshis = vinTx.vout[i].nValue; - fprintf(stderr,"vout%d %llu special case, ",(long long)assetoshis); + fprintf(stderr,"vout%d %llu special case, ",i,(long long)assetoshis); outputs += assetoshis; } } From 66bee980b50965c558373fc6e733afb598e5205f Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 20 Sep 2018 03:49:07 -1100 Subject: [PATCH 23/48] Test --- src/cc/prices.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index e8755b53e..f458ab4cc 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -400,7 +400,8 @@ std::string PricesBet(uint64_t txfee,uint256 refbettoken,uint256 fundingtxid,int mtx.vout.push_back(MakeCC1of2vout(assetscp->evalcode,CCchange,pricespk,planpk)); mtx.vout.push_back(MakeCC1vout(assetscp->evalcode,CCchange2,mypk)); // add addr2 and addr3 - return(FinalizeCCTx(0,assetscp,mtx,mypk,txfee,EncodeAssetOpRetExtra('T',tokenid,bettoken,zeroid,dir*leverage))); + //return(FinalizeCCTx(0,assetscp,mtx,mypk,txfee,EncodePricesExtra('T',tokenid,bettoken,zeroid,dir*leverage))); + return(FinalizeCCTx(0,assetscp,mtx,mypk,txfee,CScript opret)); } else { From 8fc335afe130681ee2f08bf0384b45f30fe2c938 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 20 Sep 2018 03:49:47 -1100 Subject: [PATCH 24/48] Test --- src/cc/prices.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index f458ab4cc..ca945d02f 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -401,7 +401,8 @@ std::string PricesBet(uint64_t txfee,uint256 refbettoken,uint256 fundingtxid,int mtx.vout.push_back(MakeCC1vout(assetscp->evalcode,CCchange2,mypk)); // add addr2 and addr3 //return(FinalizeCCTx(0,assetscp,mtx,mypk,txfee,EncodePricesExtra('T',tokenid,bettoken,zeroid,dir*leverage))); - return(FinalizeCCTx(0,assetscp,mtx,mypk,txfee,CScript opret)); + CScript opret; + return(FinalizeCCTx(0,assetscp,mtx,mypk,txfee,opret)); } else { From 68da1c69bd9f3342d6f8fc66f718cc5ee7716648 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 20 Sep 2018 03:50:58 -1100 Subject: [PATCH 25/48] Test --- src/cc/CCassetstx.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/CCassetstx.cpp b/src/cc/CCassetstx.cpp index 70a2c76ee..5c933bd77 100644 --- a/src/cc/CCassetstx.cpp +++ b/src/cc/CCassetstx.cpp @@ -106,7 +106,7 @@ UniValue AssetList() UniValue AssetOrders(uint256 refassetid) { static uint256 zero; - int64_t price; uint256 txid,hashBlock,assetid,assetid2,bettxid; std::vector origpubkey; CTransaction vintx; UniValue result(UniValue::VARR); std::vector > unspentOutputs; int32_t leverage; uint8_t funcid; char numstr[32],funcidstr[16],origaddr[64],assetidstr[65]; struct CCcontract_info *cp,C; + int64_t price; uint256 txid,hashBlock,assetid,assetid2; std::vector origpubkey; CTransaction vintx; UniValue result(UniValue::VARR); std::vector > unspentOutputs; uint8_t funcid; char numstr[32],funcidstr[16],origaddr[64],assetidstr[65]; struct CCcontract_info *cp,C; cp = CCinit(&C,EVAL_ASSETS); SetCCunspents(unspentOutputs,(char *)cp->unspendableCCaddr); for (std::vector >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++) @@ -114,7 +114,7 @@ UniValue AssetOrders(uint256 refassetid) txid = it->first.txhash; if ( GetTransaction(txid,vintx,hashBlock,false) != 0 ) { - if ( vintx.vout.size() > 0 && (funcid= DecodeAssetOpRet(vintx.vout[vintx.vout.size()-1].scriptPubKey,assetid,assetid2,price,origpubkey,bettxid,leverage)) != 0 ) + if ( vintx.vout.size() > 0 && (funcid= DecodeAssetOpRet(vintx.vout[vintx.vout.size()-1].scriptPubKey,assetid,assetid2,price,origpubkey)) != 0 ) { if ( refassetid != zero && assetid != refassetid ) { From 71d6712d8dbe06c17421ef846f341c8506072b3c Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 20 Sep 2018 06:47:08 -1100 Subject: [PATCH 26/48] Test --- src/wallet/rpcwallet.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index e8fff8904..80f0e4e6b 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4910,6 +4910,14 @@ UniValue channelsaddress(const UniValue& params, bool fHelp) result.push_back(Pair("otherpubkey", params[0].get_str())); GetCCaddress1of2(cp,destaddr,pk,pk2); result.push_back(Pair("channeladdress",destaddr)); + { + int32_t i; + for (i=0; i<100; i++) + { + GetCCaddress1of2(cp,destaddr,pk,pk2); + fprintf(stderr,"i.%d %s\n",i,destaddr); + } + } return(result); } From 44d8e00a25fbd877d06594eecde90cee56dfec4a Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 20 Sep 2018 07:52:46 -1100 Subject: [PATCH 27/48] +print --- src/cc/CCutils.cpp | 1 + src/wallet/rpcwallet.cpp | 1 + 2 files changed, 2 insertions(+) diff --git a/src/cc/CCutils.cpp b/src/cc/CCutils.cpp index a91d6ffdd..01e9d35ab 100644 --- a/src/cc/CCutils.cpp +++ b/src/cc/CCutils.cpp @@ -63,6 +63,7 @@ CTxOut MakeCC1of2vout(uint8_t evalcode,CAmount nValue,CPubKey pk1,CPubKey pk2) CTxOut vout; CC *payoutCond = MakeCCcond1of2(evalcode,pk1,pk2); vout = CTxOut(nValue,CCPubKey(payoutCond)); + fprintf(stderr,"payoutCond: %s\n",cc_conditionToJSONString(payoutCond)); cc_free(payoutCond); return(vout); } diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 80f0e4e6b..7c2314480 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4910,6 +4910,7 @@ UniValue channelsaddress(const UniValue& params, bool fHelp) result.push_back(Pair("otherpubkey", params[0].get_str())); GetCCaddress1of2(cp,destaddr,pk,pk2); result.push_back(Pair("channeladdress",destaddr)); + if ( 0 ) { int32_t i; for (i=0; i<100; i++) From 88b5d9e46aa28912531d7db1094e03c6b4ecafd7 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 21 Sep 2018 03:34:39 -1100 Subject: [PATCH 28/48] Fix token convert --- src/wallet/rpcwallet.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 7c2314480..5a14370c4 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -6291,7 +6291,7 @@ UniValue tokentransfer(const UniValue& params, bool fHelp) UniValue tokenconvert(const UniValue& params, bool fHelp) { UniValue result(UniValue::VOBJ); std::string hex; int32_t evalcode; int64_t amount; uint256 tokenid; - if ( fHelp || params.size() != 3 ) + if ( fHelp || params.size() != 4 ) throw runtime_error("tokenconvert evalcode tokenid pubkey 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 8267beff37fe0a7ff2af7a41eb02e10b9432836e Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 21 Sep 2018 06:56:43 -1100 Subject: [PATCH 29/48] +print --- src/cc/CCassetsCore.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/CCassetsCore.cpp b/src/cc/CCassetsCore.cpp index 3a9226a27..a9bb5b71f 100644 --- a/src/cc/CCassetsCore.cpp +++ b/src/cc/CCassetsCore.cpp @@ -349,7 +349,7 @@ int64_t IsAssetvout(int64_t &price,std::vector &origpubkey,const CTrans { n = tx.vout.size(); nValue = tx.vout[v].nValue; - //fprintf(stderr,"CC vout v.%d of n.%d %.8f\n",v,n,(double)nValue/COIN); + fprintf(stderr,"CC vout v.%d of n.%d %.8f\n",v,n,(double)nValue/COIN); if ( v >= n-1 ) return(0); if ( (funcid= DecodeAssetOpRet(tx.vout[n-1].scriptPubKey,assetid,assetid2,price,origpubkey)) == 0 ) From a4f7b6910f163282b566d5e99d89c8f4a91afdfd Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 21 Sep 2018 07:08:47 -1100 Subject: [PATCH 30/48] Fix silly bug --- src/cc/CCassetsCore.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/cc/CCassetsCore.cpp b/src/cc/CCassetsCore.cpp index a9bb5b71f..c9b975c3c 100644 --- a/src/cc/CCassetsCore.cpp +++ b/src/cc/CCassetsCore.cpp @@ -349,7 +349,7 @@ int64_t IsAssetvout(int64_t &price,std::vector &origpubkey,const CTrans { n = tx.vout.size(); nValue = tx.vout[v].nValue; - fprintf(stderr,"CC vout v.%d of n.%d %.8f\n",v,n,(double)nValue/COIN); + //fprintf(stderr,"CC vout v.%d of n.%d %.8f\n",v,n,(double)nValue/COIN); if ( v >= n-1 ) return(0); if ( (funcid= DecodeAssetOpRet(tx.vout[n-1].scriptPubKey,assetid,assetid2,price,origpubkey)) == 0 ) @@ -367,7 +367,10 @@ int64_t IsAssetvout(int64_t &price,std::vector &origpubkey,const CTrans else if ( funcid != 'E' ) { if ( assetid == refassetid ) + { + //fprintf(stderr,"returning %.8f\n",(double)nValue/COIN); return(nValue); + } } else if ( funcid == 'E' ) { @@ -488,7 +491,7 @@ bool AssetExactAmounts(struct CCcontract_info *cp,int64_t &inputs,int32_t starti } else if ( flag != 0 && tx.vout[i].scriptPubKey.IsPayToCryptoCondition() != 0 ) { - assetoshis = vinTx.vout[i].nValue; + assetoshis = tx.vout[i].nValue; fprintf(stderr,"vout%d %llu special case, ",i,(long long)assetoshis); outputs += assetoshis; } From 9a59ff3ff14385d5323d5642b6d76197dd83458c Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 21 Sep 2018 20:25:10 -1100 Subject: [PATCH 31/48] Test --- src/rpcblockchain.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index 5d73e8f6b..f66b1b204 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -1417,7 +1417,10 @@ UniValue getchaintips(const UniValue& params, bool fHelp) of another block. */ std::set setTips; BOOST_FOREACH(const PAIRTYPE(const uint256, CBlockIndex*)& item, mapBlockIndex) - setTips.insert(item.second); + { + if ( item != 0 ) + setTips.insert(item.second); + } BOOST_FOREACH(const PAIRTYPE(const uint256, CBlockIndex*)& item, mapBlockIndex) { const CBlockIndex* pprev=0; From 2dd23a26175529a520961b544098458b2f2d5efe Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 21 Sep 2018 20:29:18 -1100 Subject: [PATCH 32/48] Test --- src/rpcblockchain.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index f66b1b204..f280cfc72 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -1410,16 +1410,18 @@ UniValue getchaintips(const UniValue& params, bool fHelp) + HelpExampleRpc("getchaintips", "") ); + if ( mapBlockIndex == 0 ) + throw runtime_error("mapBlockIndex is NULL\n"); LOCK(cs_main); /* Build up a list of chain tips. We start with the list of all known blocks, and successively remove blocks that appear as pprev of another block. */ + std::set setTips; BOOST_FOREACH(const PAIRTYPE(const uint256, CBlockIndex*)& item, mapBlockIndex) { - if ( item != 0 ) - setTips.insert(item.second); + setTips.insert(item.second); } BOOST_FOREACH(const PAIRTYPE(const uint256, CBlockIndex*)& item, mapBlockIndex) { From c46c04b331e4fb8175b852b49c9a570f431e7471 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 21 Sep 2018 20:29:58 -1100 Subject: [PATCH 33/48] Test --- src/rpcblockchain.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index f280cfc72..bec1692c6 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -1410,8 +1410,6 @@ UniValue getchaintips(const UniValue& params, bool fHelp) + HelpExampleRpc("getchaintips", "") ); - if ( mapBlockIndex == 0 ) - throw runtime_error("mapBlockIndex is NULL\n"); LOCK(cs_main); /* Build up a list of chain tips. We start with the list of all From 35506c9ae6da43b94853025c9a9d0ca41f211d73 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 21 Sep 2018 20:31:19 -1100 Subject: [PATCH 34/48] Test --- src/rpcblockchain.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index bec1692c6..b78d46e19 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -1417,8 +1417,10 @@ UniValue getchaintips(const UniValue& params, bool fHelp) of another block. */ std::set setTips; + int32_t n = 0; BOOST_FOREACH(const PAIRTYPE(const uint256, CBlockIndex*)& item, mapBlockIndex) { + fprintf(stderr,"iterator %d\n",n++); setTips.insert(item.second); } BOOST_FOREACH(const PAIRTYPE(const uint256, CBlockIndex*)& item, mapBlockIndex) From a4602c8956b770dd0c483d130f2dfeaa29f9e5b1 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 21 Sep 2018 20:33:54 -1100 Subject: [PATCH 35/48] Test --- src/rpcblockchain.cpp | 41 +++++++++++++++++++++-------------------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index b78d46e19..64f3d35e8 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -1410,28 +1410,29 @@ UniValue getchaintips(const UniValue& params, bool fHelp) + HelpExampleRpc("getchaintips", "") ); - LOCK(cs_main); - - /* Build up a list of chain tips. We start with the list of all - known blocks, and successively remove blocks that appear as pprev - of another block. */ - - std::set setTips; - int32_t n = 0; - BOOST_FOREACH(const PAIRTYPE(const uint256, CBlockIndex*)& item, mapBlockIndex) { - fprintf(stderr,"iterator %d\n",n++); - setTips.insert(item.second); + LOCK(cs_main); + + /* Build up a list of chain tips. We start with the list of all + known blocks, and successively remove blocks that appear as pprev + of another block. */ + + std::set setTips; + int32_t n = 0; + BOOST_FOREACH(const PAIRTYPE(const uint256, CBlockIndex*)& item, mapBlockIndex) + { + fprintf(stderr,"iterator %d\n",n++); + setTips.insert(item.second); + } + BOOST_FOREACH(const PAIRTYPE(const uint256, CBlockIndex*)& item, mapBlockIndex) + { + const CBlockIndex* pprev=0; + if ( item.second != 0 ) + pprev = item.second->pprev; + if (pprev) + setTips.erase(pprev); + } } - BOOST_FOREACH(const PAIRTYPE(const uint256, CBlockIndex*)& item, mapBlockIndex) - { - const CBlockIndex* pprev=0; - if ( item.second != 0 ) - pprev = item.second->pprev; - if (pprev) - setTips.erase(pprev); - } - // Always report the currently active tip. setTips.insert(chainActive.LastTip()); From 4eafa6062d91fa76b25d77dccf38d7dfcc4c6838 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 21 Sep 2018 20:34:54 -1100 Subject: [PATCH 36/48] Test --- src/rpcblockchain.cpp | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index 64f3d35e8..0ce01d09f 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -1432,14 +1432,13 @@ UniValue getchaintips(const UniValue& params, bool fHelp) if (pprev) setTips.erase(pprev); } - } - // Always report the currently active tip. - setTips.insert(chainActive.LastTip()); - - /* Construct the output array. */ - UniValue res(UniValue::VARR); const CBlockIndex *forked; - BOOST_FOREACH(const CBlockIndex* block, setTips) - BOOST_FOREACH(const CBlockIndex* block, setTips) + // Always report the currently active tip. + setTips.insert(chainActive.LastTip()); + + /* Construct the output array. */ + UniValue res(UniValue::VARR); const CBlockIndex *forked; + BOOST_FOREACH(const CBlockIndex* block, setTips) + BOOST_FOREACH(const CBlockIndex* block, setTips) { UniValue obj(UniValue::VOBJ); obj.push_back(Pair("height", block->nHeight)); @@ -1449,7 +1448,7 @@ UniValue getchaintips(const UniValue& params, bool fHelp) { const int branchLen = block->nHeight - forked->nHeight; obj.push_back(Pair("branchlen", branchLen)); - + string status; if (chainActive.Contains(block)) { // This block is part of the currently active chain. @@ -1474,7 +1473,7 @@ UniValue getchaintips(const UniValue& params, bool fHelp) } res.push_back(obj); } - + } return res; } From bf8e9b4d66d6cae6f414a77b3263421a6459c419 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 21 Sep 2018 20:36:22 -1100 Subject: [PATCH 37/48] Test --- src/rpcblockchain.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index 0ce01d09f..3cfa22282 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -1410,6 +1410,7 @@ UniValue getchaintips(const UniValue& params, bool fHelp) + HelpExampleRpc("getchaintips", "") ); + UniValue res(UniValue::VARR); { LOCK(cs_main); @@ -1436,7 +1437,7 @@ UniValue getchaintips(const UniValue& params, bool fHelp) setTips.insert(chainActive.LastTip()); /* Construct the output array. */ - UniValue res(UniValue::VARR); const CBlockIndex *forked; + const CBlockIndex *forked; BOOST_FOREACH(const CBlockIndex* block, setTips) BOOST_FOREACH(const CBlockIndex* block, setTips) { From 7108bc79f56ae810ac5f6b1e3f83db103e3120bb Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 21 Sep 2018 20:44:55 -1100 Subject: [PATCH 38/48] Test --- src/komodo_gateway.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 379224b48..e355f3708 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1378,6 +1378,8 @@ void komodo_passport_iteration() fprintf(stderr,"[%s] PASSPORT iteration waiting for KOMODO_INITDONE\n",ASSETCHAINS_SYMBOL); sleep(3); } +KOMODO_PASSPORT_INITDONE = 1; +return; if ( komodo_chainactive_timestamp() > lastinterest ) { komodo_interestsum(); From 5aad1637002062efc48f629ef38cdc30d4eb49b0 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 21 Sep 2018 20:48:11 -1100 Subject: [PATCH 39/48] Test --- src/komodo_gateway.h | 2 -- src/rpcblockchain.cpp | 65 ++++++++++++++++++++++--------------------- 2 files changed, 34 insertions(+), 33 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index e355f3708..379224b48 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1378,8 +1378,6 @@ void komodo_passport_iteration() fprintf(stderr,"[%s] PASSPORT iteration waiting for KOMODO_INITDONE\n",ASSETCHAINS_SYMBOL); sleep(3); } -KOMODO_PASSPORT_INITDONE = 1; -return; if ( komodo_chainactive_timestamp() > lastinterest ) { komodo_interestsum(); diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index 3cfa22282..357b88426 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -1410,36 +1410,39 @@ UniValue getchaintips(const UniValue& params, bool fHelp) + HelpExampleRpc("getchaintips", "") ); - UniValue res(UniValue::VARR); + LOCK(cs_main); + + /* Build up a list of chain tips. We start with the list of all + known blocks, and successively remove blocks that appear as pprev + of another block. */ + + std::set setTips; + int32_t n = 0; + BOOST_FOREACH(const PAIRTYPE(const uint256, CBlockIndex*)& item, mapBlockIndex) { - LOCK(cs_main); - - /* Build up a list of chain tips. We start with the list of all - known blocks, and successively remove blocks that appear as pprev - of another block. */ - - std::set setTips; - int32_t n = 0; - BOOST_FOREACH(const PAIRTYPE(const uint256, CBlockIndex*)& item, mapBlockIndex) - { - fprintf(stderr,"iterator %d\n",n++); - setTips.insert(item.second); - } - BOOST_FOREACH(const PAIRTYPE(const uint256, CBlockIndex*)& item, mapBlockIndex) - { - const CBlockIndex* pprev=0; - if ( item.second != 0 ) - pprev = item.second->pprev; - if (pprev) - setTips.erase(pprev); - } - // Always report the currently active tip. - setTips.insert(chainActive.LastTip()); - - /* Construct the output array. */ - const CBlockIndex *forked; - BOOST_FOREACH(const CBlockIndex* block, setTips) - BOOST_FOREACH(const CBlockIndex* block, setTips) + n++; + setTips.insert(item.second); + } + fprintf(stderr,"iterations getchaintips %d\n",n); + n = 0; + BOOST_FOREACH(const PAIRTYPE(const uint256, CBlockIndex*)& item, mapBlockIndex) + { + const CBlockIndex* pprev=0; + n++; + if ( item.second != 0 ) + pprev = item.second->pprev; + if (pprev) + setTips.erase(pprev); + } + fprintf(stderr,"iterations getchaintips %d\n",n); + + // Always report the currently active tip. + setTips.insert(chainActive.LastTip()); + + /* Construct the output array. */ + UniValue res(UniValue::VARR); const CBlockIndex *forked; + BOOST_FOREACH(const CBlockIndex* block, setTips) + BOOST_FOREACH(const CBlockIndex* block, setTips) { UniValue obj(UniValue::VOBJ); obj.push_back(Pair("height", block->nHeight)); @@ -1449,7 +1452,7 @@ UniValue getchaintips(const UniValue& params, bool fHelp) { const int branchLen = block->nHeight - forked->nHeight; obj.push_back(Pair("branchlen", branchLen)); - + string status; if (chainActive.Contains(block)) { // This block is part of the currently active chain. @@ -1474,7 +1477,7 @@ UniValue getchaintips(const UniValue& params, bool fHelp) } res.push_back(obj); } - } + return res; } From 30ae7560030bde8432feaca53f80b080c27abc49 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 21 Sep 2018 20:50:42 -1100 Subject: [PATCH 40/48] Test --- src/rpcblockchain.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index 357b88426..b5815ee0b 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -1415,7 +1415,10 @@ UniValue getchaintips(const UniValue& params, bool fHelp) /* Build up a list of chain tips. We start with the list of all known blocks, and successively remove blocks that appear as pprev of another block. */ - + static pthread_mutex_t mutex; static int32_t didinit; + if ( didinit == 0 ) + portable_mutex_init(&mutex); + portable_mutex_lock(&mutex); std::set setTips; int32_t n = 0; BOOST_FOREACH(const PAIRTYPE(const uint256, CBlockIndex*)& item, mapBlockIndex) @@ -1435,6 +1438,7 @@ UniValue getchaintips(const UniValue& params, bool fHelp) setTips.erase(pprev); } fprintf(stderr,"iterations getchaintips %d\n",n); + portable_mutex_unlock(&mutex); // Always report the currently active tip. setTips.insert(chainActive.LastTip()); From 79d44e8ab5bbf1f5de42537f81f8e9a0489dc34c Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 21 Sep 2018 20:51:43 -1100 Subject: [PATCH 41/48] Test --- src/rpcblockchain.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index b5815ee0b..92f0c07a8 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -1377,6 +1377,8 @@ struct CompareBlocksByHeight } }; +#include + UniValue getchaintips(const UniValue& params, bool fHelp) { if (fHelp || params.size() != 0) From 3036a2412d3cd67892193d56385281e912967e26 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 21 Sep 2018 20:52:38 -1100 Subject: [PATCH 42/48] Test --- src/rpcblockchain.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index 92f0c07a8..39f62dfa1 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -1419,8 +1419,8 @@ UniValue getchaintips(const UniValue& params, bool fHelp) of another block. */ static pthread_mutex_t mutex; static int32_t didinit; if ( didinit == 0 ) - portable_mutex_init(&mutex); - portable_mutex_lock(&mutex); + pthread_mutex_init(&mutex); + pthread_mutex_lock(&mutex); std::set setTips; int32_t n = 0; BOOST_FOREACH(const PAIRTYPE(const uint256, CBlockIndex*)& item, mapBlockIndex) @@ -1440,7 +1440,7 @@ UniValue getchaintips(const UniValue& params, bool fHelp) setTips.erase(pprev); } fprintf(stderr,"iterations getchaintips %d\n",n); - portable_mutex_unlock(&mutex); + pthread_mutex_unlock(&mutex); // Always report the currently active tip. setTips.insert(chainActive.LastTip()); From 9892eb8a590907d81a83920a6775d19d42d49972 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 21 Sep 2018 20:53:44 -1100 Subject: [PATCH 43/48] Test --- src/rpcblockchain.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index 39f62dfa1..4915bd0cf 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -1419,7 +1419,7 @@ UniValue getchaintips(const UniValue& params, bool fHelp) of another block. */ static pthread_mutex_t mutex; static int32_t didinit; if ( didinit == 0 ) - pthread_mutex_init(&mutex); + pthread_mutex_init(&mutex,NULL); pthread_mutex_lock(&mutex); std::set setTips; int32_t n = 0; From 4e90a436f6547e055c92fa6965701a4e612e9746 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 21 Sep 2018 20:55:02 -1100 Subject: [PATCH 44/48] Test --- src/rpcblockchain.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index 4915bd0cf..3c4b926a2 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -1419,7 +1419,10 @@ UniValue getchaintips(const UniValue& params, bool fHelp) of another block. */ static pthread_mutex_t mutex; static int32_t didinit; if ( didinit == 0 ) + { pthread_mutex_init(&mutex,NULL); + didinit = 1; + } pthread_mutex_lock(&mutex); std::set setTips; int32_t n = 0; From 1313ac253d7ab52b94fba2cf9017227a2a44d39a Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 21 Sep 2018 20:56:23 -1100 Subject: [PATCH 45/48] Test --- src/rpcblockchain.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index 3c4b926a2..e9cf54bb4 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -1417,13 +1417,13 @@ UniValue getchaintips(const UniValue& params, bool fHelp) /* Build up a list of chain tips. We start with the list of all known blocks, and successively remove blocks that appear as pprev of another block. */ - static pthread_mutex_t mutex; static int32_t didinit; + /*static pthread_mutex_t mutex; static int32_t didinit; if ( didinit == 0 ) { pthread_mutex_init(&mutex,NULL); didinit = 1; } - pthread_mutex_lock(&mutex); + pthread_mutex_lock(&mutex);*/ std::set setTips; int32_t n = 0; BOOST_FOREACH(const PAIRTYPE(const uint256, CBlockIndex*)& item, mapBlockIndex) @@ -1443,7 +1443,7 @@ UniValue getchaintips(const UniValue& params, bool fHelp) setTips.erase(pprev); } fprintf(stderr,"iterations getchaintips %d\n",n); - pthread_mutex_unlock(&mutex); + //pthread_mutex_unlock(&mutex); // Always report the currently active tip. setTips.insert(chainActive.LastTip()); From 0c2c564c249d6333d36dc27a203aac7025e0a497 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 21 Sep 2018 23:29:00 -1100 Subject: [PATCH 46/48] ac_private to allow notary p2pk bouts --- src/komodo_notary.h | 15 +++++++++++++++ src/main.cpp | 6 +++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/komodo_notary.h b/src/komodo_notary.h index 4711a9afc..b619c5b29 100644 --- a/src/komodo_notary.h +++ b/src/komodo_notary.h @@ -198,6 +198,21 @@ const char *Notaries_elected1[][2] = {"xrobesx_NA", "03f0cc6d142d14a40937f12dbd99dbd9021328f45759e26f1877f2a838876709e1" }, }; +int32_t komodo_isnotaryvout(CScript scriptPubKey) // from ac_private chains only +{ + uint8_t pubkey33[33],*ptr = scriptPubKey.data(); int32_t i; + if ( scriptPubKey.size() == 35 && ptr[0] == 33 && ptr[34] == 0xac ) + { + for (i=0; i 0 && iscoinbase == 0) || tx.GetJoinSplitValueOut() > 0 ) - return state.DoS(100, error("CheckTransaction(): this is a private chain, no public allowed"),REJECT_INVALID, "bad-txns-acprivacy-chain"); + { + if ( komodo_isnotaryvout(txout.scriptPubKey) == 0 ) + return state.DoS(100, error("CheckTransaction(): this is a private chain, no public allowed"),REJECT_INVALID, "bad-txns-acprivacy-chain"); + } } if ( txout.scriptPubKey.size() > IGUANA_MAXSCRIPTSIZE ) return state.DoS(100, error("CheckTransaction(): txout.scriptPubKey.size() too big"),REJECT_INVALID, "bad-txns-vout-negative"); From 2682c88a7a87a7374f834a0e4077b3a2fcd38528 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 21 Sep 2018 23:30:34 -1100 Subject: [PATCH 47/48] Fix --- src/komodo_notary.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_notary.h b/src/komodo_notary.h index b619c5b29..3d22a5734 100644 --- a/src/komodo_notary.h +++ b/src/komodo_notary.h @@ -206,7 +206,7 @@ int32_t komodo_isnotaryvout(CScript scriptPubKey) // from ac_private chains only for (i=0; i Date: Fri, 21 Sep 2018 23:33:11 -1100 Subject: [PATCH 48/48] Fix --- src/komodo_notary.h | 8 ++++---- src/main.cpp | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/komodo_notary.h b/src/komodo_notary.h index 3d22a5734..942612465 100644 --- a/src/komodo_notary.h +++ b/src/komodo_notary.h @@ -198,15 +198,15 @@ const char *Notaries_elected1[][2] = {"xrobesx_NA", "03f0cc6d142d14a40937f12dbd99dbd9021328f45759e26f1877f2a838876709e1" }, }; -int32_t komodo_isnotaryvout(CScript scriptPubKey) // from ac_private chains only +int32_t komodo_isnotaryvout(uint8_t *script) // from ac_private chains only { - uint8_t pubkey33[33],*ptr = scriptPubKey.data(); int32_t i; - if ( scriptPubKey.size() == 35 && ptr[0] == 33 && ptr[34] == 0xac ) + uint8_t pubkey33[33]; int32_t i; + if ( script[0] == 33 && script[34] == 0xac ) { for (i=0; i 0 && iscoinbase == 0) || tx.GetJoinSplitValueOut() > 0 ) { - if ( komodo_isnotaryvout(txout.scriptPubKey) == 0 ) + if ( txout.scriptPubKey.size() == 35 && komodo_isnotaryvout((uint8_t *)txout.scriptPubKey.data()) == 0 ) return state.DoS(100, error("CheckTransaction(): this is a private chain, no public allowed"),REJECT_INVALID, "bad-txns-acprivacy-chain"); } }