Pages:
Author

Topic: ANN- The 1st blockchain Lottery | P2P Lottery | open source Lottery Launched... - page 3. (Read 4159 times)

legendary
Activity: 2254
Merit: 1290

You seem to be headed for a really intense educational experience, quite soon.

Cheers

Graham
hero member
Activity: 980
Merit: 1010
Blockchain engineer
hero member
Activity: 980
Merit: 1010
Blockchain engineer
Quote
Because no one can customize a future block's HASH, so, blockchain's lottery is fair and equitable.

If the lottery reward became greater than the block reward, then mining pools would have a very strong incentive to ensure that they win. The way they could do that (assuming 50% of network hashing power or more) is they would mine the block, check if they won the lottery and if not, then discard the block and try mining another block with a block hash where they win the lottery. If the major pools collude together to do this (lets say, 90% of hash power). Then it would be fairly trivial to increase your chances of winning by at least 9 times. (you would get at least 9 "draws").

Also, there is more evil that lurks under the covers. With 90% hashing power, you could orphan off a winning lottery block by going backwards in the blockchain and mining old blocks again (with timestamp manipulation so your blocks are more difficult and thus better).

Cool idea, but it has serious security implications and will not work. All of this applies also to basing the lottery on a Bitcoin block hash as well, though your lottery would have to be really valuable to get Bitcoin mining pools to care.

Hello,
Maybe you not read our codes,
We use a future block as target, no one know the answer, so your say "check if they won the lottery and if not" is not established.
And we set bet block range is "Start block number + 1" to "Target block number - 3",
Maybe Someone can control the next one block, but no one can keep a block to future + 3.

Thanks.

Let me break it down into Chenglish for you.

Miner make block future + 3. He no win lottery with block. he decide not to publish block. he mine new block. he get second chance at lottery. he maybe win. unfair for people not miners.



Vpncoin is a PoS coin.
We set bet block range is "Start block number + 1" to "Target block number - 3",
For example:
Lottery's "Start block number" is 100, "Target block number" is 200, the valid Bet block range is 101 ~ 197,
And current block number is 196, you can DIY block 197, but our target block is 200, and when current block number > 197 every betting is invalid.

I know your mean is 51% attack? even you do that, it is also under our Lottery rules.
Why?
Because You cant know a future (target) block's hash, when you get the target block, you can't bet, it's under my rules.
Bet is a transaction, it must Stored in a block, you need think about this.
Like this:


Thanks.
legendary
Activity: 1036
Merit: 1000
https://bmy.guide
Quote
Because no one can customize a future block's HASH, so, blockchain's lottery is fair and equitable.

If the lottery reward became greater than the block reward, then mining pools would have a very strong incentive to ensure that they win. The way they could do that (assuming 50% of network hashing power or more) is they would mine the block, check if they won the lottery and if not, then discard the block and try mining another block with a block hash where they win the lottery. If the major pools collude together to do this (lets say, 90% of hash power). Then it would be fairly trivial to increase your chances of winning by at least 9 times. (you would get at least 9 "draws").

Also, there is more evil that lurks under the covers. With 90% hashing power, you could orphan off a winning lottery block by going backwards in the blockchain and mining old blocks again (with timestamp manipulation so your blocks are more difficult and thus better).

Cool idea, but it has serious security implications and will not work. All of this applies also to basing the lottery on a Bitcoin block hash as well, though your lottery would have to be really valuable to get Bitcoin mining pools to care.

Hello,
Maybe you not read our codes,
We use a future block as target, no one know the answer, so your say "check if they won the lottery and if not" is not established.
And we set bet block range is "Start block number + 1" to "Target block number - 3",
Maybe Someone can control the next one block, but no one can keep a block to future + 3.

Thanks.

Let me break it down into Chenglish for you.

Miner make block future + 3. He no win lottery with block. he decide not to publish block. he mine new block. he get second chance at lottery. he maybe win. unfair for people not miners.




lol he no know dat
sr. member
Activity: 439
Merit: 250
mmmmmm
Quote
Because no one can customize a future block's HASH, so, blockchain's lottery is fair and equitable.

If the lottery reward became greater than the block reward, then mining pools would have a very strong incentive to ensure that they win. The way they could do that (assuming 50% of network hashing power or more) is they would mine the block, check if they won the lottery and if not, then discard the block and try mining another block with a block hash where they win the lottery. If the major pools collude together to do this (lets say, 90% of hash power). Then it would be fairly trivial to increase your chances of winning by at least 9 times. (you would get at least 9 "draws").

Also, there is more evil that lurks under the covers. With 90% hashing power, you could orphan off a winning lottery block by going backwards in the blockchain and mining old blocks again (with timestamp manipulation so your blocks are more difficult and thus better).

Cool idea, but it has serious security implications and will not work. All of this applies also to basing the lottery on a Bitcoin block hash as well, though your lottery would have to be really valuable to get Bitcoin mining pools to care.

Hello,
Maybe you not read our codes,
We use a future block as target, no one know the answer, so your say "check if they won the lottery and if not" is not established.
And we set bet block range is "Start block number + 1" to "Target block number - 3",
Maybe Someone can control the next one block, but no one can keep a block to future + 3.

Thanks.

Let me break it down into Chenglish for you.

Miner make block future + 3. He no win lottery with block. he decide not to publish block. he mine new block. he get second chance at lottery. he maybe win. unfair for people not miners.

hero member
Activity: 980
Merit: 1010
Blockchain engineer
seems good. but please take a look around NAScoin , its  Lottery function have been launched  a year ago but still dead already. that means  Lottery is not fit for us.

If you read my idea, you would not say that,
thanks.
hero member
Activity: 980
Merit: 1010
Blockchain engineer
hero member
Activity: 980
Merit: 1010
Blockchain engineer
Quote
Because no one can customize a future block's HASH, so, blockchain's lottery is fair and equitable.

If the lottery reward became greater than the block reward, then mining pools would have a very strong incentive to ensure that they win. The way they could do that (assuming 50% of network hashing power or more) is they would mine the block, check if they won the lottery and if not, then discard the block and try mining another block with a block hash where they win the lottery. If the major pools collude together to do this (lets say, 90% of hash power). Then it would be fairly trivial to increase your chances of winning by at least 9 times. (you would get at least 9 "draws").

Also, there is more evil that lurks under the covers. With 90% hashing power, you could orphan off a winning lottery block by going backwards in the blockchain and mining old blocks again (with timestamp manipulation so your blocks are more difficult and thus better).

Cool idea, but it has serious security implications and will not work. All of this applies also to basing the lottery on a Bitcoin block hash as well, though your lottery would have to be really valuable to get Bitcoin mining pools to care.

Hello,
Maybe you not read our codes,
We use a future block as target, no one know the answer, so your say "check if they won the lottery and if not" is not established.
And we set bet block range is "Start block number + 1" to "Target block number - 3",
Maybe Someone can control the next one block, but no one can keep a block to future + 3.

Thanks.
legendary
Activity: 2254
Merit: 1290
sr. member
Activity: 249
Merit: 250
seems good. but please take a look around NAScoin , its  Lottery function have been launched  a year ago but still dead already. that means  Lottery is not fit for us.
sr. member
Activity: 439
Merit: 250
mmmmmm
Quote
Because no one can customize a future block's HASH, so, blockchain's lottery is fair and equitable.

If the lottery reward became greater than the block reward, then mining pools would have a very strong incentive to ensure that they win. The way they could do that (assuming 50% of network hashing power or more) is they would mine the block, check if they won the lottery and if not, then discard the block and try mining another block with a block hash where they win the lottery. If the major pools collude together to do this (lets say, 90% of hash power). Then it would be fairly trivial to increase your chances of winning by at least 9 times. (you would get at least 9 "draws").

Also, there is more evil that lurks under the covers. With 90% hashing power, you could orphan off a winning lottery block by going backwards in the blockchain and mining old blocks again (with timestamp manipulation so your blocks are more difficult and thus better).

Cool idea, but it has serious security implications and will not work. All of this applies also to basing the lottery on a Bitcoin block hash as well, though your lottery would have to be really valuable to get Bitcoin mining pools to care.
hero member
Activity: 980
Merit: 1010
Blockchain engineer
Hello,

Looks good, but I think you are posting in the wrong section of the forum.
I believe this is the place for your ANN.

Cheers

I must remove this thread?
legendary
Activity: 1960
Merit: 1176
@FAILCommunity
Hello,

Looks good, but I think you are posting in the wrong section of the forum.
I believe this is the place for your ANN.

Cheers
hero member
Activity: 980
Merit: 1010
Blockchain engineer
go on..... tell me more.... Smiley

Please wait, I'll posting here.
Thank you for attention.
hero member
Activity: 980
Merit: 1010
Blockchain engineer
hero member
Activity: 560
Merit: 500
Am i broke yet?
go on..... tell me more.... Smiley
hero member
Activity: 980
Merit: 1010
Blockchain engineer
hero member
Activity: 980
Merit: 1010
Blockchain engineer
hero member
Activity: 980
Merit: 1010
Blockchain engineer
How can I win bonus?  How to Betting?

1, Save a Lottery card image to file,
2, Import this image file, on Betting GUI,
3, Set your Bet Text,
4, Click Bet Button.
hero member
Activity: 980
Merit: 1010
Blockchain engineer
Hello everyone,
Today I am pleased to announce that we create a based on blockchain's P2P lottery, it is open source.
We call it BitNet Lottery, we plan to launch it at Vpncoin's 320000th block.

Source code: http://github.com/bit-net/vpncoin
Windows qt version: https://drive.google.com/file/d/0B7Kd-l4hTU3GV3o4WG5LZjd2Uzg/view?usp=sharing

Because no one can customize a future block's HASH, so, blockchain's lottery is fair and equitable.
BitNet Lottery is a transaction, it comes with specific transaction messages and stored in the block chain.

Below is BitNet Lottery Format Description:
Lottery Flag | Lottery ID | Lottery Type (Genesis = 1, Bet = 2, Cash = 3) | Bet Type | Bet Amount | Mini Bet Amount | Start block | Target block | Guess HASH Length | Bet Text | Lottery wallet address | Lottery wallet Private Key | Bettor's default Wallet Address | Lottery Tx ID | Sign message

For example:
Genesis Lottery  
Bet Lottery        
BitNet Lottery: | 00000000E3C9 | 2 | 1 | 100 | 30 | 305048 | 305068 | 3 | 26 | VtV3QA45Cd6wNbgQsZoGaxTPoJzMKrtmpK | 0 | VevimYsrNKWbx2W6Bnq2qyLthcnEasLMTg | ed88213480fa502936141016b912c920a43c488e7b9045605fa945b61c74493f | 0

Parameter   1: BitNet Lottery: BitNet Lottery flag
Parameter   2: 00000000E3C9 BitNet Lottery serial number
Parameter   3: 2 BitNet Lottery type, Genesis BitNet Lottery = 1, Bet BitNet Lottery = 2, Encash BitNet Lottery = 3
Parameter   4: 1 betting type, Guess a future block's hash(last N byte) = 0, guess a future block's hash(last N byte)'s digit value = 1
Parameter   5: 100 bet amount
Parameter   6: 30 minimum bet, the player bets must >= this number
Parameter   7: 305048 BitNet Lottery start block,
Parameter   8: 305068, BitNet Lottery target block, the answer from this block,
Parameter   9: 3   guess the last N characters from the target block
Parameter 10: 26 betting number
Parameter 11: VtV3QA45Cd6wNbgQsZoGaxTPoJzMKrtmpK BitNet Lottery wallet address
Parameter 12: 0 BitNet Lottery wallet address's private key, BitNet Lottery Type = 1 (Genesis BitNet Lottery) must be specified this, when encase,
                    player need to import the private key, and then send coins from this address.
Parameter 13: VevimYsrNKWbx2W6Bnq2qyLthcnEasLMTg bettors wallet address, if winning, prize will be sent to this address.
Parameter 14: ed88213480fa502936141016b912c920a43c488e7b9045605fa945b61c74493f betting transaction hash,
                    BitNet Lottery Type = 1 (Genesis BitNet Lottery) is set to 0,
                    BitNet Lottery Type = 2 (Bet BitNet Lottery), is the "Genesis BitNet Lottery" transaction HASH (tx id),
                    BitNet Lottery Type = 3 (Encase BitNet Lottery), is the genesis or bet transaction HASH (tx id), for prove the player is betted.
Parameter 15: 0 use "bettors wallet address" signature "betting transaction hash"'s text,
                    BitNet Lottery Type = 3 (Encase BitNet Lottery) must be specified this,
                    to prove that the player is "bettor's wallet address"'s owner, other Type set to 0

How does it work?




Some people think that use 51% attack will break our lottery rules, this is not established.
Because, in the valid bet block range, you do not know the answer, when you use 51% attack get the target block, you will lose the opportunity to bet, no one can be insert a Bet transaction into an existing block.
So, our rules are valid.


We add some codes in main.cpp to check every transaction.
If the tx's transaction message field include BitNet Lottery flags, will check its legality.

Code:
bool IsStandardTx(const CTransaction& tx)
{
if (tx.nVersion > CTransaction::CURRENT_VERSION)
        return false;
        ......
if( isRejectTransaction(tx) )
{
if( fDebug ){ printf("IsStandardTx: isRejectTransaction = true, ban. \n"); }
return false;
}
        ......
}

......


bool CBlock::AcceptBlock()
{
    AssertLockHeld(cs_main);
    ......
    // Check that all transactions are finalized
    BOOST_FOREACH(const CTransaction& tx, vtx)
    {
        if (!IsFinalTx(tx, nHeight, GetBlockTime()))
            return DoS(10, error("AcceptBlock() : contains a non-final transaction"));
if( isRejectTransaction(tx) ){ return error("AcceptBlock() : block includes not under rules tx, ban."); }
     }
    ......
}

isRejectTransaction function:
Code:
bool isRejectTransaction(const CTransaction& tx)
{
bool rzt = false;
bool bCasherIsWinner = false;
//-- first check it is a valid lottery tx,
string sCashTxHash = tx.GetHash().ToString();
if( fDebug ){ printf("\n\n\n******************** begin [%s]\n", sCashTxHash.c_str()); }
int iCashTxHei = GetTransactionBlockHeight(sCashTxHash);
if( iCashTxHei == 0 )
{
if( fDebug )printf("isRejectTransaction: Cash tx's hei = [%u], set to nBestHeight [%u] \n", iCashTxHei, nBestHeight);
iCashTxHei = nBestHeight;  
}
string sTxMsg = tx.vpndata;
if( fDebug ){ printf("isRejectTransaction: Tx hei = [%u], nBestHeight [%u], Tx Msg = [%s] \n", iCashTxHei, nBestHeight, sTxMsg.c_str()); }

string sLotId_cash = "", sGuessTxt = "", sLotteryAddr_bet = "", sLotteryPrivKey_bet = "", sMakerAddr_cash = "", sLotteryBetTxid = "", sSignMsg = "";
int iLotteryType_cash = 0, iGuessType = 0, iKeyLen = 0;
int64_t iAmount = 0, iMiniBet = 0, iStartBlock = 0, iEndBlock = 0;

string sRztBiggerAddr = "", sCashTxLinkedGenesisTx = "";
int64_t i6RztBiggerValue = 0;

bool bCashMsgSignOk = false;
int i = 0, iWillBan = 0;

if( iCashTxHei < BitNetLotteryStartTestBlock_286000 ){ goto check_Complete; }
if( sTxMsg.length() < 34){ goto check_Complete; }

i = GetTxMsgParam(tx, sLotId_cash, iLotteryType_cash, iGuessType, iAmount, iMiniBet, iStartBlock, iEndBlock, iKeyLen,
sGuessTxt, sLotteryAddr_bet, sLotteryPrivKey_bet, sMakerAddr_cash, sLotteryBetTxid, sSignMsg);
if( i > 14 )
{
string sLotteryAnswer = "";
if(  iLotteryType_cash != 3 ) // if not a cash tx
{
if( iLotteryType_cash == 1 ) // is Genesis tx
{
if( isValidLotteryGenesisTx(tx, iCashTxHei, -1, -1, 0, "", "") == false )
{
iWillBan++;  printf("isRejectTransaction: Genesis tx [%s] not under rules, will ban :(\n", sCashTxHash.c_str());
if( isBitNetLotteryRuleStart() )
{
if( fDebug ){ printf("[%s] end ********************\n\n\n", sCashTxHash.c_str()); }
return true;
}
}
}
else if( iLotteryType_cash == 2 ) // is Bet tx
{
//bool isValidLotteryBetTx(const CTransaction& tx, int iTxHei, int iTargetGuessType, int iTargetGuessLen, int64_t i6TargetBlock, const string sTargetMaker, const string sTargetGenesisAddr)
if( isValidLotteryBetTx(tx, iCashTxHei, -1, -1, 0, "", "") == false )
{
iWillBan++;  printf("isRejectTransaction: Bet tx [%s] not under rules, will ban :(\n", sCashTxHash.c_str());
if( isBitNetLotteryRuleStart() )
{
if( fDebug ){ printf("[%s] end ********************\n\n\n", sCashTxHash.c_str()); }
return true;
}
}
}else{ printf("isRejectTransaction: [%s] not a Lottery tx, invalid type \n", sCashTxHash.c_str()); }
goto check_Complete;
}
// is a lottery cash tx
//if( validateAddress(sMakerAddr_cash) == false ){ goto check_Complete; }
if( sSignMsg.length() < 60 ){
printf("isRejectTransaction: Cash tx [%s]'s  msg sign [%s] invalid \n", sCashTxHash.c_str(), sSignMsg.c_str());
goto check_Complete;
}
if( verifyMessage(sMakerAddr_cash, sSignMsg, sLotteryBetTxid) == false ) // check cash sender is sMakerAddr_cash's owner
{
printf("isRejectTransaction: Cash tx [%s] sign invalid \n", sCashTxHash.c_str());
goto check_Complete;
}
bCashMsgSignOk = true;
if( fDebug ){ printf("isRejectTransaction: Cash Msg Sign Ok \n"); }

string sLotId_bet, sGuessTxt_bet, sMakerAddr_bet, sLotteryLinkedTxid_gen, sSignMsg_bet;
int iLotteryType_bet, iGuessType_bet, iKeyLen_bet;
int64_t iAmount_bet, iMiniBet_bet, iStartBlock_bet, iEndBlock_bet;

int iBetTxHei = GetTransactionBlockHeight(sLotteryBetTxid);
if( iBetTxHei < BitNetLotteryStartTestBlock_286000 )
{
printf("isRejectTransaction: Bet tx [%s] not exists or invalid, hei =[%u] \n", sLotteryBetTxid.c_str(), iBetTxHei);
goto check_Complete;
}
// get linked bet tx info
i = GetTxMsgParam(sLotteryBetTxid, sLotId_bet, iLotteryType_bet, iGuessType_bet, iAmount_bet, iMiniBet_bet, iStartBlock_bet, iEndBlock_bet, iKeyLen_bet,
sGuessTxt_bet, sLotteryAddr_bet, sLotteryPrivKey_bet, sMakerAddr_bet, sLotteryLinkedTxid_gen, sSignMsg);
if( i < 15 )
{
printf("isRejectTransaction: Cash tx [%s] linked bet tx [%s] is invalid, params count < 15 \n", sCashTxHash.c_str(), sLotteryBetTxid.c_str());
goto check_Complete;
}
if( sMakerAddr_cash != sMakerAddr_bet )
{
printf("isRejectTransaction: Cash tx [%s] maker [%s] != bet tx [%s] maker [%s], invalid \n", sCashTxHash.c_str(), sMakerAddr_cash.c_str(), sLotteryBetTxid.c_str(), sMakerAddr_bet.c_str());
goto check_Complete;
}
if(  iLotteryType_bet != 2 )
{
if(  iLotteryType_bet != 1 ) // If no one guessed, Lottery maker can cash it.
{
printf("isRejectTransaction: [%s] not a bet and genesis tx, invalid type \n", sLotteryBetTxid.c_str());
goto check_Complete;
}
if( fDebug ){ printf("isRejectTransaction: Cash tx linked genesis lottery \n"); }
// Is a Genesis lottery, Cash tx linked a Genesis tx, sMakerAddr_cash must be this lottery's creater
if( iCashTxHei < (iEndBlock_bet + iBitNetBlockMargin3) )
{
printf("isRejectTransaction: Can't cash, iCashTxHei [%u] < [%I64u], please wait :(\n", iCashTxHei, (iEndBlock_bet + iBitNetBlockMargin3));
goto check_Complete;
}
/* if( sMakerAddr_cash != sMakerAddr_bet ){
printf("sMakerAddr_cash [%s] != sMakerAddr_bet [%s], not this lottery's creater :( ", sMakerAddr_cash.c_str(), sMakerAddr_bet.c_str());
goto check_Complete;
} */
//bool isValidLotteryGenesisTxs(const string& txID, int iTxHei, int iTargetGuessType, int iTargetGuessLen, int64_t i6TargetBlock, const string sTargetMaker, const string sTargetGenesisAddr)
if( isValidLotteryGenesisTxs(sLotteryBetTxid, iBetTxHei, -1, -1, 0, sMakerAddr_cash, "") == false )
{
printf("isRejectTransaction: [%s] is a genesis tx, but not under rules :(\n", sLotteryBetTxid.c_str());
goto check_Complete;
}
sCashTxLinkedGenesisTx = sLotteryBetTxid.c_str();
// sMakerAddr_cash is this lottery's creater
// scan all of (iStartBlock ~ iEndBlock) blocks, find Bet biggest winner
sLotteryAnswer = getBlockNByteHashStrByType(iEndBlock_bet, iKeyLen_bet, iGuessType_bet);
if( fDebug ){ printf("isRejectTransaction:  sLotteryAnswer = [%s], sGuessTxt_bet = [%s] \n", sLotteryAnswer.c_str(), sGuessTxt_bet.c_str()); }
//int getBetBiggerWinnerFromBlockRange(int iBlockBegin, int iBlockEnd, int iTargetGuessLen, int iTargetGuessType, const string sCorrectAnswer, const string sLotteryGenAddr,
//  int64_t v_TargetValue, string& sRztBiggerAddr, int64_t& i6RztBiggerValue)  
if( getBetBiggerWinnerFromBlockRange(iStartBlock_bet, (iEndBlock_bet - iBitNetBlockMargin3), iKeyLen_bet, iGuessType_bet, sLotteryAnswer, sLotteryAddr_bet, iMiniBet_bet, sRztBiggerAddr, i6RztBiggerValue) > 0 )
{
// someone guessed
if( sRztBiggerAddr == sMakerAddr_cash )
{
bCasherIsWinner = true;
if( fDebug ){ printf("isRejectTransaction: [%s] linked lottery's winner is creator [%s]\n", sCashTxHash.c_str(), sRztBiggerAddr.c_str()); }
}else{ if( fDebug ){ printf("isRejectTransaction: [%s] linked lottery's winner is [%s], not creator [%s] \n", sCashTxHash.c_str(), sRztBiggerAddr.c_str(), sMakerAddr_cash.c_str()); } }
}else{ // no one guessed, lottery creater is winner
sRztBiggerAddr = sMakerAddr_cash;
i6RztBiggerValue = iAmount_bet;
bCasherIsWinner = true;
if( fDebug ){ printf("isRejectTransaction: [%s] linked lottery's winner is creator [%s]\n", sCashTxHash.c_str(), sRztBiggerAddr.c_str()); }
}
goto check_Complete;
}
// is lottery bet tx
if( fDebug ){ printf("isRejectTransaction: Cash tx linked bet lottery \n"); }
if( (iGuessType_bet < 0) || (iGuessType_bet > 1) ) // 0 = guess n byte of block hash text,  1 = guess n byte of block hash digital add
{
printf("isRejectTransaction: Bet guess type [%u] invalid \n", iGuessType_bet);
goto check_Complete;
}
int iGenTxHei = GetTransactionBlockHeight(sLotteryLinkedTxid_gen);
if( (iGenTxHei < BitNetLotteryStartTestBlock_286000) || (iBetTxHei < iGenTxHei) )
{
printf("isRejectTransaction: Genesis tx [%s] not exists or invalid, hei =[%u] \n", sLotteryLinkedTxid_gen.c_str(), iGenTxHei);
goto check_Complete;
}

//bool isValidLotteryGenesisTxs(const string& txID, int iTxHei, int iTargetGuessType, int iTargetGuessLen, int64_t i6TargetBlock, const string sTargetMaker, const string sTargetGenesisAddr)
/* if( isValidLotteryGenesisTxs(sLotteryLinkedTxid_gen, iGenTxHei, iGuessType_bet, iKeyLen_bet, 0, sMakerAddr_cash, sLotteryAddr_bet) == false )
{
printf("Bet tx [%s] linked genesis tx [%s] not under rules :(\n", sLotteryBetTxid.c_str(), sLotteryLinkedTxid_gen.c_str());
goto check_Complete;
} */
string sLotId_gen, sGuessTxt_gen, sLotteryAddr_gen, sLotteryPrivKey_gen, sMakerAddr_gen, sLotteryGenesisTxid_gen;
int iLotteryType_gen, iGuessType_gen, iKeyLen_gen;
int64_t iAmount_gen, iMiniBet_gen, iStartBlock_gen, iEndBlock_gen;
// get linked Genesis tx info
i = GetTxMsgParam(sLotteryLinkedTxid_gen, sLotId_gen, iLotteryType_gen, iGuessType_gen, iAmount_gen, iMiniBet_gen, iStartBlock_gen, iEndBlock_gen, iKeyLen_gen,
sGuessTxt_gen, sLotteryAddr_gen, sLotteryPrivKey_gen, sMakerAddr_gen, sLotteryGenesisTxid_gen, sSignMsg);
if( i < 15 )
{
printf("isRejectTransaction: Cash tx [%s] linked bet tx [%s] linked [%s] invalid, params count < 15 \n", sCashTxHash.c_str(), sLotteryBetTxid.c_str(), sLotteryLinkedTxid_gen.c_str());
goto check_Complete;
}
if( iLotteryType_gen != 1 )
{
printf("isRejectTransaction: [%s] not a genesis tx, invalid type \n", sLotteryLinkedTxid_gen.c_str());
goto check_Complete;
}
// is lottery Genesis tx
if( iCashTxHei <= (iEndBlock_gen + iBitNetBlockMargin3) )
{
printf("isRejectTransaction: Cash tx [%s]'s hei [%u] must > [%I64u], please wait \n", sCashTxHash.c_str(), iCashTxHei, (int64_t)(iEndBlock_gen + iBitNetBlockMargin3));
goto check_Complete;
}
//if( (iGenTxHei < iStartBlock_gen) || (iGenTxHei > iEndBlock) || (iEndBlock - iBitNetBlockMargin3)) )

if( (iBetTxHei < iStartBlock_gen) || (iBetTxHei > (iEndBlock_gen - iBitNetBlockMargin3)) )
{
printf("isRejectTransaction: Bet tx [%s]'s Hei (%u) not under rules, invalid :(\n", sLotteryBetTxid.c_str(), iBetTxHei);
goto check_Complete;
}
int64_t i6Mini = MIN_Lottery_Create_Amount;
if( isBitNetLotteryRuleStart() ){ i6Mini = BitNet_Lottery_Create_Mini_Amount_5K; }
if( iAmount_gen < i6Mini )
{
printf("isRejectTransaction: Genesis tx Amount [%I64u] < lottery's mini value [%I64u] :(\n", (iAmount_gen / COIN), (i6Mini / COIN));
goto check_Complete;
}
if( iAmount_bet < iMiniBet_gen )
{
printf("isRejectTransaction: bet amount [%I64u] < mini bet [%I64u] \n", (iAmount_bet / COIN), (iMiniBet_gen / COIN));
goto check_Complete;
}
if( iGuessType_bet != iGuessType_gen )
{
printf("isRejectTransaction: bet type [%u] != genesis type [%u] \n", iGuessType_bet, iGuessType_gen);
goto check_Complete;
}
if( iKeyLen_bet != iKeyLen_gen ) // guess block's hash text
{
printf("isRejectTransaction: bet type [%u], guess len [%u] != genesis guess key len [%u] \n", iGuessType_bet, iKeyLen_bet, iKeyLen_gen);
goto check_Complete;
}

if( isValidPrivKeysAddress(sLotteryPrivKey_gen, sLotteryAddr_gen) == 0 )
{
printf("isRejectTransaction: Genesis lottery PrivKey [%s]'s PubKey not  equ [%s] :(\n", sLotteryPrivKey_gen.c_str(), sLotteryAddr_gen.c_str());
goto check_Complete;
}

if( GetCoinAddrInTxOutIndex(sLotteryLinkedTxid_gen, sLotteryAddr_gen, iAmount_gen) == -1 ) // Check Lottery Amount, =-1 is invalid
{
printf("isRejectTransaction: Genesis tx not include: [%I64u] coins sent to Genesis lottery address [%s] \n", (iAmount_gen / COIN), sLotteryAddr_gen.c_str());
goto check_Complete;
}
if( GetCoinAddrInTxOutIndex(sLotteryBetTxid, sLotteryAddr_gen, iAmount_bet) == -1 )
{
printf("isRejectTransaction: Bet tx not include: [%I64u] coins sent to Genesis lottery address [%s] \n", (iAmount_bet / COIN), sLotteryAddr_gen.c_str());
goto check_Complete;
}

sLotteryAnswer = getBlockNByteHashStrByType(iEndBlock_gen, iKeyLen_gen, iGuessType_gen);
if( fDebug ){ printf("isRejectTransaction:  sLotteryAnswer = [%s], Bet txt = [%s] \n", sLotteryAnswer.c_str(), sGuessTxt_bet.c_str()); }
if( sGuessTxt_bet != sLotteryAnswer )
{
printf("isRejectTransaction: Bet guess text [%s] != [%s], Type = [%u] \n", sGuessTxt_bet.c_str(), sLotteryAnswer.c_str(), iGuessType_gen);
goto check_Complete;
}
// scan all of (iStartBlock_gen ~ iEndBlock_gen)'s block includes tx, find the "Bet Max" and "Bet first" bettor's address
if( getBetBiggerWinnerFromBlockRange(iStartBlock_gen, (iEndBlock_gen - iBitNetBlockMargin3), iKeyLen_gen, iGuessType_gen, sGuessTxt_bet, sLotteryAddr_gen, iAmount_bet, sRztBiggerAddr, i6RztBiggerValue) > 0 )
{
// someone guessed
if( sRztBiggerAddr == sMakerAddr_cash )
{
bCasherIsWinner = true;
sCashTxLinkedGenesisTx = sLotteryLinkedTxid_gen;
if( fDebug ){ printf("isRejectTransaction: [%s] linked lottery's winner is casher [%s]\n", sCashTxHash.c_str(), sRztBiggerAddr.c_str()); }
}else{ if( fDebug ){ printf("[%s] linked lottery's winner is [%s], not casher [%s] \n", sCashTxHash.c_str(), sRztBiggerAddr.c_str(), sMakerAddr_cash.c_str()); } }
}else{ // no one guessed, lottery creater is winner
if( fDebug ){ printf("isRejectTransaction: [%s] linked bet lottery's winner != [%s]\n", sCashTxHash.c_str(), sMakerAddr_cash.c_str()); }
}

}else{ if( fDebug )printf("isRejectTransaction: [%s] not a lottery tx, params count [%u] < 15 \n", sCashTxHash.c_str(), i); }

check_Complete:
if( fDebug ){ printf( "isRejectTransaction: check_Complete, bCasherIsWinner = [%u], tx.vin.size() = [%u], sCashTxLinkedGenesisTx = [%s], sRztBiggerAddr = [%s], \n", bCasherIsWinner, tx.vin.size(), sCashTxLinkedGenesisTx.c_str(), sRztBiggerAddr.c_str() ); }
int j = 0;
BOOST_FOREACH(const CTxIn& txin, tx.vin)
    {
        uint256 hashBlock = 0;
        CTransaction txPrev;
j++;

        if( GetTransaction(txin.prevout.hash, txPrev, hashBlock) ) // get the vin's previous transaction
{  
string sPrevTxMsg = txPrev.vpndata;
CTxDestination source;
string preTxAddress = "";
string sPreTxHash = txPrev.GetHash().ToString();
int iPreTxHei = GetTransactionBlockHeight(sPreTxHash);

if (ExtractDestination(txPrev.vout[txin.prevout.n].scriptPubKey, source))  
{
                                CBitcoinAddress addressSource(source);
preTxAddress = addressSource.ToString();
}

// check for lottery tx, only protect under rules lottery.
string sLotId_Pre, sGuessTxt_Pre, sLotteryAddr_Pre, sLotteryPrivKey_Pre, sMakerAddr_Pre, sLotteryLinkedTxid_Pre, sSignMsg_Pre;
int iLotteryType_Pre, iGuessType_Pre, iKeyLen_Pre;
int64_t iAmount_Pre, iMiniBet_Pre, iStartBlock_Pre, iEndBlock_Pre;

i = GetTxMsgParam(txPrev, sLotId_Pre, iLotteryType_Pre, iGuessType_Pre, iAmount_Pre, iMiniBet_Pre, iStartBlock_Pre, iEndBlock_Pre, iKeyLen_Pre,
sGuessTxt_Pre, sLotteryAddr_Pre, sLotteryPrivKey_Pre, sMakerAddr_Pre, sLotteryLinkedTxid_Pre, sSignMsg_Pre);
if( fDebug ){ printf("isRejectTransaction: (%u) iLotteryType_Pre = [%u], Hei = [%u], Prev Address = [%s], Prev Tx Hash = [%s], Tx Msg = [%s] \n", j, iLotteryType_Pre, iPreTxHei, preTxAddress.c_str(), sPreTxHash.c_str(), sPrevTxMsg.c_str()); }
//if( (sPrevTxMsg.length() > 34) && (sPrevTxMsg.find(strBitNetLotteryMagic) == 0) )   //  "BitNet Lottery:"
if( i < 15 )
{
if( fDebug ){ printf("isRejectTransaction: (%u) Prev Tx [%s] not a lottery tx, params count [%u] < 15, continue \n", j, sPreTxHash.c_str(), i); }
continue;
}

// it's a lottery tx
bool bValidPayTx = false;
int iPreTx_linked_Hei = GetTransactionBlockHeight(sLotteryLinkedTxid_Pre); // genesis tx's sLotteryLinkedTxid_Pre is empt
if( fDebug ){ printf("isRejectTransaction: (%u) iPreTx_linked_Hei = [%u],  iCashTxHei = [%u], sLotteryLinkedTxid_Pre [%s] \n", j, iPreTx_linked_Hei, iCashTxHei, sLotteryLinkedTxid_Pre.c_str()); }
if( (iPreTxHei < BitNetLotteryStartTestBlock_286000) || (iCashTxHei <= iPreTxHei) )
{
if( fDebug )printf("isRejectTransaction: (%u) iPreTxHei = [%u] not under rules,  iCashTxHei = [%u], continue :(\n", j, iPreTxHei, iCashTxHei);
continue;
}
if( iLotteryType_Pre == 1 ) // genesis tx
{
//bool isValidLotteryGenesisTx(const CTransaction& tx, int iTxHei, int iTargetGuessType, int iTargetGuessLen, int64_t i6TargetBlock, const string sTargetMaker, const string sTargetGenesisAddr)
bValidPayTx = isValidLotteryGenesisTx(txPrev, iPreTxHei, -1, -1, 0, "", "");
}
else if( iLotteryType_Pre == 2 ) // bet tx
{
//bool isValidLotteryBetTx(const CTransaction& tx, int iTxHei, int iTargetGuessType, int iTargetGuessLen, int64_t i6TargetBlock, const string sTargetMaker, const string sTargetGenesisAddr)
bValidPayTx = isValidLotteryBetTx(txPrev, iPreTxHei, -1, -1, 0, "", "");
}else{
if( fDebug )printf("isRejectTransaction: (%u) invalid lottery, type [%u], continue \n", j, iLotteryType_Pre);
continue;
}

if( fDebug ){ printf("isRejectTransaction: (%u) bValidPayTx = [%u], bCasherIsWinner = [%u] \n", j, bValidPayTx, bCasherIsWinner); }
if( bCasherIsWinner == false )
{
if( bValidPayTx )
{
iWillBan++;
if( fDebug )printf("isRejectTransaction: (%u) sMakerAddr_cash(%s) not lottery cash tx [%s] linked tx's winner, will ban. \n", j, sMakerAddr_cash.c_str(), sCashTxHash.c_str());
if( isBitNetLotteryRuleStart() )
{
if( fDebug )printf("isRejectTransaction: (%u) isBitNetLotteryRuleStart, bCasherIsWinner = false, bValidPayTx = [%u], ban! \n*******************\n\n\n", j, bValidPayTx);
return true;
}
}else{ if( fDebug ){ printf("isRejectTransaction: (%u) bCasherIsWinner = false, bValidPayTx = false ... \n", j); } }
}
else{
// sMakerAddr_cash is a winner, but it's all input lottery tx's winner? let's check it (check the lottery genesis tx).
if( fDebug ){ printf("isRejectTransaction: (%u) bCasherIsWinner = true, bValidPayTx = [%u], iLotteryType_Pre = [%u] \n", j, bValidPayTx, iLotteryType_Pre); }
if( bValidPayTx )
{
if( iLotteryType_Pre == 1 ) // genesis tx
{
if( sPreTxHash != sCashTxLinkedGenesisTx )
{
iWillBan++;
if( fDebug )printf("isRejectTransaction: (%u) [%s] is genesis tx [%s]'s winner, but can't cash other genesis tx [%s]'s, will ban. \n", j, sMakerAddr_cash.c_str(), sCashTxLinkedGenesisTx.c_str(), sPreTxHash.c_str());
if( isBitNetLotteryRuleStart() )
{
if( fDebug ){ printf("[%s] end ********************\n\n\n", sCashTxHash.c_str()); }
return true;
}
}
}
else if( iLotteryType_Pre == 2 ) // bet tx
{
if( sLotteryLinkedTxid_Pre != sCashTxLinkedGenesisTx )
{
iWillBan++;
if( fDebug )printf("isRejectTransaction: (%u) [%s] is genesis tx [%s]'s winner, but can't cash bet tx linked other genesis tx [%s]'s, will ban. \n", j, sMakerAddr_cash.c_str(), sCashTxLinkedGenesisTx.c_str(), sLotteryLinkedTxid_Pre.c_str());
if( isBitNetLotteryRuleStart() )
{
if( fDebug ){ printf("[%s] end ********************\n\n\n", sCashTxHash.c_str()); }
return true;
}
}
}
}else{ if( fDebug )printf("isRejectTransaction: (%u) bCasherIsWinner = true, bValidPayTx = false, iLotteryType_Pre = [%u],  continue\n", j, iLotteryType_Pre); }
}
}else{ if( fDebug )printf("isRejectTransaction: (%u) GetTransaction(txin.prevout.hash, txPrev, hashBlock) false, continue \n", j); }
}
if( !rzt ){ if( fDebug ){ printf("isRejectTransaction: i Will Ban = [%u], bCashMsgSign = [%u], bCasherIsWinner = [%u] \n", iWillBan, bCashMsgSignOk, bCasherIsWinner); }}
if( fDebug ){ printf("[%s] end ********************\n\n\n", sCashTxHash.c_str()); }
return rzt;
}

Some related functions:
Code:
string GetPrivKeysAddress(string &strSecret)
{
    string rzt = "";
    CBitcoinSecret vchSecret;
    bool fGood = vchSecret.SetString(strSecret);
    if ( !fGood ) return rzt;

    CKey key;
    bool fCompressed;
    CSecret secret = vchSecret.GetSecret(fCompressed);
    key.SetSecret(secret, fCompressed);
    CKeyID vchAddress = key.GetPubKey().GetID();
CBitcoinAddress ba(vchAddress);
rzt = ba.ToString();
    return rzt;
}

bool isValidPrivKeysAddress(string &strSecret, string &sAddr)
{
bool rzt = false;
if( strSecret.length() < 34 ) return rzt;
if( sAddr.length() < 34 ) return rzt;
string vAddr = GetPrivKeysAddress(strSecret);
rzt = ( sAddr == vAddr );
return rzt;
}

int GetTxMsgParam(const CTransaction& tx, string& sLotteryId, int& iCardType, int& iGuessType, int64_t& iAmount, int64_t& iMiniBet, int64_t& iStartBlock, int64_t& iEndBlock, int& iKeyLen,
    string& sGuessTxt, string& sLotteryAddr, string& sLotteryPrivKey, string& sMakerAddr, string& sLotteryLinkedTxid, string& sSignMsg)
{
int rzt = 0;
string stxData = "";
if( tx.vpndata.length() > 0 ){ stxData = tx.vpndata.c_str(); }
//if( fDebug ){ printf("GetTxMsgParam: tx Msg = [%s] \n", stxData.c_str()); }
// Lottery Flag | Lottery ID | Card Type( Create = 1, Bet = 2, Cash = 3 ) | Guess Type | Amount | Mini Bet | Start block | Target block | Guess HASH Len | Guess Txt | Lottery wallet address | Lottery wallet PrivKey | Def_WalletAddress | Lottery Tx ID Str ( If it's Bet tx ) | SignMsg ( if it's Cash tx )
// BitNet Lottery: | 123456 | 1 | 0 | 10000 | 500 | 234000 | 235000 | 6 | Vbq7grdv6caVBf1RoHPJZ9RuhsHqmY3bLi | WarWyAu2UsCKzjQWvKMT5vBbMypMuS2ru37QtUdNoFDySTjxH8uY | VevimYsrNKWbx2W6Bnq2qyLthcnEasLMTg | 21051c47f29dd01a828cd6197ce6563d4c184ecff3e34a0599fa2af8d6c65ef5 | H3rQLBiDTZwKB1OGFo8zs5RJr/XH2ubrIHGTCKnOdP4bHsu5KgikkBPujJWJ6VweY7ZZR19JbjH7kZ8qKI50h1k=
if( (stxData.length() > 34) && (stxData.find(strBitNetLotteryMagic) == 0) )   //  "BitNet Lottery:"
{
char * pch;
char *delim = "|";
int i = 0;
sLotteryId = "";
string sAmount = "", sMiniBet = "";
sGuessTxt = "", sSignMsg = "";
string sStartBlock = "", sEndBlock = "", sKeyLen = "";
sLotteryAddr = "", sLotteryPrivKey = "", sMakerAddr = "",  sLotteryLinkedTxid = "";
iAmount = 0, iMiniBet = 0, iStartBlock = 0, iEndBlock = 0;
iKeyLen = 0, iCardType = 0, iGuessType = 0;
double dv = 0;

char * pVpn = (char *)stxData.c_str();
//printf ("vpndata = [%s]\n", pVpn);
pch = strtok(pVpn, delim);
while (pch != NULL)
{
i++;
if( i == 2 ){ sLotteryId = pch; }
else if( i == 3 ){ iCardType = atoi(pch); } //  create = 1, bet = 2, cash = 3
else if( i == 4 ){ iGuessType = atoi(pch); }
else if( i == 5 ){ sAmount = pch; dv = atof(pch); iAmount = roundint64(dv * COIN); }
else if( i == 6 ){ sMiniBet = pch; dv = atof(pch); iMiniBet = roundint64(dv * COIN); }
else if( i == 7 ){ sStartBlock = pch;  dv =  atof(pch); iStartBlock = roundint64(dv); }  //S_To_64(pch); }
else if( i == 8 ){ sEndBlock = pch; iEndBlock = S_To_64(pch); }
else if( i == 9 ){ sKeyLen = pch; iKeyLen = atoi(pch); }
else if( i == 10 ){ sGuessTxt = pch; }
else if( i == 11 ){ sLotteryAddr = pch; }
else if( i == 12 ){ sLotteryPrivKey = pch; }
else if( i == 13 ){ sMakerAddr = pch; }
else if( i == 14 ){ sLotteryLinkedTxid = pch; }
else if( i == 15 ){ sSignMsg = pch; }
//if( fDebug ){ printf ("%s, %d\n", pch, i); }
pch = strtok (NULL, delim);
}
rzt = i;
}
return rzt;
}

Code:
bool isValidLotteryGenesisTx(const CTransaction& tx, int iTxHei, int iTargetGuessType, int iTargetGuessLen, int64_t i6TargetBlock, const string sTargetMaker, const string sTargetGenesisAddr)
{
bool rzt = false;

string sTxHash = tx.GetHash().ToString();
if( iTxHei == -1 ){ iTxHei = GetTransactionBlockHeight(sTxHash); }
if( iTxHei == 0 ){
if( fDebug ) printf("isValidLotteryGenesisTx: Tx [%s] Hei = 0, set to nBestHeight [%u] \n", sTxHash.c_str(), nBestHeight);
iTxHei = nBestHeight;
}
if( fDebug ){ printf("isValidLotteryGenesisTx: Tx [%s] Hei = [%u], nBestHeight [%u] \n", sTxHash.c_str(), iTxHei, nBestHeight); }
if( iTxHei < BitNetLotteryStartTestBlock_286000 ){ return rzt; }

string sLotId, sGuessTxt, sLotteryAddr, sLotteryPrivKey, sMakerAddr, sLotteryGenesisTxid, sSignMsg;
int iLotteryType, iGuessType, iHashLen;
int64_t iAmount, iMiniBet, iStartBlock, iEndBlock;

int i = GetTxMsgParam(tx, sLotId, iLotteryType, iGuessType, iAmount, iMiniBet, iStartBlock, iEndBlock, iHashLen, sGuessTxt, sLotteryAddr, sLotteryPrivKey, sMakerAddr, sLotteryGenesisTxid, sSignMsg);
if( (i < 15) || (iLotteryType != 1) || (iHashLen < 1) || (iHashLen > 64) )
{
if( fDebug ){ printf("isValidLotteryGenesisTx: i (%u) < 15 or iLotteryType(%u) != 1 or iHashLen(%u) < 1 or > 64 \n", i, iLotteryType, iHashLen); }
return rzt;
} // block hash len = 64
if( fDebug ){ printf("isValidLotteryGenesisTx: iGuessType = [%u], sLotteryAddr = [%s],  sMakerAddr = [%s]\n", iGuessType, sLotteryAddr.c_str(), sMakerAddr.c_str()); }
if(  (iGuessType < 0) ||  (iGuessType > 1) ){ return rzt; }
if( validateAddress(sLotteryAddr) == false ){ return rzt; }
if( validateAddress(sMakerAddr) == false ){ return rzt; }

if( (iTargetGuessType != -1) && (iTargetGuessType != iGuessType) ){ return rzt; }
if( (iTargetGuessLen != -1) && (iTargetGuessLen != iHashLen) ){ return rzt; }
if( (i6TargetBlock != 0) && (i6TargetBlock != iEndBlock) ){ return rzt; }
if( (sTargetMaker.length() > 30) && (sTargetMaker != sMakerAddr) ){ return rzt; }
if( (sTargetGenesisAddr.length() > 30) && (sLotteryAddr != sTargetGenesisAddr) ){ return rzt; }

int64_t i6Mini = MIN_Lottery_Create_Amount;
if( isBitNetLotteryRuleStart() ){ i6Mini = BitNet_Lottery_Create_Mini_Amount_5K; }
if( iAmount < i6Mini )
{
if( fDebug ) printf("isValidLotteryGenesisTx: Amount [%I64u] < publish lottery's mini value [%I64u] :(\n", iAmount / COIN, i6Mini / COIN);
return rzt;
}
if( (iTxHei < iStartBlock) || (iTxHei > (iEndBlock - (BitNetBeginAndEndBlockMargin_Mini_30 - 10))) ) //iBitNetBlockMargin3
{
if( fDebug ) printf("isValidLotteryGenesisTx: Blocks not under rules, Hei = [%u] : [%I64u ~ %I64u] :(\n", iTxHei, iStartBlock, (iEndBlock - 20));
return rzt;
}

int64_t i6mg = iEndBlock - iStartBlock;
if( (iEndBlock > iStartBlock) && (i6mg >= BitNetBeginAndEndBlockMargin_Mini_30) && (i6mg <= BitNetBeginAndEndBlockMargin_Max_4320) ) // Target block number must big than start block
{
if( isValidPrivKeysAddress(sLotteryPrivKey, sLotteryAddr) )
{
if( GetCoinAddrInTxOutIndex(tx, sLotteryAddr, iAmount) >= 0 ) // Check Lottery Amount, =-1 is invalid
{
rzt = true;
if( fDebug ){ printf("isValidLotteryGenesisTx: Yes :) \n"); }
}else{ printf("isValidLotteryGenesisTx: [%I64u] coins not send to [%s] :(\n", iAmount, sLotteryAddr.c_str()); }
}else{ printf("isValidLotteryGenesisTx: Lottery PrivKey [%s]'s PubKey not  equ [%s] :(\n", sLotteryPrivKey.c_str(), sLotteryAddr.c_str()); }
}else{ printf("isValidLotteryGenesisTx: Lottery Block (%I64u) : (%I64u) not under rules :(\n", iStartBlock, iEndBlock); }
return rzt;
}

Code:
bool isValidLotteryBetTx(const CTransaction& tx, int iTxHei, int iTargetGuessType, int iTargetGuessLen, int64_t i6TargetBlock, const string sTargetMaker, const string sTargetGenesisAddr)
{
bool rzt = false;

string sTxHash = tx.GetHash().ToString();
if( iTxHei == -1 ){ iTxHei = GetTransactionBlockHeight(sTxHash); }
if( iTxHei == 0 ){
if( fDebug ) printf("isValidLotteryBetTx: Tx [%s] Hei = 0, set to nBestHeight [%u] \n", sTxHash.c_str(), nBestHeight);
iTxHei = nBestHeight;
}
if( fDebug ){ printf("isValidLotteryBetTx: Tx [%s] Hei = [%u], nBestHeight = [%u] \n", sTxHash.c_str(), iTxHei, nBestHeight); }
if( iTxHei < BitNetLotteryStartTestBlock_286000 ){ return rzt; }

string sLotId, sGuessTxt, sLotteryAddr, sLotteryPrivKey, sMakerAddr, sLotteryGenesisTxid, sSignMsg;
int iLotteryType, iGuessType, iHashLen;
int64_t iAmount, iMiniBet, iStartBlock, iEndBlock;

int i = GetTxMsgParam(tx, sLotId, iLotteryType, iGuessType, iAmount, iMiniBet, iStartBlock, iEndBlock, iHashLen, sGuessTxt, sLotteryAddr, sLotteryPrivKey, sMakerAddr, sLotteryGenesisTxid, sSignMsg);
if( (i < 15) || (iLotteryType != 2) || (iHashLen < 1) || (iHashLen > 64) )
{
if( fDebug ) printf("isValidLotteryBetTx: (i[%u] < 15) || (iLotteryType[%u] != 2) || (iHashLen[%u] < 1) || (iHashLen > 64) :( \n", i, iLotteryType, iHashLen);
return rzt;
} // block hash len = 64
if(  (iGuessType < 0) ||  (iGuessType > 1) )
{
if( fDebug ) printf("isValidLotteryBetTx: (iGuessType < 0) ||  (iGuessType > 1) :( \n");
return rzt;
}
if( validateAddress(sMakerAddr) == false )
{
if( fDebug ) printf("isValidLotteryBetTx: sMakerAddr [%s] invalid :( \n", sMakerAddr.c_str());
return rzt;
}
if( validateAddress(sLotteryAddr) == false )
{
if( fDebug ) printf("isValidLotteryBetTx: sLotteryAddr [%s] invalid :( \n", sLotteryAddr.c_str());
return rzt;
}

if( (iTargetGuessType != -1) && (iTargetGuessType != iGuessType) )
{
if( fDebug ) printf("isValidLotteryBetTx: '(iTargetGuessType != -1) && (iTargetGuessType != iGuessType)' :(\n");
return rzt;
}
if( (iTargetGuessLen != -1) && (iTargetGuessLen != iHashLen) )
{
if( fDebug ) printf("isValidLotteryBetTx: '(iTargetGuessLen != -1) && (iTargetGuessLen != iHashLen)' :(\n");
return rzt;
}
if( (i6TargetBlock > BitNetLotteryStartTestBlock_286000) && (i6TargetBlock != iEndBlock) )
{
if( fDebug ) printf("isValidLotteryBetTx: 'i6TargetBlock > BitNetLotteryStartTestBlock_286000) && (i6TargetBlock != iEndBlock)' :( \n");
return rzt;
}
if( (sTargetMaker.length() > 30) && (sTargetMaker != sMakerAddr) )
{
if( fDebug ) printf("isValidLotteryBetTx: '(sTargetMaker.length() > 30) && (sTargetMaker != sMakerAddr)' :(\n");
return rzt;
}
if( (sTargetGenesisAddr.length() > 30) && (sLotteryAddr != sTargetGenesisAddr) )
{
if( fDebug ) printf("isValidLotteryBetTx: '(sTargetGenesisAddr.length() > 30) && (sLotteryAddr != sTargetGenesisAddr)' :( \n");
return rzt;
}

int iTxHei_gen = GetTransactionBlockHeight(sLotteryGenesisTxid);
if( fDebug ){ printf("isValidLotteryBetTx: iTxHei_gen = [%u], iTxHei = [%u], [%s] \n", iTxHei_gen, iTxHei, sLotteryGenesisTxid.c_str()); }
//isValidLotteryBetTx: iTxHei_gen = [286893], iTxHei = [286893], [91b12f9f1961233ec9e2ddbbb3363b45d5b6a701bbbd8b332361a123b29cd343]
if( (iTxHei_gen < BitNetLotteryStartTestBlock_286000) || (iTxHei <= iTxHei_gen) )
{
if( fDebug ) printf("isValidLotteryBetTx: '(iTxHei_gen(%u) < BitNetLotteryStartTestBlock_286000) || (iTxHei[%u] <= iTxHei_gen)' :( \n", iTxHei_gen, iTxHei);
return rzt;
}

//bool isValidLotteryGenesisTxs(const string& txID, int iTxHei, int iTargetGuessType, int iTargetGuessLen, int64_t i6TargetBlock, const string sTargetMaker, const string sTargetGenesisAddr)
if( isValidLotteryGenesisTxs(sLotteryGenesisTxid, iTxHei_gen, iGuessType, iHashLen, iEndBlock, "", sLotteryAddr) == false )
{
if( fDebug ) printf("isValidLotteryBetTx: Tx [%s] linked Genesis tx [%s] invalid :( \n", sTxHash.c_str(), sLotteryGenesisTxid.c_str());
return rzt;
}

string sLotId_gen, sGuessTxt_gen, sLotteryAddr_gen, sLotteryPrivKey_gen, sMakerAddr_gen, sLotteryGenesisTxid_gen, sSignMsg_gen;
int iLotteryType_gen, iGuessType_gen, iKeyLen_gen;
int64_t iAmount_gen, iMiniBet_gen, iStartBlock_gen, iEndBlock_gen;

i = GetTxMsgParam(sLotteryGenesisTxid, sLotId_gen, iLotteryType_gen, iGuessType_gen, iAmount_gen, iMiniBet_gen, iStartBlock_gen, iEndBlock_gen, iKeyLen_gen,
sGuessTxt_gen, sLotteryAddr_gen, sLotteryPrivKey_gen, sMakerAddr_gen, sLotteryGenesisTxid_gen, sSignMsg_gen);
if( (i < 15) || (iLotteryType_gen != 1) )
{
if( fDebug ) printf("isValidLotteryBetTx: params count [%u] < 15 Or iLotteryType_gen(%u) != 1:( \n", i, iLotteryType_gen);
return rzt;
}
if( (iTxHei < iStartBlock_gen) || (iTxHei > (iEndBlock_gen - iBitNetBlockMargin3)) )
{
if( fDebug ) printf( "isValidLotteryBetTx: Hei (%u) not under rules (%I64u ~ %I64u), invalid :( \n", iTxHei, iStartBlock_gen, (iEndBlock_gen - iBitNetBlockMargin3) );
return rzt;
}
if( iAmount < iMiniBet_gen )
{
if( fDebug ) printf("isValidLotteryBetTx: Bet Amount [%I64u] less than genesis tx's MiniBet [%I64u] :( \n", iAmount, iMiniBet_gen);
return rzt;
}
if( GetCoinAddrInTxOutIndex(tx, sLotteryAddr_gen, iAmount) >= 0 ) // Check bet is send to lottery genesis tx's Address
{
rzt = true;
if( fDebug ){ printf("isValidLotteryBetTx: Yes :) \n"); }
}else{ printf("isValidLotteryBetTx: not found bet [%I64u] send to gen address [%s] :( \n", iAmount, sLotteryAddr_gen.c_str()); }
return rzt;
}




BitNet Lottery GUI:


Pages:
Jump to: