Initial rewards CC

This commit is contained in:
jl777
2018-07-23 18:37:46 -11:00
parent 728965dfee
commit 194ad5b859
7 changed files with 280 additions and 8 deletions

View File

@@ -28,6 +28,7 @@
CC *MakeAssetCond(CPubKey pk);
CC *MakeFaucetCond(CPubKey pk);
CC *MakeRewardsCond(CPubKey pk);
//BTCD Address: RAssetsAtGnvwgK9gVHBbAU4sVTah1hAm5
//BTCD Privkey: UvtvQVgVScXEYm4J3r4nE4nbFuGXSVM5pKec8VWXwgG9dmpWBuDh
@@ -36,10 +37,14 @@ CC *MakeFaucetCond(CPubKey pk);
const char *AssetsCCaddr = "RGKRjeTBw4LYFotSDLT6RWzMHbhXri6BG6" ;//"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 };
const char *FaucetCCaddr = "R9zHrofhRbub7ER77B7NrVch3A63R39GuC" ;//"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 };
const char *RewardsCCaddr = "R9zHrofhRbub7ER77B7NrVch3A63R39GuC" ;//"RKQV4oYs4rvxAWx1J43VnT73rSTVtUeckk";
char RewardsCChexstr[67] = { "03682b255c40d0cde8faee381a1a50bbb89980ff24539cb8518e294d3a63cefe12" };
uint8_t RewardsCCpriv[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 };
bool IsAssetsInput(CScript const& scriptSig)
{
@@ -75,6 +80,23 @@ bool IsFaucetInput(CScript const& scriptSig)
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;
}
CPubKey GetUnspendable(uint8_t evalcode,uint8_t *unspendablepriv)
{
static CPubKey nullpk;
@@ -92,12 +114,18 @@ CPubKey GetUnspendable(uint8_t evalcode,uint8_t *unspendablepriv)
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);
}
CC *MakeCC(uint8_t evalcode,CPubKey pk)
{
if ( evalcode == EVAL_ASSETS || evalcode == EVAL_FAUCET )
if ( evalcode == EVAL_ASSETS || evalcode == EVAL_FAUCET || evalcode == EVAL_REWARDS )
{
std::vector<CC*> pks;
pks.push_back(CCNewSecp256k1(pk));
@@ -131,6 +159,15 @@ bool GetCCaddress(uint8_t evalcode,char *destaddr,CPubKey pk)
}
return(destaddr[0] != 0);
}
else if ( evalcode == EVAL_REWARDS )
{
if ( (payoutCond= MakeRewardsCond(pk)) != 0 )
{
Getscriptaddress(destaddr,CCPubKey(payoutCond));
cc_free(payoutCond);
}
return(destaddr[0] != 0);
}
fprintf(stderr,"GetCCaddress %02x is invalid evalcode\n",evalcode);
return false;
}