Author

Topic: Sample account system using JSON-RPC needed (Read 10797 times)

brand new
Activity: 0
Merit: 0
April 12, 2021, 03:39:05 PM
#17
Hi *atoshi. Pls. Read this with you heart.  I sent this to almost 100 users of bitcoin. Nobody talk to me.  Just to ask. Are you okay? Well. I'm not scammer.  I'm a woker that do everything wrong. I Hope that you read this

I took the liberty of writing on Twitter without comment. To stay private. I ask God to read it.
I am using a secondary account. I'm ashamed. My official twitter is @ berthalouu.
My Instagram is @ berthatouu

Like many people, I didn't have an easy life. Alcoholic father, fights between my parents. I was abused with a 5-year-old, by a family friend. Of course, this is not to call attention.

But it's just for you to understand how difficult it is for me to live in this world. And how much it affected my self-esteem.
Rebs

So from an early age my mother showed that the path was to study. I took a course in industrial electronics, but women here are little valued in the area. So I passed a bank competition and went to college.


But I was the only one in my family to go further. However, since 2010, I initially had to pay rent, as this new job was in another city, joining college and at the same time having to help my family (many brothers).

my mother can never leave the house, because she had to take care of my brother with severe autism, totally unable to go to the bathroom alone, to make his own food. He does not speak. And the institutions here were very limited. They did not accept my brother's degree.


So I always had to help around the house. With all this, and I know I did it the wrong way, I accumulated a lot of debt. In the meantime, I even managed to finance a house.

I managed to go paying without delay to where it went. I made the mistake of taking out a loan to cover another. And now I'm in a no-win situation. I've lived in this nightmare for years, I got an anxiety crisis, I don't sleep.
Rebs

Last weekend that I almost took my life. Because it is very difficult to live with the shame of being in debt. At the same time, knowing that I can lose my home is being charged. And I work at a bank. It's a shame.

But what worries me most is that I will not be able to complete my goals. That was to give my mother a more stable life, since she is 64 years old and soon she will have no more strength to take care of my brother.
Rebs

I was her hope. And now I’m useless. And living with this frustration of having failed, it hurts too much. I almost took my life, because I thought that with my life insurance, that amount could at least fix the mistakes I left. My husband could pay off the debts.

And help my mom a little. I don't love myself. What happened to me in the past makes me think that I am worthless. But I need to work on that.

I would also like to do things for a better world. But I feel so helpless now. I didn't have the courage to take my life. Because I couldn't stop thinking about the people who would stay here.

 But I also can't stop thinking that I failed, I have no way out, and that with everything that is happening in the world, do I deserve to be here?
 
That is why I ask from the heart. With $ 100,000, I am able to pay off everything, and focus only on giving back to those who help me. I promise I will return it. If you can't, or know someone who can help me.

I am sending my bitcoin wallet as it is the easiest way to send it to another country. I beg. You can ask anything you want via DM, or email.

 I send you documents, proof of address. Anything you can ask. I never ask anyone for money. The bubble burst in February of that year. Then I thought, I can't take it anymore. Just dying.

That's when I thought, if I open this up to someone, and that person can lend it to me, who knows I can change it. I'm sending it to you because I think that if you can't help me, at least show Mr *atoshi.

Please. I ask with all my heart. my emails are [email protected] and [email protected].
My Instagram is @ berthalouu. I delete it all (tweets) after you answer me.

my bitcoin wallet is
39Pn4cu1rZNnXDoQJXuzxJUDMstp9GULLH

mr. * atoshi, I asked several people. Some of these must have money for this life and for some more 3. Nobody even questioned it.

I will wait with hope in my heart. Thanks
sr. member
Activity: 294
Merit: 250
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?
full member
Activity: 144
Merit: 100
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.
sr. member
Activity: 294
Merit: 250
What do you mean?
full member
Activity: 144
Merit: 100
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)

Oh and one more thing..
 not right..assume this ->

$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.
sr. member
Activity: 294
Merit: 250
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)

Oh and one more thing..
 not right..assume this ->

$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!
legendary
Activity: 1232
Merit: 1072
hero member
Activity: 714
Merit: 500
newbie
Activity: 26
Merit: 0
Anyone done one in perl?
Thanks!
its quite easy to do same in perl if there are any json-rpc library for perl.
newbie
Activity: 14
Merit: 0
Anyone done one in perl?
Thanks!
hero member
Activity: 532
Merit: 505
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:
// IMPORTANT!
// This is NOT SECURE by default, restrict access to this script,
// password protect it, check the referrer, session, or whatever else you like.
// Anyone able to reach this script AS IS is able to send your balance to another address!


// simply call commands like this 
// ./SAMPLE_JSON.PHP?command=getinfo
// or with parameter
// ./SAMPLE_JSON.PHP?command=getnewaddress¶meter=username
// ./SAMPLE_JSON.PHP?command=getreceivedbylabel¶meter=username


// set the URL to JSON-API
$url 'http://127.0.0.1:8332';  
// set a JSON id
$jsonid 'unique'  

// which command has been called?
if ($_GET['command'])
$command $_GET['command'];
// and if what parameter?
if ($_GET['parameter'])
$para $_GET['parameter'];
if (
$para$parb = array($para);
// if none, we create an empty array
else $parb = array();
// and encode all of it to JSON
$arr = array (
 'id'=>$jsonid,
 'method'=>$command,
 'params'=>$parb
);
$data json_encode($arr);
// run cURL to transfer our data
  
$ch curl_init();
  
curl_setopt($chCURLOPT_HTTPHEADER, array('Content-Type: application/json')); 
  
curl_setopt($chCURLOPT_RETURNTRANSFERtrue);
  
curl_setopt($chCURLOPT_POST1);
  
curl_setopt($chCURLOPT_URL$url);
  
curl_setopt($chCURLOPT_POSTFIELDS$data);
  
$output curl_exec($ch); 
// debug - to check the response we can just view our JSON output here
echo $output."
\n\r"
;  
// if $output looks ok, we decode it here and close our cURL session
  
$obj json_decode($output);
  
curl_close($ch); 

// and that's it, just handle the $obj and show it, add/compare it to DBs, or whatever else is needed.

// below  is just some basic samples 
   
if ($obj->error != "null")
     
echo $obj->error;   
     

if (
$obj->id == $jsonid) {    
 
if (is_object($obj->result))
$info get_object_vars($obj->result);
     
   
if ($command == "getinfo") {
    
 if ($info) {
            echo 
"Balance: "$info['balance']."
\n\r"
;
            echo 
"Blocks: "$info['blocks']."
\n\r"
;
            echo 
"Connections: "$info['connections']."
\n\r"
;
            if (
$info['generate'])
            
$gen "yes";
            else
            
$gen "no";
            echo 
"Generating: "$gen."
\n\r"
;
            echo 
"Difficulty: "$info['difficulty']."
\n\r"
;
         }
     } 
     if (
$command == "getreceivedbylabel") {
     
echo $obj->result."\n";
     }
     if (
$command == "getnewaddress") {
     
echo $obj->result."\n";
     }
}   
?>


be sure to restrict access somehow!

I guess there's easier, or simpler ways to do this, maybe you know of one.
full member
Activity: 202
Merit: 109
GCC - Global cryptocurrency
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


import jsonrpc
import time
import datetime

from database import *


class BitcoinInterface(object):

    def __init__(self):
        self.access = jsonrpc.ServiceProxy("http://127.0.0.1:8332")
        return

    def issueBitcoinAddresses(self):
        localBitcoinAddresses = list(Address.select(AND(Address.q.type_ == "localBitcoin", Address.q.value == None)))    # Get all unassigned local Bitcoin Addresses
        for localBitcoinAddress in localBitcoinAddresses:
            localBitcoinAddress.value = self.access.getnewaddress()
            client = Client.get(localBitcoinAddress.clientID)
            print "New Address:\nUsername:  %s\nClientID:  %i\nValue:  %s\n" % (client.username, client.id, localBitcoinAddress.value)
        return

    def takeDeposits(self):
        localBitcoinAddresses = list(Address.select(AND(Address.q.type_ == "localBitcoin", Address.q.value != None)))    # Get all assigned local Bitcoin Addresses
        for localBitcoinAddress in localBitcoinAddresses:
            amountReceived = self.access.getamountreceived(localBitcoinAddress.value)
            if amountReceived > localBitcoinAddress.amountReceived:
                client = Client.get(localBitcoinAddress.clientID)
                quantity = amountReceived - localBitcoinAddress.amountReceived
                client.bitcoins = client.bitcoins + quantity
                localBitcoinAddress.amountReceived = amountReceived
                transaction = Transaction(clientID = client.id)
                transaction.datetime = datetime.datetime.now()
                transaction.type_ = "Deposit"
                transaction.quantity = quantity    # Transaction quantity is positive for "Deposit"
                print "Deposit:\nUsername:  %s\nClientID:  %i\nQuantity:  %f\n" % (client.username, client.id, quantity)
        return

    def issueWithdrawals(self):
        clients = list(Client.select(Client.q.bitcoinsToWithdraw > 0))
        for client in clients:
            if client.bitcoinsToWithdraw <= client.bitcoins:    # Redundancy check
                foreignBitcoinAddress = list(Address.select(AND(Address.q.clientID == client.id, Address.q.type_ == "foreignBitcoin")))[0]
                try:
                    quantity = client.bitcoinsToWithdraw
                    self.access.sendtoaddress(foreignBitcoinAddress.value, quantity)
                    client.bitcoins = client.bitcoins - quantity
                    transaction = Transaction(clientID = client.id)
                    transaction.datetime = datetime.datetime.now()
                    transaction.type_ = "Withdrawal"
                    transaction.quantity = -quantity    # Transaction quantity is negative for "Withdrawal"
                    client.bitcoinsToWithdraw = 0
                    print "Withdrawal:\nUsername:  %s\nClientID:  %i\nQuantity:  %f\n" % (client.username, client.id, quantity)
                except:
                    print "Failed Withdrawal:\nUsername:  %s\nClientID:  %i\nQuantity:  %f\n" % (client.username, client.id, client.bitcoinsToWithdraw)              
            else:
                print "Failed Withdrawal, Not Enough Bitcoins:\nUsername:  %s\nClientID:  %i\n" % (client.username, client.id)
        return

bitcoinInterface = BitcoinInterface()
while 1:
    bitcoinInterface.issueBitcoinAddresses()
    bitcoinInterface.takeDeposits()
    bitcoinInterface.issueWithdrawals()
    time.sleep(300)
newbie
Activity: 11
Merit: 0
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
import jsonrpc
MyBCAddress = 'YOUR BITCOIN ADDRESS HERE'

b = jsonrpc.ServiceProxy("http://localhost:8332/")
bal = float(b.getbalance())

if bal > 0.01:
    print "We have a balance of {0:.2f}BC. Sending...".format(bal)
    b.sendtoaddress(MyBCAddress,bal)
else:
    print "No coins here."
newbie
Activity: 11
Merit: 0
bitcoinmarket.com is doing all of these things now. perhaps the author of that site can share some code as well.
founder
Activity: 364
Merit: 6472
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 ).  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 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.
Jump to: