Skip to content
prediction market on lotionjs with tendermint
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
cryptography_trial
examples
public
test
.gitignore
README.md
app.js
common.js
json.js
license
local_testnet_keys.txt
package-lock.json
package.json
sigHash.js
stateUtil.js
web.js

README.md

prediction market

market phase

  1. open new market
  2. allow bet
  3. someone bets (record them)
  4. market closes (by time)

oracle phase

condition to enter phase: time

  1. get data from oracle
  2. determine the result and record it

condition to end phase: time

challenge phase

condition to enter phase: time, someone triggers it

  1. someone stake their coin and challenges

condition to end phase: time

vote phase

condition to enter phase: challenge phase completed

  1. anyone can stake their coin and vote

condition to end phase: time

distribute phase

condition to enter phase: time

  1. determine the final outcome
if (challenged)
  update the final outcome according to voting results
  distributed the staked coins in voting pool according to voting results.
distribute betting pool coins according to outcome

condition to end phase: when everything in the phase is executed

note

the time of the phase is indicated by block height. since we have finality, the phase start and stop block can be next to each other. in other ledger that lacks finality, we should reserve more time (several blocks) between each phase.

run

node app.js

test invocation:

it is possible to do test invocation using curl. however, you will need to supply signature yourself.
it is recommended to use test/testCommon.js complexSendTx(), which will handle the signature, public key (pubkey), and sequence.

for example of test invocation, please see test/testIntegrate2.js


if you need to if you need to send a transaction manually, you need to supply from.pubkey, from.signature, from.sequence, and to. the format is as follows.

curl -X POST http://localhost:3000/txs -d '{"type": "verifySig", "from": { "pubkey": "rewlkjrlw", "signature": "rewlkajrlewk", "sequence": 0 }, "to": {} }'

all of the tx will need from and to. however, for brevity purpose, they are omitted in the following calls:

curl -X POST http://localhost:3000/txs -d '{"type": "start", "marketId": "market2", "startInfo": ...}'

example startInfo:

  "startInfo": {
      "question": "Who will win FIFA 2018?",
      "outcomes": [
        "england",
        "italy",
        "brazil",
        "germany"
      ],
      "oracle": ["9x2yu6AzwWphm3j6h9pTaJh63h5ioG8RL","5wvwWgKP3Qfw1akQoXWg4NtKmzx5v4dTj"], // addresses of approved oracles
      // meta data about oracle.  eg. description
      "oracleMeta": "http://data.com/oracleinfo",
      "phaseTime":{
        "marketStart":9,"marketEnd":3609,
        "oracleStart":3610,"oracleEnd":7210,
        "challengeStart":7211,"challengeEnd":10811,
        "voteStart":10812,"voteEnd":14412,
        "distributeStart":14413,"distributeEnd":18013
      },
    }

curl -X POST http://localhost:3000/txs -d '{"type": "bet", "marketId": "market2", "outcome": 1, "amount": 10, "user": "5wvwWgKP3Qfw1akQoXWg4NtKmzx5v4dTj"}'

curl -X POST http://localhost:3000/txs -d '{"type": "bet", "marketId": "market2", "outcome": 2, "amount": 10, "user": "9x2yu6AzwWphm3j6h9pTaJh63h5ioG8RL"}'

curl -X POST http://localhost:3000/txs -d '{"type": "oracle", "marketId": "market2", "outcome": 2}'

curl -X POST http://localhost:3000/txs -d '{"type": "challenge", "marketId": "market2", "user": "5wvwWgKP3Qfw1akQoXWg4NtKmzx5v4dTj", "amount": 100}'

curl -X POST http://localhost:3000/txs -d '{"type": "vote", "marketId": "market2", "user": "5wvwWgKP3Qfw1akQoXWg4NtKmzx5v4dTj", "amount": 1000, "outcome": 1}'

curl -X POST http://localhost:3000/txs -d '{"type": "vote", "marketId": "market2", "user": "9x2yu6AzwWphm3j6h9pTaJh63h5ioG8RL", "amount": 10, "outcome": 2}'

curl -X POST http://localhost:3000/txs -d '{"type": "vote", "marketId": "market2", "user": "9x2yu6AzwWphm3j6h9pTaJh63h5ioG8RL", "amount": 1000, "outcome": 1}'

curl -X POST http://localhost:3000/txs -d '{"type": "distribute", "marketId": "market2"}'

for example of sending token to another address, see test/testSend.js for example of tx format.

update

You can’t perform that action at this time.