Faucet
This commit is contained in:
@@ -48,6 +48,7 @@ char *uint256_str(char *dest,uint256 txid);
|
|||||||
uint256 Parseuint256(char *hexstr);
|
uint256 Parseuint256(char *hexstr);
|
||||||
CPubKey pubkey2pk(std::vector<uint8_t> pubkey);
|
CPubKey pubkey2pk(std::vector<uint8_t> pubkey);
|
||||||
bool ConstrainVout(CTxOut vout,int32_t CCflag,char *cmpaddr,uint64_t nValue);
|
bool ConstrainVout(CTxOut vout,int32_t CCflag,char *cmpaddr,uint64_t nValue);
|
||||||
|
bool PreventCC(const CTransaction &tx,int32_t preventCCvins,int32_t numvins,int32_t preventCCvouts,int32_t numvouts);
|
||||||
bool Getscriptaddress(char *destaddr,const CScript &scriptPubKey);
|
bool Getscriptaddress(char *destaddr,const CScript &scriptPubKey);
|
||||||
std::vector<uint8_t> Mypubkey();
|
std::vector<uint8_t> Mypubkey();
|
||||||
bool Myprivkey(uint8_t myprivkey[]);
|
bool Myprivkey(uint8_t myprivkey[]);
|
||||||
|
|||||||
@@ -56,8 +56,12 @@ char *uint256_str(char *dest,uint256 txid)
|
|||||||
uint256 Parseuint256(char *hexstr)
|
uint256 Parseuint256(char *hexstr)
|
||||||
{
|
{
|
||||||
uint256 txid; int32_t i; std::vector<unsigned char> txidbytes(ParseHex(hexstr));
|
uint256 txid; int32_t i; std::vector<unsigned char> txidbytes(ParseHex(hexstr));
|
||||||
for (i=31; i>=0; i--)
|
memset(&txid,0,sizeof(txid));
|
||||||
((uint8_t *)&txid)[31-i] = ((uint8_t *)txidbytes.data())[i];
|
if ( strlen(hexstr) == 64 )
|
||||||
|
{
|
||||||
|
for (i=31; i>=0; i--)
|
||||||
|
((uint8_t *)&txid)[31-i] = ((uint8_t *)txidbytes.data())[i];
|
||||||
|
}
|
||||||
return(txid);
|
return(txid);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -96,6 +100,28 @@ bool ConstrainVout(CTxOut vout,int32_t CCflag,char *cmpaddr,uint64_t nValue)
|
|||||||
else return(true);
|
else return(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool PreventCC(const CTransaction &tx,int32_t preventCCvins,int32_t numvins,int32_t preventCCvouts,int32_t numvouts)
|
||||||
|
{
|
||||||
|
int32_t i;
|
||||||
|
if ( preventCCvins >= 0 )
|
||||||
|
{
|
||||||
|
for (i=preventCCvins; i<numvins; i++)
|
||||||
|
{
|
||||||
|
if ( IsCCInput(tx.vin[i].scriptSig) != 0 )
|
||||||
|
return eval->Invalid("invalid CC vin");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ( preventCCvouts >= 0 )
|
||||||
|
{
|
||||||
|
for (i=preventCCvouts; i<numvouts; i++)
|
||||||
|
{
|
||||||
|
if ( tx.vout[i].scriptPubKey.IsPayToCryptoCondition() != 0 )
|
||||||
|
return eval->Invalid("invalid CC vout");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return(true);
|
||||||
|
}
|
||||||
|
|
||||||
std::vector<uint8_t> Mypubkey()
|
std::vector<uint8_t> Mypubkey()
|
||||||
{
|
{
|
||||||
extern uint8_t NOTARY_PUBKEY33[33];
|
extern uint8_t NOTARY_PUBKEY33[33];
|
||||||
|
|||||||
@@ -301,23 +301,7 @@ bool AssetValidate(Eval* eval,const CTransaction &tx,int32_t numvouts,uint8_t fu
|
|||||||
fprintf(stderr,"fill validated\n");
|
fprintf(stderr,"fill validated\n");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if ( preventCCvins >= 0 )
|
return(PreventCC(tx,preventCCvins,numvins,preventCCvouts,numvouts));
|
||||||
{
|
|
||||||
for (i=preventCCvins; i<numvins; i++)
|
|
||||||
{
|
|
||||||
if ( IsCCInput(tx.vin[i].scriptSig) != 0 )
|
|
||||||
return eval->Invalid("invalid CC vin");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if ( preventCCvouts >= 0 )
|
|
||||||
{
|
|
||||||
for (i=preventCCvouts; i<numvouts; i++)
|
|
||||||
{
|
|
||||||
if ( tx.vout[i].scriptPubKey.IsPayToCryptoCondition() != 0 )
|
|
||||||
return eval->Invalid("invalid CC vout");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return(true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ProcessAssets(Eval* eval, std::vector<uint8_t> paramsNull,const CTransaction &ctx, unsigned int nIn)
|
bool ProcessAssets(Eval* eval, std::vector<uint8_t> paramsNull,const CTransaction &ctx, unsigned int nIn)
|
||||||
|
|||||||
@@ -88,6 +88,7 @@ bool Eval::GetSpendsConfirmed(uint256 hash, std::vector<CTransaction> &spends) c
|
|||||||
bool Eval::GetTxUnconfirmed(const uint256 &hash, CTransaction &txOut, uint256 &hashBlock) const
|
bool Eval::GetTxUnconfirmed(const uint256 &hash, CTransaction &txOut, uint256 &hashBlock) const
|
||||||
{
|
{
|
||||||
bool myGetTransaction(const uint256 &hash, CTransaction &txOut, uint256 &hashBlock);
|
bool myGetTransaction(const uint256 &hash, CTransaction &txOut, uint256 &hashBlock);
|
||||||
|
// there is a LOCK(cs_main) in the normal GetTransaction(), which leads to deadlocks
|
||||||
//bool fAllowSlow = false; // Don't allow slow
|
//bool fAllowSlow = false; // Don't allow slow
|
||||||
//return GetTransaction(hash, txOut, hashBlock, fAllowSlow);
|
//return GetTransaction(hash, txOut, hashBlock, fAllowSlow);
|
||||||
return myGetTransaction(hash, txOut,hashBlock);
|
return myGetTransaction(hash, txOut,hashBlock);
|
||||||
@@ -110,7 +111,6 @@ unsigned int Eval::GetCurrentHeight() const
|
|||||||
return chainActive.Height();
|
return chainActive.Height();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool Eval::GetBlock(uint256 hash, CBlockIndex& blockIdx) const
|
bool Eval::GetBlock(uint256 hash, CBlockIndex& blockIdx) const
|
||||||
{
|
{
|
||||||
auto r = mapBlockIndex.find(hash);
|
auto r = mapBlockIndex.find(hash);
|
||||||
@@ -122,7 +122,6 @@ bool Eval::GetBlock(uint256 hash, CBlockIndex& blockIdx) const
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
extern int32_t komodo_notaries(uint8_t pubkeys[64][33],int32_t height,uint32_t timestamp);
|
extern int32_t komodo_notaries(uint8_t pubkeys[64][33],int32_t height,uint32_t timestamp);
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -43,18 +43,20 @@ CTxOut MakeFaucetVout(CAmount nValue,CPubKey pk)
|
|||||||
return(vout);
|
return(vout);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t IsFaucetvout(uint64_t &price,std::vector<uint8_t> &origpubkey,CTransaction& tx,int32_t v,uint256 refassetid)
|
uint64_t IsFaucetvout(const CTransaction& tx,int32_t v)
|
||||||
{
|
{
|
||||||
|
char destaddr[64];
|
||||||
if ( tx.vout[v].scriptPubKey.IsPayToCryptoCondition() != 0 )
|
if ( tx.vout[v].scriptPubKey.IsPayToCryptoCondition() != 0 )
|
||||||
return(tx.vout[v].nValue);
|
{
|
||||||
|
if ( Getscriptaddress(destaddr,tx.vout[v].scriptPubKey) > 0 && strcmp(destaddr,FaucetCCaddr) == 0 )
|
||||||
|
return(tx.vout[v].nValue);
|
||||||
|
}
|
||||||
return(0);
|
return(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef notyet
|
bool FaucetExactAmounts(Eval* eval,const CTransaction &tx)
|
||||||
|
|
||||||
bool FaucetExactAmounts(Eval* eval,CTransaction &tx,uint256 assetid)
|
|
||||||
{
|
{
|
||||||
CTransaction vinTx; uint256 hashBlock; int32_t i,numvins,numvouts; uint64_t inputs=0,outputs=0,assetoshis; std::vector<uint8_t> tmporigpubkey; uint64_t tmpprice;
|
CTransaction vinTx; uint256 hashBlock; int32_t i,numvins,numvouts; uint64_t inputs=0,outputs=0,assetoshis;
|
||||||
numvins = tx.vin.size();
|
numvins = tx.vin.size();
|
||||||
numvouts = tx.vout.size();
|
numvouts = tx.vout.size();
|
||||||
for (i=1; i<numvins; i++)
|
for (i=1; i<numvins; i++)
|
||||||
@@ -63,13 +65,13 @@ bool FaucetExactAmounts(Eval* eval,CTransaction &tx,uint256 assetid)
|
|||||||
{
|
{
|
||||||
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");
|
||||||
else if ( (assetoshis= IsFaucetvout(tmpprice,tmporigpubkey,vinTx,tx.vin[i].prevout.n,assetid)) != 0 )
|
else if ( (assetoshis= IsFaucetvout(vinTx,tx.vin[i].prevout.n)) != 0 )
|
||||||
inputs += assetoshis;
|
inputs += assetoshis;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (i=0; i<numvouts; i++)
|
for (i=0; i<numvouts; i++)
|
||||||
{
|
{
|
||||||
if ( (assetoshis= IsFaucetvout(tmpprice,tmporigpubkey,tx,i,assetid)) != 0 )
|
if ( (assetoshis= IsFaucetvout(tx,i)) != 0 )
|
||||||
outputs += assetoshis;
|
outputs += assetoshis;
|
||||||
}
|
}
|
||||||
if ( inputs != outputs )
|
if ( inputs != outputs )
|
||||||
@@ -77,42 +79,21 @@ bool FaucetExactAmounts(Eval* eval,CTransaction &tx,uint256 assetid)
|
|||||||
else return(true);
|
else return(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FaucetValidate(Eval* eval,CTransaction &tx)
|
bool FaucetValidate(Eval* eval,const CTransaction &tx)
|
||||||
{
|
{
|
||||||
static uint256 zero;
|
int32_t numvins,numvouts,preventCCvins,preventCCvouts;
|
||||||
CTxDestination address; CTransaction vinTx; uint256 hashBlock; int32_t i,numvins,preventCCvins,preventCCvouts; uint64_t nValue,assetoshis,outputs,inputs,tmpprice,ignore; std::vector<uint8_t> tmporigpubkey,ignorepubkey; char destaddr[64],origaddr[64],CCaddr[64];
|
fprintf(stderr,"FaucetValidate\n");
|
||||||
fprintf(stderr,"FaucetValidate (%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 ( 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");
|
||||||
else if ( funcid != 'c' )
|
else if ( FaucetExactAmounts(eval,tx) == false )
|
||||||
{
|
eval->Invalid("asset inputs != outputs");
|
||||||
if ( assetid == zero )
|
else return(PreventCC(tx,preventCCvins,numvins,preventCCvouts,numvouts));
|
||||||
return eval->Invalid("illegal assetid");
|
|
||||||
else if ( FaucetExactAmounts(eval,tx,assetid) == false )
|
|
||||||
eval->Invalid("asset inputs != outputs");
|
|
||||||
}
|
|
||||||
if ( preventCCvins >= 0 )
|
|
||||||
{
|
|
||||||
for (i=preventCCvins; i<numvins; i++)
|
|
||||||
{
|
|
||||||
if ( IsCCInput(tx.vin[i].scriptSig) != 0 )
|
|
||||||
return eval->Invalid("invalid CC vin");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if ( preventCCvouts >= 0 )
|
|
||||||
{
|
|
||||||
for (i=preventCCvouts; i<numvouts; i++)
|
|
||||||
{
|
|
||||||
if ( tx.vout[i].scriptPubKey.IsPayToCryptoCondition() != 0 )
|
|
||||||
return eval->Invalid("invalid CC vout");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return(true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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)
|
||||||
@@ -121,12 +102,11 @@ bool ProcessFaucet(Eval* eval, std::vector<uint8_t> paramsNull,const CTransactio
|
|||||||
txid = ctx.GetHash();
|
txid = ctx.GetHash();
|
||||||
if ( txid == prevtxid )
|
if ( txid == prevtxid )
|
||||||
return(true);
|
return(true);
|
||||||
CTransaction tx = *(CTransaction *)&ctx;
|
|
||||||
if ( paramsNull.size() != 0 ) // Don't expect params
|
if ( paramsNull.size() != 0 ) // Don't expect params
|
||||||
return eval->Invalid("Cannot have params");
|
return eval->Invalid("Cannot have params");
|
||||||
else if ( tx.vout.size() == 0 )
|
else if ( ctx.vout.size() == 0 )
|
||||||
return eval->Invalid("no-vouts");
|
return eval->Invalid("no-vouts");
|
||||||
if ( FaucetValidate(eval,tx,n) != 0 )
|
if ( FaucetValidate(eval,ctx,n) != 0 )
|
||||||
{
|
{
|
||||||
prevtxid = txid;
|
prevtxid = txid;
|
||||||
return(true);
|
return(true);
|
||||||
|
|||||||
Reference in New Issue
Block a user