Author

Topic: Couple of questions about the raw tx API commands (Read 1542 times)

legendary
Activity: 1890
Merit: 1086
Ian Knowles - CIYAM Lead Developer
November 20, 2012, 10:41:02 PM
#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 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).
legendary
Activity: 1652
Merit: 2311
Chief Scientist
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 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).
legendary
Activity: 1890
Merit: 1086
Ian Knowles - CIYAM Lead Developer
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",
kjj
legendary
Activity: 1302
Merit: 1026
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)

// 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;
}

?>

legendary
Activity: 1890
Merit: 1086
Ian Knowles - CIYAM Lead Developer
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.
kjj
legendary
Activity: 1302
Merit: 1026
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.
legendary
Activity: 1890
Merit: 1086
Ian Knowles - CIYAM Lead Developer
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)?
Jump to: