These scripts were developed in order to provide a bitcoin based, pseudorandom, auditable, reprocible loterry for the portuguese speaking community in bitcointalk forum.
-
Download from github:
git clone https://github.com/girino/BTCTalkPTSorteioAnoNovo
-
Enter the folder:
cd BTCTalkPTSorteioAnoNovo
-
copy
config.php-sample
toconfig.ph
-
Edit the new file (follow the comments).
-
Run it:
php script.php
Command line options override defaults defined in config.php
-a
Change default loterry address.
-b
Set initial block (only transactions after this block (inclusive) will participate in the lottery). This block will also be used as basis for the pseudorandom number.
-e
Set final block (only transactions before this block (inclusive) will participate in the lottery). This block will also be used as basis for the pseudorandom number.
-m
Change the loterry ticket value (min bet, or "min" in the config file).
--core
Use bitcoin core engine (needs to set up the "$rpc" section in the config.php file).
--btrail
Use BlockTrail.com API (needs to add the API key set in the "$apikeys" section in the config.php file).
--bcinfo (default) Use Blockchain.info API. This is slower than blocktrail, and unstable (sometimes breaks because of high load).
The scripts generate pseudorandom ticket numbers (hashes) for each transaction, whith chances proportional to the amount each transaction payed to the loterry (if base price is 0.001 BTC and transaction value was 0.003 BTC, 3 tickets (with same hash) are generated. If value is not exact (i.e. 0.0015 for a 0.001 ticket), the number of tickets is rounded down.
Tickets are then ordered lexicografically by ticket hash. A new pseudorandom hash is generated by hashing toghether
the hashes of the initial and final blocks. The selected ticket will be the remainder of the division of this hash by
the total number of tickets: $winner = $hash % count($tickets_array)
. (note: in order to facilitate the
mathematical operations, only the last 6 bytes of the hash are considered, and converted to an integer, before dividing).