Bitcoin Forum
November 06, 2024, 09:26:06 AM *
News: Latest Bitcoin Core release: 28.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Couple of questions about the raw tx API commands  (Read 1535 times)
CIYAM (OP)
Legendary
*
Offline Offline

Activity: 1890
Merit: 1086


Ian Knowles - CIYAM Lead Developer


View Profile WWW
November 20, 2012, 08:49:06 AM
 #1

I have just started playing the the listunspent/createrawtransaction/signrawtransaction/sendrawtransaction RPC commands which work great, however, there are a couple of things I am wondering about.

1) Why doesn't the listunspent include a bitcoin "address" as well as the public key in the JSON output (as I can't easily tell what is what when I'm looking at that without jumping into blockchain.info to look up the tx)?

2) If I want to send to more than one output address with createrawtransaction what is the exact syntax (an example somewhere in the docco would be nice)?

With CIYAM anyone can create 100% generated C++ web applications in literally minutes.

GPG Public Key | 1ciyam3htJit1feGa26p2wQ4aw6KFTejU
kjj
Legendary
*
Offline Offline

Activity: 1302
Merit: 1026



View Profile
November 20, 2012, 09:51:46 PM
 #2

I have just started playing the the listunspent/createrawtransaction/signrawtransaction/sendrawtransaction RPC commands which work great, however, there are a couple of things I am wondering about.

1) Why doesn't the listunspent include a bitcoin "address" as well as the public key in the JSON output (as I can't easily tell what is what when I'm looking at that without jumping into blockchain.info to look up the tx)?

2) If I want to send to more than one output address with createrawtransaction what is the exact syntax (an example somewhere in the docco would be nice)?

1) No idea.  I've never felt like it was "missing" as such, and I've done quite a bit with raw transactions.  It is trivial to figure out the address, when one exists.  A normal sendtoaddress transaction will start with 76a914 and end with 88ac * (both in hex), with the pubkey in between, and from there it is just a matter of hashing and base58check encoding.  A P2SH address will have a different scheme, as will a generate transaction.

2) the output section of createrawtransaction is a list, {"address1":"amount1","address2":"amount2","address3":"amount3"...}.

*  In case anyone was wondering, 76a914 is OP_DUP OP_HASH160 PUSH_20BYTES and 88ac is OP_EQUALVERIFY OP_CHECKSIG.

17Np17BSrpnHCZ2pgtiMNnhjnsWJ2TMqq8
I routinely ignore posters with paid advertising in their sigs.  You should too.
CIYAM (OP)
Legendary
*
Offline Offline

Activity: 1890
Merit: 1086


Ian Knowles - CIYAM Lead Developer


View Profile WWW
November 21, 2012, 01:33:38 AM
 #3

1) No idea.  I've never felt like it was "missing" as such, and I've done quite a bit with raw transactions.  It is trivial to figure out the address, when one exists.  A normal sendtoaddress transaction will start with 76a914 and end with 88ac * (both in hex), with the pubkey in between, and from there it is just a matter of hashing and base58check encoding.  A P2SH address will have a different scheme, as will a generate transaction.

Sounds like you are a lot more familiar with the inner workings of Bitcoin than me - but how exactly (say from a bash shell) do I get the hash of the public key and base58 encode it (which is why I thought bitcoind should do this for me)?

2) the output section of createrawtransaction is a list, {"address1":"amount1","address2":"amount2","address3":"amount3"...}.

Thanks for that.

With CIYAM anyone can create 100% generated C++ web applications in literally minutes.

GPG Public Key | 1ciyam3htJit1feGa26p2wQ4aw6KFTejU
kjj
Legendary
*
Offline Offline

Activity: 1302
Merit: 1026



View Profile
November 21, 2012, 01:51:19 AM
 #4

1) No idea.  I've never felt like it was "missing" as such, and I've done quite a bit with raw transactions.  It is trivial to figure out the address, when one exists.  A normal sendtoaddress transaction will start with 76a914 and end with 88ac * (both in hex), with the pubkey in between, and from there it is just a matter of hashing and base58check encoding.  A P2SH address will have a different scheme, as will a generate transaction.

Sounds like you are a lot more familiar with the inner workings of Bitcoin than me - but how exactly (say from a bash shell) do I get the hash of the public key and base58 encode it (which is why I thought bitcoind should do this for me)?

Well, I do most of my stuff in PHP.  Here is some code, intended more as an example than as something to use.  You'll need some support functions to use it, etc, etc.

Code: (PHP)
<?php

// takes $pubkey as a hex string, returns an address
function gen_addr($pubkey){
 
$h=hash("sha256",hex2bin($pubkey),TRUE);
 
$h2=hash("ripemd160",$h,TRUE);
 
$h3="\x00".$h2;
 
$h4=hash("sha256",$h3,TRUE);
 
$h5=hash("sha256",$h4,TRUE);
 
$chk=substr($h5,0,4);
 
$addr_bin=$h3.$chk;
 
$addr=encodeBase58($addr_bin);
 return 
$addr;
}

?>


17Np17BSrpnHCZ2pgtiMNnhjnsWJ2TMqq8
I routinely ignore posters with paid advertising in their sigs.  You should too.
CIYAM (OP)
Legendary
*
Offline Offline

Activity: 1890
Merit: 1086


Ian Knowles - CIYAM Lead Developer


View Profile WWW
November 21, 2012, 02:36:19 AM
 #5

Okay - after mulling over your hex hints I worked out that from:

Code:
"scriptPubKey" : "76a91406c1991c6466a550b66931ea48970cfd17ff51b388ac",

if I remove the 76a914 prefix and the 88ac suffix then I get 06c1991c6466a550b66931ea48970cfd17ff51b3 which if convert to base58 using brainwallet.html (as there doesn't seem to be any standard Linux program to do this conversion and I don't use PHP) I finally get 1ciyam3htJit1feGa26p2wQ4aw6KFTejU.

That is really a PITA - I guess I could write my own program to do this, however, I really hope one of the devs is reading this and might consider adding the following to the listunspent outout:

Code:
"scriptPubKey" : "76a91406c1991c6466a550b66931ea48970cfd17ff51b388ac",
"address" : "1ciyam3htJit1feGa26p2wQ4aw6KFTejU",

With CIYAM anyone can create 100% generated C++ web applications in literally minutes.

GPG Public Key | 1ciyam3htJit1feGa26p2wQ4aw6KFTejU
Gavin Andresen
Legendary
*
qt
Offline Offline

Activity: 1652
Merit: 2301


Chief Scientist


View Profile WWW
November 21, 2012, 02:54:08 AM
 #6

listunspent output is designed to be read by machines, not people, and its output is designed to go directly into createrawtransaction.

If you need all the human-friendly details of a transaction, use getrawtransaction <txid> 1

I'm against adding "address" to the listunspent output, because most of the time it will be unused and sometimes it would just not appear at all (because not all scriptPubKeys are bitcoin addresses).

How often do you get the chance to work on a potentially world-changing project?
CIYAM (OP)
Legendary
*
Offline Offline

Activity: 1890
Merit: 1086


Ian Knowles - CIYAM Lead Developer


View Profile WWW
November 21, 2012, 03:41:02 AM
 #7

listunspent output is designed to be read by machines, not people, and its output is designed to go directly into createrawtransaction.

If you need all the human-friendly details of a transaction, use getrawtransaction <txid> 1

Thanks Gavin - I hadn't realised I could do that (although it is one extra step it should be easy enough) - understand that I need to know the address (if present) as my raw transaction needs to include that as the "change address" (yes - am not wanting to be anonymous at all with this use case) so indeed I am wanting to automate this but the "machine" still needs the address.

I'm against adding "address" to the listunspent output, because most of the time it will be unused and sometimes it would just not appear at all (because not all scriptPubKeys are bitcoin addresses).

I understand - but it would make my job as a developer easier if I could just make one RPC call rather than several (as I need to find a specific address that I am going to create a raw tx to send coins to another address with change being sent back to itself).

With CIYAM anyone can create 100% generated C++ web applications in literally minutes.

GPG Public Key | 1ciyam3htJit1feGa26p2wQ4aw6KFTejU
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!