Bitcoin Forum
November 01, 2024, 11:59:43 AM *
News: Bitcoin Pumpkin Carving Contest
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: move method in bitcoind  (Read 1198 times)
arixpcx (OP)
Newbie
*
Offline Offline

Activity: 14
Merit: 0


View Profile
July 29, 2014, 06:19:07 PM
 #1

Hi Smiley
I'm creating an exchange website and the first step is to allow users to deposit and withdraw bitcoins from and to external wallets.
Right now i'm using the json rpc api from blockchain.info, since i don't have where to host my bitcoind client.
But since the json rpc api of blockchain.info implements the same methods that the bitcoind client supplies, i know that in the future i'll be able to move to my own bitcoind client easily so i'm not concerned about using third party api right now (referring to my previous post).

So in my website there will be 2 types of transactions:

External transactions - Transactions between the user's address in my website and an external wallet (Example: User A deposits bitcoins in his account in my website from his external wallet).

Internal transactions - Transactions between bitcoins and my local coin (The one that users will be able to exchange bitcoins with) inside the website itself (Example: User A buys 10 local coins for 0.003 bitcoins per coin from user B).

Now, before i had heard about the method move in the bitcoind client, i thought about adding a column in the users database of my website which would hold only the bitcoins that were earned/spent in internal transactions. The total amount of bitcoins that are in possession of a user would then be the amount that's written in that column + the amount that's returned from the method getBalance of the bitcoind client(the bitcoins that were earned/spent in external transactions).

But obviously, i ditched that idea after hearing about the move method in the bitcoind client(the method takes the address of user A and the address of user B and an amount and sends that amount from user A to user B).

So now my idea is, whenever some user puts a buying order (buying local coins for bitcoins), i will use the method move to move the requested amount from the user's address to another address that doesn't belong to any user.

Whenever some user puts a selling order and that order gets evaluated(someone sells to him), i will use the method move to move the requested amount from the address that doesn't belong to any user (the same address from case A) to the address of the user that sold the local coins.

The first question is: Is that the correct way of doing it? Am i over complicating things and there's a much easier way to implement this?

Second question: Does the move method moves the bitcoins from address A to address B instantly? or there's some delay?

Thank you Smiley
DannyHamilton
Legendary
*
Offline Offline

Activity: 3472
Merit: 4801



View Profile
July 29, 2014, 06:35:26 PM
 #2

Like many people trying to use bitcoind for the first time you are confusing "accounts" with "addresses".  They are not the same thing, and the "accounts" features of bitcoind generally do not work the way people want them to.

The "move" does not move and bitcoins from any address to any other address.  All it does is update an "account" with an indication of an increase or decrease in value associated with it.

You should really consider implementing the accounts in your own database, and consider all received bitcoins to be mixed together in the wallet.

Much like the way cash is all mixed together in a bank when you make a deposit.  There is no label on individual deposits that keep them tied to the account that they were deposited into.  When you later withdraw from a bank, it is very likely that the cash you receive will not be the exact same bills you deposited.  When you later send transactions from an account in bitcoind, it is very likely that the bitcoins you send will not be the exact same bitcoins you deposited.
arixpcx (OP)
Newbie
*
Offline Offline

Activity: 14
Merit: 0


View Profile
July 29, 2014, 06:47:20 PM
 #3

I'm implementing the accounts in my own database my i don't store the amount of bitcoins of the account in my own database.
I though about supplying the id of the user in my database when using the method getnewaddress i.e. whenever a new user is created in my website, i would use the method getnewaddress and supply it with the user id that's stored in the database.

whenever i would like to know how much bitcoins a user has, i would just use the method getbalance with the userid.
That's my idea of implementing the users in my website.

Aren't all the bitcoins already mixed together in the wallet? my website consists only of one wallet, my wallet.
All the address that are created for the users, point at my wallet. So in that sense, all the bitcoins are mixed together in my wallet, No?
DannyHamilton
Legendary
*
Offline Offline

Activity: 3472
Merit: 4801



View Profile
July 29, 2014, 06:53:01 PM
 #4

I'm implementing the accounts in my own database my i don't store the amount of bitcoins of the account in my own database.
I though about supplying the id of the user in my database when using the method getnewaddress i.e. whenever a new user is created in my website, i would use the method getnewaddress and supply it with the user id that's stored in the database.

whenever i would like to know how much bitcoins a user has, i would just use the method getbalance with the userid.
That's my idea of implementing the users in my website.

Aren't all the bitcoins already mixed together in the wallet? my website consists only of one wallet, my wallet.
All the address that are created for the users, point at my wallet. So in that sense, all the bitcoins are mixed together in my wallet, No?

Exactly.

But getbalance gets the balance of an "account", not an "address". You probably don't want to be trying to keep track of account balances in bitcoind.  Your database should keep track of account balances.  You can use walletnotify and blocknotify to run a program when a transaction is received to an address in your wallet.  Then you can update the proper account in your database with the amount received.

When you create a transaction to send bitcoins to a customer, you can update the account in your database indicating how much was sent.

Instead of using the bitcoind "move" command to move balances between accounts, you'll just need to update your own database.

The accounting system built into bitcoind is not a very good accounting system.  Many developers have even talked about removing it in future releases, so you won't want to depend on it for your business in the future.  You should implement a proper accounting system in your own software.
arixpcx (OP)
Newbie
*
Offline Offline

Activity: 14
Merit: 0


View Profile
July 29, 2014, 07:02:05 PM
 #5

I know that the blockchain.info receive payments api does something like that.
It creates an unique address to a user that points at my wallet at blockchain.info.
Whenever a user sends bitcoins to the address that was created for him, blockchain.info sends a request to my website and that way i can know which user had received the payment.

I just thought that using the json rpc api would be more convenient for me since i'm relying on a third party api just for now...
Are walletnotify and blocknotify part of the bitcoind client?

DannyHamilton
Legendary
*
Offline Offline

Activity: 3472
Merit: 4801



View Profile
July 29, 2014, 07:13:43 PM
 #6

Are walletnotify and blocknotify part of the bitcoind client?

Yes.
arixpcx (OP)
Newbie
*
Offline Offline

Activity: 14
Merit: 0


View Profile
July 29, 2014, 07:17:20 PM
 #7

Alright, then i'll have a look at it.

Anyway it seems much more easier to do it your way (storing the balance in my database).
Thank you for the help Smiley
uBm
Member
**
Offline Offline

Activity: 88
Merit: 10


View Profile
August 01, 2014, 09:55:35 AM
 #8

Just as a side Note: using Move on hundreds/thousands transactions , will let the wallet grow (internal transactions are stored in the wallet) after a certain ammount of time your wallet will get very slow - best is to use a external DB Wink


Alright, then i'll have a look at it.

Anyway it seems much more easier to do it your way (storing the balance in my database).
Thank you for the help Smiley
dandouna
Newbie
*
Offline Offline

Activity: 31
Merit: 0


View Profile
August 03, 2014, 03:55:49 PM
 #9

Hello,

Please what s the method to move in bitcoind?
MUSCLEGIRLS
Member
**
Offline Offline

Activity: 112
Merit: 10


View Profile
August 03, 2014, 07:39:31 PM
 #10

I am not sure what your question is?
miso
Newbie
*
Offline Offline

Activity: 37
Merit: 0


View Profile
August 04, 2014, 12:54:06 PM
 #11

I was wondering how to properly store user balances in (sql).

Method 1:
1. On each blocknotify cache new transactions to own DB / or since blockXZY.
2. For each TX from own DB where confirms < 6 update TX confirms with bitcoind.
- This way, it is possible to get balance with SQL count function from ALL transactions in own DB. It is critical to have synced every relevant TX. If TX gets deleted/unconfirmed, no problem here, just "recach" all.

Method 2:
1. On each blocknotify cache new transactions to own DB.
2. For each TX from own DB where confirms < 6 update TX confirms with bitcoind.
3. From each TX from own DB where confirms = 6 compute user balances and store it.
4. Delete each TX from own DB where confirms => 6.
- This way it is not required to store each TX. If transaction gets deleted/unconfirmed after 6 confirms, It creates problem.
vit1988
Sr. Member
****
Offline Offline

Activity: 313
Merit: 250


i ♥ coinichiwa


View Profile WWW
August 04, 2014, 08:29:46 PM
 #12

As it is a userfriendly good practice to give immediate feedback as soon as you receive a transaction it is better to use walletnotify as a trigger or pull the data again and again in an endless loop or cronjob. Then just take the last n transactions (just in case if you missed some notifications because of any obscure failures) and push them into your db.

Pseudocode:

Code:
$transactions = $bitcoinrpc->listtransactions('accountname', 500);
foreach ($transactions as $tx) {

    if ($tx['category'] == 'receive' && $tx['confirmations'] < 10) {
        $id_user = $db->query('SELECT id_user FROM addresses WHERE address={$tx['address']}');
        $db->query('INSERT INTO balance (txid, id_user, amount, confirmations) VALUES ({$tx['txid']}, {$id_user}, {$tx['amount']}, {$tx['confirmations']})
                           ON DUPLICATE KEY UPDATE confirmations={$tx['confirmations']}');
        // (balance.txid must be defined as unique key of course)

        if ($db->affectedRows() > 0) {
            // number of confirmations for $tx has changed, do any prefered action
        }
    }
}

It is also a good idea to write the users withdrawals as a negative amount into that balance table, so you can easily (and more important consistently) get the users balance by summing up the `amount` column.


Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!