Bitcoin Forum

Bitcoin => Development & Technical Discussion => Topic started by: Xayan on May 02, 2014, 04:14:55 PM



Title: Bitcoind RPC - create a new address for every payment?
Post by: Xayan on May 02, 2014, 04:14:55 PM
Hi!

I'm currently working on a PHP library that will help web developers receiving payments in BTC and other cryptocurrencies.

My question is - should it create a new address for every payment? As far as I know, bitcoind doesn't allow deleting addresses - can it cause troubles when numbers of addresses will go thousands? Or maybe there's a different way to do what I want to do?


Title: Re: Bitcoind RPC - create a new address for every payment?
Post by: telepatheic on May 02, 2014, 04:40:46 PM
My question is - should it create a new address for every payment?

Yes, however if you plan on going over about 5000 addresses you might run into trouble with bitcoind.

Not knowing the architecture of your system, I can't tell you the best method to use. Is the idea that a developer would run a hot wallet and your PHP library on the server?


Title: Re: Bitcoind RPC - create a new address for every payment?
Post by: Xayan on May 02, 2014, 05:24:29 PM
Is the idea that a developer would run a hot wallet and your PHP library on the server?

Exactly. My library is meant to be doing all the JSON-RPC-releated stuff to communicate with bitcoind to make receiving payments in various cryptocurrencies as simple as possible. Example code:

Code:
$client = new Client();
$payment = $client->createPayment();
$payment->setCurrency('BTC');
$payment->setAmount(0.01);
$payment->save();
print($payment->address);

Then, to check if user has paid:

Code:
$client = new Client();
$payment = $client->loadPayment($payment_id);
print($payment->status);

Maybe there is some way to modify wallet.dat file? I have found out that it's a Berkeley DB file. However, I'm afraid my script won't be able to edit it without root access. Additionally, modifying it while bitcoind is running may cause some troubles. And it HAS to be on all the time to update the blockchain...


Title: Re: Bitcoind RPC - create a new address for every payment?
Post by: telepatheic on May 02, 2014, 06:10:53 PM
Do you want payments to be detected as soon as they are sent (0-confirmations) or after they have been included in a block (1-confirmation)?


Title: Re: Bitcoind RPC - create a new address for every payment?
Post by: Xayan on May 02, 2014, 06:13:31 PM
Do you want payments to be detected as soon as they are sent (0-confirmations) or after they have been included in a block (1-confirmation)?

I want to make it customizable. However, I think at least 1 confirmation should be a requirement. But wait... is it even possible to detect a payment without any confirmations?


Title: Re: Bitcoind RPC - create a new address for every payment?
Post by: telepatheic on May 02, 2014, 06:52:31 PM
I want to make it customizable. However, I think at least 1 confirmation should be a requirement. But wait... is it even possible to detect a payment without any confirmations?

Yes it is possible in most cases to detect transactions as soon as they are sent to the network (that is how you can pay for things in less than 10 minutes with bitcoin).

What I would suggest is that you generate a master private key offline. You now have a private key P and a public key p.

With elliptic curve cryptography if you generate another private key Q with public key q. The public key formed by adding the private keys together will be equal to the public keys added together (in modular arithmetic). P+Q --> p+q

This means that you can use PHP to generate new public keys on the fly by setting Q = $payment.id

You can safely store p on the server (but never store P online) this means you can work out the public key the user has to pay to = p+q.

Now you can use a bitcoin api like blockchain's (https://blockchain.info/q) to work out if a user has paid or not (and you can set how many confirmations)

You can use this library (https://github.com/mdanter/phpecc) to do the elliptic curve stuff (although you will have to add in the parameters for the secp256k1 curve).


Title: Re: Bitcoind RPC - create a new address for every payment?
Post by: Xayan on May 02, 2014, 07:19:36 PM
Now you can use a bitcoin api like blockchain's (https://blockchain.info/q) to work out if a user has paid or not (and you can set how many confirmations)

Sorry, but I don't want to involve any third-party apps.

Let's say I have generated random private key (256-bit number) and then its public address. All that in PHP only. I will still need a method to check in blockchain if there is required amount of BTC. Importing it into bitcoind won't solve the problem. Is there any way I can search blockchain? Maybe there is some open-source program that allows to filter transactions by public address or private key without importing it at all?


Title: Re: Bitcoind RPC - create a new address for every payment?
Post by: telepatheic on May 02, 2014, 07:30:18 PM
Sorry, but I don't want to involve any third-party apps.

Let's say I have generated random private key (256-bit number) and then its public address. All that in PHP only. I will still need a method to check in blockchain if there is required amount of BTC. Importing it into bitcoind won't solve the problem. Is there any way I can search blockchain? Maybe there is some open-source program that allows to filter transactions by public address or private key without importing it at all?

You can check the blockchain using bitcoind without having the private keys in the wallet. This blog post (http://www.wildbunny.co.uk/blog/2014/03/18/watch_only_wallet/) explains how.


Title: Re: Bitcoind RPC - create a new address for every payment?
Post by: Xayan on May 02, 2014, 07:44:23 PM
You can check the blockchain using bitcoind without having the private keys in the wallet. This blog post (http://www.wildbunny.co.uk/blog/2014/03/18/watch_only_wallet/) explains how.

Excellent, that's what I needed! Thank you so much! :)