Browse Source

Get credit loop

pull/4/head
jl777 5 years ago
parent
commit
6873cb6653
  1. 2
      src/cc/CCMarmara.h
  2. 5
      src/cc/CCinclude.h
  3. 34
      src/cc/CCtx.cpp
  4. 20
      src/cc/marmara.cpp
  5. 4
      src/wallet/rpcwallet.cpp

2
src/cc/CCMarmara.h

@ -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);

5
src/cc/CCinclude.h

@ -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);

34
src/cc/CCtx.cpp

@ -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;

20
src/cc/marmara.cpp

@ -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 )

4
src/wallet/rpcwallet.cpp

@ -5601,7 +5601,7 @@ UniValue marmara_issue(const UniValue& params, bool fHelp)
UniValue marmara_transfer(const UniValue& params, bool fHelp)
{
UniValue result(UniValue::VOBJ); uint256 approvaltxid,batontxid; std::vector<uint8_t> receiverpub; int64_t amount; int32_t matures; std::string currency;
UniValue result(UniValue::VOBJ); uint256 approvaltxid,batontxid; std::vector<uint8_t> receiverpub; int64_t amount; int32_t matures; std::string currency; std::vector<uint256> creditloop;
if ( fHelp || params.size() != 5 )
{
// marmaratransfer 028076d42eb20efc10007fafb5ca66a2052523c0d2221e607adf958d1a332159f6 7.5 MARMARA 3903 748a4c80e6f6b725340fb0f52738f38a11c422d59b3034c8366b3d7b33c99a1e
@ -5619,7 +5619,7 @@ UniValue marmara_transfer(const UniValue& params, bool fHelp)
currency = params[2].get_str();
matures = atol(params[3].get_str().c_str());
approvaltxid = Parseuint256((char *)params[4].get_str().c_str());
if ( MarmaraGetbatontxid(batontxid,approvaltxid) < 0 )
if ( MarmaraGetbatontxid(creditloop,batontxid,approvaltxid) < 0 )
throw runtime_error("couldnt find batontxid\n");
return(MarmaraIssue(0,'T',pubkey2pk(receiverpub),amount,currency,matures,approvaltxid,batontxid));
}

Loading…
Cancel
Save