MakeCC1vout
This commit is contained in:
@@ -31,7 +31,7 @@ extern char AssetsCChexstr[67];
|
||||
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);
|
||||
|
||||
@@ -97,7 +97,7 @@ bool SetAssetFillamounts(int32_t sellflag,uint64_t &received_nValue,uint64_t &re
|
||||
} 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));
|
||||
@@ -109,11 +109,11 @@ CC *MakeAssetCond(CPubKey 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)
|
||||
{
|
||||
|
||||
@@ -104,7 +104,7 @@ std::string CreateAsset(uint64_t txfee,uint64_t assetsupply,std::string name,std
|
||||
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)));
|
||||
}
|
||||
@@ -129,9 +129,9 @@ std::string AssetTransfer(uint64_t txfee,uint256 assetid,std::vector<uint8_t> de
|
||||
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());
|
||||
@@ -147,7 +147,7 @@ std::string CreateBuyOffer(uint64_t txfee,uint64_t bidamount,uint256 assetid,uin
|
||||
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);
|
||||
@@ -163,11 +163,11 @@ std::string CreateSell(uint64_t txfee,uint64_t askamount,uint256 assetid,uint256
|
||||
{
|
||||
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());
|
||||
@@ -208,7 +208,7 @@ std::string CancelSell(uint64_t txfee,uint256 assetid,uint256 asktxid)
|
||||
{
|
||||
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())));
|
||||
}
|
||||
}
|
||||
@@ -233,11 +233,11 @@ std::string FillBuyOffer(uint64_t txfee,uint256 assetid,uint256 bidtxid,uint64_t
|
||||
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");
|
||||
@@ -267,11 +267,11 @@ std::string FillSell(uint64_t txfee,uint256 assetid,uint256 assetid2,uint256 ask
|
||||
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");
|
||||
|
||||
@@ -26,9 +26,9 @@
|
||||
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
|
||||
@@ -143,7 +143,7 @@ bool GetCCaddress(uint8_t evalcode,char *destaddr,CPubKey pk)
|
||||
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);
|
||||
@@ -162,7 +162,7 @@ bool GetCCaddress(uint8_t evalcode,char *destaddr,CPubKey pk)
|
||||
}
|
||||
else if ( evalcode == EVAL_REWARDS )
|
||||
{
|
||||
if ( (payoutCond= MakeRewardsCond(pk)) != 0 )
|
||||
if ( (payoutCond= MakeCCcond1(evalcode,pk)) != 0 )
|
||||
{
|
||||
Getscriptaddress(destaddr,CCPubKey(payoutCond));
|
||||
cc_free(payoutCond);
|
||||
|
||||
@@ -41,6 +41,7 @@ CPubKey GetUnspendable(uint8_t evalcode,uint8_t *unspendablepriv);
|
||||
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);
|
||||
|
||||
@@ -19,6 +19,15 @@
|
||||
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;
|
||||
|
||||
@@ -33,7 +33,7 @@
|
||||
CC *faucetCC = CCNewEval(E_MARSHAL(ss << evalcode));
|
||||
CC *Sig = CCNewThreshold(1, pks);
|
||||
return CCNewThreshold(2, {faucetCC, Sig});
|
||||
}*/
|
||||
}
|
||||
|
||||
CTxOut MakeFaucetVout(CAmount nValue,CPubKey pk)
|
||||
{
|
||||
@@ -43,7 +43,7 @@ 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)
|
||||
{
|
||||
@@ -186,7 +186,7 @@ std::string FaucetFund(uint64_t txfee,uint64_t funds)
|
||||
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);
|
||||
@@ -204,7 +204,7 @@ std::string FaucetGet(uint64_t txfee)
|
||||
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");
|
||||
|
||||
@@ -28,7 +28,7 @@ uint64_t RewardsCalc(uint64_t claim,uint256 txid)
|
||||
return(reward);
|
||||
}
|
||||
|
||||
CC *MakeRewardsCond(CPubKey pk)
|
||||
/*CC *MakeRewardsCond(CPubKey pk)
|
||||
{
|
||||
std::vector<CC*> pks; uint8_t evalcode = EVAL_REWARDS;
|
||||
pks.push_back(CCNewSecp256k1(pk));
|
||||
@@ -40,11 +40,11 @@ CC *MakeRewardsCond(CPubKey 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)
|
||||
{
|
||||
@@ -183,7 +183,7 @@ std::string RewardsFund(uint64_t txfee,uint64_t funds,uint64_t APR,uint64_t mins
|
||||
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));
|
||||
@@ -202,7 +202,7 @@ std::string RewardsLock(uint64_t txfee,uint64_t amount)
|
||||
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));
|
||||
@@ -224,7 +224,7 @@ std::string RewardsUnlock(uint64_t txfee)
|
||||
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));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user