1

I was expecting that, in the case when getFromAddress() returns an address, transactioninput.getConnectedOutput().getAddressFromP2SH(networkparameter)) should return the same address. But, sometimes transactioninput.getConnectedOutput() returns a null value, despite getFromAddress() returning a proper address. What is the reason?

If these two methods are different, how could I return the value of field "addr" of the object "prev_out" of the items in the array "input" in the JSON object returned without the use of blockchain.info-api? (for example, for this https://blockchain.info/address/1LoD9DeUeCfnZueSVPzFaFkfFcx8mG1Add?format=json).

  • I have tried with input.getOutpoint().getConnectedOutput() , which does not make a difference. – Aqqqq Feb 28 '17 at 9:34
  • Which library are you using? – Shabahat M. Ayubi Mar 1 '17 at 8:08
  • I am using bitconj. – Aqqqq Mar 1 '17 at 8:47
2

After going through bitcoinj API documentation regarding the methods you have asked about, the way you make the second method work, you are supposed to connect the input transaction to get the output from that particular tx. You can go through the link I have given above and report back if required.

  • I have gone through the link already in regard to my purposes and I think I have connected the input transaction to get the output from that particular tx with the code shown. What did I do wrong? – Aqqqq Mar 1 '17 at 17:53
2

Shabahat's answer is good, but here's how each method of getting an address works:

  1. getFromAddress() takes the last element of the scriptSig, and hashes it to find the P2SH address. If the transaction is valid and P2SH, this will always be correct. You can do something similar for P2PKH, but you can't do this for P2PK. (P2PK does not include the public key in the scriptSig.)
  2. transactioninput.getConnectedOutput().getAddressFromP2SH() looks at the scriptPubKey from the previous transaction, and tries to convert it to an address. Not all valid scriptPubKey's can be represented by a standard address format, so this won't always work. (It will work for the common cases of P2PKH, P2SH, and P2PK, though.)

I have gone through the link already in regard to my purposes and I think I have connected the input transaction to get the output from that particular tx with the code shown.

Are you checking the return value of connect?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.