mirror of
https://github.com/bitcoinj/bitcoinj.git
synced 2025-03-13 11:36:15 +01:00
Block: construct genesis block coinbase from individual values
In particular, - the input script is constructed from the difficulty target and the genesis message - the output script is constructed from the pubkey via ScriptBuilder.createP2PKOutputScript()
This commit is contained in:
parent
4fe444ddb2
commit
4b826aac8c
1 changed files with 11 additions and 14 deletions
|
@ -32,7 +32,6 @@ import org.bitcoinj.crypto.ECKey;
|
|||
import org.bitcoinj.params.BitcoinNetworkParams;
|
||||
import org.bitcoinj.script.Script;
|
||||
import org.bitcoinj.script.ScriptBuilder;
|
||||
import org.bitcoinj.script.ScriptOpCodes;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
@ -43,6 +42,7 @@ import java.io.OutputStream;
|
|||
import java.math.BigInteger;
|
||||
import java.nio.BufferUnderflowException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.time.Duration;
|
||||
import java.time.Instant;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
|
@ -239,22 +239,19 @@ public class Block extends BaseMessage {
|
|||
}
|
||||
|
||||
private static List<Transaction> genesisTransactions() {
|
||||
Transaction tx = Transaction.coinbase(genesisTxInputScriptBytes);
|
||||
tx.addOutput(new TransactionOutput(tx, FIFTY_COINS, genesisTxScriptPubKeyBytes));
|
||||
byte[] messageBytes = GENESIS_MESSAGE.getBytes(StandardCharsets.US_ASCII);
|
||||
Script scriptSig = // TODO find out what the pushdata(4) is supposed to mean
|
||||
new ScriptBuilder().bigNum(STANDARD_MAX_DIFFICULTY_TARGET).bigNum(4).data(messageBytes).build();
|
||||
Transaction tx = Transaction.coinbase(scriptSig.program());
|
||||
tx.addOutput(new TransactionOutput(
|
||||
tx, FIFTY_COINS, ScriptBuilder.createP2PKOutputScript(GENESIS_OUTPUT_PUBKEY).program()));
|
||||
return Collections.singletonList(tx);
|
||||
}
|
||||
|
||||
// A script containing the difficulty bits and the following message:
|
||||
//
|
||||
// "The Times 03/Jan/2009 Chancellor on brink of second bailout for banks"
|
||||
private static final byte[] genesisTxInputScriptBytes = ByteUtils.parseHex
|
||||
("04ffff001d0104455468652054696d65732030332f4a616e2f32303039204368616e63656c6c6f72206f6e206272696e6b206f66207365636f6e64206261696c6f757420666f722062616e6b73");
|
||||
|
||||
private static final byte[] genesisTxScriptPubKeyBytes = new ScriptBuilder()
|
||||
.data(ByteUtils.parseHex("04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5f"))
|
||||
.op(ScriptOpCodes.OP_CHECKSIG)
|
||||
.build()
|
||||
.program();
|
||||
private static final String GENESIS_MESSAGE =
|
||||
"The Times 03/Jan/2009 Chancellor on brink of second bailout for banks";
|
||||
private static final byte[] GENESIS_OUTPUT_PUBKEY = ByteUtils.parseHex(
|
||||
"04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5f");
|
||||
|
||||
@Override
|
||||
public int messageSize() {
|
||||
|
|
Loading…
Add table
Reference in a new issue