0

I'm trying to decode testnet transaction using bitcoinj 0.14.7. This is HEX of the transaction I'm trying to decode:

02000000000101ef4c1c3c60028b050a5798265c0b37719418dd71b0621e76a68a47d5d9eef55f000000001716001467d7c32c0dad98bf8dd3dea81cbb1dbd4ea4afb5feffffff02b7df02000000000017a914ebb55a85454dc15589b8a87bab4b438892b54c0c87b0ad0100000000001976a914140b85a1c430c8f4fd1f91ae1c7451902b8ce76c88ac024730440220359623836f97e9e4c04917455ed2f9fb2343b0bf96853d47313b0c96d828c889022046da37bfda03cf3481e3ef5c5b5e655d6fd280c2aec2831b6494a8207b76655b01210224c44e1af98b5c28ebf822b65e4a2872d0780b4b6935b3100f60d3ac3b78cb00b2f81500

When I go to the blockcipher https://live.blockcypher.com/btc/decodetx/ and decode the transaction there - it's decoded no problem. But when I'm trying to do this:

Transaction tx = new Transaction(params, HexUtils.hexToBytes(txHex));
LOGGER.info(tx.toString());

it prints

4c67f1e1b10b063210e59400466383fb18634c05430d4f53795a16216dd34ffd 
version 2 
INCOMPLETE: No inputs! 
out [exception: Push of data element that is larger than remaining data] 
prps UNKNOWN

Also, I checked my code against master and it worded like a charm! Here is the output:

65b47da760fb781a80e8607e19c82454f12c4ee8dd699045d4e96c869e07bf25
version 2
time locked until block 1439922
in PUSHDATA(22)[001467d7c32c0dad98bf8dd3dea81cbb1dbd4ea4afb5]
witness:30440220359623836f97e9e4c04917455ed2f9fb2343b0bf96853d47313b0c96d828c889022046da37bfda03cf3481e3ef5c5b5e655d6fd280c2aec2831b6494a8207b76655b01 0224c44e1af98b5c28ebf822b65e4a2872d0780b4b6935b3100f60d3ac3b78cb00
outpoint:5ff5eed9d5478aa6761e62b071dd189471370b5c2698570a058b02603c1c4cef:0
sequence:fffffffe
out HASH160 PUSHDATA(20)[ebb55a85454dc15589b8a87bab4b438892b54c0c] EQUAL 0.00188343 BTC
P2SH addr:2NEjY32rnrCdi8Cve6yJ4RaPanugBnJ8fme
out DUP HASH160 PUSHDATA(20)[140b85a1c430c8f4fd1f91ae1c7451902b8ce76c] EQUALVERIFY CHECKSIG 0.0011 BTC
P2PKH addr:mhLwcTEoquZcAjT34fD4uPySUAdK77uqvL
prps UNKNOWN

Please, help!

reaktor_2004
  • 49
  • 1
  • 1
  • 6

1 Answers1

0

Your code just creating a transaction object so that's not enough.

Your requirement is fetching a transaction from block. So You need to connect a testnet node. Just create a PeerGroup connect local or remote bitcoin testnet node.

Check that example below.

    final NetworkParameters params = TestNet3Params.get();

    BlockStore blockStore = new MemoryBlockStore(params);
    BlockChain chain = new BlockChain(params, blockStore);
    PeerGroup peerGroup = new PeerGroup(params, chain);
    peerGroup.start();
    // Alternatively you can connect your localhost or another working testnet node
    peerGroup.addAddress(new PeerAddress(params, "testnet-seed.bitcoin.jonasschnelli.ch", 18333));
    peerGroup.waitForPeers(1).get();
    Peer peer = peerGroup.getConnectedPeers().get(0);

    Sha256Hash txHash = Sha256Hash.wrap(hexString);
    ListenableFuture<Transaction> future = peer.getPeerMempoolTransaction(txHash);
    System.out.println("Waiting for node to send us the requested transaction: " + txHash);
    Transaction tx = future.get();
    System.out.println(tx);
İlker Korkut
  • 3,129
  • 3
  • 30
  • 51
  • I'm trying to decode the transaction. Fetching transaction from block will return me same transaction payload HEX that I'm trying to decode. I'm trying to decode full transaction HEX, not the transaction hash. – reaktor_2004 Oct 24 '18 at 07:35
  • May you share what do you try exactly in your code? – İlker Korkut Oct 25 '18 at 08:43
  • I'm just trying to decode the transaction, e.g. get the inputs, outputs, scripts, witnesses etc. – reaktor_2004 Oct 25 '18 at 12:48