Closed GoogleCodeExporter closed 9 years ago
You can just create a Transaction object and then use addInput and addOutput as
needed. I'm not sure what else is required - bitcoinj can and does create
coinbase transactions, see the unit tests for examples of doing that.
Is there something specific missing?
Original comment by hearn@google.com
on 11 Feb 2013 at 9:55
The missing thing is probably understanding on my part. When I looked, it
seemed there was no way to create a TransactionInput that had a zero hash
output transaction and -1 output index. Maybe I was looking at an old version,
I think I had 0.6.1.
I am also really unclear on where and how to substitute in the extra nonce
bytes needed for stratum mining.
Original comment by fireduck@gmail.com
on 11 Feb 2013 at 10:20
Look at the implementation of (package private) method
Block.addCoinbaseTransaction
Transaction coinbase = new Transaction(params);
coinbase.addInput(new TransactionInput(params, coinbase, new byte[]{(byte) txCounter++, (byte) 1}));
coinbase.addOutput(new TransactionOutput(params, coinbase, value, Script.createOutputScript(pubKeyTo)));
In this case it's just stuffing a counter inside the coinbase scriptSig, but of
course, you can use the methods on the Script object to create your own
scriptSig with the right things in it.
The TransactionInput c'tor used above creates an input with an outpoint of
Sha256Hash.ZERO so it is suitable for a coinbase input.
Original comment by hearn@google.com
on 11 Feb 2013 at 10:39
Sweet, this helps a lot. Let me make sure I understand:
The script bytes for the input of the coinbase transaction can be literally
whatever I want (limited to 100 bytes)?
I was thinking it had to be a valid script that terminated in such a way that
code evaluating the script knew to not bother evaluating the rest to allow some
other data to be crammed in.
Original comment by fireduck@gmail.com
on 11 Feb 2013 at 10:58
Look at the format of existing Stratum mined scriptSigs and match them.
Original comment by hearn@google.com
on 11 Feb 2013 at 11:11
Request: make constructor public
TransactionInput(NetworkParameters params, Transaction parentTransaction,
byte[] scriptBytes)
Original comment by fireduck@gmail.com
on 11 Feb 2013 at 11:26
OK, done (on master).
Original comment by hearn@google.com
on 14 Feb 2013 at 2:53
Original issue reported on code.google.com by
fireduck@gmail.com
on 11 Feb 2013 at 9:49