Faucet
This commit is contained in:
@@ -48,6 +48,7 @@ char *uint256_str(char *dest,uint256 txid);
|
||||
uint256 Parseuint256(char *hexstr);
|
||||
CPubKey pubkey2pk(std::vector<uint8_t> pubkey);
|
||||
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);
|
||||
std::vector<uint8_t> Mypubkey();
|
||||
bool Myprivkey(uint8_t myprivkey[]);
|
||||
|
||||
@@ -56,8 +56,12 @@ char *uint256_str(char *dest,uint256 txid)
|
||||
uint256 Parseuint256(char *hexstr)
|
||||
{
|
||||
uint256 txid; int32_t i; std::vector<unsigned char> txidbytes(ParseHex(hexstr));
|
||||
for (i=31; i>=0; i--)
|
||||
((uint8_t *)&txid)[31-i] = ((uint8_t *)txidbytes.data())[i];
|
||||
memset(&txid,0,sizeof(txid));
|
||||
if ( strlen(hexstr) == 64 )
|
||||
{
|
||||
for (i=31; i>=0; i--)
|
||||
((uint8_t *)&txid)[31-i] = ((uint8_t *)txidbytes.data())[i];
|
||||
}
|
||||
return(txid);
|
||||
}
|
||||
|
||||
@@ -96,6 +100,28 @@ bool ConstrainVout(CTxOut vout,int32_t CCflag,char *cmpaddr,uint64_t nValue)
|
||||
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()
|
||||
{
|
||||
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");
|
||||
break;
|
||||
}
|
||||
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);
|
||||
return(PreventCC(tx,preventCCvins,numvins,preventCCvouts,numvouts));
|
||||
}
|
||||
|
||||
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 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
|
||||
//return GetTransaction(hash, txOut, hashBlock, fAllowSlow);
|
||||
return myGetTransaction(hash, txOut,hashBlock);
|
||||
@@ -110,7 +111,6 @@ unsigned int Eval::GetCurrentHeight() const
|
||||
return chainActive.Height();
|
||||
}
|
||||
|
||||
|
||||
bool Eval::GetBlock(uint256 hash, CBlockIndex& blockIdx) const
|
||||
{
|
||||
auto r = mapBlockIndex.find(hash);
|
||||
@@ -122,7 +122,6 @@ bool Eval::GetBlock(uint256 hash, CBlockIndex& blockIdx) const
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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 )
|
||||
return(tx.vout[v].nValue);
|
||||
{
|
||||
if ( Getscriptaddress(destaddr,tx.vout[v].scriptPubKey) > 0 && strcmp(destaddr,FaucetCCaddr) == 0 )
|
||||
return(tx.vout[v].nValue);
|
||||
}
|
||||
return(0);
|
||||
}
|
||||
|
||||
#ifdef notyet
|
||||
|
||||
bool FaucetExactAmounts(Eval* eval,CTransaction &tx,uint256 assetid)
|
||||
bool FaucetExactAmounts(Eval* eval,const CTransaction &tx)
|
||||
{
|
||||
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();
|
||||
numvouts = tx.vout.size();
|
||||
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 )
|
||||
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;
|
||||
}
|
||||
}
|
||||
for (i=0; i<numvouts; i++)
|
||||
{
|
||||
if ( (assetoshis= IsFaucetvout(tmpprice,tmporigpubkey,tx,i,assetid)) != 0 )
|
||||
if ( (assetoshis= IsFaucetvout(tx,i)) != 0 )
|
||||
outputs += assetoshis;
|
||||
}
|
||||
if ( inputs != outputs )
|
||||
@@ -77,42 +79,21 @@ bool FaucetExactAmounts(Eval* eval,CTransaction &tx,uint256 assetid)
|
||||
else return(true);
|
||||
}
|
||||
|
||||
bool FaucetValidate(Eval* eval,CTransaction &tx)
|
||||
bool FaucetValidate(Eval* eval,const CTransaction &tx)
|
||||
{
|
||||
static uint256 zero;
|
||||
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 (%c)\n",funcid);
|
||||
int32_t numvins,numvouts,preventCCvins,preventCCvouts;
|
||||
fprintf(stderr,"FaucetValidate\n");
|
||||
numvins = tx.vin.size();
|
||||
numvouts = tx.vout.size();
|
||||
outputs = inputs = 0;
|
||||
preventCCvins = preventCCvouts = -1;
|
||||
if ( IsCCInput(tx.vin[0].scriptSig) != 0 )
|
||||
return eval->Invalid("illegal asset vin0");
|
||||
else if ( numvouts < 1 )
|
||||
return eval->Invalid("no vouts");
|
||||
else if ( funcid != 'c' )
|
||||
{
|
||||
if ( assetid == zero )
|
||||
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);
|
||||
else if ( FaucetExactAmounts(eval,tx) == false )
|
||||
eval->Invalid("asset inputs != outputs");
|
||||
else return(PreventCC(tx,preventCCvins,numvins,preventCCvouts,numvouts));
|
||||
}
|
||||
|
||||
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();
|
||||
if ( txid == prevtxid )
|
||||
return(true);
|
||||
CTransaction tx = *(CTransaction *)&ctx;
|
||||
if ( paramsNull.size() != 0 ) // Don't expect params
|
||||
return eval->Invalid("Cannot have params");
|
||||
else if ( tx.vout.size() == 0 )
|
||||
else if ( ctx.vout.size() == 0 )
|
||||
return eval->Invalid("no-vouts");
|
||||
if ( FaucetValidate(eval,tx,n) != 0 )
|
||||
if ( FaucetValidate(eval,ctx,n) != 0 )
|
||||
{
|
||||
prevtxid = txid;
|
||||
return(true);
|
||||
|
||||
Reference in New Issue
Block a user