NPE on addresses in Block -> Transaction -> Output
mik3hall opened this issue · 2 comments
I was getting
java.lang.NullPointerException
[java] at info.blockchain.api.blockexplorer.Output.(Output.java:38)
[java] at info.blockchain.api.blockexplorer.Output.(Output.java:31)
[java] at info.blockchain.api.blockexplorer.Transaction.(Transaction.java:83)
[java] at info.blockchain.api.blockexplorer.Block.(Block.java:76)
[java] at info.blockchain.api.blockexplorer.BlockExplorer.getBlock(BlockExplorer.java:89)
[java] at us.hall.btc.Script.dataApi(Script.java:255)
[java] at us.hall.btc.Script.main(Script.java:65)
on trying to access the latest block via hash to get more detailed information than SimpleBlock or LatestBlock provide.
This appears to be because some transactions include no address in the Output?
Like...
*** Entry Set ***
[java] [spent=false, tx_index=105319741, type=0, value=0, n=0, script="6a28466100000000133bd152b84dcca46592cce80eb17f73251b8ea87688d8b35babde18b1b2fa134e3b"]
[java] ********
[java] *** Entry Set ***
[java] [spent=false, tx_index=105319741, type=0, addr="1K2SXgApmo9uZoyahvsbSanpVWbzZWVVMF", value=650000, n=1, script="76a914c5b7fd920dce5f61934e792c7e6fcc829aff533d88ac"]
[java] ********
The first has no address while the second entry set does.
Changing this constructor in Output seems a workaround for me anyhow for now.
public Output(JsonObject o, boolean spent)
{
this( o.get("n").getAsInt(),
o.get("value").getAsLong(),
o.get("addr") != null ? o.get("addr").getAsString() : null,
o.get("tx_index").getAsLong(),
o.get("script").getAsString(),
spent);
}
I saw a somewhat similar construct in Transaction.
Thanks.
I applied your suggested fix and added another field spentToAddress in case the output does not translate towards an address. This is an issue for outputscripts that are not in the format of P2PK/P2PKH/P2SH.
On Oct 13, 2015, at 5:11 AM, matsjj notifications@github.com wrote:
I applied your suggested fix and added another field spentToAddress in case the output does not translate towards an address. This is an issue for outputscripts that are not in the format of P2PK/P2PKH/P2SH.
Thanks
Michael Hall