Get credit loop

This commit is contained in:
jl777
2019-01-15 00:09:07 -11:00
parent 9755dbc647
commit 6873cb6653
5 changed files with 58 additions and 7 deletions

View File

@@ -26,7 +26,7 @@
uint64_t komodo_block_prg(uint32_t nHeight);
int32_t MarmaraGetcreatetxid(uint256 &createtxid,uint256 txid);
int32_t MarmaraGetbatontxid(uint256 &batontxid,uint256 txid);
int32_t MarmaraGetbatontxid(std::vector<uint256> &creditloop,uint256 &batontxid,uint256 txid);
UniValue MarmaraPoolPayout(uint64_t txfee,int32_t firstheight,double perc,char *jsonstr); // [[pk0, shares0], [pk1, shares1], ...]
UniValue MarmaraReceive(uint64_t txfee,CPubKey senderpk,int64_t amount,std::string currency,int32_t matures,uint256 batontxid);

View File

@@ -105,15 +105,18 @@ struct oracleprice_info
#ifdef ENABLE_WALLET
extern CWallet* pwalletMain;
#endif
//extern CCoinsViewCache *pcoinsTip;
bool GetAddressUnspent(uint160 addressHash, int type,std::vector<std::pair<CAddressUnspentKey,CAddressUnspentValue> > &unspentOutputs);
CBlockIndex *komodo_getblockindex(uint256 hash);
int32_t komodo_nextheight();
int32_t CCgetspenttxid(uint256 &spenttxid,int32_t &vini,int32_t &height,uint256 txid,int32_t vout);
static const uint256 zeroid;
bool myGetTransaction(const uint256 &hash, CTransaction &txOut, uint256 &hashBlock);
int32_t is_hexstr(char *str,int32_t n);
bool myAddtomempool(CTransaction &tx, CValidationState *pstate = NULL, bool fSkipExpiry = false);
//uint64_t myGettxout(uint256 hash,int32_t n);
int32_t CCgettxout(uint256 txid,int32_t vout,int32_t mempoolflag);
bool myIsutxo_spentinmempool(uint256 txid,int32_t vout);
bool mytxid_inmempool(uint256 txid);
int32_t myIsutxo_spent(uint256 &spenttxid,uint256 txid,int32_t vout);

View File

@@ -247,6 +247,40 @@ int64_t CCutxovalue(char *coinaddr,uint256 utxotxid,int32_t utxovout)
return(0);
}
int32_t CCgettxout(uint256 txid,int32_t vout,int32_t mempoolflag)
{
CCoins coins;
if ( mempoolflag != 0 )
{
LOCK(mempool.cs);
CCoinsViewMemPool view(pcoinsTip, mempool);
if (!view.GetCoins(txid, coins))
return(-1);
if ( myIsutxo_spentinmempool(txid,vout) != 0 )
return(-1);
}
else
{
if (!pcoinsTip->GetCoins(hash, coins))
return(-1);
}
if ( vout < coins.vout.size() )
return(coins.vout[vout].nValue);
else return(-1);
}
int32_t CCgetspenttxid(uint256 &spenttxid,int32_t &vini,int32_t &height,uint256 txid,int32_t vout)
{
CSpentIndexKey key(txid, vout);
CSpentIndexValue value;
if ( !GetSpentIndex(key, value) )
return(-1);
spenttxid = value.txid;
vini = (int32_t)value.inputIndex;
height = value.blockHeight;
return(0);
}
int64_t CCaddress_balance(char *coinaddr)
{
int64_t sum = 0; std::vector<std::pair<CAddressUnspentKey, CAddressUnspentValue> > unspentOutputs;

View File

@@ -186,13 +186,25 @@ int32_t MarmaraGetcreatetxid(uint256 &createtxid,uint256 txid)
return(-1);
}
int32_t MarmaraGetbatontxid(uint256 &batontxid,uint256 txid)
int32_t MarmaraGetbatontxid(std::vector<uint256> &creditloop,uint256 &batontxid,uint256 txid)
{
uint256 createtxid;
uint256 createtxid,spenttxid; int64_t value; int32_t vini,height,vout = 0;
memset(&batontxid,0,sizeof(batontxid));
if ( MarmaraGetcreatetxid(createtxid,txid) == 0 )
{
return(0);
txid = createtxid;
while ( CCgetspenttxid(spenttxid,vini,height,txid,vout) == 0 )
{
if ( (value= CCgettxout(spenttxid,vout,1)) > 0 )
{
batontxid = txid;
fprintf(stderr,"got baton %s %.8f\n",batontxid.GetHex(),(double)value/COIN);
return(0);
}
creditloop.push_back(spenttxid);
fprintf(stderr,"%s\n",spenttxid.GetHex());
txid = spenttxid;
}
}
return(-1);
}
@@ -456,6 +468,8 @@ UniValue MarmaraIssue(uint64_t txfee,uint8_t funcid,CPubKey receiverpk,int64_t a
mypk = pubkey2pk(Mypubkey());
if ( MarmaraGetcreatetxid(createtxid,approvaltxid) < 0 )
errorstr = (char *)"cant get createtxid from approvaltxid";
else if ( batontxid == zeroid )
errorstr = (char *)"null batontxid";
else if ( currency != "MARMARA" )
errorstr = (char *)"for now, only MARMARA loops are supported";
else if ( amount < txfee )