From d082e563f3fb7eb16a9fc6863fd6cd07ebb06b85 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 22 Jul 2018 10:28:47 -1100 Subject: [PATCH] Fixes --- src/Makefile.am | 1 + src/cc/CCassets.h | 3 +- src/cc/CCassetsCore.cpp | 19 +- src/cc/CCcustom.cpp | 52 +- src/cc/CCfaucet.h | 30 + src/cc/CCinclude.h | 1 + src/cc/CCutils.cpp | 12 + src/cc/assets copy.cpp | 1242 --------------------------------------- src/cc/assets.cpp | 26 +- src/cc/eval.h | 4 +- src/cc/faucet.cpp | 132 +++++ 11 files changed, 242 insertions(+), 1280 deletions(-) create mode 100644 src/cc/CCfaucet.h delete mode 100644 src/cc/assets copy.cpp create mode 100644 src/cc/faucet.cpp diff --git a/src/Makefile.am b/src/Makefile.am index 4ff1e63c6..3baa2fde4 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -262,6 +262,7 @@ libbitcoin_server_a_SOURCES = \ cc/CCtx.cpp \ cc/CCutils.cpp \ cc/assets.cpp \ + cc/faucet.cpp \ cc/betprotocol.cpp \ chain.cpp \ checkpoints.cpp \ diff --git a/src/cc/CCassets.h b/src/cc/CCassets.h index b2eb8fa56..0c62c26d2 100644 --- a/src/cc/CCassets.h +++ b/src/cc/CCassets.h @@ -41,8 +41,7 @@ bool ValidateAssetRemainder(uint64_t remaining_price,uint64_t remaining_nValue,u bool SetAssetFillamounts(uint64_t &paid,uint64_t &remaining_price,uint64_t orig_nValue,uint64_t &received,uint64_t totalprice); uint64_t AssetValidateBuyvin(Eval* eval,uint64_t &tmpprice,std::vector &tmporigpubkey,char *CCaddr,char *origaddr,CTransaction &tx,uint256 refassetid); uint64_t AssetValidateSellvin(Eval* eval,uint64_t &tmpprice,std::vector &tmporigpubkey,char *CCaddr,char *origaddr,CTransaction &tx,uint256 assetid); -bool ConstrainAssetVout(CTxOut vout,int32_t CCflag,char *cmpaddr,uint64_t nValue); -bool AssetExactAmounts(Eval* eval,CTransaction &tx,uint256 assetid); +bool AssetExactAmounts(uint64_t &inputs,uint64_t &outputs,Eval* eval,CTransaction &tx,uint256 assetid); // CCassetstx uint64_t GetAssetBalance(CPubKey pk,uint256 tokenid); diff --git a/src/cc/CCassetsCore.cpp b/src/cc/CCassetsCore.cpp index eae6df8bf..14066f43b 100644 --- a/src/cc/CCassetsCore.cpp +++ b/src/cc/CCassetsCore.cpp @@ -135,7 +135,7 @@ bool GetAssetorigaddrs(char *CCaddr,char *destaddr,CTransaction& tx) uint64_t IsAssetvout(uint64_t &price,std::vector &origpubkey,CTransaction& tx,int32_t v,uint256 refassetid) { uint256 assetid,assetid2; uint64_t nValue=0; int32_t n; uint8_t funcid; - if ( tx.vout[v].scriptPubKey.IsPayToCryptoCondition() != 0 ) + if ( tx.vout[v].scriptPubKey.IsPayToCryptoCondition() != 0 ) // maybe check address too? { n = tx.vout.size(); nValue = tx.vout[v].nValue; @@ -277,23 +277,12 @@ uint64_t AssetValidateSellvin(Eval* eval,uint64_t &tmpprice,std::vector else return(assetoshis); } -bool ConstrainAssetVout(CTxOut vout,int32_t CCflag,char *cmpaddr,uint64_t nValue) +bool AssetExactAmounts(uint64_t &inputs,uint64_t &outputs,Eval* eval,CTransaction &tx,uint256 assetid) { - char destaddr[64]; - if ( vout.scriptPubKey.IsPayToCryptoCondition() != CCflag ) - return(false); - else if ( cmpaddr != 0 && (Getscriptaddress(destaddr,vout.scriptPubKey) == 0 || strcmp(destaddr,cmpaddr) != 0) ) - return(false); - else if ( (nValue == 0 && vout.nValue < 10000) || nValue != vout.nValue ) - return(false); - else return(true); -} - -bool AssetExactAmounts(Eval* eval,CTransaction &tx,uint256 assetid) -{ - CTransaction vinTx; uint256 hashBlock; int32_t i,numvins,numvouts; uint64_t inputs=0,outputs=0,assetoshis; std::vector tmporigpubkey; uint64_t tmpprice; + CTransaction vinTx; uint256 hashBlock; int32_t i,numvins,numvouts; uint64_t assetoshis; std::vector tmporigpubkey; uint64_t tmpprice; numvins = tx.vin.size(); numvouts = tx.vout.size(); + inputs = outputs = 0; for (i=1; icodeLength == 1 && cond->code[0] == EVAL_FAUCET; + // false for a match, true for continue + return r ? 0 : 1; + }; + CCVisitor visitor = {findEval, (uint8_t*)"", 0, NULL}; + bool out =! cc_visit(cond, visitor); + cc_free(cond); + return out; +} + CPubKey GetUnspendable(uint8_t evalcode,uint8_t *unspendablepriv) { static CPubKey nullpk; @@ -62,13 +84,20 @@ CPubKey GetUnspendable(uint8_t evalcode,uint8_t *unspendablepriv) { if ( unspendablepriv != 0 ) memcpy(unspendablepriv,AssetsCCpriv,32); - } else return(nullpk); - return(pubkey2pk(ParseHex(AssetsCChexstr))); + return(pubkey2pk(ParseHex(AssetsCChexstr))); + } + else if ( evalcode == EVAL_FAUCET ) + { + if ( unspendablepriv != 0 ) + memcpy(unspendablepriv,FaucetCCpriv,32); + return(pubkey2pk(ParseHex(FaucetCChexstr))); + } + else return(nullpk); } CC *MakeCC(uint8_t evalcode,CPubKey pk) { - if ( evalcode == EVAL_ASSETS ) + if ( evalcode == EVAL_ASSETS || evalcode == EVAL_FAUCET ) { std::vector pks; pks.push_back(CCNewSecp256k1(pk)); @@ -82,10 +111,10 @@ bool GetCCaddress(uint8_t evalcode,char *destaddr,CPubKey pk) { CC *payoutCond; destaddr[0] = 0; + if ( pk.size() == 0 ) + pk = GetUnspendable(evalcode,0); if ( evalcode == EVAL_ASSETS ) { - if ( pk.size() == 0 ) - pk = GetUnspendable(EVAL_ASSETS,0); if ( (payoutCond= MakeAssetCond(pk)) != 0 ) { Getscriptaddress(destaddr,CCPubKey(payoutCond)); @@ -93,7 +122,16 @@ bool GetCCaddress(uint8_t evalcode,char *destaddr,CPubKey pk) } return(destaddr[0] != 0); } - fprintf(stderr,"%02x is invalid evalcode\n",evalcode); + else if ( evalcode == EVAL_FAUCET ) + { + if ( (payoutCond= MakeFaucetCond(pk)) != 0 ) + { + Getscriptaddress(destaddr,CCPubKey(payoutCond)); + cc_free(payoutCond); + } + return(destaddr[0] != 0); + } + fprintf(stderr,"GetCCaddress %02x is invalid evalcode\n",evalcode); return false; } diff --git a/src/cc/CCfaucet.h b/src/cc/CCfaucet.h new file mode 100644 index 000000000..4da50591d --- /dev/null +++ b/src/cc/CCfaucet.h @@ -0,0 +1,30 @@ +/****************************************************************************** + * Copyright © 2014-2018 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + + +#ifndef CC_FAUCET_H +#define CC_FAUCET_H + +#include "CCinclude.h" + +extern const char *FaucetCCaddr = "RGKRjeTBw4LYFotSDLT6RWzMHbhXri6BG6" ;//"RFYE2yL3KknWdHK6uNhvWacYsCUtwzjY3u"; +extern char FaucetCChexstr[67] = { "02adf84e0e075cf90868bd4e3d34a03420e034719649c41f371fc70d8e33aa2702" }; + +// CCcustom +bool IsFaucetInput(CScript const& scriptSig); +CC *MakeFaucetCond(CPubKey pk); + + +#endif diff --git a/src/cc/CCinclude.h b/src/cc/CCinclude.h index 9533dc994..7793622b7 100644 --- a/src/cc/CCinclude.h +++ b/src/cc/CCinclude.h @@ -47,6 +47,7 @@ uint256 revuint256(uint256 txid); char *uint256_str(char *dest,uint256 txid); uint256 Parseuint256(char *hexstr); CPubKey pubkey2pk(std::vector pubkey); +bool ConstrainVout(CTxOut vout,int32_t CCflag,char *cmpaddr,uint64_t nValue); bool Getscriptaddress(char *destaddr,const CScript &scriptPubKey); std::vector Mypubkey(); bool Myprivkey(uint8_t myprivkey[]); diff --git a/src/cc/CCutils.cpp b/src/cc/CCutils.cpp index 7ac92a51c..b641b8813 100644 --- a/src/cc/CCutils.cpp +++ b/src/cc/CCutils.cpp @@ -84,6 +84,18 @@ bool Getscriptaddress(char *destaddr,const CScript &scriptPubKey) return(false); } +bool ConstrainVout(CTxOut vout,int32_t CCflag,char *cmpaddr,uint64_t nValue) +{ + char destaddr[64]; + if ( vout.scriptPubKey.IsPayToCryptoCondition() != CCflag ) + return(false); + else if ( cmpaddr != 0 && (Getscriptaddress(destaddr,vout.scriptPubKey) == 0 || strcmp(destaddr,cmpaddr) != 0) ) + return(false); + else if ( (nValue == 0 && vout.nValue < 10000) || nValue != vout.nValue ) + return(false); + else return(true); +} + std::vector Mypubkey() { extern uint8_t NOTARY_PUBKEY33[33]; diff --git a/src/cc/assets copy.cpp b/src/cc/assets copy.cpp deleted file mode 100644 index f823b5a1a..000000000 --- a/src/cc/assets copy.cpp +++ /dev/null @@ -1,1242 +0,0 @@ -/****************************************************************************** - * Copyright © 2014-2018 The SuperNET Developers. * - * * - * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * - * the top-level directory of this distribution for the individual copyright * - * holder information and the developer policies on copyright and licensing. * - * * - * Unless otherwise agreed in a custom licensing agreement, no part of the * - * SuperNET software, including this file may be copied, modified, propagated * - * or distributed except according to the terms contained in the LICENSE file * - * * - * Removal or modification of this copyright notice is prohibited. * - * * - ******************************************************************************/ - -#include -#include