Skip to content

girino/BTCTalkPTSorteioAnoNovo

Repository files navigation

BTCTalkPTSorteioAnoNovo

These scripts were developed in order to provide a bitcoin based, pseudorandom, auditable, reprocible loterry for the portuguese speaking community in bitcointalk forum.

Instalation instructions

  1. Download from github:

    git clone https://github.com/girino/BTCTalkPTSorteioAnoNovo

  2. Enter the folder:

    cd BTCTalkPTSorteioAnoNovo

  3. copy config.php-sample to config.ph

  4. Edit the new file (follow the comments).

  5. Run it:

    php script.php

optional command lines

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

How it works internally?

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

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages