Title: Sample account system using JSON-RPC needed Post by: satoshi on July 16, 2010, 07:45:10 PM We need someone to write sample code, preferably Python or Java, showing the recommended way to use the JSON-RPC interface to create an account system. Most sites that sell things will need something like this. Someone who's kept up on the JSON-RPC threads here should have some idea how it should work.
When a user is logged in to their account, you show the bitcoin address they can send to to add funds. Before showing it, you check if it's been used, if it has then you replace it with a new one (getnewaddress <username>). You only need to keep the latest bitcoin address for the account in your database. (I posted a sample code fragment for this in an earlier thread somewhere, search on getnewaddress) You use getreceivedbylabel <username> with the username as the label to get the "credit" amount of the account. You need to keep a "debit" amount in your database. The current balance of the account is (credit - debit). When the user spends money, you increase debit. If you're requiring more than 0 confirmations, it's nice if you show the current balance (0 confirmations) and the available balance (1 or more confirmations), so they can immediately see that their payment is acknowledged. Not all sites need to wait for confirmations, so the dual current & available should be optional. Most sites selling digital goods are fine to accept 0 confirmations. A nice sample app for this would be a simple bank site, which would have the above, plus the option to send a payment to a bitcoin address. The sample code should be the simplest possible with the minimum extra stuff to make it a working site. vekja.net is an example of a site like this. Title: Re: Sample account system using JSON-RPC needed Post by: RudeDude on July 16, 2010, 08:18:45 PM bitcoinmarket.com is doing all of these things now. perhaps the author of that site can share some code as well.
Title: Re: Sample account system using JSON-RPC needed Post by: RudeDude on July 16, 2010, 08:23:48 PM I should also point out that this site has some JSON code in Python.
http://www.alloscomp.com/bitcoin/ Specifically this code that checks the balance and sends it to a static address. Code: #!/usr/bin/python Title: Re: Sample account system using JSON-RPC needed Post by: dwdollar on July 16, 2010, 10:22:22 PM I've been meaning to post this for some time. I wanted to clean it up into a simple example, so it would be easy to understand. I don't know when I'll have a chance now. So... I'll just go ahead and post it as is. Maybe it will help somebody.
It probably isn't the best approach (after talking to Satoshi a while back). In fact, I haven't tried applying the new functions in the API, that were added later on and now in Version .3. But, it is battle tested. Why fix what isn't broken (yet)? It runs as a separate process on the machine with the Bitcoin server. The only thing I left out was a break handler for the while loop. Anytime you see "list(something_inside)", realize it's a query to the database using SQLObject. When I go through it again, I'll post a revision here. Code: #! /usr/bin/python Title: Re: Sample account system using JSON-RPC needed Post by: BitLex on July 17, 2010, 01:01:59 PM not exactly a complete account system (maybe half of it),
but i'd like to share my SAMPLE_JSON.PHP anyway, maybe it's of use for someone. it's using cURL to connect to the API. Code: <?php be sure to restrict access somehow! I guess there's easier, or simpler ways to do this, maybe you know of one. Title: Re: Sample account system using JSON-RPC needed Post by: denger on July 18, 2010, 03:12:14 AM Anyone done one in perl?
Thanks! Title: Re: Sample account system using JSON-RPC needed Post by: ArtemZ on July 18, 2010, 03:28:33 AM Anyone done one in perl? its quite easy to do same in perl if there are any json-rpc library for perl.Thanks! Title: Re: Sample account system using JSON-RPC needed Post by: melvster on July 26, 2010, 07:18:38 PM Anyone done one in perl? Thanks! http://goddamn.co.uk/viewvc/perlmods/Finance-Bitcoin/lib/Finance/Bitcoin/ Title: Re: Sample account system using JSON-RPC needed Post by: vual on February 06, 2012, 04:35:34 AM worth a bump, its needed to be up the top:
https://en.bitcoin.it/wiki/API_tutorial_%28JSON-RPC%29 https://en.bitcoin.it/wiki/Proper_Money_Handling_%28JSON-RPC%29 Title: Re: Sample account system using JSON-RPC needed Post by: genjix on February 06, 2012, 11:31:50 AM worth a bump, its needed to be up the top: https://en.bitcoin.it/wiki/API_tutorial_%28JSON-RPC%29 https://en.bitcoin.it/wiki/Proper_Money_Handling_%28JSON-RPC%29 I wrote those a long time ago and they're old. This is the updated version: http://bitcoinmedia.com/merchant-developer-tutorial/ Title: Re: Sample account system using JSON-RPC needed Post by: vual on February 06, 2012, 11:59:22 AM worth a bump, its needed to be up the top: https://en.bitcoin.it/wiki/API_tutorial_%28JSON-RPC%29 https://en.bitcoin.it/wiki/Proper_Money_Handling_%28JSON-RPC%29 I wrote those a long time ago and they're old. This is the updated version: http://bitcoinmedia.com/merchant-developer-tutorial/ wow... thanks kindly!! Title: Re: Sample account system using JSON-RPC needed Post by: akipfer on March 08, 2014, 08:49:19 AM I don't get it yet...
Its like this -> I'm making some kind of game using bitcoins as payable coin, but how do i know if the player has payd let's say 0.0001BTC, Player doesn't do LOGIN, just select diff and play, BUT to been able to play, he need to pay a little low amout, let's say-> 0.0001BTC.... How do i know (my system, PHP only..) if he has payed...causa i will to send him an email with tx and all, saying that has confirmed(when =>6 conf just to be sure that has actually payed... Some thing that i see on here -> https://en.bitcoin.it/wiki/Proper_Money_Handling_(JSON-RPC) (https://en.bitcoin.it/wiki/Proper_Money_Handling_(JSON-RPC)) Oh and one more thing.. not right..assume this -> <?php $RoundValue = 0.12345678; echo 'BTC 0,12345678 = "' .round($RoundValue * 1e8).'"'; ?> THIS will turn out to be \/ BTC 0,12345678 = "12345678" That just not right! and without that " round($RoundValue * 1e8) " Its goes all FINE, the way is mean to be...or i forgetting something really bad ..? So..What the hell? Without that i think is okay...if not, why not? Explain it to me! Thx4All till now! Title: Re: Sample account system using JSON-RPC needed Post by: 12648430 on March 08, 2014, 09:18:13 AM I don't get it yet... Its like this -> I some kind of game using bitcoins, but how do i know if the player has payd let's say 0.0001BTC, Player doesn't do LOGIN, just select diff and play, BUT to been able to play, he need to pay a low amout of 0.0001BTC.... How do i know (my system, PHP only..) if he has payed... Thx4All till now! Some thing that i see on here -> https://en.bitcoin.it/wiki/Proper_Money_Handling_(JSON-RPC) (https://en.bitcoin.it/wiki/Proper_Money_Handling_(JSON-RPC)) Oh and one more thing.. not right..assume this -> <?php $RoundValue = 0.12345678; echo 'BTC 0,12345678 = "' .round($RoundValue * 1e8).'"'; ?> THIS WILL TURNS OUT TO BE BTC 0,12345678 = "12345678" That just not right! and without that " round($RoundValue * 1e8) " Its goes all FINE, the way is mean to be...or i forgetting something really bad ..? So..What the hell? Please don't write software that handles money. Title: Re: Sample account system using JSON-RPC needed Post by: akipfer on March 08, 2014, 09:19:34 AM What do you mean?
Title: Re: Sample account system using JSON-RPC needed Post by: 12648430 on March 08, 2014, 09:27:48 AM What do you mean? It is difficult to write software that is suitable for handling money, especially when it's other peoples' and your software is online for anyone to interact with. Your current programming knowledge is not up to the task. You can solve some problems like the one you posted by asking people to help you with them, but though you may end up with something that "runs" you can't write secure software without really knowing what you're doing. Title: Re: Sample account system using JSON-RPC needed Post by: akipfer on March 08, 2014, 09:33:38 AM To be honest, i'm not new with PHP, i'm with Bitcoin it self(json-rpc)
the game it self is pretty simple, can't get hacked by any means, seriously! i only need to know how is that my scrypt can know if when the player send money, to tell me(or auto send an email) I can't figure it out how, just that, i mean, i use getnewaddress every time some one click on pay? if so...hell that would make like so, so many addresses listed on my bitcoin(not qt for now, but still..) Ps: I get that, on a high level i'm sure i need to learn a lot about json-rpc to do something like a coin trader or something 'BAD ASS' like that.. but i won't be abble to 'write secure software ' if i never do try... just saying...Won't u agree with me? |