Bitcoin Forum

Bitcoin => Technical Support => Topic started by: TAiS46 on June 25, 2012, 01:13:36 PM



Title: Bitcoind and php - get the newest transactions
Post by: TAiS46 on June 25, 2012, 01:13:36 PM
Hello,

how is it possible, to get the newest transactions and put them into the database?
Dose someone found a way to do this?

At this moment I don't save receive transactions in the database, but I will
do this in the future.

Is it the correct way to list the transactions "bitcoind listtransactions"
and put them into the database and sync every 5 minutes the transacions?

I think this is not the best way?

Greetings
Simon


Title: Re: Bitcoind an php - get the newest transactions
Post by: Stephen Gornick on June 26, 2012, 01:03:08 AM
Is it the correct way to list the transactions "bitcoind listtransactions"

Just transactions for addresses in your wallet or all transactions?

Using Armory is one way:
 - https://bitcointalk.org/index.php?topic=77650.msg866810#msg866810

Others:
 - BitcoinJ
 - libbitcoin
 - ABE Blockchain explorer


Title: Re: Bitcoind an php - get the newest transactions
Post by: weex on June 26, 2012, 02:46:33 AM
Yes, depending on volume you may also want to add a txn count to that request.


Title: Re: Bitcoind an php - get the newest transactions
Post by: notme on June 26, 2012, 04:08:55 AM
If you're talking about php (assumed from the title), look at https://github.com/mikegogulski/bitcoin-php

Also,

> bitcoind help listtransactions
listtransactions [account] [count=10] [from=0]
Returns up to [count] most recent transactions skipping the first [from] transactions for account [account].

You can use '*' for the account to get all transactions, so I'd keep track of the how many transactions you've recorded (T) and do this:

bitcoind listtransactions 10000 T

If you expect to ever have more than 10000 transactions per 5 minute period (or however often you check), bump that number up.


Title: Re: Bitcoind an php - get the newest transactions
Post by: TAiS46 on June 26, 2012, 12:24:08 PM
> bitcoind help listtransactions
listtransactions [account] [count=10] [from=0]
Returns up to [count] most recent transactions skipping the first [from] transactions for account [account].

You can use '*' for the account to get all transactions, so I'd keep track of the how many transactions you've recorded (T) and do this:

bitcoind listtransactions 10000 T

If you expect to ever have more than 10000 transactions per 5 minute period (or however often you check), bump that number up.

What dose T mean?
What dose from mean? The time?

I think it looks good wo work with it when I know what "from" is :)


Edit:
I dont understand, why the transactions will not get an id on my own server.
So the "from" value will be get more interesting!


Title: Re: Bitcoind an php - get the newest transactions
Post by: notme on June 26, 2012, 02:36:40 PM
> bitcoind help listtransactions
listtransactions [account] [count=10] [from=0]
Returns up to [count] most recent transactions skipping the first [from] transactions for account [account].

You can use '*' for the account to get all transactions, so I'd keep track of the how many transactions you've recorded (T) and do this:

bitcoind listtransactions 10000 T

If you expect to ever have more than 10000 transactions per 5 minute period (or however often you check), bump that number up.

What dose T mean?
What dose from mean? The time?

I think it looks good wo work with it when I know what "from" is :)


Edit:
I dont understand, why the transactions will not get an id on my own server.
So the "from" value will be get more interesting!

Quote
keep track of the how many transactions you've recorded (T)

Quote
skipping the first [from] transactions


Title: Re: Bitcoind an php - get the newest transactions
Post by: TAiS46 on June 26, 2012, 02:49:02 PM
skipping the first [from] transactions

i think this is not correct!

If you use: bitcoind listtransactions "*" 1 0
it will not show you the first transaction, it will show you the last transaction made!

It count from backward, not forward!
For what is the function?


Title: Re: Bitcoind an php - get the newest transactions
Post by: notme on June 26, 2012, 03:04:26 PM
skipping the first [from] transactions

i think this is not correct!

If you use: bitcoind listtransactions "*" 1 0
it will not show you the first transaction, it will show you the last transaction made!

It count from backward, not forward!
For what is the function?

I've not used listtransactions like this before, I'm only pulling that from the help.  It look like you're right about it being backwards.  You're probably better off with listsinceblock.  With no parameters, it returns all transactions, and a lastblock value.  Save that last block each time, then pass it as the first parameter to the next call of listsinceblock.  This should get you any new transactions since your last sync. (And you don't have any magic numbers that leave you vulnerable to someone intentionally overflowing your transaction buffer.)


Title: Re: Bitcoind and php - get the newest transactions
Post by: TAiS46 on June 26, 2012, 03:38:35 PM
Thats a nice idea to use listsinceblock.

But I think I can get a problem with that function!
What is, if two blocks will find within 1 minute and I only
check every 5 minutes?
So I skip one block, correct?


I think the best solution is:

bitcoind getinfo
to look, if there is a new block (blocks count)
if there is a new block, get the blockhash

bitcoind getblockhash 186334
so with this blockhash you can use now

bitcoind listsinceblock 00000000000006e5cd708f7d0825b9c6b2746f36fc9045c4c0025c839a28cfc1

now I can check the transactions and write it into my database / check the txid.


I am trying to get off the json rpc! I will all make over the database and the server directly.
Also I will not use bitcoin accounts anymore for my customers.
I will have only account "" and and every user will get his own address.


Title: Re: Bitcoind and php - get the newest transactions
Post by: notme on June 26, 2012, 03:43:03 PM
Thats a nice idea to use listsinceblock.

But I think I can get a problem with that function!
What is, if two blocks will find within 1 minute and I only
check every 5 minutes?
So I skip one block, correct?


I think the best solution is:

bitcoind getinfo
to look, if there is a new block (blocks count)
if there is a new block, get the blockhash

bitcoind getblockhash 186334
so with this blockhash you can use now

bitcoind listsinceblock 00000000000006e5cd708f7d0825b9c6b2746f36fc9045c4c0025c839a28cfc1

now I can check the transactions and write it into my database / check the txid.


I am trying to get off the json rpc! I will all make over the database and the server directly.
Also I will not use bitcoin accounts anymore for my customers.
I will have only account "" and and every user will get his own address.

I'm pretty sure you're overcomplicating it.  It will not skip over blocks.  It lists every transaction since the blockhash you give it.  It also gives you the blockhash you're currently on, so you can save that for your next call.


Title: Re: Bitcoind and php - get the newest transactions
Post by: TAiS46 on June 26, 2012, 04:06:13 PM
ok, now I have it!

As example, there are 5 blocks in the network.
I use bitcoind listsinceblock 3
So I will get all transactions, that are in the blocks 3, 4, 5!

lastblock = block 5.

I can put now the transactions into the database, and check their confirmations.
are the confirmations are higher than 6, will will count the confirmations with the blockid :)


Thank you for your support


Title: Re: Bitcoind and php - get the newest transactions
Post by: notme on June 26, 2012, 04:12:16 PM
ok, now I have it!

As example, there are 5 blocks in the network.
I use bitcoind listsinceblock 3
So I will get all transactions, that are in the blocks 3, 4, 5!

lastblock = block 5.

I can put now the transactions into the database, and check their confirmations.
are the confirmations are higher than 6, will will count the confirmations with the blockid :)


Thank you for your support

Pretty much, although listsinceblock takes the block hash, not the block number.


Title: Re: Bitcoind and php - get the newest transactions
Post by: weex on June 27, 2012, 12:08:39 AM
With this listsinceblock, what happens on a reorg?


Title: Re: Bitcoind and php - get the newest transactions
Post by: notme on June 27, 2012, 12:31:44 AM
With this listsinceblock, what happens on a reorg?

Good question.


Title: Re: Bitcoind and php - get the newest transactions
Post by: weex on June 27, 2012, 06:00:31 AM
I think you're better off doing a listtransactions, there you can see the confirmations and update your db accordingly. Then by looking at your db you'll know for sure if a transaction reached your target number of confirmations.


Title: Re: Bitcoind and php - get the newest transactions
Post by: TAiS46 on June 27, 2012, 07:17:09 AM
I think you're better off doing a listtransactions, there you can see the confirmations and update your db accordingly. Then by looking at your db you'll know for sure if a transaction reached your target number of confirmations.

listtransaction with what parameters?
The only way is with listtransactions to get the last 1000 transactions and check them for confirmations.
But I think it will cost much performance?