Bitcoin Forum
May 12, 2024, 05:57:02 AM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: regex for bitcointransaction string  (Read 791 times)
kangarooz (OP)
Newbie
*
Offline Offline

Activity: 4
Merit: 0


View Profile
May 26, 2014, 12:50:13 PM
 #1

Dear guys;

Is there any RegEx for checking if a string could be a valid bitcointransaction?
A currently use gettransaction() to check the confirmations of the transaction, as you may know gettransaction() only accepts txids made by the wallet of the bitcoind running this command, so I want to check the entered txid before, to catch as many faults as I can.
Programming language: Python

All the best;
Remember that Bitcoin is still beta software. Don't put all of your money into BTC!
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
grue
Legendary
*
Offline Offline

Activity: 2058
Merit: 1431



View Profile
May 26, 2014, 04:34:24 PM
 #2

Is there any RegEx for checking if a string could be a valid bitcointransaction?
string as in what? the transaction id?

It is pitch black. You are likely to be eaten by a grue.

Adblock for annoying signature ads | Enhanced Merit UI
kangarooz (OP)
Newbie
*
Offline Offline

Activity: 4
Merit: 0


View Profile
May 26, 2014, 05:47:31 PM
 #3

I got a string containing the "txid" which should be checked.

All the best;
grue
Legendary
*
Offline Offline

Activity: 2058
Merit: 1431



View Profile
May 26, 2014, 07:04:34 PM
 #4

I got a string containing the "txid" which should be checked.

All the best;
the txid is the sha-1 hash of a transaction. you can't use the txid to determine whether a transaction is valid, because any 64 digit hexadecimal number can be a txid.

It is pitch black. You are likely to be eaten by a grue.

Adblock for annoying signature ads | Enhanced Merit UI
telepatheic
Jr. Member
*
Offline Offline

Activity: 56
Merit: 1


View Profile
May 26, 2014, 08:38:29 PM
 #5

I got a string containing the "txid" which should be checked.

All the best;
the txid is the sha-1 hash of a transaction. you can't use the txid to determine whether a transaction is valid, because any 64 digit hexadecimal number can be a txid.

It's not the SHA-1 it is the SHA256d. Also quite confusingly, the output bytes are reversed when displayed to the user!

The RegEx you are looking for is:

Code:
/^[0-9a-f]{64}$/i 
grue
Legendary
*
Offline Offline

Activity: 2058
Merit: 1431



View Profile
May 26, 2014, 11:23:48 PM
 #6

anyways, the best solution is to use getrawtransaction, which allows you to retrieve any transaction.

It is pitch black. You are likely to be eaten by a grue.

Adblock for annoying signature ads | Enhanced Merit UI
fbueller
Sr. Member
****
Offline Offline

Activity: 412
Merit: 275


View Profile
May 28, 2014, 09:10:20 PM
 #7

anyways, the best solution is to use getrawtransaction, which allows you to retrieve any transaction.

Only if your bitcoin.conf has txindex=1 in it. And you've reindexed by running: ./bitcoind -reindex. That will let you run getrawtransaction() on any txid.

To get confirmations for the transaction, as well as the raw and decoded tx, you can use getrawtransaction(txid, 1);

Bitwasp Developer.
grue
Legendary
*
Offline Offline

Activity: 2058
Merit: 1431



View Profile
May 28, 2014, 10:35:11 PM
 #8

Only if your bitcoin.conf has txindex=1 in it. And you've reindexed by running: ./bitcoind -reindex. That will let you run getrawtransaction() on any txid.

To get confirmations for the transaction, as well as the raw and decoded tx, you can use getrawtransaction(txid, 1);
that's weird. because it works fine on my bitcoin core instance, and it doesn't have txindex enabled.

It is pitch black. You are likely to be eaten by a grue.

Adblock for annoying signature ads | Enhanced Merit UI
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!