Skip to content

Commit

Permalink
Merge branch 'workspace'
Browse files Browse the repository at this point in the history
  • Loading branch information
spark0huang committed Aug 18, 2014
2 parents 4bccce1 + a02e054 commit f325bfa
Show file tree
Hide file tree
Showing 8 changed files with 175 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ bool CTxOut::GetLottoTxOutType(TransactionState &TxType) const
if (!lotto::CLotto::IsValid(vchPushValue,nValue))
{
TxType = INVALID_LOTTO_STATE;
return false;
}
TxType = VALID_LOTTO_STATE;
return true;
Expand Down
68 changes: 68 additions & 0 deletions src/lotto/CLotto.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,74 @@ int CLotto::GetReWardOutput(std::vector<CTxOut> &vOuts, int64_t &llRemains) {

}

string CLotto::ComputePeerReward(string &nStr)
{
std::map<BET_TYPE, std::map<RWD_TYPE, int64_t> > mReward;
CreateRewardSchemeMap();
CreateStatisticsRewardMap();
int64_t peerValue = 0;
int64_t Countbet = 0;
nStr = "";
BOOST_FOREACH(boost::shared_ptr<CBet> &v, vBet) {

if (v.get()->isWinning()) {
std::map<RWD_TYPE, int64_t> reward = v.get()->GetBetRewardMap();
std::map<RWD_TYPE, int64_t>::iterator item;
CTxOut tx;
Countbet = v.get()->getTotalBer();
peerValue = v.get()->nValue/Countbet;
tx.nValue = 0;
string tem = "";
for (item = reward.begin(); item != reward.end(); item++) {
if (mRewardScheme[v.get()->type].count(item->first) != 0) {
mReward[v.get()->type][item->first]= (int64_t) (mRewardScheme[v.get()->type][item->first] * item->second);
} else {
mReward[v.get()->type][item->first]= v.get()->GetMulit(item->first) * item->second;

}

}
}
}
string str = "";
if(mReward.size()>0)
{
std::map<lotto::BET_TYPE, std::map<lotto::RWD_TYPE, int64_t> >::iterator item;
item = mReward.begin();
for(item = mReward.begin();item != mReward.end();item++)
{
string first= "";
if(item->first == lotto::TYPE_15_6)
{
first = "TYPE_15_6:";
}
if(item->first == lotto::TYPE_MULILT)
{
first = "TYPE_MULILT:";
}
std::map<lotto::RWD_TYPE, int64_t> it = item->second;
string second ="";
BOOST_FOREACH(const PAIRTYPE(lotto::RWD_TYPE, int64_t)& tep2 , it)
{

int pcount = tep2.second/peerValue;
second+=tfm::format("Prize level:%d,Total Tickets:%d,",tep2.first+1,pcount);
double count = tep2.second/100000000.0;
second +=tfm::format("Prize amount:%f, ",count);
}
if(second != "")
{
nStr +=tfm::format("%s,",first);
nStr +=tfm::format("Draw No:%d,Winning No:%s,Amout per bet:%f,Total Tickets:%ld,",key.Index,HexStr(mLuckyStar[item->first].begin(),mLuckyStar[item->first].end()),peerValue/100000000.0,Countbet);
str +=tfm::format("%s}",second);
}
}

}

return str;
}

int CLotto::CreateLuckyStarMap() {
if (hash == uint256(0))
return 0;
Expand Down
1 change: 1 addition & 0 deletions src/lotto/CLotto.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class CLotto {
void Init(const std::vector<CTxOut>& txOutV);
bool print()const ;
std::map<BET_TYPE, std::vector<unsigned char> >&GetLuckyNum(){ return mLuckyStar;};
string ComputePeerReward(string &nStr);
private:
int CreateLuckyStarMap();
void CreateRewardSchemeMap();
Expand Down
1 change: 1 addition & 0 deletions src/miner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ std::string DrawLottery(int64_t drawPool, CBlockIndex *pindexPrev, std::vector<C
CTransaction tx = lotteryBlock.vtx[i];
TransactionState iTxType(NORMAL_STATE);
if (!tx.IsTransactionValid()) {
if(pDrawLotteryIndex->nHeight > 4380)
throw std::runtime_error("CreateNewBlock(): lottery bet is invalid");
}
if (!tx.IsCoinBase()) {
Expand Down
1 change: 1 addition & 0 deletions src/rpcserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,7 @@ static const CRPCCommand vRPCCommands[] =
{ "listsetblockindexvalid", &listsetblockindexvalid, false, false, true},
{ "listcheckpoint", &listcheckpoint, false, false, true},
{ "sendcheckpointchain", &sendcheckpointchain, false, false, true},
{ "getrewardbyaddr", &getrewardbyaddr, false, false, true},
};

CRPCTable::CRPCTable()
Expand Down
1 change: 1 addition & 0 deletions src/rpcserver.h
Original file line number Diff line number Diff line change
Expand Up @@ -205,4 +205,5 @@ extern json_spirit::Value computepeernumcount(const json_spirit:: Array& params,
extern json_spirit::Value listsetblockindexvalid(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value sendcheckpointchain(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value listcheckpoint(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value getrewardbyaddr(const json_spirit::Array& params, bool fHelp);
#endif
101 changes: 100 additions & 1 deletion src/rpcwallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,13 @@ int64_t ComputTheBetReturnValue(int height,CTxOut txout)
int64_t llRemains = 0;
plotto.GetReWardOutput(ret,llRemains);
if(ret.size() >=1)
return ret[0].nValue;
{
int64_t value = 0;
for(int i=0;i<ret.size();i++)
value += ret[i].nValue;
return value;
}

}
return 0;
}
Expand Down Expand Up @@ -2826,3 +2832,96 @@ Value computepeernumcount(const Array& params, bool fHelp)
return str;

}

string ComputBetpeerCount(int height,CTxOut txout,string &nstr)
{

std::vector<CTxOut> vBet;
vBet.push_back(txout);
CBlockIndex* blockindex = chainActive[height];
int64_t Pool= chainActive[height-1]->GetBlockHeader().lottoHeader.llPool;
uint256 bithash = GetLotteryHash(blockindex);
string ret = "";
if(blockindex->lottoHeader.uLottoKey != uint256(0))
{
lotto::CLotto plotto(bithash,blockindex->lottoHeader.nLottoID,blockindex->lottoHeader.uLottoKey,Pool,vBet);
ret = plotto.ComputePeerReward(nstr);
}
return ret;
}
Value getrewardbyaddr(const Array& params, bool fHelp) {
//params.size() < 1
if (fHelp) {
throw runtime_error("gettransactionbyaddr \n"
"\nArguments:\n"
"1. \"address\" (string, required) get the transaction of the address \n");
}

map<uint256, CTransaction> revMoneyTx;
map<uint256, CTransaction> spendTx;
map<uint256,Info> spendInfo;
map<uint256, Info> revMoneyInfo;
string address = "";
if(params.size() == 1)
{
address = params[0].get_str();
}
else
{
BOOST_FOREACH(const PAIRTYPE(CBitcoinAddress, CAddressBookData)& item, pwalletMain->mapAddressBook)
{
const CBitcoinAddress& addr = item.first;
const string& strName = item.second.name;
if (strName == "")
{
address =addr.ToString();
break;
}

}
}
string str= address + ",";
CBlockIndex *pBlockIndex = chainActive.Genesis();
while ((pBlockIndex = chainActive.Next(pBlockIndex))) {
CBlock block;
if (!ReadBlockFromDisk(block, pBlockIndex))
return error("CreateNewBlock() : Read current tip block from disk failed");

BOOST_FOREACH(CTransaction &tx, block.vtx) {
bool bFind = false;
BOOST_FOREACH(CTxOut &txOut, tx.vout) {
CTxDestination desAddress;
TransactionState iTxType(NORMAL_STATE);
if (txOut.GetLottoTxOutType(iTxType)) {
if (iTxType == VALID_LOTTO_STATE) {
std::vector<unsigned char> betdata;
txOut.scriptPubKey.GetBetData(betdata);
lotto::CBetData strData;
strData << betdata;
if (address == CBitcoinAddress(CKeyID(strData.GetAddr())).ToString()) {
int beginlottoblock = pBlockIndex->nHeight + 2*GetArg("-intervallotto", nIntervalLottery);
if (beginlottoblock <chainActive.Height()) {
string strTemp = "";
string temp1 = ComputBetpeerCount(beginlottoblock, txOut,strTemp);
if(temp1 !="")
{
double temp = txOut.nValue/100000000.0;

str += tfm::format("{%s,value:%f,Select No:%s,",strTemp,temp, HexStr(strData.GetSelectV()));

str +=tfm::format("%s,",temp1);

}
}

}
}

}
}

}
}

return str;
}
2 changes: 2 additions & 0 deletions src/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1367,6 +1367,8 @@ bool CWallet::CreateTransaction(const vector<pair<CScript, int64_t> >& vecSend,
}
}
}
if(!wtxNew.IsTransactionValid())
return false;
return true;
}

Expand Down

0 comments on commit f325bfa

Please sign in to comment.