CCcontract_info

This commit is contained in:
jl777
2018-07-24 00:05:30 -11:00
parent 4a4ab6c76b
commit 287efad431
13 changed files with 135 additions and 170 deletions

View File

@@ -25,10 +25,8 @@
#include "CCinclude.h" #include "CCinclude.h"
extern const char *AssetsCCaddr;
extern char AssetsCChexstr[67];
// CCcustom // CCcustom
bool IsAssetsInput(CScript const& scriptSig); bool AssetsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx);
// CCassetsCore // CCassetsCore
//CTxOut MakeAssetsVout(CAmount nValue,CPubKey pk); //CTxOut MakeAssetsVout(CAmount nValue,CPubKey pk);

View File

@@ -14,22 +14,20 @@
******************************************************************************/ ******************************************************************************/
#include "CCinclude.h" #include "CCinclude.h"
#include "CCassets.h"
#include "CCfaucet.h"
#include "CCrewards.h"
/* /*
CCcustom has most of the functions that need to be extended to create a new CC contract. CCcustom has most of the functions that need to be extended to create a new CC contract.
EVAL_CONTRACT is the naming convention and it should be added to cc/eval.h EVAL_CONTRACT is the naming convention and it should be added to cc/eval.h
bool Eval::Dispatch() in cc/eval.h needs to add the validation function in the switch
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. 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. 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.
*/ */
//CC *MakeAssetCond(CPubKey pk);
//CC *MakeFaucetCond(CPubKey pk);
//CC *MakeRewardsCond(CPubKey pk);
//BTCD Address: RAssetsAtGnvwgK9gVHBbAU4sVTah1hAm5 //BTCD Address: RAssetsAtGnvwgK9gVHBbAU4sVTah1hAm5
//BTCD Privkey: UvtvQVgVScXEYm4J3r4nE4nbFuGXSVM5pKec8VWXwgG9dmpWBuDh //BTCD Privkey: UvtvQVgVScXEYm4J3r4nE4nbFuGXSVM5pKec8VWXwgG9dmpWBuDh
//BTCD Address: RSavingsEYcivt2DFsxsKeCjqArV6oVtVZ //BTCD Address: RSavingsEYcivt2DFsxsKeCjqArV6oVtVZ
@@ -67,82 +65,33 @@ uint8_t RewardsCCpriv[32] = { 0x9f, 0x0c, 0x57, 0xdc, 0x6f, 0x78, 0xae, 0xb0, 0x
#undef FUNCNAME #undef FUNCNAME
#undef EVALCODE #undef EVALCODE
/*bool IsAssetsInput(CScript const& scriptSig) struct CCcontract_info *CCinit(struct CCcontract_info *cp,uint8_t evalcode)
{ {
CC *cond; cp->evalcode = evalcode;
if (!(cond = GetCryptoCondition(scriptSig))) switch ( evalcode )
return false; {
// Recurse the CC tree to find asset condition case EVAL_ASSETS:
auto findEval = [&] (CC *cond, struct CCVisitor _) { strcpy(cp->CCaddress,AssetsCCaddr);
bool r = cc_typeId(cond) == CC_Eval && cond->codeLength == 1 && cond->code[0] == EVAL_ASSETS; strcpy(cp->CChexstr,AssetsCChexstr);
// false for a match, true for continue memcpy(cp->CCpriv,AssetsCCpriv,32);
return r ? 0 : 1; cp->validate = AssetsValidate;
}; cp->ismyvin = IsAssetsInput;
CCVisitor visitor = {findEval, (uint8_t*)"", 0, NULL}; break;
bool out =! cc_visit(cond, visitor); case EVAL_FAUCET:
cc_free(cond); strcpy(cp->CCaddress,FaucetCCaddr);
return out; strcpy(cp->CChexstr,FaucetCChexstr);
} memcpy(cp->CCpriv,FaucetCCpriv,32);
cp->validate = FaucetValidate;
bool IsFaucetInput(CScript const& scriptSig) cp->ismyvin = IsFaucetInput;
{ break;
CC *cond; case EVAL_REWARDS:
if (!(cond = GetCryptoCondition(scriptSig))) strcpy(cp->CCaddress,RewardsCCaddr);
return false; strcpy(cp->CChexstr,RewardsCChexstr);
// Recurse the CC tree to find asset condition memcpy(cp->CCpriv,RewardsCCpriv,32);
auto findEval = [&] (CC *cond, struct CCVisitor _) { cp->validate = RewardsValidate;
bool r = cc_typeId(cond) == CC_Eval && cond->codeLength == 1 && cond->code[0] == EVAL_FAUCET; cp->ismyvin = IsRewardsInput;
// false for a match, true for continue break;
return r ? 0 : 1; }
}; return(cp);
CCVisitor visitor = {findEval, (uint8_t*)"", 0, NULL};
bool out =! cc_visit(cond, visitor);
cc_free(cond);
return out;
}
bool IsRewardsInput(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] == EVAL_REWARDS;
// 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;
}*/
uint64_t AddFaucetInputs(CMutableTransaction &mtx,CPubKey pk,uint64_t total,int32_t maxinputs);
CPubKey GetUnspendable(uint8_t evalcode,uint8_t *unspendablepriv)
{
static CPubKey nullpk;
if ( unspendablepriv != 0 )
memset(unspendablepriv,0,32);
if ( evalcode == EVAL_ASSETS )
{
if ( unspendablepriv != 0 )
memcpy(unspendablepriv,AssetsCCpriv,32);
return(pubkey2pk(ParseHex(AssetsCChexstr)));
}
else if ( evalcode == EVAL_FAUCET )
{
if ( unspendablepriv != 0 )
memcpy(unspendablepriv,FaucetCCpriv,32);
return(pubkey2pk(ParseHex(FaucetCChexstr)));
}
else if ( evalcode == EVAL_REWARDS )
{
if ( unspendablepriv != 0 )
memcpy(unspendablepriv,RewardsCCpriv,32);
return(pubkey2pk(ParseHex(RewardsCChexstr)));
}
else return(nullpk);
} }

View File

@@ -15,4 +15,3 @@ bool FUNCNAME(CScript const& scriptSig)
cc_free(cond); cc_free(cond);
return out; return out;
} }

View File

@@ -21,11 +21,9 @@
#define EVAL_FAUCET 0xe4 #define EVAL_FAUCET 0xe4
extern const char *FaucetCCaddr; bool FaucetValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx);
extern char FaucetCChexstr[67];
// CCcustom // CCcustom
bool IsFaucetInput(CScript const& scriptSig);
std::string FaucetFund(uint64_t txfee,uint64_t funds); std::string FaucetFund(uint64_t txfee,uint64_t funds);
std::string FaucetGet(uint64_t txfee); std::string FaucetGet(uint64_t txfee);

View File

@@ -28,6 +28,16 @@
#include <univalue.h> #include <univalue.h>
#include <exception> #include <exception>
struct CCcontract_info
{
char CCaddress[64],CChexstr[72];
uint8_t CCpriv[32];
bool (*validate)(Eval* eval,struct CCcontract_info *cp,const CTransaction &tx);
bool (*ismyvin)(CScript const& scriptSig);
uint8_t evalcode;
};
struct CCcontract_info *CCinit(struct CCcontract_info *cp,uint8_t evalcode);
#ifdef ENABLE_WALLET #ifdef ENABLE_WALLET
extern CWallet* pwalletMain; extern CWallet* pwalletMain;
#endif #endif

30
src/cc/CCrewards.h Normal file
View File

@@ -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_REWARDS_H
#define CC_REWARDS_H
#include "CCinclude.h"
#define EVAL_REWARDS 0xe5
bool RewardsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx);
std::string RewardsFund(uint64_t txfee,uint64_t funds,uint64_t APR,uint64_t minseconds,uint64_t maxseconds,uint64_t mindeposit);
std::string RewardsLock(uint64_t txfee,uint64_t amount);
std::string RewardsUnlock(uint64_t txfee);
#endif

View File

@@ -207,3 +207,31 @@ bool Myprivkey(uint8_t myprivkey[])
return(false); return(false);
} }
CPubKey GetUnspendable(struct CCcontract_info *cp,uint8_t *unspendablepriv)
{
if ( unspendablepriv != 0 )
memcpy(unspendablepriv,cp->CCpriv,32);
return(pubkey2pk(ParseHex(cp->CChexstr)));
}
bool ProcessCC(struct CCcontract_info *cp,Eval* eval, std::vector<uint8_t> paramsNull,const CTransaction &ctx, unsigned int nIn)
{
CTransaction createTx; uint256 txid,assetid,assetid2,hashBlock; uint8_t funcid; int32_t i,n; uint64_t amount; std::vector<uint8_t> origpubkey;
txid = ctx.GetHash();
if ( txid == cp->prevtxid )
return(true);
if ( paramsNull.size() != 0 ) // Don't expect params
return eval->Invalid("Cannot have params");
else if ( ctx.vout.size() == 0 )
return eval->Invalid("no-vouts");
else if ( (*cp->validate)(cp,eval,ctx) != 0 )
{
cp->prevtxid = txid;
return(true);
}
return(false);
}
uint64_t AddFaucetInputs(CMutableTransaction &mtx,CPubKey pk,uint64_t total,int32_t maxinputs);

View File

@@ -129,15 +129,22 @@
vout.n-1: opreturn [EVAL_ASSETS] ['E'] [assetid vin0+1] [assetid vin2] [remaining asset2 required] [origpubkey] vout.n-1: opreturn [EVAL_ASSETS] ['E'] [assetid vin0+1] [assetid vin2] [remaining asset2 required] [origpubkey]
*/ */
bool AssetValidate(Eval* eval,const CTransaction &tx,int32_t numvouts,uint8_t funcid,uint256 assetid,uint256 assetid2,uint64_t remaining_price,std::vector<uint8_t> origpubkey) bool AssetsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx)
{ {
static uint256 zero; static uint256 zero;
CTxDestination address; const CTransaction vinTx; uint256 hashBlock; int32_t i,starti,numvins,preventCCvins,preventCCvouts; uint64_t nValue,assetoshis,outputs,inputs,tmpprice,totalunits,ignore; std::vector<uint8_t> tmporigpubkey,ignorepubkey; char destaddr[64],origaddr[64],CCaddr[64]; CTxDestination address; const CTransaction vinTx; uint256 hashBlock,assetid,assetid2; int32_t i,starti,numvins,numvouts,preventCCvins,preventCCvouts; uint64_t remaining_price,nValue,assetoshis,outputs,inputs,tmpprice,totalunits,ignore; std::vector<uint8_t> origpubkey,tmporigpubkey,ignorepubkey; uint8_t funcid; char destaddr[64],origaddr[64],CCaddr[64];
fprintf(stderr,"AssetValidate (%c)\n",funcid);
numvins = tx.vin.size(); numvins = tx.vin.size();
numvouts = tx.vout.size();
outputs = inputs = 0; outputs = inputs = 0;
preventCCvins = preventCCvouts = -1; preventCCvins = preventCCvouts = -1;
if ( IsCCInput(tx.vin[0].scriptSig) != 0 ) if ( (funcid= DecodeAssetOpRet(ctx.vout[n-1].scriptPubKey,assetid,assetid2,amount,origpubkey)) == 0 )
return eval->Invalid("Invalid opreturn payload");
fprintf(stderr,"AssetValidate (%c)\n",funcid);
if ( eval->GetTxUnconfirmed(assetid,createTx,hashBlock) == 0 )
return eval->Invalid("cant find asset create txid");
else if ( assetid2 != zero && eval->GetTxUnconfirmed(assetid2,createTx,hashBlock) == 0 )
return eval->Invalid("cant find asset2 create txid");
else if ( IsCCInput(tx.vin[0].scriptSig) != 0 )
return eval->Invalid("illegal asset vin0"); return eval->Invalid("illegal asset vin0");
else if ( numvouts < 1 ) else if ( numvouts < 1 )
return eval->Invalid("no vouts"); return eval->Invalid("no vouts");
@@ -314,31 +321,4 @@ bool AssetValidate(Eval* eval,const CTransaction &tx,int32_t numvouts,uint8_t fu
return(PreventCC(eval,tx,preventCCvins,numvins,preventCCvouts,numvouts)); return(PreventCC(eval,tx,preventCCvins,numvins,preventCCvouts,numvouts));
} }
bool ProcessAssets(Eval* eval, std::vector<uint8_t> paramsNull,const CTransaction &ctx, unsigned int nIn)
{
static uint256 zero,prevtxid;
CTransaction createTx; uint256 txid,assetid,assetid2,hashBlock; uint8_t funcid; int32_t i,n; uint64_t amount; std::vector<uint8_t> origpubkey;
txid = ctx.GetHash();
if ( txid == prevtxid )
return(true);
fprintf(stderr,"ProcessAssets\n");
if ( paramsNull.size() != 0 ) // Don't expect params
return eval->Invalid("Cannot have params");
else if ( (n= ctx.vout.size()) == 0 )
return eval->Invalid("no-vouts");
else if ( (funcid= DecodeAssetOpRet(ctx.vout[n-1].scriptPubKey,assetid,assetid2,amount,origpubkey)) == 0 )
return eval->Invalid("Invalid opreturn payload");
else if ( eval->GetTxUnconfirmed(assetid,createTx,hashBlock) == 0 )
return eval->Invalid("cant find asset create txid");
else if ( assetid2 != zero && eval->GetTxUnconfirmed(assetid2,createTx,hashBlock) == 0 )
return eval->Invalid("cant find asset2 create txid");
else if ( AssetValidate(eval,ctx,n,funcid,assetid,assetid2,amount,origpubkey) != 0 )
{
prevtxid = txid;
fprintf(stderr,"AssetValidate.(%c) passed\n",funcid);
return(true);
}
fprintf(stderr,"AssetValidate.(%c) failed\n",funcid);
return(false);
}

View File

@@ -21,6 +21,7 @@
#include "script/cc.h" #include "script/cc.h"
#include "cc/eval.h" #include "cc/eval.h"
#include "cc/utils.h" #include "cc/utils.h"
#include "cc/CCutils.h"
#include "main.h" #include "main.h"
#include "chain.h" #include "chain.h"
#include "core_io.h" #include "core_io.h"
@@ -28,12 +29,11 @@
Eval* EVAL_TEST = 0; Eval* EVAL_TEST = 0;
struct CCcontract_info CCinfos[0x100];
bool RunCCEval(const CC *cond, const CTransaction &tx, unsigned int nIn) bool RunCCEval(const CC *cond, const CTransaction &tx, unsigned int nIn)
{ {
EvalRef eval; EvalRef eval;
bool out = eval->Dispatch(cond, tx, nIn); bool out = eval->Dispatch(cond, tx, nIn);
//fprintf(stderr,"out %d vs %d isValid\n",(int32_t)out,(int32_t)eval->state.IsValid()); //fprintf(stderr,"out %d vs %d isValid\n",(int32_t)out,(int32_t)eval->state.IsValid());
assert(eval->state.IsValid() == out); assert(eval->state.IsValid() == out);
@@ -56,10 +56,17 @@ bool RunCCEval(const CC *cond, const CTransaction &tx, unsigned int nIn)
*/ */
bool Eval::Dispatch(const CC *cond, const CTransaction &txTo, unsigned int nIn) bool Eval::Dispatch(const CC *cond, const CTransaction &txTo, unsigned int nIn)
{ {
struct CCcontract_info *cp;
if (cond->codeLength == 0) if (cond->codeLength == 0)
return Invalid("empty-eval"); return Invalid("empty-eval");
uint8_t ecode = cond->code[0]; uint8_t ecode = cond->code[0];
cp = &CCinfos[(int32_t)ecode];
if ( cp->didinit == 0 )
{
CCinit(cp,ecode);
cp->didinit = 1;
}
std::vector<uint8_t> vparams(cond->code+1, cond->code+cond->codeLength); std::vector<uint8_t> vparams(cond->code+1, cond->code+cond->codeLength);
switch ( ecode ) switch ( ecode )
{ {
@@ -71,16 +78,8 @@ bool Eval::Dispatch(const CC *cond, const CTransaction &txTo, unsigned int nIn)
return ImportCoin(vparams, txTo, nIn); return ImportCoin(vparams, txTo, nIn);
break; break;
case EVAL_ASSETS: default:
return ProcessAssets(this, vparams, txTo, nIn); return(ProcessCC(cp,this, vparams, txTo, nIn));
break;
case EVAL_FAUCET:
return ProcessFaucet(this, vparams, txTo, nIn);
break;
case EVAL_REWARDS:
return ProcessRewards(this, vparams, txTo, nIn);
break; break;
} }
return Invalid("invalid-code, dont forget to add EVAL_NEWCC to Eval::Dispatch"); return Invalid("invalid-code, dont forget to add EVAL_NEWCC to Eval::Dispatch");

View File

@@ -268,9 +268,8 @@ typedef std::pair<uint256,MerkleBranch> TxProof;
uint256 GetMerkleRoot(const std::vector<uint256>& vLeaves); uint256 GetMerkleRoot(const std::vector<uint256>& vLeaves);
bool ProcessAssets(Eval* eval, std::vector<uint8_t> paramsNull, const CTransaction &tx, unsigned int nIn); void CCinit(struct CCcontract_info *cp,uint8_t evalcode);
bool ProcessFaucet(Eval* eval, std::vector<uint8_t> paramsNull, const CTransaction &tx, unsigned int nIn); bool ProcessCC(struct CCcontract_info *cp,Eval* eval, std::vector<uint8_t> paramsNull, const CTransaction &tx, unsigned int nIn);
bool ProcessRewards(Eval* eval, std::vector<uint8_t> paramsNull, const CTransaction &tx, unsigned int nIn);
#endif /* CC_EVAL_H */ #endif /* CC_EVAL_H */

View File

@@ -37,7 +37,7 @@ uint64_t IsFaucetvout(const CTransaction& tx,int32_t v)
return(0); return(0);
} }
bool FaucetExactAmounts(Eval* eval,const CTransaction &tx,int32_t minage,uint64_t txfee) bool FaucetExactAmounts(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx,int32_t minage,uint64_t txfee)
{ {
static uint256 zerohash; static uint256 zerohash;
CTransaction vinTx; uint256 hashBlock,activehash; int32_t i,numvins,numvouts; uint64_t inputs=0,outputs=0,assetoshis; CTransaction vinTx; uint256 hashBlock,activehash; int32_t i,numvins,numvouts; uint64_t inputs=0,outputs=0,assetoshis;
@@ -46,7 +46,7 @@ bool FaucetExactAmounts(Eval* eval,const CTransaction &tx,int32_t minage,uint64_
for (i=0; i<numvins; i++) for (i=0; i<numvins; i++)
{ {
//fprintf(stderr,"vini.%d\n",i); //fprintf(stderr,"vini.%d\n",i);
if ( IsFaucetInput(tx.vin[i].scriptSig) != 0 ) if ( (*cp->ismyvin)(tx.vin[i].scriptSig) != 0 )
{ {
//fprintf(stderr,"vini.%d check mempool\n",i); //fprintf(stderr,"vini.%d check mempool\n",i);
if ( eval->GetTxUnconfirmed(tx.vin[i].prevout.hash,vinTx,hashBlock) == 0 ) if ( eval->GetTxUnconfirmed(tx.vin[i].prevout.hash,vinTx,hashBlock) == 0 )
@@ -111,7 +111,7 @@ bool FaucetValidate(Eval* eval,const CTransaction &tx)
} }
} }
bool ProcessFaucet(Eval* eval, std::vector<uint8_t> paramsNull,const CTransaction &ctx, unsigned int nIn) /*bool ProcessFaucet(Eval* eval, std::vector<uint8_t> paramsNull,const CTransaction &ctx, unsigned int nIn)
{ {
static uint256 prevtxid; uint256 txid; static uint256 prevtxid; uint256 txid;
txid = ctx.GetHash(); txid = ctx.GetHash();
@@ -130,7 +130,7 @@ bool ProcessFaucet(Eval* eval, std::vector<uint8_t> paramsNull,const CTransactio
} }
fprintf(stderr,"faucet validate failed\n"); fprintf(stderr,"faucet validate failed\n");
return(false); return(false);
} }*/
uint64_t AddFaucetInputs(CMutableTransaction &mtx,CPubKey pk,uint64_t total,int32_t maxinputs) uint64_t AddFaucetInputs(CMutableTransaction &mtx,CPubKey pk,uint64_t total,int32_t maxinputs)
{ {

View File

@@ -18,34 +18,12 @@
/* /*
*/ */
extern const char *RewardsCCaddr;
extern char RewardsCChexstr[67];
bool IsRewardsInput(CScript const& scriptSig);
uint64_t RewardsCalc(uint64_t claim,uint256 txid) uint64_t RewardsCalc(uint64_t claim,uint256 txid)
{ {
uint64_t reward = 0; uint64_t reward = 0;
return(reward); return(reward);
} }
/*CC *MakeRewardsCond(CPubKey pk)
{
std::vector<CC*> pks; uint8_t evalcode = EVAL_REWARDS;
pks.push_back(CCNewSecp256k1(pk));
CC *rewardsCC = CCNewEval(E_MARSHAL(ss << evalcode));
CC *Sig = CCNewThreshold(1, pks);
return CCNewThreshold(2, {rewardsCC, Sig});
}
CTxOut MakeRewardsVout(CAmount nValue,CPubKey pk)
{
CTxOut vout;
CC *payoutCond = MakeCCcond1(EVAL_REWARDS,pk);
vout = CTxOut(nValue,CCPubKey(payoutCond));
cc_free(payoutCond);
return(vout);
}*/
uint64_t IsRewardsvout(const CTransaction& tx,int32_t v) uint64_t IsRewardsvout(const CTransaction& tx,int32_t v)
{ {
char destaddr[64]; char destaddr[64];
@@ -57,7 +35,7 @@ uint64_t IsRewardsvout(const CTransaction& tx,int32_t v)
return(0); return(0);
} }
bool RewardsExactAmounts(Eval* eval,const CTransaction &tx,int32_t minage,uint64_t txfee) bool RewardsExactAmounts(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx,int32_t minage,uint64_t txfee)
{ {
static uint256 zerohash; static uint256 zerohash;
CTransaction vinTx; uint256 hashBlock,activehash; int32_t i,numvins,numvouts; uint64_t inputs=0,outputs=0,assetoshis; CTransaction vinTx; uint256 hashBlock,activehash; int32_t i,numvins,numvouts; uint64_t inputs=0,outputs=0,assetoshis;
@@ -65,7 +43,7 @@ bool RewardsExactAmounts(Eval* eval,const CTransaction &tx,int32_t minage,uint64
numvouts = tx.vout.size(); numvouts = tx.vout.size();
for (i=0; i<numvins; i++) for (i=0; i<numvins; i++)
{ {
if ( IsRewardsInput(tx.vin[i].scriptSig) != 0 ) if ( (*cp->ismyvin)(tx.vin[i].scriptSig) != 0 )
{ {
if ( eval->GetTxUnconfirmed(tx.vin[i].prevout.hash,vinTx,hashBlock) == 0 ) if ( eval->GetTxUnconfirmed(tx.vin[i].prevout.hash,vinTx,hashBlock) == 0 )
return eval->Invalid("always should find vin, but didnt"); return eval->Invalid("always should find vin, but didnt");
@@ -92,7 +70,7 @@ bool RewardsExactAmounts(Eval* eval,const CTransaction &tx,int32_t minage,uint64
else return(true); else return(true);
} }
bool RewardsValidate(Eval* eval,const CTransaction &tx) bool RewardsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx)
{ {
int32_t numvins,numvouts,preventCCvins,preventCCvouts,i; int32_t numvins,numvouts,preventCCvins,preventCCvouts,i;
numvins = tx.vin.size(); numvins = tx.vin.size();
@@ -107,7 +85,7 @@ bool RewardsValidate(Eval* eval,const CTransaction &tx)
if ( IsCCInput(tx.vin[0].scriptSig) == 0 ) if ( IsCCInput(tx.vin[0].scriptSig) == 0 )
return eval->Invalid("illegal normal vini"); return eval->Invalid("illegal normal vini");
} }
if ( RewardsExactAmounts(eval,tx,1,10000) == false ) if ( RewardsExactAmounts(cp,eval,tx,1,10000) == false )
return false; return false;
else else
{ {
@@ -125,7 +103,7 @@ bool RewardsValidate(Eval* eval,const CTransaction &tx)
return(true); return(true);
} }
bool ProcessRewards(Eval* eval, std::vector<uint8_t> paramsNull,const CTransaction &ctx, unsigned int nIn) /*bool ProcessRewards(Eval* eval, std::vector<uint8_t> paramsNull,const CTransaction &ctx, unsigned int nIn)
{ {
static uint256 prevtxid; uint256 txid; static uint256 prevtxid; uint256 txid;
txid = ctx.GetHash(); txid = ctx.GetHash();
@@ -144,7 +122,7 @@ bool ProcessRewards(Eval* eval, std::vector<uint8_t> paramsNull,const CTransacti
} }
fprintf(stderr,"ProcessRewards failed\n"); fprintf(stderr,"ProcessRewards failed\n");
return(false); return(false);
} }*/
uint64_t AddRewardsInputs(CMutableTransaction &mtx,CPubKey pk,uint64_t total,int32_t maxinputs) uint64_t AddRewardsInputs(CMutableTransaction &mtx,CPubKey pk,uint64_t total,int32_t maxinputs)
{ {

View File

@@ -4842,10 +4842,7 @@ int32_t ensure_CCrequirements()
#include "../cc/CCfaucet.h" #include "../cc/CCfaucet.h"
#include "../cc/CCassets.h" #include "../cc/CCassets.h"
#define EVAL_REWARDS 0xe5 #include "../cc/CCrewards.h"
std::string RewardsFund(uint64_t txfee,uint64_t funds,uint64_t APR,uint64_t minseconds,uint64_t maxseconds,uint64_t mindeposit);
std::string RewardsLock(uint64_t txfee,uint64_t amount);
std::string RewardsUnlock(uint64_t txfee);
UniValue rewardsaddress(const UniValue& params, bool fHelp) UniValue rewardsaddress(const UniValue& params, bool fHelp)
{ {