bool IsAssetsInput(CScript const& scriptSig);
// CCassetsCore
-CTxOut MakeAssetsVout(CAmount nValue,CPubKey pk);
+//CTxOut MakeAssetsVout(CAmount nValue,CPubKey pk);
CScript EncodeAssetCreateOpRet(uint8_t funcid,std::vector<uint8_t> origpubkey,std::string name,std::string description);
CScript EncodeAssetOpRet(uint8_t funcid,uint256 assetid,uint256 assetid2,uint64_t price,std::vector<uint8_t> origpubkey);
uint8_t DecodeAssetOpRet(const CScript &scriptPubKey,uint256 &assetid,uint256 &assetid2,uint64_t &price,std::vector<uint8_t> &origpubkey);
} else return(false);
}
-CC *MakeAssetCond(CPubKey pk)
+/*CC *MakeAssetCond(CPubKey pk)
{
std::vector<CC*> pks; uint8_t evalcode = EVAL_ASSETS;
pks.push_back(CCNewSecp256k1(pk));
CTxOut MakeAssetsVout(CAmount nValue,CPubKey pk)
{
CTxOut vout;
- CC *payoutCond = MakeAssetCond(pk);
+ CC *payoutCond = MakeCCcond1(EVAL_ASSETS,pk);
vout = CTxOut(nValue,CCPubKey(payoutCond));
cc_free(payoutCond);
return(vout);
-}
+}*/
CScript EncodeAssetCreateOpRet(uint8_t funcid,std::vector<uint8_t> origpubkey,std::string name,std::string description)
{
mypk = pubkey2pk(Mypubkey());
if ( AddNormalinputs(mtx,mypk,assetsupply+2*txfee,64) > 0 )
{
- mtx.vout.push_back(MakeAssetsVout(assetsupply,mypk));
+ mtx.vout.push_back(MakeCC1vout(EVAL_ASSETS,assetsupply,mypk));
mtx.vout.push_back(CTxOut(txfee,CScript() << ParseHex(AssetsCChexstr) << OP_CHECKSIG));
return(FinalizeCCTx(EVAL_ASSETS,mtx,mypk,txfee,EncodeAssetCreateOpRet('c',Mypubkey(),name,description)));
}
if ( inputs > total )
CCchange = (inputs - total);
//for (i=0; i<n; i++)
- mtx.vout.push_back(MakeAssetsVout(total,pubkey2pk(destpubkey)));
+ mtx.vout.push_back(MakeCC1vout(EVAL_ASSETS,total,pubkey2pk(destpubkey)));
if ( CCchange != 0 )
- mtx.vout.push_back(MakeAssetsVout(CCchange,mypk));
+ mtx.vout.push_back(MakeCC1vout(EVAL_ASSETS,CCchange,mypk));
return(FinalizeCCTx(EVAL_ASSETS,mtx,mypk,txfee,EncodeAssetOpRet('t',assetid,zeroid,0,Mypubkey())));
} else fprintf(stderr,"not enough CC asset inputs for %.8f\n",(double)total/COIN);
//} else fprintf(stderr,"numoutputs.%d != numamounts.%d\n",n,(int32_t)amounts.size());
mypk = pubkey2pk(Mypubkey());
if ( AddNormalinputs(mtx,mypk,bidamount+txfee,64) > 0 )
{
- mtx.vout.push_back(MakeAssetsVout(bidamount,GetUnspendable(EVAL_ASSETS,0)));
+ mtx.vout.push_back(MakeCC1vout(EVAL_ASSETS,bidamount,GetUnspendable(EVAL_ASSETS,0)));
return(FinalizeCCTx(EVAL_ASSETS,mtx,mypk,txfee,EncodeAssetOpRet('b',assetid,zeroid,pricetotal,Mypubkey())));
}
return(0);
{
if ( (inputs= AddAssetInputs(mtx,mypk,assetid,askamount,60)) > 0 )
{
- mtx.vout.push_back(MakeAssetsVout(askamount,GetUnspendable(EVAL_ASSETS,0)));
+ mtx.vout.push_back(MakeCC1vout(EVAL_ASSETS,askamount,GetUnspendable(EVAL_ASSETS,0)));
if ( inputs > askamount )
CCchange = (inputs - askamount);
if ( CCchange != 0 )
- mtx.vout.push_back(MakeAssetsVout(CCchange,mypk));
+ 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());
{
askamount = vintx.vout[0].nValue;
mtx.vin.push_back(CTxIn(asktxid,0,CScript()));
- mtx.vout.push_back(MakeAssetsVout(askamount,mypk));
+ mtx.vout.push_back(MakeCC1vout(EVAL_ASSETS,askamount,mypk));
return(FinalizeCCTx(EVAL_ASSETS,mtx,mypk,txfee,EncodeAssetOpRet('x',assetid,zeroid,0,Mypubkey())));
}
}
if ( inputs > fillamount )
CCchange = (inputs - fillamount);
SetAssetFillamounts(0,paid_amount,remaining_required,bidamount,fillamount,origprice);
- mtx.vout.push_back(MakeAssetsVout(bidamount - paid_amount,GetUnspendable(EVAL_ASSETS,0)));
+ mtx.vout.push_back(MakeCC1vout(EVAL_ASSETS,bidamount - paid_amount,GetUnspendable(EVAL_ASSETS,0)));
mtx.vout.push_back(CTxOut(paid_amount,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG));
- mtx.vout.push_back(MakeAssetsVout(fillamount,pubkey2pk(origpubkey)));
+ mtx.vout.push_back(MakeCC1vout(EVAL_ASSETS,fillamount,pubkey2pk(origpubkey)));
if ( CCchange != 0 )
- mtx.vout.push_back(MakeAssetsVout(CCchange,mypk));
+ mtx.vout.push_back(MakeCC1vout(EVAL_ASSETS,CCchange,mypk));
fprintf(stderr,"remaining %llu -> origpubkey\n",(long long)remaining_required);
return(FinalizeCCTx(EVAL_ASSETS,mtx,mypk,txfee,EncodeAssetOpRet('B',assetid,zeroid,remaining_required,origpubkey)));
} else fprintf(stderr,"filltx wasnt for assetid\n");
if ( assetid2 == zeroid && inputs > fillamount )
CCchange = (inputs - fillamount);
SetAssetFillamounts(1,paid_amount,remaining_required,askamount,fillamount,totalunits);
- mtx.vout.push_back(MakeAssetsVout(askamount - paid_amount,GetUnspendable(EVAL_ASSETS,0)));
- mtx.vout.push_back(MakeAssetsVout(paid_amount,mypk));
- mtx.vout.push_back(MakeAssetsVout(fillamount,pubkey2pk(origpubkey)));
+ mtx.vout.push_back(MakeCC1vout(EVAL_ASSETS,askamount - paid_amount,GetUnspendable(EVAL_ASSETS,0)));
+ mtx.vout.push_back(MakeCC1vout(EVAL_ASSETS,paid_amount,mypk));
+ mtx.vout.push_back(MakeCC1vout(EVAL_ASSETS,fillamount,pubkey2pk(origpubkey)));
if ( CCchange != 0 )
- mtx.vout.push_back(MakeAssetsVout(CCchange,mypk));
+ mtx.vout.push_back(MakeCC1vout(EVAL_ASSETS,CCchange,mypk));
fprintf(stderr,"remaining %llu -> origpubkey\n",(long long)remaining_required);
return(FinalizeCCTx(EVAL_ASSETS,mtx,mypk,txfee,EncodeAssetOpRet(assetid2==zeroid?'E':'S',assetid,assetid2,remaining_required,origpubkey)));
} else fprintf(stderr,"filltx not enough utxos\n");
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 *MakeAssetCond(CPubKey pk);
//CC *MakeFaucetCond(CPubKey pk);
-CC *MakeRewardsCond(CPubKey pk);
+//CC *MakeRewardsCond(CPubKey pk);
//BTCD Address: RAssetsAtGnvwgK9gVHBbAU4sVTah1hAm5
//BTCD Privkey: UvtvQVgVScXEYm4J3r4nE4nbFuGXSVM5pKec8VWXwgG9dmpWBuDh
pk = GetUnspendable(evalcode,0);
if ( evalcode == EVAL_ASSETS )
{
- if ( (payoutCond= MakeAssetCond(pk)) != 0 )
+ if ( (payoutCond= MakeCCcond1(evalcode,pk)) != 0 )
{
Getscriptaddress(destaddr,CCPubKey(payoutCond));
cc_free(payoutCond);
}
else if ( evalcode == EVAL_REWARDS )
{
- if ( (payoutCond= MakeRewardsCond(pk)) != 0 )
+ if ( (payoutCond= MakeCCcond1(evalcode,pk)) != 0 )
{
Getscriptaddress(destaddr,CCPubKey(payoutCond));
cc_free(payoutCond);
bool GetCCaddress(uint8_t evalcode,char *destaddr,CPubKey pk);
// CCutils
+CTxOut MakeCC1vout(uint8_t evalcode,CAmount nValue,CPubKey pk);
CC *MakeCCcond1(uint8_t evalcode,CPubKey pk);
CC* GetCryptoCondition(CScript const& scriptSig);
bool IsCCInput(CScript const& scriptSig);
CCutils has low level functions that are universally useful for all contracts.
*/
+CTxOut MakeCC1vout(uint8_t evalcode,CAmount nValue,CPubKey pk)
+{
+ CTxOut vout;
+ CC *payoutCond = MakeCCcond1(evalcode,pk);
+ vout = CTxOut(nValue,CCPubKey(payoutCond));
+ cc_free(payoutCond);
+ return(vout);
+}
+
CC *MakeCCcond1(uint8_t evalcode,CPubKey pk)
{
std::vector<CC*> pks;
CC *faucetCC = CCNewEval(E_MARSHAL(ss << evalcode));
CC *Sig = CCNewThreshold(1, pks);
return CCNewThreshold(2, {faucetCC, Sig});
-}*/
+}
CTxOut MakeFaucetVout(CAmount nValue,CPubKey pk)
{
vout = CTxOut(nValue,CCPubKey(payoutCond));
cc_free(payoutCond);
return(vout);
-}
+}*/
uint64_t IsFaucetvout(const CTransaction& tx,int32_t v)
{
faucetpk = GetUnspendable(EVAL_FAUCET,0);
if ( AddNormalinputs(mtx,mypk,funds+txfee,64) > 0 )
{
- mtx.vout.push_back(MakeFaucetVout(funds,faucetpk));
+ mtx.vout.push_back(MakeCC1vout(EVAL_FAUCET,funds,faucetpk));
return(FinalizeCCTx(EVAL_FAUCET,mtx,mypk,txfee,opret));
}
return(0);
if ( inputs > nValue )
CCchange = (inputs - nValue - txfee);
if ( CCchange != 0 )
- mtx.vout.push_back(MakeFaucetVout(CCchange,faucetpk));
+ mtx.vout.push_back(MakeCC1vout(EVAL_FAUCET,CCchange,faucetpk));
mtx.vout.push_back(CTxOut(nValue,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG));
return(FinalizeCCTx(EVAL_FAUCET,mtx,mypk,txfee,opret));
} else fprintf(stderr,"cant find faucet inputs\n");
return(reward);
}
-CC *MakeRewardsCond(CPubKey pk)
+/*CC *MakeRewardsCond(CPubKey pk)
{
std::vector<CC*> pks; uint8_t evalcode = EVAL_REWARDS;
pks.push_back(CCNewSecp256k1(pk));
CTxOut MakeRewardsVout(CAmount nValue,CPubKey pk)
{
CTxOut vout;
- CC *payoutCond = MakeRewardsCond(pk);
+ 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)
{
rewardspk = GetUnspendable(EVAL_REWARDS,0);
if ( AddNormalinputs(mtx,mypk,funds+2*txfee,64) > 0 )
{
- mtx.vout.push_back(MakeRewardsVout(funds,rewardspk));
+ mtx.vout.push_back(MakeCC1vout(EVAL_REWARDS,funds,rewardspk));
mtx.vout.push_back(CTxOut(APR,CScript() << ParseHex(HexStr(rewardspk)) << OP_CHECKSIG));
mtx.vout.push_back(CTxOut(minseconds,CScript() << ParseHex(HexStr(rewardspk)) << OP_CHECKSIG));
mtx.vout.push_back(CTxOut(maxseconds,CScript() << ParseHex(HexStr(rewardspk)) << OP_CHECKSIG));
mypk = pubkey2pk(Mypubkey());
if ( AddNormalinputs(mtx,mypk,amount+2*txfee,64) > 0 )
{
- mtx.vout.push_back(MakeRewardsVout(amount,rewardspk));
+ mtx.vout.push_back(MakeCC1vout(EVAL_REWARDS,amount,rewardspk));
// specify destination pubkey, funding txid
//opret = ;//
return(FinalizeCCTx(EVAL_REWARDS,mtx,mypk,txfee,opret));
if ( inputs > (reward+txfee) )
CCchange = (inputs - reward - txfee);
if ( CCchange != 0 )
- mtx.vout.push_back(MakeRewardsVout(CCchange,rewardspk));
+ mtx.vout.push_back(MakeCC1vout(EVAL_REWARDS,CCchange,rewardspk));
mtx.vout.push_back(CTxOut(claim+reward,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG));
return(FinalizeCCTx(EVAL_REWARDS,mtx,mypk,txfee,opret));
}