diff --git a/src/Makefile.am b/src/Makefile.am index f9b19978b..a44839781 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -257,6 +257,17 @@ libbitcoin_server_a_SOURCES = \ bloom.cpp \ cc/eval.cpp \ cc/import.cpp \ + cc/CCassetsCore.cpp \ + cc/CCcustom.cpp \ + cc/CCtx.cpp \ + cc/CCutils.cpp \ + cc/assets.cpp \ + cc/faucet.cpp \ + cc/rewards.cpp \ + cc/dice.cpp \ + cc/lotto.cpp \ + cc/ponzi.cpp \ + cc/auction.cpp \ cc/betprotocol.cpp \ chain.cpp \ checkpoints.cpp \ @@ -333,6 +344,8 @@ libbitcoin_wallet_a_SOURCES = \ paymentdisclosuredb.cpp \ wallet/rpcdisclosure.cpp \ wallet/rpcdump.cpp \ + cc/CCassetstx.cpp \ + cc/CCtx.cpp \ wallet/rpcwallet.cpp \ wallet/wallet.cpp \ wallet/wallet_ismine.cpp \ diff --git a/src/assetchains b/src/assetchains index a204e5218..57e705d5c 100755 --- a/src/assetchains +++ b/src/assetchains @@ -1,73 +1,19 @@ #!/bin/bash +set -eo pipefail -source pubkey.txt # You can now add delay line to pubkey.txt file - -args=("$@") +source pubkey.txt +overide_args="$@" seed_ip=`getent hosts zero.kolo.supernet.org | awk '{ print $1 }'` -komodo_binary='./komodod' if [ -z "$delay" ]; then delay=20; fi -function komodo_asset () -{ - if [ $[RANDOM % 10] == 1 ] - then - gen=" -gen" - else - gen="" - fi +./listassetchainparams | while read args; do + gen="" + if [ $[RANDOM % 10] == 1 ]; then + gen=" -gen" + fi - if [ -n "$2" ] - then - supply=" -ac_supply=$2" - else - supply=" " - fi - - if [ -n "$3" ] - then - reward=" -ac_reward=$3" - else - reward=" " - fi - - $komodo_binary -ac_name=$1 $gen $supply $reward $args -pubkey=$pubkey -addnode=$seed_ip & - sleep $delay -} - -#set -x - -komodo_asset REVS 1300000 -komodo_asset SUPERNET 816061 -komodo_asset DEX 999999 -komodo_asset PANGEA 999999 -komodo_asset JUMBLR 999999 -komodo_asset BET 999999 -komodo_asset CRYPTO 999999 -komodo_asset HODL 9999999 -komodo_asset MSHARK 1400000 -komodo_asset BOTS 999999 -komodo_asset MGW 999999 -komodo_asset COQUI 72000000 -komodo_asset WLC 210000000 -komodo_asset KV 1000000 -komodo_asset CEAL 366666666 -komodo_asset MESH 1000007 -komodo_asset MNZ 257142858 -komodo_asset AXO 200000000 -komodo_asset ETOMIC 100000000 -komodo_asset BTCH 20998641 -komodo_asset PIZZA 100000000 -komodo_asset BEER 100000000 -komodo_asset NINJA 100000000 -komodo_asset OOT 216000000 -komodo_asset BNTN 500000000 -komodo_asset CHAIN 999999 -komodo_asset PRLPAY 500000000 -komodo_asset DSEC 7000000 -komodo_asset GLXT 10000000000 -komodo_asset EQL 500000000 -komodo_asset ZILLA 11000000 -komodo_asset RFOX 1000000000 100000000 -komodo_asset SEC 1000000000 + ./komodod $gen $args $overide_args -pubkey=$pubkey -addnode=$seed_ip & + sleep $delay +done diff --git a/src/assetchains.json b/src/assetchains.json new file mode 100644 index 000000000..5f0d3464f --- /dev/null +++ b/src/assetchains.json @@ -0,0 +1,136 @@ +[ + { + "ac_name": "REVS", + "ac_supply": "1300000" + }, + { + "ac_name": "SUPERNET", + "ac_supply": "816061" + }, + { + "ac_name": "DEX", + "ac_supply": "999999" + }, + { + "ac_name": "PANGEA", + "ac_supply": "999999" + }, + { + "ac_name": "JUMBLR", + "ac_supply": "999999" + }, + { + "ac_name": "BET", + "ac_supply": "999999" + }, + { + "ac_name": "CRYPTO", + "ac_supply": "999999" + }, + { + "ac_name": "HODL", + "ac_supply": "9999999" + }, + { + "ac_name": "MSHARK", + "ac_supply": "1400000" + }, + { + "ac_name": "BOTS", + "ac_supply": "999999" + }, + { + "ac_name": "MGW", + "ac_supply": "999999" + }, + { + "ac_name": "COQUI", + "ac_supply": "72000000" + }, + { + "ac_name": "WLC", + "ac_supply": "210000000" + }, + { + "ac_name": "KV", + "ac_supply": "1000000" + }, + { + "ac_name": "CEAL", + "ac_supply": "366666666" + }, + { + "ac_name": "MESH", + "ac_supply": "1000007" + }, + { + "ac_name": "MNZ", + "ac_supply": "257142858" + }, + { + "ac_name": "AXO", + "ac_supply": "200000000" + }, + { + "ac_name": "ETOMIC", + "ac_supply": "100000000" + }, + { + "ac_name": "BTCH", + "ac_supply": "20998641" + }, + { + "ac_name": "PIZZA", + "ac_supply": "100000000" + }, + { + "ac_name": "BEER", + "ac_supply": "100000000" + }, + { + "ac_name": "NINJA", + "ac_supply": "100000000" + }, + { + "ac_name": "OOT", + "ac_supply": "216000000" + }, + { + "ac_name": "BNTN", + "ac_supply": "500000000" + }, + { + "ac_name": "CHAIN", + "ac_supply": "999999" + }, + { + "ac_name": "PRLPAY", + "ac_supply": "500000000" + }, + { + "ac_name": "DSEC", + "ac_supply": "7000000" + }, + { + "ac_name": "GLXT", + "ac_supply": "10000000000" + }, + { + "ac_name": "EQL", + "ac_supply": "500000000" + }, + { + "ac_name": "ZILLA", + "ac_supply": "11000000" + }, + { + "ac_name": "RFOX", + "ac_supply": "1000000000", + "ac_reward": "100000000" + }, + { + "ac_name": "SEC", + "ac_supply": "1000000000", + "ac_cc": "333" + } +] diff --git a/src/assetchains_stop b/src/assetchains_stop index 66dd35fc0..60549dc20 100755 --- a/src/assetchains_stop +++ b/src/assetchains_stop @@ -1,41 +1,6 @@ #!/bin/bash -args=("$@") -komodo_cli='./komodo-cli' -delay=20 +set -eo pipefail -function komodo_stop () -{ - $komodo_cli --ac_name=$1 stop -} - -#set -x - -komodo_stop REVS -komodo_stop SUPERNET -komodo_stop DEX -komodo_stop PANGEA -komodo_stop JUMBLR -komodo_stop BET -komodo_stop CRYPTO -komodo_stop HODL -komodo_stop MSHARK -komodo_stop BOTS -komodo_stop MGW -komodo_stop COQUI -komodo_stop WLC -komodo_stop KV -komodo_stop CEAL -komodo_stop MESH -komodo_stop MNZ -komodo_stop AXO -komodo_stop ETOMIC -komodo_stop BTCH -komodo_stop PIZZA -komodo_stop BEER -komodo_stop NINJA -komodo_stop OOT -komodo_stop BNTN -komodo_stop CHAIN -komodo_stop PRLPAY -komodo_stop DSEC -komodo_stop SEC +./listassetchains | while read chain; do + ./komodo-cli --ac_name=$chain stop +done diff --git a/src/cc/CCassets.h b/src/cc/CCassets.h new file mode 100644 index 000000000..9a0f2a0ea --- /dev/null +++ b/src/cc/CCassets.h @@ -0,0 +1,65 @@ +/****************************************************************************** + * 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. * + * * + ******************************************************************************/ + + +/* + CCassetstx has the functions that create the EVAL_ASSETS transactions. It is expected that rpc calls would call these functions. For EVAL_ASSETS, the rpc functions are in rpcwallet.cpp + + CCassetsCore has functions that are used in two contexts, both during rpc transaction create time and also during the blockchain validation. Using the identical functions is a good way to prevent them from being mismatched. The must match or the transaction will get rejected. + */ + +#ifndef CC_ASSETS_H +#define CC_ASSETS_H + +#include "CCinclude.h" + +// CCcustom +bool AssetsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx); + +// CCassetsCore +//CTxOut MakeAssetsVout(CAmount nValue,CPubKey pk); +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); +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); +bool ValidateAskRemainder(int64_t remaining_price,int64_t remaining_nValue,int64_t orig_nValue,int64_t received_nValue,int64_t paidprice,int64_t totalprice); +bool ValidateSwapRemainder(int64_t remaining_price,int64_t remaining_nValue,int64_t orig_nValue,int64_t received_nValue,int64_t paidprice,int64_t totalprice); +bool SetBidFillamounts(int64_t &paid,int64_t &remaining_price,int64_t orig_nValue,int64_t &received,int64_t totalprice); +bool SetAskFillamounts(int64_t &paid,int64_t &remaining_price,int64_t orig_nValue,int64_t &received,int64_t totalprice); +bool SetSwapFillamounts(int64_t &paid,int64_t &remaining_price,int64_t orig_nValue,int64_t &received,int64_t totalprice); +int64_t AssetValidateBuyvin(struct CCcontract_info *cp,Eval* eval,int64_t &tmpprice,std::vector &tmporigpubkey,char *CCaddr,char *origaddr,const CTransaction &tx,uint256 refassetid); +int64_t AssetValidateSellvin(struct CCcontract_info *cp,Eval* eval,int64_t &tmpprice,std::vector &tmporigpubkey,char *CCaddr,char *origaddr,const CTransaction &tx,uint256 assetid); +bool AssetExactAmounts(struct CCcontract_info *cp,int64_t &inputs,int32_t starti,int64_t &outputs,Eval* eval,const CTransaction &tx,uint256 assetid); + +// CCassetstx +int64_t GetAssetBalance(CPubKey pk,uint256 tokenid); +int64_t AddAssetInputs(CMutableTransaction &mtx,CPubKey pk,uint256 assetid,int64_t total,int32_t maxinputs); +UniValue AssetOrders(uint256 tokenid); +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 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); +std::string CreateSell(int64_t txfee,int64_t askamount,uint256 assetid,int64_t pricetotal); +std::string CreateSwap(int64_t txfee,int64_t askamount,uint256 assetid,uint256 assetid2,int64_t pricetotal); +std::string CancelSell(int64_t txfee,uint256 assetid,uint256 asktxid); +std::string FillSell(int64_t txfee,uint256 assetid,uint256 assetid2,uint256 asktxid,int64_t fillamount); + +#endif diff --git a/src/cc/CCassetsCore.cpp b/src/cc/CCassetsCore.cpp new file mode 100644 index 000000000..da505db9c --- /dev/null +++ b/src/cc/CCassetsCore.cpp @@ -0,0 +1,478 @@ +/****************************************************************************** + * 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 "CCassets.h" + +/* + The SetAssetFillamounts() and ValidateAssetRemainder() work in tandem to calculate the vouts for a fill and to validate the vouts, respectively. + + This pair of functions are critical to make sure the trading is correct and is the trickiest part of the assets contract. + + //vin.0: normal input + //vin.1: unspendable.(vout.0 from buyoffer) buyTx.vout[0] + //vin.2+: valid CC output satisfies buyoffer (*tx.vin[2])->nValue + //vout.0: remaining amount of bid to unspendable + //vout.1: vin.1 value to signer of vin.2 + //vout.2: vin.2 assetoshis to original pubkey + //vout.3: CC output for assetoshis change (if any) + //vout.4: normal output for change (if any) + //vout.n-1: opreturn [EVAL_ASSETS] ['B'] [assetid] [remaining asset required] [origpubkey] + ValidateAssetRemainder(remaining_price,tx.vout[0].nValue,nValue,tx.vout[1].nValue,tx.vout[2].nValue,totalunits); + + Yes, this is quite confusing... + + In ValudateAssetRemainder the naming convention is nValue is the coin/asset with the offer on the books and "units" is what it is being paid in. The high level check is to make sure we didnt lose any coins or assets, the harder to validate is the actual price paid as the "orderbook" is in terms of the combined nValue for the combined totalunits. + + We assume that the effective unit cost in the orderbook is valid and that that amount was paid and also that any remainder will be close enough in effective unit cost to not matter. At the edge cases, this will probably be not true and maybe some orders wont be practically fillable when reduced to fractional state. However, the original pubkey that created the offer can always reclaim it. +*/ + +bool ValidateBidRemainder(int64_t remaining_units,int64_t remaining_nValue,int64_t orig_nValue,int64_t received_nValue,int64_t paidunits,int64_t totalunits) +{ + int64_t unitprice,recvunitprice,newunitprice=0; + if ( orig_nValue == 0 || received_nValue == 0 || paidunits == 0 || totalunits == 0 ) + { + fprintf(stderr,"ValidateAssetRemainder: orig_nValue == %llu || received_nValue == %llu || paidunits == %llu || totalunits == %llu\n",(long long)orig_nValue,(long long)received_nValue,(long long)paidunits,(long long)totalunits); + return(false); + } + else if ( totalunits != (remaining_units + paidunits) ) + { + fprintf(stderr,"ValidateAssetRemainder: totalunits %llu != %llu (remaining_units %llu + %llu paidunits)\n",(long long)totalunits,(long long)(remaining_units + paidunits),(long long)remaining_units,(long long)paidunits); + return(false); + } + else if ( orig_nValue != (remaining_nValue + received_nValue) ) + { + fprintf(stderr,"ValidateAssetRemainder: orig_nValue %llu != %llu (remaining_nValue %llu + %llu received_nValue)\n",(long long)orig_nValue,(long long)(remaining_nValue - received_nValue),(long long)remaining_nValue,(long long)received_nValue); + return(false); + } + else + { + unitprice = (orig_nValue * COIN) / totalunits; + recvunitprice = (received_nValue * COIN) / paidunits; + if ( remaining_units != 0 ) + newunitprice = (remaining_nValue * COIN) / remaining_units; + if ( recvunitprice < unitprice ) + { + fprintf(stderr,"error recvunitprice %.16f < %.16f unitprice, new unitprice %.16f\n",(double)recvunitprice/(COIN*COIN),(double)unitprice/(COIN*COIN),(double)newunitprice/(COIN*COIN)); + return(false); + } + fprintf(stderr,"orig %llu total %llu, recv %llu paid %llu,recvunitprice %.16f >= %.16f unitprice, new unitprice %.16f\n",(long long)orig_nValue,(long long)totalunits,(long long)received_nValue,(long long)paidunits,(double)recvunitprice/(COIN*COIN),(double)unitprice/(COIN*COIN),(double)newunitprice/(COIN*COIN)); + } + return(true); +} + +bool SetBidFillamounts(int64_t &received_nValue,int64_t &remaining_units,int64_t orig_nValue,int64_t &paidunits,int64_t totalunits) +{ + int64_t remaining_nValue,unitprice; double dprice; + if ( totalunits == 0 ) + { + received_nValue = remaining_units = paidunits = 0; + return(false); + } + if ( paidunits >= totalunits ) + { + paidunits = totalunits; + received_nValue = orig_nValue; + remaining_units = 0; + fprintf(stderr,"totally filled!\n"); + return(true); + } + remaining_units = (totalunits - paidunits); + unitprice = (orig_nValue * COIN) / totalunits; + received_nValue = (paidunits * unitprice) / COIN; + if ( unitprice > 0 && received_nValue > 0 && received_nValue <= orig_nValue ) + { + remaining_nValue = (orig_nValue - received_nValue); + printf("total.%llu - paid.%llu, remaining %llu <- %llu (%llu - %llu)\n",(long long)totalunits,(long long)paidunits,(long long)remaining_nValue,(long long)(orig_nValue - received_nValue),(long long)orig_nValue,(long long)received_nValue); + return(ValidateBidRemainder(remaining_units,remaining_nValue,orig_nValue,received_nValue,paidunits,totalunits)); + } else return(false); +} + +bool SetAskFillamounts(int64_t &received_assetoshis,int64_t &remaining_nValue,int64_t orig_assetoshis,int64_t &paid_nValue,int64_t total_nValue) +{ + int64_t remaining_assetoshis; double dunitprice; + if ( total_nValue == 0 ) + { + received_assetoshis = remaining_nValue = paid_nValue = 0; + return(false); + } + if ( paid_nValue >= total_nValue ) + { + paid_nValue = total_nValue; + received_assetoshis = orig_assetoshis; + remaining_nValue = 0; + fprintf(stderr,"totally filled!\n"); + return(true); + } + remaining_nValue = (total_nValue - paid_nValue); + dunitprice = ((double)total_nValue / orig_assetoshis); + received_assetoshis = (paid_nValue / dunitprice); + fprintf(stderr,"remaining_nValue %.8f (%.8f - %.8f)\n",(double)remaining_nValue/COIN,(double)total_nValue/COIN,(double)paid_nValue/COIN); + fprintf(stderr,"unitprice %.8f received_assetoshis %llu orig %llu\n",dunitprice/COIN,(long long)received_assetoshis,(long long)orig_assetoshis); + if ( fabs(dunitprice) > SMALLVAL && received_assetoshis > 0 && received_assetoshis <= orig_assetoshis ) + { + remaining_assetoshis = (orig_assetoshis - received_assetoshis); + return(ValidateAskRemainder(remaining_nValue,remaining_assetoshis,orig_assetoshis,received_assetoshis,paid_nValue,total_nValue)); + } else return(false); +} + +bool ValidateAskRemainder(int64_t remaining_nValue,int64_t remaining_assetoshis,int64_t orig_assetoshis,int64_t received_assetoshis,int64_t paid_nValue,int64_t total_nValue) +{ + int64_t unitprice,recvunitprice,newunitprice=0; + if ( orig_assetoshis == 0 || received_assetoshis == 0 || paid_nValue == 0 || total_nValue == 0 ) + { + fprintf(stderr,"ValidateAssetRemainder: orig_assetoshis == %llu || received_assetoshis == %llu || paid_nValue == %llu || total_nValue == %llu\n",(long long)orig_assetoshis,(long long)received_assetoshis,(long long)paid_nValue,(long long)total_nValue); + return(false); + } + else if ( total_nValue != (remaining_nValue + paid_nValue) ) + { + fprintf(stderr,"ValidateAssetRemainder: total_nValue %llu != %llu (remaining_nValue %llu + %llu paid_nValue)\n",(long long)total_nValue,(long long)(remaining_nValue + paid_nValue),(long long)remaining_nValue,(long long)paid_nValue); + return(false); + } + else if ( orig_assetoshis != (remaining_assetoshis + received_assetoshis) ) + { + fprintf(stderr,"ValidateAssetRemainder: orig_assetoshis %llu != %llu (remaining_nValue %llu + %llu received_nValue)\n",(long long)orig_assetoshis,(long long)(remaining_assetoshis - received_assetoshis),(long long)remaining_assetoshis,(long long)received_assetoshis); + return(false); + } + else + { + unitprice = (total_nValue / orig_assetoshis); + recvunitprice = (paid_nValue / received_assetoshis); + if ( remaining_nValue != 0 ) + newunitprice = (remaining_nValue / remaining_assetoshis); + if ( recvunitprice < unitprice ) + { + fprintf(stderr,"error recvunitprice %.8f < %.8f unitprice, new unitprice %.8f\n",(double)recvunitprice/COIN,(double)unitprice/COIN,(double)newunitprice/COIN); + return(false); + } + fprintf(stderr,"got recvunitprice %.8f >= %.8f unitprice, new unitprice %.8f\n",(double)recvunitprice/COIN,(double)unitprice/COIN,(double)newunitprice/COIN); + } + return(true); +} + +bool SetSwapFillamounts(int64_t &received_assetoshis,int64_t &remaining_assetoshis2,int64_t orig_assetoshis,int64_t &paid_assetoshis2,int64_t total_assetoshis2) +{ + int64_t remaining_assetoshis; double dunitprice; + if ( total_assetoshis2 == 0 ) + { + fprintf(stderr,"total_assetoshis2.0 origsatoshis.%llu paid_assetoshis2.%llu\n",(long long)orig_assetoshis,(long long)paid_assetoshis2); + received_assetoshis = remaining_assetoshis2 = paid_assetoshis2 = 0; + return(false); + } + if ( paid_assetoshis2 >= total_assetoshis2 ) + { + paid_assetoshis2 = total_assetoshis2; + received_assetoshis = orig_assetoshis; + remaining_assetoshis2 = 0; + fprintf(stderr,"totally filled!\n"); + return(true); + } + remaining_assetoshis2 = (total_assetoshis2 - paid_assetoshis2); + dunitprice = ((double)total_assetoshis2 / orig_assetoshis); + received_assetoshis = (paid_assetoshis2 / dunitprice); + fprintf(stderr,"remaining_assetoshis2 %llu (%llu - %llu)\n",(long long)remaining_assetoshis2/COIN,(long long)total_assetoshis2/COIN,(long long)paid_assetoshis2/COIN); + fprintf(stderr,"unitprice %.8f received_assetoshis %llu orig %llu\n",dunitprice/COIN,(long long)received_assetoshis,(long long)orig_assetoshis); + if ( fabs(dunitprice) > SMALLVAL && received_assetoshis > 0 && received_assetoshis <= orig_assetoshis ) + { + remaining_assetoshis = (orig_assetoshis - received_assetoshis); + return(ValidateAskRemainder(remaining_assetoshis2,remaining_assetoshis,orig_assetoshis,received_assetoshis,paid_assetoshis2,total_assetoshis2)); + } else return(false); +} + +bool ValidateSwapRemainder(int64_t remaining_price,int64_t remaining_nValue,int64_t orig_nValue,int64_t received_nValue,int64_t paidunits,int64_t totalunits) +{ + int64_t unitprice,recvunitprice,newunitprice=0; + if ( orig_nValue == 0 || received_nValue == 0 || paidunits == 0 || totalunits == 0 ) + { + fprintf(stderr,"ValidateAssetRemainder: orig_nValue == %llu || received_nValue == %llu || paidunits == %llu || totalunits == %llu\n",(long long)orig_nValue,(long long)received_nValue,(long long)paidunits,(long long)totalunits); + return(false); + } + else if ( totalunits != (remaining_price + paidunits) ) + { + fprintf(stderr,"ValidateAssetRemainder: totalunits %llu != %llu (remaining_price %llu + %llu paidunits)\n",(long long)totalunits,(long long)(remaining_price + paidunits),(long long)remaining_price,(long long)paidunits); + return(false); + } + else if ( orig_nValue != (remaining_nValue + received_nValue) ) + { + fprintf(stderr,"ValidateAssetRemainder: orig_nValue %llu != %llu (remaining_nValue %llu + %llu received_nValue)\n",(long long)orig_nValue,(long long)(remaining_nValue - received_nValue),(long long)remaining_nValue,(long long)received_nValue); + return(false); + } + else + { + unitprice = (orig_nValue * COIN) / totalunits; + recvunitprice = (received_nValue * COIN) / paidunits; + if ( remaining_price != 0 ) + newunitprice = (remaining_nValue * COIN) / remaining_price; + if ( recvunitprice < unitprice ) + { + fprintf(stderr,"error recvunitprice %.16f < %.16f unitprice, new unitprice %.16f\n",(double)recvunitprice/(COIN*COIN),(double)unitprice/(COIN*COIN),(double)newunitprice/(COIN*COIN)); + return(false); + } + fprintf(stderr,"recvunitprice %.16f >= %.16f unitprice, new unitprice %.16f\n",(double)recvunitprice/(COIN*COIN),(double)unitprice/(COIN*COIN),(double)newunitprice/(COIN*COIN)); + } + return(true); +} + +CScript EncodeAssetCreateOpRet(uint8_t funcid,std::vector origpubkey,std::string name,std::string description) +{ + CScript opret; uint8_t evalcode = EVAL_ASSETS; + opret << OP_RETURN << E_MARSHAL(ss << evalcode << funcid << origpubkey << name << description); + return(opret); +} + +CScript EncodeAssetOpRet(uint8_t funcid,uint256 assetid,uint256 assetid2,int64_t price,std::vector origpubkey) +{ + CScript opret; uint8_t evalcode = EVAL_ASSETS; + assetid = revuint256(assetid); + switch ( funcid ) + { + case 't': case 'x': case 'o': + opret << OP_RETURN << E_MARSHAL(ss << evalcode << funcid << assetid); + break; + case 's': case 'b': case 'S': case 'B': + opret << OP_RETURN << E_MARSHAL(ss << evalcode << funcid << assetid << price << origpubkey); + break; + case 'E': case 'e': + assetid2 = revuint256(assetid2); + opret << OP_RETURN << E_MARSHAL(ss << evalcode << funcid << assetid << assetid2 << price << origpubkey); + break; + default: + fprintf(stderr,"EncodeOpRet: illegal funcid.%02x\n",funcid); + opret << OP_RETURN; + break; + } + return(opret); +} + +bool DecodeAssetCreateOpRet(const CScript &scriptPubKey,std::vector &origpubkey,std::string &name,std::string &description) +{ + std::vector vopret; uint8_t evalcode,funcid,*script; + GetOpReturnData(scriptPubKey, vopret); + script = (uint8_t *)vopret.data(); + if ( script != 0 && vopret.size() > 2 && script[0] == EVAL_ASSETS && script[1] == 'c' ) + { + if ( E_UNMARSHAL(vopret,ss >> evalcode; ss >> funcid; ss >> origpubkey; ss >> name; ss >> description) != 0 ) + return(true); + } + return(0); +} + +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); + script = (uint8_t *)vopret.data(); + memset(&assetid,0,sizeof(assetid)); + memset(&assetid2,0,sizeof(assetid2)); + price = 0; + if ( script != 0 && script[0] == EVAL_ASSETS ) + { + funcid = script[1]; + //fprintf(stderr,"decode.[%c]\n",funcid); + switch ( funcid ) + { + case 'c': return(funcid); + break; + case 't': case 'x': case 'o': + if ( E_UNMARSHAL(vopret,ss >> e; ss >> f; ss >> assetid) != 0 ) + { + assetid = revuint256(assetid); + 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 ) + { + assetid = revuint256(assetid); + //fprintf(stderr,"got price %llu\n",(long long)price); + return(funcid); + } + break; + case 'E': case 'e': + if ( E_UNMARSHAL(vopret,ss >> e; ss >> f; ss >> assetid; ss >> assetid2; ss >> price; ss >> origpubkey) != 0 ) + { + //fprintf(stderr,"got price %llu\n",(long long)price); + assetid = revuint256(assetid); + assetid2 = revuint256(assetid2); + return(funcid); + } + break; + default: + fprintf(stderr,"DecodeAssetOpRet: illegal funcid.%02x\n",funcid); + funcid = 0; + break; + } + } + return(funcid); +} + +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 ) + 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; + n = tx.vout.size(); + 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); + else return(false); +} + +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; + if ( tx.vout[v].scriptPubKey.IsPayToCryptoCondition() != 0 ) // maybe check address too? + { + 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); + if ( v >= n-1 ) + return(0); + if ( (funcid= DecodeAssetOpRet(tx.vout[n-1].scriptPubKey,assetid,assetid2,price,origpubkey)) == 0 ) + { + fprintf(stderr,"null decodeopret\n"); + return(0); + } + else if ( funcid == 'c' ) + { + if ( refassetid == tx.GetHash() && v == 0 ) + return(nValue); + } + else if ( (funcid == 'b' || funcid == 'B') && v == 0 ) // critical! 'b'/'B' vout0 is NOT asset + return(0); + else if ( funcid != 'E' ) + { + if ( assetid == refassetid ) + return(nValue); + } + else if ( funcid == 'E' ) + { + if ( v < 2 && assetid == refassetid ) + return(nValue); + else if ( v == 2 && assetid2 == refassetid ) + return(nValue); + } + } + //fprintf(stderr,"Isassetvout: normal output v.%d %.8f\n",v,(double)tx.vout[v].nValue/COIN); + return(0); +} + +int64_t AssetValidateCCvin(struct CCcontract_info *cp,Eval* eval,char *CCaddr,char *origaddr,const CTransaction &tx,int32_t vini,CTransaction &vinTx) +{ + uint256 hashBlock; char destaddr[64]; + origaddr[0] = destaddr[0] = CCaddr[0] = 0; + if ( tx.vin.size() < 2 ) + return eval->Invalid("not enough for CC vins"); + else if ( tx.vin[vini].prevout.n != 0 ) + return eval->Invalid("vin1 needs to be buyvin.vout[0]"); + else if ( eval->GetTxUnconfirmed(tx.vin[vini].prevout.hash,vinTx,hashBlock) == 0 ) + { + int32_t z; + for (z=31; z>=0; z--) + fprintf(stderr,"%02x",((uint8_t *)&tx.vin[vini].prevout.hash)[z]); + fprintf(stderr," vini.%d\n",vini); + return eval->Invalid("always should find CCvin, but didnt"); + } + else if ( Getscriptaddress(destaddr,vinTx.vout[tx.vin[vini].prevout.n].scriptPubKey) == 0 || strcmp(destaddr,(char *)cp->unspendableCCaddr) != 0 ) + { + fprintf(stderr,"%s vs %s\n",destaddr,(char *)cp->unspendableCCaddr); + return eval->Invalid("invalid vin AssetsCCaddr"); + } + //else if ( vinTx.vout[0].nValue < 10000 ) + // return eval->Invalid("invalid dust for buyvin"); + else if ( GetAssetorigaddrs(cp,CCaddr,origaddr,vinTx) == 0 ) + return eval->Invalid("couldnt get origaddr for buyvin"); + fprintf(stderr,"Got %.8f to origaddr.(%s)\n",(double)vinTx.vout[tx.vin[vini].prevout.n].nValue/COIN,origaddr); + if ( vinTx.vout[0].nValue == 0 ) + return eval->Invalid("null value CCvin"); + return(vinTx.vout[0].nValue); +} + +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; + CCaddr[0] = origaddr[0] = 0; + if ( (nValue= AssetValidateCCvin(cp,eval,CCaddr,origaddr,tx,1,vinTx)) == 0 ) + return(0); + else if ( vinTx.vout[0].scriptPubKey.IsPayToCryptoCondition() == 0 ) + return eval->Invalid("invalid normal vout0 for buyvin"); + 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' ) + return eval->Invalid("invalid opreturn for buyvin"); + else if ( refassetid != assetid ) + return eval->Invalid("invalid assetid for buyvin"); + //int32_t i; for (i=31; i>=0; i--) + // fprintf(stderr,"%02x",((uint8_t *)&assetid)[i]); + //fprintf(stderr," AssetValidateBuyvin assetid for %s\n",origaddr); + } + return(nValue); +} + +int64_t AssetValidateSellvin(struct CCcontract_info *cp,Eval* eval,int64_t &tmpprice,std::vector &tmporigpubkey,char *CCaddr,char *origaddr,const CTransaction &tx,uint256 assetid) +{ + CTransaction vinTx; int64_t nValue,assetoshis; + fprintf(stderr,"AssetValidateSellvin\n"); + if ( (nValue= AssetValidateCCvin(cp,eval,CCaddr,origaddr,tx,1,vinTx)) == 0 ) + return(0); + if ( (assetoshis= IsAssetvout(tmpprice,tmporigpubkey,vinTx,0,assetid)) == 0 ) + return eval->Invalid("invalid missing CC vout0 for sellvin"); + else return(assetoshis); +} + +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; + numvins = tx.vin.size(); + numvouts = tx.vout.size(); + inputs = outputs = 0; + for (i=starti; iismyvin)(tx.vin[i].scriptSig) != 0 ) + { + if ( eval->GetTxUnconfirmed(tx.vin[i].prevout.hash,vinTx,hashBlock) == 0 ) + { + 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 ) + { + fprintf(stderr,"vin%d %llu, ",i,(long long)assetoshis); + inputs += assetoshis; + } + } + } + for (i=0; i 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; j 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 GetAssetBalance(CPubKey pk,uint256 tokenid) +{ + CMutableTransaction mtx; struct CCcontract_info *cp,C; + cp = CCinit(&C,EVAL_ASSETS); + return(AddAssetInputs(cp,mtx,pk,tokenid,0,0)); +} + +UniValue AssetInfo(uint256 assetid) +{ + UniValue result(UniValue::VOBJ); uint256 hashBlock; CTransaction vintx; std::vector origpubkey; std::string name,description; char str[67],numstr[65]; + if ( GetTransaction(assetid,vintx,hashBlock,false) == 0 ) + { + fprintf(stderr,"cant find assetid\n"); + result.push_back(Pair("error","cant find assetid")); + return(0); + } + if ( vintx.vout.size() > 0 && DecodeAssetCreateOpRet(vintx.vout[vintx.vout.size()-1].scriptPubKey,origpubkey,name,description) == 0 ) + { + fprintf(stderr,"assetid isnt assetcreation txid\n"); + result.push_back(Pair("error","assetid isnt assetcreation txid")); + } + result.push_back(Pair("result","success")); + result.push_back(Pair("tokenid",uint256_str(str,assetid))); + result.push_back(Pair("owner",pubkey33_str(str,origpubkey.data()))); + result.push_back(Pair("name",name)); + sprintf(numstr,"%.8f",(double)vintx.vout[0].nValue/COIN); + result.push_back(Pair("supply",numstr)); + result.push_back(Pair("description",description)); + return(result); +} + +UniValue AssetList() +{ + UniValue result(UniValue::VARR); std::vector > addressIndex; struct CCcontract_info *cp,C; uint256 txid,hashBlock; CTransaction vintx; std::vector origpubkey; std::string name,description; char str[65]; + cp = CCinit(&C,EVAL_ASSETS); + 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 && DecodeAssetCreateOpRet(vintx.vout[vintx.vout.size()-1].scriptPubKey,origpubkey,name,description) != 0 ) + { + result.push_back(uint256_str(str,txid)); + } + } + } + return(result); +} + +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; + cp = CCinit(&C,EVAL_ASSETS); + SetCCunspents(unspentOutputs,(char *)cp->unspendableCCaddr); + for (std::vector >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++) + { + 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 ( refassetid != zero && assetid != refassetid ) + { + //int32_t z; + //for (z=31; z>=0; z--) fprintf(stderr,"%02x",((uint8_t *)&txid)[z]); + //fprintf(stderr," txid\n"); + //for (z=31; z>=0; z--) fprintf(stderr,"%02x",((uint8_t *)&assetid)[z]); + //fprintf(stderr," assetid\n"); + //for (z=31; z>=0; z--) fprintf(stderr,"%02x",((uint8_t *)&refassetid)[z]); + //fprintf(stderr," refassetid\n"); + continue; + } + if ( vintx.vout[it->first.index].nValue == 0 ) + continue; + UniValue item(UniValue::VOBJ); + funcidstr[0] = funcid; + funcidstr[1] = 0; + item.push_back(Pair("funcid", funcidstr)); + item.push_back(Pair("txid", uint256_str(assetidstr,txid))); + item.push_back(Pair("vout", (int64_t)it->first.index)); + if ( funcid == 'b' || funcid == 'B' ) + { + sprintf(numstr,"%.8f",(double)vintx.vout[it->first.index].nValue/COIN); + item.push_back(Pair("amount",numstr)); + sprintf(numstr,"%.8f",(double)vintx.vout[0].nValue/COIN); + item.push_back(Pair("bidamount",numstr)); + } + else + { + sprintf(numstr,"%llu",(long long)vintx.vout[it->first.index].nValue); + item.push_back(Pair("amount",numstr)); + sprintf(numstr,"%llu",(long long)vintx.vout[0].nValue); + item.push_back(Pair("askamount",numstr)); + } + if ( origpubkey.size() == 33 ) + { + GetCCaddress(cp,origaddr,pubkey2pk(origpubkey)); + item.push_back(Pair("origaddress",origaddr)); + } + if ( assetid != zeroid ) + item.push_back(Pair("tokenid",uint256_str(assetidstr,assetid))); + if ( assetid2 != zeroid ) + item.push_back(Pair("otherid",uint256_str(assetidstr,assetid2))); + if ( price > 0 ) + { + if ( funcid == 's' || funcid == 'S' || funcid == 'e' || funcid == 'e' ) + { + sprintf(numstr,"%.8f",(double)price / COIN); + item.push_back(Pair("totalrequired", numstr)); + sprintf(numstr,"%.8f",(double)price / (COIN * vintx.vout[0].nValue)); + item.push_back(Pair("price", numstr)); + } + else + { + item.push_back(Pair("totalrequired", (int64_t)price)); + sprintf(numstr,"%.8f",(double)vintx.vout[0].nValue / (price * COIN)); + item.push_back(Pair("price",numstr)); + } + } + result.push_back(item); + //fprintf(stderr,"func.(%c) %s/v%d %.8f\n",funcid,uint256_str(assetidstr,txid),(int32_t)it->first.index,(double)vintx.vout[it->first.index].nValue/COIN); + } + } + } + return(result); +} + +std::string CreateAsset(int64_t txfee,int64_t assetsupply,std::string name,std::string description) +{ + CMutableTransaction mtx; CPubKey mypk; struct CCcontract_info *cp,C; + if ( assetsupply < 0 ) + { + fprintf(stderr,"negative assetsupply %lld\n",(long long)assetsupply); + return(0); + } + cp = CCinit(&C,EVAL_ASSETS); + if ( name.size() > 32 || description.size() > 4096 ) + { + fprintf(stderr,"name.%d or description.%d is too big\n",(int32_t)name.size(),(int32_t)description.size()); + return(0); + } + if ( txfee == 0 ) + txfee = 10000; + mypk = pubkey2pk(Mypubkey()); + if ( AddNormalinputs(mtx,mypk,assetsupply+2*txfee,64) > 0 ) + { + mtx.vout.push_back(MakeCC1vout(EVAL_ASSETS,assetsupply,mypk)); + mtx.vout.push_back(CTxOut(txfee,CScript() << ParseHex(cp->CChexstr) << OP_CHECKSIG)); + return(FinalizeCCTx(0,cp,mtx,mypk,txfee,EncodeAssetCreateOpRet('c',Mypubkey(),name,description))); + } + return(0); +} + +std::string AssetTransfer(int64_t txfee,uint256 assetid,std::vector destpubkey,int64_t total) +{ + CMutableTransaction mtx; CPubKey mypk; uint64_t mask; int64_t CCchange=0,inputs=0; struct CCcontract_info *cp,C; + if ( total < 0 ) + { + fprintf(stderr,"negative total %lld\n",(long long)total); + return(0); + } + cp = CCinit(&C,EVAL_ASSETS); + if ( txfee == 0 ) + txfee = 10000; + mypk = pubkey2pk(Mypubkey()); + if ( AddNormalinputs(mtx,mypk,txfee,1) > 0 ) + { + /*n = outputs.size(); + if ( n == amounts.size() ) + { + for (i=0; i 0 ) + { + if ( inputs > total ) + CCchange = (inputs - total); + //for (i=0; i origpubkey; std::string name,description; + if ( bidamount < 0 || pricetotal < 0 ) + { + fprintf(stderr,"negative bidamount %lld, pricetotal %lld\n",(long long)bidamount,(long long)pricetotal); + return(0); + } + if ( GetTransaction(assetid,vintx,hashBlock,false) == 0 ) + { + fprintf(stderr,"cant find assetid\n"); + return(0); + } + if ( vintx.vout.size() > 0 && DecodeAssetCreateOpRet(vintx.vout[vintx.vout.size()-1].scriptPubKey,origpubkey,name,description) == 0 ) + { + fprintf(stderr,"assetid isnt assetcreation txid\n"); + return(0); + } + cp = CCinit(&C,EVAL_ASSETS); + if ( txfee == 0 ) + txfee = 10000; + mypk = pubkey2pk(Mypubkey()); + if ( AddNormalinputs(mtx,mypk,bidamount+txfee,64) > 0 ) + { + mtx.vout.push_back(MakeCC1vout(EVAL_ASSETS,bidamount,GetUnspendable(cp,0))); + return(FinalizeCCTx(0,cp,mtx,mypk,txfee,EncodeAssetOpRet('b',assetid,zeroid,pricetotal,Mypubkey()))); + } + return(0); +} + +std::string CreateSell(int64_t txfee,int64_t askamount,uint256 assetid,int64_t pricetotal) +{ + CMutableTransaction mtx; CPubKey mypk; uint64_t mask; int64_t inputs,CCchange; CScript opret; struct CCcontract_info *cp,C; + if ( askamount < 0 || pricetotal < 0 ) + { + fprintf(stderr,"negative askamount %lld, askamount %lld\n",(long long)pricetotal,(long long)askamount); + return(0); + } + cp = CCinit(&C,EVAL_ASSETS); + if ( txfee == 0 ) + txfee = 10000; + mypk = pubkey2pk(Mypubkey()); + if ( AddNormalinputs(mtx,mypk,txfee,1) > 0 ) + { + mask = ~((1LL << mtx.vin.size()) - 1); + if ( (inputs= AddAssetInputs(cp,mtx,mypk,assetid,askamount,60)) > 0 ) + { + if ( inputs < askamount ) + askamount = inputs; + mtx.vout.push_back(MakeCC1vout(EVAL_ASSETS,askamount,GetUnspendable(cp,0))); + if ( inputs > askamount ) + CCchange = (inputs - askamount); + if ( CCchange != 0 ) + mtx.vout.push_back(MakeCC1vout(EVAL_ASSETS,CCchange,mypk)); + opret = EncodeAssetOpRet('s',assetid,zeroid,pricetotal,Mypubkey()); + return(FinalizeCCTx(mask,cp,mtx,mypk,txfee,opret)); + } else fprintf(stderr,"need some assets to place ask\n"); + } + fprintf(stderr,"need some native coins to place ask\n"); + return(0); +} + +std::string CreateSwap(int64_t txfee,int64_t askamount,uint256 assetid,uint256 assetid2,int64_t pricetotal) +{ + CMutableTransaction mtx; CPubKey mypk; uint64_t mask; int64_t inputs,CCchange; CScript opret; struct CCcontract_info *cp,C; + if ( askamount < 0 || pricetotal < 0 ) + { + fprintf(stderr,"negative askamount %lld, askamount %lld\n",(long long)pricetotal,(long long)askamount); + return(0); + } + cp = CCinit(&C,EVAL_ASSETS); + if ( txfee == 0 ) + txfee = 10000; + mypk = pubkey2pk(Mypubkey()); + if ( AddNormalinputs(mtx,mypk,txfee,1) > 0 ) + { + mask = ~((1LL << mtx.vin.size()) - 1); + if ( (inputs= AddAssetInputs(cp,mtx,mypk,assetid,askamount,60)) > 0 ) + { + if ( inputs < askamount ) + askamount = inputs; + mtx.vout.push_back(MakeCC1vout(EVAL_ASSETS,askamount,GetUnspendable(cp,0))); + if ( inputs > askamount ) + CCchange = (inputs - askamount); + if ( CCchange != 0 ) + mtx.vout.push_back(MakeCC1vout(EVAL_ASSETS,CCchange,mypk)); + if ( assetid2 == zeroid ) + opret = EncodeAssetOpRet('s',assetid,zeroid,pricetotal,Mypubkey()); + else + { + opret = EncodeAssetOpRet('e',assetid,assetid2,pricetotal,Mypubkey()); + } + return(FinalizeCCTx(mask,cp,mtx,mypk,txfee,opret)); + } else fprintf(stderr,"need some assets to place ask\n"); + } + fprintf(stderr,"need some native coins to place ask\n"); + return(0); +} + +std::string CancelBuyOffer(int64_t txfee,uint256 assetid,uint256 bidtxid) +{ + CMutableTransaction mtx; CTransaction vintx; uint64_t mask; uint256 hashBlock; int64_t bidamount; CPubKey mypk; struct CCcontract_info *cp,C; + cp = CCinit(&C,EVAL_ASSETS); + if ( txfee == 0 ) + txfee = 10000; + mypk = pubkey2pk(Mypubkey()); + if ( AddNormalinputs(mtx,mypk,txfee,1) > 0 ) + { + mask = ~((1LL << mtx.vin.size()) - 1); + if ( GetTransaction(bidtxid,vintx,hashBlock,false) != 0 ) + { + bidamount = vintx.vout[0].nValue; + mtx.vin.push_back(CTxIn(bidtxid,0,CScript())); + mtx.vout.push_back(CTxOut(bidamount,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG)); + return(FinalizeCCTx(mask,cp,mtx,mypk,txfee,EncodeAssetOpRet('o',assetid,zeroid,0,Mypubkey()))); + } + } + return(0); +} + +std::string CancelSell(int64_t txfee,uint256 assetid,uint256 asktxid) +{ + CMutableTransaction mtx; CTransaction vintx; uint64_t mask; uint256 hashBlock; int64_t askamount; CPubKey mypk; struct CCcontract_info *cp,C; + cp = CCinit(&C,EVAL_ASSETS); + if ( txfee == 0 ) + txfee = 10000; + mypk = pubkey2pk(Mypubkey()); + if ( AddNormalinputs(mtx,mypk,txfee,1) > 0 ) + { + mask = ~((1LL << mtx.vin.size()) - 1); + if ( GetTransaction(asktxid,vintx,hashBlock,false) != 0 ) + { + askamount = vintx.vout[0].nValue; + mtx.vin.push_back(CTxIn(asktxid,0,CScript())); + mtx.vout.push_back(MakeCC1vout(EVAL_ASSETS,askamount,mypk)); + return(FinalizeCCTx(mask,cp,mtx,mypk,txfee,EncodeAssetOpRet('x',assetid,zeroid,0,Mypubkey()))); + } + } + return(0); +} + +std::string FillBuyOffer(int64_t txfee,uint256 assetid,uint256 bidtxid,int64_t fillamount) +{ + CTransaction vintx; uint256 hashBlock; CMutableTransaction mtx; CPubKey mypk; std::vector origpubkey; int32_t bidvout=0; uint64_t mask; int64_t origprice,bidamount,paid_amount,remaining_required,inputs,CCchange=0; struct CCcontract_info *cp,C; + if ( fillamount < 0 ) + { + fprintf(stderr,"negative fillamount %lld\n",(long long)fillamount); + return(0); + } + cp = CCinit(&C,EVAL_ASSETS); + if ( txfee == 0 ) + txfee = 10000; + mypk = pubkey2pk(Mypubkey()); + if ( AddNormalinputs(mtx,mypk,txfee,1) > 0 ) + { + mask = ~((1LL << mtx.vin.size()) - 1); + if ( GetTransaction(bidtxid,vintx,hashBlock,false) != 0 ) + { + bidamount = vintx.vout[bidvout].nValue; + SetAssetOrigpubkey(origpubkey,origprice,vintx); + mtx.vin.push_back(CTxIn(bidtxid,bidvout,CScript())); + if ( (inputs= AddAssetInputs(cp,mtx,mypk,assetid,fillamount,60)) > 0 ) + { + if ( inputs < fillamount ) + fillamount = inputs; + SetBidFillamounts(paid_amount,remaining_required,bidamount,fillamount,origprice); + if ( inputs > fillamount ) + CCchange = (inputs - fillamount); + mtx.vout.push_back(MakeCC1vout(EVAL_ASSETS,bidamount - paid_amount,GetUnspendable(cp,0))); + mtx.vout.push_back(CTxOut(paid_amount,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG)); + mtx.vout.push_back(MakeCC1vout(EVAL_ASSETS,fillamount,pubkey2pk(origpubkey))); + if ( CCchange != 0 ) + mtx.vout.push_back(MakeCC1vout(EVAL_ASSETS,CCchange,mypk)); + fprintf(stderr,"remaining %llu -> origpubkey\n",(long long)remaining_required); + return(FinalizeCCTx(mask,cp,mtx,mypk,txfee,EncodeAssetOpRet('B',assetid,zeroid,remaining_required,origpubkey))); + } else return("dont have any assets to fill bid\n"); + } + } + return("no normal coins left"); +} + +std::string FillSell(int64_t txfee,uint256 assetid,uint256 assetid2,uint256 asktxid,int64_t fillunits) +{ + CTransaction vintx,filltx; uint256 hashBlock; CMutableTransaction mtx; CPubKey mypk; std::vector origpubkey; double dprice; uint64_t mask; int32_t askvout=0; int64_t received_assetoshis,total_nValue,orig_assetoshis,paid_nValue,remaining_nValue,inputs,CCchange=0; struct CCcontract_info *cp,C; + if ( fillunits < 0 ) + { + fprintf(stderr,"negative fillunits %lld\n",(long long)fillunits); + return(0); + } + cp = CCinit(&C,EVAL_ASSETS); + if ( txfee == 0 ) + txfee = 10000; + mypk = pubkey2pk(Mypubkey()); + if ( AddNormalinputs(mtx,mypk,txfee,1) > 0 ) + { + mask = ~((1LL << mtx.vin.size()) - 1); + if ( GetTransaction(asktxid,vintx,hashBlock,false) != 0 ) + { + orig_assetoshis = vintx.vout[askvout].nValue; + SetAssetOrigpubkey(origpubkey,total_nValue,vintx); + dprice = (double)total_nValue / orig_assetoshis; + paid_nValue = dprice * fillunits; + mtx.vin.push_back(CTxIn(asktxid,askvout,CScript())); + if ( assetid2 != zeroid ) + inputs = AddAssetInputs(cp,mtx,mypk,assetid2,paid_nValue,60); + else + { + inputs = AddNormalinputs(mtx,mypk,paid_nValue,60); + mask = ~((1LL << mtx.vin.size()) - 1); + } + if ( inputs > 0 ) + { + if ( inputs < paid_nValue ) + paid_nValue = inputs; + if ( assetid2 != zeroid ) + SetSwapFillamounts(received_assetoshis,remaining_nValue,orig_assetoshis,paid_nValue,total_nValue); + else SetAskFillamounts(received_assetoshis,remaining_nValue,orig_assetoshis,paid_nValue,total_nValue); + if ( assetid2 != zeroid && inputs > paid_nValue ) + CCchange = (inputs - paid_nValue); + mtx.vout.push_back(MakeCC1vout(EVAL_ASSETS,orig_assetoshis - received_assetoshis,GetUnspendable(cp,0))); + mtx.vout.push_back(MakeCC1vout(EVAL_ASSETS,received_assetoshis,mypk)); + mtx.vout.push_back(CTxOut(paid_nValue,CScript() << origpubkey << OP_CHECKSIG)); + if ( CCchange != 0 ) + mtx.vout.push_back(MakeCC1vout(EVAL_ASSETS,CCchange,mypk)); + return(FinalizeCCTx(mask,cp,mtx,mypk,txfee,EncodeAssetOpRet(assetid2!=zeroid?'E':'S',assetid,assetid2,remaining_nValue,origpubkey))); + } else fprintf(stderr,"filltx not enough utxos\n"); + } + } + return(0); +} diff --git a/src/cc/CCauction.h b/src/cc/CCauction.h new file mode 100644 index 000000000..52cd03d14 --- /dev/null +++ b/src/cc/CCauction.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_AUCTION_H +#define CC_AUCTION_H + +#include "CCinclude.h" + +#define EVAL_AUCTION 0xe8 + +bool AuctionValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx); + +std::string AuctionPost(uint64_t txfee,uint256 itemhash,uint64_t minbid,char *title,char *description); +std::string AuctionBid(uint64_t txfee,uint256 itemhash,uint64_t amount); +std::string AuctionDeliver(uint64_t txfee,uint256 itemhash,uint256 bidtxid); + +#endif diff --git a/src/cc/CCcustom.cpp b/src/cc/CCcustom.cpp new file mode 100644 index 000000000..2b1c83b20 --- /dev/null +++ b/src/cc/CCcustom.cpp @@ -0,0 +1,195 @@ +/****************************************************************************** + * 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 "CCinclude.h" +#include "CCassets.h" +#include "CCfaucet.h" +#include "CCrewards.h" +#include "CCdice.h" +#include "CCauction.h" +#include "CClotto.h" +#include "CCponzi.h" + +/* + CCcustom has most of the functions that need to be extended to create a new CC contract. + + A CC scriptPubKey can only be spent if it is properly signed and validated. By constraining the vins and vouts, it is possible to implement a variety of functionality. CC vouts have an otherwise non-standard form, but it is properly supported by the enhanced bitcoin protocol code as a "cryptoconditions" output and the same pubkey will create a different address. + + This allows creation of a special address(es) for each contract type, which has the privkey public. That allows anybody to properly sign and spend it, but with the constraints on what is allowed in the validation code, the contract functionality can be implemented. + + what needs to be done to add a new contract: + 1. add EVAL_CODE to eval.h + 2. initialize the variables in the CCinit function below + 3. write a Validate function to reject any unsanctioned usage of vin/vout + 4. make helper functions to create rawtx for RPC functions + 5. add rpc calls to rpcserver.cpp and rpcserver.h and in one of the rpc.cpp files + 6. add the new .cpp files to src/Makefile.am + + IMPORTANT: make sure that all CC inputs and CC outputs are properly accounted for and reconcile to the satoshi. The built in utxo management will enforce overall vin/vout constraints but it wont know anything about the CC constraints. That is what your Validate function needs to do. + + Generally speaking, there will be normal coins that change into CC outputs, CC outputs that go back to being normal coins, CC outputs that are spent to new CC outputs. + + Make sure both the CC coins and normal coins are preserved and follow the rules that make sense. It is a good idea to define specific roles for specific vins and vouts to reduce the complexity of validation. + */ + +//BTCD Address: RAssetsAtGnvwgK9gVHBbAU4sVTah1hAm5 +//BTCD Privkey: UvtvQVgVScXEYm4J3r4nE4nbFuGXSVM5pKec8VWXwgG9dmpWBuDh +//BTCD Address: RSavingsEYcivt2DFsxsKeCjqArV6oVtVZ +//BTCD Privkey: Ux6XQekTxokko6gZHz24B7PUsmUQtWFzG2W9nUA8jba7UoVbPBF4 + +// Assets, aka Tokens +#define FUNCNAME IsAssetsInput +#define EVALCODE EVAL_ASSETS +const char *AssetsCCaddr = "RGKRjeTBw4LYFotSDLT6RWzMHbhXri6BG6"; +const char *AssetsNormaladdr = "RFYE2yL3KknWdHK6uNhvWacYsCUtwzjY3u"; +char AssetsCChexstr[67] = { "02adf84e0e075cf90868bd4e3d34a03420e034719649c41f371fc70d8e33aa2702" }; +uint8_t AssetsCCpriv[32] = { 0x9b, 0x17, 0x66, 0xe5, 0x82, 0x66, 0xac, 0xb6, 0xba, 0x43, 0x83, 0x74, 0xf7, 0x63, 0x11, 0x3b, 0xf0, 0xf3, 0x50, 0x6f, 0xd9, 0x6b, 0x67, 0x85, 0xf9, 0x7a, 0xf0, 0x54, 0x4d, 0xb1, 0x30, 0x77 }; + +#include "CCcustom.inc" +#undef FUNCNAME +#undef EVALCODE + +// Faucet +#define FUNCNAME IsFaucetInput +#define EVALCODE EVAL_FAUCET +const char *FaucetCCaddr = "R9zHrofhRbub7ER77B7NrVch3A63R39GuC"; +const char *FaucetNormaladdr = "RKQV4oYs4rvxAWx1J43VnT73rSTVtUeckk"; +char FaucetCChexstr[67] = { "03682b255c40d0cde8faee381a1a50bbb89980ff24539cb8518e294d3a63cefe12" }; +uint8_t FaucetCCpriv[32] = { 0xd4, 0x4f, 0xf2, 0x31, 0x71, 0x7d, 0x28, 0x02, 0x4b, 0xc7, 0xdd, 0x71, 0xa0, 0x39, 0xc4, 0xbe, 0x1a, 0xfe, 0xeb, 0xc2, 0x46, 0xda, 0x76, 0xf8, 0x07, 0x53, 0x3d, 0x96, 0xb4, 0xca, 0xa0, 0xe9 }; + +#include "CCcustom.inc" +#undef FUNCNAME +#undef EVALCODE + +// Rewards +#define FUNCNAME IsRewardsInput +#define EVALCODE EVAL_REWARDS +const char *RewardsCCaddr = "RTsRBYL1HSvMoE3qtBJkyiswdVaWkm8YTK"; +const char *RewardsNormaladdr = "RMgye9jeczNjQx9Uzq8no8pTLiCSwuHwkz"; +char RewardsCChexstr[67] = { "03da60379d924c2c30ac290d2a86c2ead128cb7bd571f69211cb95356e2dcc5eb9" }; +uint8_t RewardsCCpriv[32] = { 0x82, 0xf5, 0xd2, 0xe7, 0xd6, 0x99, 0x33, 0x77, 0xfb, 0x80, 0x00, 0x97, 0x23, 0x3d, 0x1e, 0x6f, 0x61, 0xa9, 0xb5, 0x2e, 0x5e, 0xb4, 0x96, 0x6f, 0xbc, 0xed, 0x6b, 0xe2, 0xbb, 0x7b, 0x4b, 0xb3 }; +#include "CCcustom.inc" +#undef FUNCNAME +#undef EVALCODE + +// Dice +#define FUNCNAME IsDiceInput +#define EVALCODE EVAL_DICE +const char *DiceCCaddr = "REabWB7KjFN5C3LFMZ5odExHPenYzHLtVw"; +const char *DiceNormaladdr = "RLEe8f7Eg3TDuXii9BmNiiiaVGraHUt25c"; +char DiceCChexstr[67] = { "039d966927cfdadab3ee6c56da63c21f17ea753dde4b3dfd41487103e24b27e94e" }; +uint8_t DiceCCpriv[32] = { 0x0e, 0xe8, 0xf5, 0xb4, 0x3d, 0x25, 0xcc, 0x35, 0xd1, 0xf1, 0x2f, 0x04, 0x5f, 0x01, 0x26, 0xb8, 0xd1, 0xac, 0x3a, 0x5a, 0xea, 0xe0, 0x25, 0xa2, 0x8f, 0x2a, 0x8e, 0x0e, 0xf9, 0x34, 0xfa, 0x77 }; +#include "CCcustom.inc" +#undef FUNCNAME +#undef EVALCODE + +// Lotto +#define FUNCNAME IsLottoInput +#define EVALCODE EVAL_LOTTO +const char *LottoCCaddr = "RNXZxgyWSAE6XS3qGnTaf5dVNCxnYzhPrg"; +const char *LottoNormaladdr = "RLW6hhRqBZZMBndnyPv29Yg3krh6iBYCyg"; +char LottoCChexstr[67] = { "03f72d2c4db440df1e706502b09ca5fec73ffe954ea1883e4049e98da68690d98f" }; +uint8_t LottoCCpriv[32] = { 0xb4, 0xac, 0xc2, 0xd9, 0x67, 0x34, 0xd7, 0x58, 0x80, 0x4e, 0x25, 0x55, 0xc0, 0x50, 0x66, 0x84, 0xbb, 0xa2, 0xe7, 0xc0, 0x39, 0x17, 0xb4, 0xc5, 0x07, 0xb7, 0x3f, 0xca, 0x07, 0xb0, 0x9a, 0xeb }; +#include "CCcustom.inc" +#undef FUNCNAME +#undef EVALCODE + +// Ponzi +#define FUNCNAME IsPonziInput +#define EVALCODE EVAL_PONZI +const char *PonziCCaddr = "RUKTbLBeKgHkm3Ss4hKZP3ikuLW1xx7B2x"; +const char *PonziNormaladdr = "RWSHRbxnJYLvDjpcQ2i8MekgP6h2ctTKaj"; +char PonziCChexstr[67] = { "039b52d294b413b07f3643c1a28c5467901a76562d8b39a785910ae0a0f3043810" }; +uint8_t PonziCCpriv[32] = { 0x11, 0xe1, 0xea, 0x3e, 0xdb, 0x36, 0xf0, 0xa8, 0xc6, 0x34, 0xe1, 0x21, 0xb8, 0x02, 0xb9, 0x4b, 0x12, 0x37, 0x8f, 0xa0, 0x86, 0x23, 0x50, 0xb2, 0x5f, 0xe4, 0xe7, 0x36, 0x0f, 0xda, 0xae, 0xfc }; +#include "CCcustom.inc" +#undef FUNCNAME +#undef EVALCODE + +// Auction +#define FUNCNAME IsAuctionInput +#define EVALCODE EVAL_AUCTION +const char *AuctionCCaddr = "RL4YPX7JYG3FnvoPqWF2pn3nQknH5NWEwx"; +const char *AuctionNormaladdr = "RFtVDNmdTZBTNZdmFRbfBgJ6LitgTghikL"; +char AuctionCChexstr[67] = { "037eefe050c14cb60ae65d5b2f69eaa1c9006826d729bc0957bdc3024e3ca1dbe6" }; +uint8_t AuctionCCpriv[32] = { 0x8c, 0x1b, 0xb7, 0x8c, 0x02, 0xa3, 0x9d, 0x21, 0x28, 0x59, 0xf5, 0xea, 0xda, 0xec, 0x0d, 0x11, 0xcd, 0x38, 0x47, 0xac, 0x0b, 0x6f, 0x19, 0xc0, 0x24, 0x36, 0xbf, 0x1c, 0x0a, 0x06, 0x31, 0xfb }; +#include "CCcustom.inc" +#undef FUNCNAME +#undef EVALCODE + +struct CCcontract_info *CCinit(struct CCcontract_info *cp,uint8_t evalcode) +{ + cp->evalcode = evalcode; + switch ( evalcode ) + { + case EVAL_ASSETS: + strcpy(cp->unspendableCCaddr,AssetsCCaddr); + strcpy(cp->normaladdr,AssetsNormaladdr); + strcpy(cp->CChexstr,AssetsCChexstr); + memcpy(cp->CCpriv,AssetsCCpriv,32); + cp->validate = AssetsValidate; + cp->ismyvin = IsAssetsInput; + break; + case EVAL_FAUCET: + strcpy(cp->unspendableCCaddr,FaucetCCaddr); + strcpy(cp->normaladdr,FaucetNormaladdr); + strcpy(cp->CChexstr,FaucetCChexstr); + memcpy(cp->CCpriv,FaucetCCpriv,32); + cp->validate = FaucetValidate; + cp->ismyvin = IsFaucetInput; + break; + case EVAL_REWARDS: + strcpy(cp->unspendableCCaddr,RewardsCCaddr); + strcpy(cp->normaladdr,RewardsNormaladdr); + strcpy(cp->CChexstr,RewardsCChexstr); + memcpy(cp->CCpriv,RewardsCCpriv,32); + cp->validate = RewardsValidate; + cp->ismyvin = IsRewardsInput; + break; + case EVAL_DICE: + strcpy(cp->unspendableCCaddr,DiceCCaddr); + strcpy(cp->normaladdr,DiceNormaladdr); + strcpy(cp->CChexstr,DiceCChexstr); + memcpy(cp->CCpriv,DiceCCpriv,32); + cp->validate = DiceValidate; + cp->ismyvin = IsDiceInput; + break; + case EVAL_LOTTO: + strcpy(cp->unspendableCCaddr,LottoCCaddr); + strcpy(cp->normaladdr,LottoNormaladdr); + strcpy(cp->CChexstr,LottoCChexstr); + memcpy(cp->CCpriv,LottoCCpriv,32); + cp->validate = LottoValidate; + cp->ismyvin = IsLottoInput; + break; + case EVAL_PONZI: + strcpy(cp->unspendableCCaddr,PonziCCaddr); + strcpy(cp->normaladdr,PonziNormaladdr); + strcpy(cp->CChexstr,PonziCChexstr); + memcpy(cp->CCpriv,PonziCCpriv,32); + cp->validate = PonziValidate; + cp->ismyvin = IsPonziInput; + break; + case EVAL_AUCTION: + strcpy(cp->unspendableCCaddr,AuctionCCaddr); + strcpy(cp->normaladdr,AuctionNormaladdr); + strcpy(cp->CChexstr,AuctionCChexstr); + memcpy(cp->CCpriv,AuctionCCpriv,32); + cp->validate = AuctionValidate; + cp->ismyvin = IsAuctionInput; + break; + } + return(cp); +} + diff --git a/src/cc/CCcustom.inc b/src/cc/CCcustom.inc new file mode 100644 index 000000000..c33ca4f5b --- /dev/null +++ b/src/cc/CCcustom.inc @@ -0,0 +1,17 @@ + +bool FUNCNAME(CScript const& scriptSig) +{ + CC *cond; + if (!(cond = GetCryptoCondition(scriptSig))) + return false; + // Recurse the CC tree to find asset condition + auto findEval = [] (CC *cond, struct CCVisitor _) { + bool r = cc_typeId(cond) == CC_Eval && cond->codeLength == 1 && cond->code[0] == EVALCODE; + // 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; +} diff --git a/src/cc/CCdice.h b/src/cc/CCdice.h new file mode 100644 index 000000000..23adb0ffb --- /dev/null +++ b/src/cc/CCdice.h @@ -0,0 +1,32 @@ +/****************************************************************************** + * 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_DICE_H +#define CC_DICE_H + +#include "CCinclude.h" + +#define EVAL_DICE 0xe6 + +bool DiceValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx); + +std::string DiceBet(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t bet,int32_t odds); +std::string DiceCreateFunding(uint64_t txfee,char *planstr,int64_t funds,int64_t minbet,int64_t maxbet,int64_t maxodds,int64_t forfeitblocks); +std::string DiceAddfunding(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t amount); +UniValue DiceInfo(uint256 diceid); +UniValue DiceList(); + +#endif diff --git a/src/cc/CCfaucet.h b/src/cc/CCfaucet.h new file mode 100644 index 000000000..b478165b5 --- /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" + +#define EVAL_FAUCET 0xe4 + +bool FaucetValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx); + +// CCcustom +std::string FaucetFund(uint64_t txfee,uint64_t funds); +std::string FaucetGet(uint64_t txfee); + +#endif diff --git a/src/cc/CCinclude.h b/src/cc/CCinclude.h new file mode 100644 index 000000000..b7186e317 --- /dev/null +++ b/src/cc/CCinclude.h @@ -0,0 +1,82 @@ +/****************************************************************************** + * 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_INCLUDE_H +#define CC_INCLUDE_H + +#include +#include