Magicdice Python library
magicdice is a (unofficial) Python library and set of tools to play and analyze STEEM based magic dice game. It has the functionality to verify bid and rolls, create bids in the game. It also includes a simple API wrapper for @magicdice's public API.
Installation
Minimum Python requirement is Python3.6 and greater.
$ (sudo) pip install magicdice
Bidding
Bid 0.100 STEEM for under number 50 with the client seed foo
.
from magicdice.core import Magicdice
m = Magicdice(
'<account>', '<active_key>')
resp = m.bid('under', '50', '0.100 STEEM', 'foo')
print(resp)
However, this doesn't guarantee that the bid is picked up by the game. If you want to ensure the bid is recognised by the game, you can pass ensure_pickup
flag:
from magicdice.core import Magicdice
m = Magicdice(
'<account>', '<active_key>')
resp = m.bid('under', '50', '0.100 STEEM', 'foo', ensure_pickup=True)
print(resp)
Which will include the roll (bid result) data.
magic-dice api client
from magicdice.api_client import ApiClient
api_client = ApiClient()
Global Properties
Returns the global properties of the game. (min/max prediction, max payout, house edge, etc.)
api_client.globals()
Bets
Returns the last N bets:
api_client.bets('<username>', {"limit": N})
User info
Returns the general user information. (wagered steem, token balances, delegation bonuses, etc.)
api_client.user('<username>')
Rare wins
Returns the rare win rolls.
api_client.rare_wins({"limit": 10})
Top winners
Returns the top winners.
api_client.top_winners({"limit": 10})
Verifying Bids
A simple roll verifier script. You need bid_block_id
, bid_block_tx
, roll_block_id
, roll_block_tx
, and server seed
variables.
It also has a logical check if the roll was a win but the magicdice interpreters as a loss.
from magicdice.utils import verify
bid_block_id = 30710738
bid_tx_id = "1ddbb2ccd975c7339a22c284fd0a91781ec99094"
roll_block_id = 30710739
roll_tx_id = "7b143697e667fd2a706ab0f88cc1dd9b6f252241"
server_seed = "8cc9pxehpq3kuoi9j5qd"
if verify(
bid_block_id,
bid_tx_id,
roll_block_id,
roll_tx_id,
server_seed,
):
print("Roll is solid!")
Only non-trivial variable is server_seed
here. You need to get that seed from the custom_json transactions broadcasted by @magicdice.
A simple bot
from magicdice.core import Magicdice
m = Magicdice(
'<account>', '<private_active_key>')
# Send 10 0.100 STEEM bids with under 50 prediction
for i in range(0, 10):
resp = m.bid('under', '50', '0.100 STEEM', 'foo', ensure_pickup=True)
roll = resp[2]
status = "won" if roll["won"] else "lost"
print(f"{status} {roll['amount']} {roll['asset']}")
Disclaimer
This library may contain unexpected bugs. Audit the code before using ut and use it at your own risk.
Commits
The project is brand new. All available commits can be checked at: emre/magicdice/commits/master
Thank you for your contribution. I am sure this library will be much useful to build up many apps upon magic-dice.
Regarding your
bid
function, I am not sure thesleep(4)
is a good idea as whenensurePickUp=true
, it will always slow down the function. It will be better to move the logics outside the function e.g.bid(something).sleep(4).verify().
Your contribution has been evaluated according to Utopian policies and guidelines, as well as a predefined set of questions pertaining to the category.
To view those questions and the relevant answers related to your post, click here.
Need help? Chat with us on Discord.
[utopian-moderator]
Thank you for your review, @justyy! Keep up the good work!
Hi @emrebeyler!
Your post was upvoted by @steem-ua, new Steem dApp, using UserAuthority for algorithmic post curation!
Your post is eligible for our upvote, thanks to our collaboration with @utopian-io!
Feel free to join our @steem-ua Discord server
Üretim tam gaz devam :)
üretime ara vermek yok hocam. :)
In testing the verifier, did you ever find magic dice count a loss when it was actually a win?
no.
Hey, @emrebeyler!
Thanks for contributing on Utopian.
We’re already looking forward to your next contribution!
Get higher incentives and support Utopian.io!
Simply set @utopian.pay as a 5% (or higher) payout beneficiary on your contribution post (via SteemPlus or Steeditor).
Want to chat? Join us on Discord https://discord.gg/h52nFrV.
Vote for Utopian Witness!
This post has been included in the latest edition of SoS Daily News - a digest of all you need to know about the State of Steem.