本文整理汇总了Java中com.google.bitcoin.script.ScriptOpCodes类的典型用法代码示例。如果您正苦于以下问题:Java ScriptOpCodes类的具体用法?Java ScriptOpCodes怎么用?Java ScriptOpCodes使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ScriptOpCodes类属于com.google.bitcoin.script包,在下文中一共展示了ScriptOpCodes类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createGenesis
import com.google.bitcoin.script.ScriptOpCodes; //导入依赖的package包/类
private static Block createGenesis(NetworkParameters n) {
Block genesisBlock = new Block(n);
Transaction t = new Transaction(n);
try {
// A script containing the difficulty bits and the following message:
//
// coin dependent
byte[] bytes = Hex.decode(CoinDefinition.genesisXInBytes);
//byte[] bytes = Hex.decode("04ffff001d0104294469676974616c636f696e2c20412043757272656e637920666f722061204469676974616c20416765");
t.addInput(new TransactionInput(n, t, bytes));
ByteArrayOutputStream scriptPubKeyBytes = new ByteArrayOutputStream();
Script.writeBytes(scriptPubKeyBytes, Hex.decode(CoinDefinition.genessiXOutBytes));
//("04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5f"));
scriptPubKeyBytes.write(ScriptOpCodes.OP_CHECKSIG);
t.addOutput(new TransactionOutput(n, t, Utils.toNanoCoins(CoinDefinition.genesisBlockValue, 0), scriptPubKeyBytes.toByteArray()));
} catch (Exception e) {
// Cannot happen.
throw new RuntimeException(e);
}
genesisBlock.addTransaction(t);
return genesisBlock;
}
示例2: createGenesis1
import com.google.bitcoin.script.ScriptOpCodes; //导入依赖的package包/类
private static Block createGenesis1(NetworkParameters n) {
Block genesisBlock = new Block(n);
Transaction t = new Transaction(n);
try {
// A script containing the difficulty bits and the following message:
//
// "Digitalcoin, A Currency for a Digital Age"
byte[] bytes = Hex.decode
("04b217bb4e022309");
t.addInput(new TransactionInput(n, t, bytes));
ByteArrayOutputStream scriptPubKeyBytes = new ByteArrayOutputStream();
Script.writeBytes(scriptPubKeyBytes, Hex.decode
("04a5814813115273a109cff99907ba4a05d951873dae7acb6c973d0c9e7c88911a3dbc9aa600deac241b91707e7b4ffb30ad91c8e56e695a1ddf318592988afe0a"));
scriptPubKeyBytes.write(ScriptOpCodes.OP_CHECKSIG);
t.addOutput(new TransactionOutput(n, t, Utils.toNanoCoins(50, 0), scriptPubKeyBytes.toByteArray()));
} catch (Exception e) {
// Cannot happen.
throw new RuntimeException(e);
}
genesisBlock.addTransaction(t);
return genesisBlock;
}
示例3: createGenesis
import com.google.bitcoin.script.ScriptOpCodes; //导入依赖的package包/类
private static Block createGenesis(NetworkParameters n) {
Block genesisBlock = new Block(n);
Transaction t = new Transaction(n);
try {
// A script containing the difficulty bits and the following message:
//
// "The Times 03/Jan/2009 Chancellor on brink of second bailout for banks"
byte[] bytes = Hex.decode
("04ffff001d0104455468652054696d65732030332f4a616e2f32303039204368616e63656c6c6f72206f6e206272696e6b206f66207365636f6e64206261696c6f757420666f722062616e6b73");
t.addInput(new TransactionInput(n, t, bytes));
ByteArrayOutputStream scriptPubKeyBytes = new ByteArrayOutputStream();
Script.writeBytes(scriptPubKeyBytes, Hex.decode
("04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5f"));
scriptPubKeyBytes.write(ScriptOpCodes.OP_CHECKSIG);
t.addOutput(new TransactionOutput(n, t, Utils.toNanoCoins(50, 0), scriptPubKeyBytes.toByteArray()));
} catch (Exception e) {
// Cannot happen.
throw new RuntimeException(e);
}
genesisBlock.addTransaction(t);
return genesisBlock;
}
示例4: createGenesis
import com.google.bitcoin.script.ScriptOpCodes; //导入依赖的package包/类
private static Block createGenesis(NetworkParameters n) {
Block genesisBlock = new Block(n);
Transaction t = new Transaction(n);
try {
// A script containing the difficulty bits and the following message:
//
// coin dependent
byte[] bytes = Hex.decode(CoinDefinition.genesisXInBytes);
t.addInput(new TransactionInput(n, t, bytes));
ByteArrayOutputStream scriptPubKeyBytes = new ByteArrayOutputStream();
Script.writeBytes(scriptPubKeyBytes, Hex.decode(CoinDefinition.genessiXOutBytes));
scriptPubKeyBytes.write(ScriptOpCodes.OP_CHECKSIG);
t.addOutput(new TransactionOutput(n, t, Utils.toNanoCoins(CoinDefinition.genesisBlockValue, 0), scriptPubKeyBytes.toByteArray()));
} catch (Exception e) {
// Cannot happen.
throw new RuntimeException(e);
}
genesisBlock.addTransaction(t);
return genesisBlock;
}
示例5: createGenesis
import com.google.bitcoin.script.ScriptOpCodes; //导入依赖的package包/类
private static Block createGenesis(NetworkParameters n) {
Block genesisBlock = new Block(n);
Transaction t = new Transaction(n);
try {
// A script containing the difficulty bits and the following message:
//
// coin dependent
byte[] bytes = Hex.decode(CoinDefinition.genesisTxInBytes);
//byte[] bytes = Hex.decode("04ffff001d0104294469676974616c636f696e2c20412043757272656e637920666f722061204469676974616c20416765");
t.addInput(new TransactionInput(n, t, bytes));
ByteArrayOutputStream scriptPubKeyBytes = new ByteArrayOutputStream();
Script.writeBytes(scriptPubKeyBytes, Hex.decode(CoinDefinition.genesisTxOutBytes));
//("04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5f"));
scriptPubKeyBytes.write(ScriptOpCodes.OP_CHECKSIG);
t.addOutput(new TransactionOutput(n, t, Utils.toNanoCoins(CoinDefinition.genesisBlockValue, 0), scriptPubKeyBytes.toByteArray()));
genesisBlock.setMerkleRoot(new Sha256Hash("868b2fb28cb1a0b881480cc85eb207e29e6ae75cdd6d26688ed34c2d2d23c776"));
} catch (Exception e) {
// Cannot happen.
throw new RuntimeException(e);
}
genesisBlock.addTransaction(t);
log.info("Genesis Block Information (tx only):" + genesisBlock.toString());
return genesisBlock;
}
示例6: createGenesis
import com.google.bitcoin.script.ScriptOpCodes; //导入依赖的package包/类
private static Block createGenesis(NetworkParameters n) {
Block genesisBlock = new Block(n);
Transaction t = new Transaction(n);
try {
// A script containing the difficulty bits and the following message:
//
// coin dependent
byte[] bytes = Hex.decode(CoinDefinition.genesisTxInBytes);
//byte[] bytes = Hex.decode("04ffff001d0104294469676974616c636f696e2c20412043757272656e637920666f722061204469676974616c20416765");
t.addInput(new TransactionInput(n, t, bytes));
ByteArrayOutputStream scriptPubKeyBytes = new ByteArrayOutputStream();
Script.writeBytes(scriptPubKeyBytes, Hex.decode(CoinDefinition.genesisTxOutBytes));
//("04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5f"));
scriptPubKeyBytes.write(ScriptOpCodes.OP_CHECKSIG);
t.addOutput(new TransactionOutput(n, t, Utils.toNanoCoins(CoinDefinition.genesisBlockValue, 0), scriptPubKeyBytes.toByteArray()));
genesisBlock.setMerkleRoot(new Sha256Hash("448f7de5e3a564ad723ea1ac11186466e35c9315acfba89d9b956b303340a7a9"));
} catch (Exception e) {
// Cannot happen.
throw new RuntimeException(e);
}
genesisBlock.addTransaction(t);
log.info("Genesis Block Information (tx only):" + genesisBlock.toString());
return genesisBlock;
}
示例7: createGenesis
import com.google.bitcoin.script.ScriptOpCodes; //导入依赖的package包/类
private static Block createGenesis(NetworkParameters n) {
Block genesisBlock = new Block(n);
Transaction t = new Transaction(n);
try {
// A script containing the difficulty bits and the following message:
//
// coin dependent
byte[] bytes = Hex.decode(CoinDefinition.genesisTxInBytes);
t.addInput(new TransactionInput(n, t, bytes));
ByteArrayOutputStream scriptPubKeyBytes = new ByteArrayOutputStream();
Script.writeBytes(scriptPubKeyBytes, Hex.decode(CoinDefinition.genesisTxOutBytes));
scriptPubKeyBytes.write(ScriptOpCodes.OP_CHECKSIG);
t.addOutput(new TransactionOutput(n, t, Utils.toNanoCoins(CoinDefinition.genesisBlockValue, 0), scriptPubKeyBytes.toByteArray()));
} catch (Exception e) {
// Cannot happen.
throw new RuntimeException(e);
}
genesisBlock.addTransaction(t);
return genesisBlock;
}
示例8: testUpdateLength
import com.google.bitcoin.script.ScriptOpCodes; //导入依赖的package包/类
@Test
public void testUpdateLength() {
NetworkParameters params = UnitTestParams.get();
Block block = params.getGenesisBlock().createNextBlockWithCoinbase(new ECKey().getPubKey());
assertEquals(block.bitcoinSerialize().length, block.length);
final int origBlockLen = block.length;
Transaction tx = new Transaction(params);
// this is broken until the transaction has > 1 input + output (which is required anyway...)
//assertTrue(tx.length == tx.bitcoinSerialize().length && tx.length == 8);
byte[] outputScript = new byte[10];
Arrays.fill(outputScript, (byte) ScriptOpCodes.OP_FALSE);
tx.addOutput(new TransactionOutput(params, null, BigInteger.valueOf(1), outputScript));
tx.addInput(new TransactionInput(params, null, new byte[] {(byte) ScriptOpCodes.OP_FALSE},
new TransactionOutPoint(params, 0, Sha256Hash.create(new byte[] {1}))));
int origTxLength = 8 + 2 + 8 + 1 + 10 + 40 + 1 + 1;
assertEquals(tx.bitcoinSerialize().length, tx.length);
assertEquals(origTxLength, tx.length);
block.addTransaction(tx);
assertEquals(block.bitcoinSerialize().length, block.length);
assertEquals(origBlockLen + tx.length, block.length);
block.getTransactions().get(1).getInputs().get(0).setScriptBytes(new byte[] {(byte) ScriptOpCodes.OP_FALSE, (byte) ScriptOpCodes.OP_FALSE});
assertEquals(block.length, origBlockLen + tx.length);
assertEquals(tx.length, origTxLength + 1);
block.getTransactions().get(1).getInputs().get(0).setScriptBytes(new byte[] {});
assertEquals(block.length, block.bitcoinSerialize().length);
assertEquals(block.length, origBlockLen + tx.length);
assertEquals(tx.length, origTxLength - 1);
block.getTransactions().get(1).addInput(new TransactionInput(params, null, new byte[] {(byte) ScriptOpCodes.OP_FALSE},
new TransactionOutPoint(params, 0, Sha256Hash.create(new byte[] {1}))));
assertEquals(block.length, origBlockLen + tx.length);
assertEquals(tx.length, origTxLength + 41); // - 1 + 40 + 1 + 1
}
示例9: computeMinLength
import com.google.bitcoin.script.ScriptOpCodes; //导入依赖的package包/类
protected void computeMinLength() throws VerificationException {
Script outScript = tx.getOutput(0).getScriptPubKey();
List<ScriptChunk> chunks = outScript.getChunks();
ListIterator<ScriptChunk> it = chunks.listIterator();
while(it.hasNext()) {
if (it.next().equalsOpCode(ScriptOpCodes.OP_SIZE)) {
minLength = Integer.parseInt(Utils.bytesToHexString(it.next().data), 16);
return;
}
}
throw new VerificationException("Wrong out script.");
}
示例10: getCommitOutScript
import com.google.bitcoin.script.ScriptOpCodes; //导入依赖的package包/类
protected Script getCommitOutScript(byte[] receiverAddress) {
byte[] min = Utils.parseAsHexOrBase58(Integer.toHexString(minLength));
byte[] max = Utils.parseAsHexOrBase58(Integer.toHexString(minLength+noPlayers));
return new ScriptBuilder()
.op(ScriptOpCodes.OP_SIZE)
.data(min)
.data(max)
.op(ScriptOpCodes.OP_WITHIN)
.op(ScriptOpCodes.OP_SWAP)
.op(BitcoinLotterySettings.hashFunctionOpCode)
.data(hash)
.op(ScriptOpCodes.OP_EQUAL)
.op(ScriptOpCodes.OP_BOOLAND)
.op(ScriptOpCodes.OP_ROT)
.op(ScriptOpCodes.OP_ROT)
.op(ScriptOpCodes.OP_DUP)
.op(ScriptOpCodes.OP_HASH160)
.data(receiverAddress)
.op(ScriptOpCodes.OP_EQUALVERIFY)
.op(ScriptOpCodes.OP_CHECKSIG)
.op(ScriptOpCodes.OP_BOOLOR)
.op(ScriptOpCodes.OP_VERIFY)
.op(ScriptOpCodes.OP_DUP)
.op(ScriptOpCodes.OP_HASH160)
.data(commiterAddress)
.op(ScriptOpCodes.OP_EQUALVERIFY)
.op(ScriptOpCodes.OP_CHECKSIG)
.build();
}
示例11: createGenesis
import com.google.bitcoin.script.ScriptOpCodes; //导入依赖的package包/类
private static Block createGenesis(NetworkParameters n) {
Block genesisBlock = new Block(n);
Transaction t = new Transaction(n);
try {
// A script containing the difficulty bits and the following message:
//
// coin dependent
byte[] bytes = Hex.decode(CoinDefinition.genesisXInBytes);
//byte[] bytes = Hex.decode("04ffff001d0104294469676974616c636f696e2c20412043757272656e637920666f722061204469676974616c20416765");
t.addInput(new TransactionInput(n, t, bytes));
ByteArrayOutputStream scriptPubKeyBytes = new ByteArrayOutputStream();
Script.writeBytes(scriptPubKeyBytes, Hex.decode(CoinDefinition.genessiXOutBytes));
System.out.println("genesisXInBytes:"+CoinDefinition.genesisXInBytes); //("04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5f"));
scriptPubKeyBytes.write(ScriptOpCodes.OP_CHECKSIG);
t.addOutput(new TransactionOutput(n, t, Utils.toNanoCoins(CoinDefinition.genesisBlockValue, 0), scriptPubKeyBytes.toByteArray()));
System.out.println("genessiXOutBytes:"+CoinDefinition.genessiXOutBytes);
System.out.println("genesisBlockValue:"+CoinDefinition.genesisBlockValue);
} catch (Exception e) {
// Cannot happen.
throw new RuntimeException(e);
}
genesisBlock.addTransaction(t);
return genesisBlock;
}
示例12: calculateOutScript
import com.google.bitcoin.script.ScriptOpCodes; //导入依赖的package包/类
protected Script calculateOutScript() {
ScriptBuilder sb = new ScriptBuilder();
byte[] dataMinLength = {(byte) minLength};
sb.smallNum(0);
for (int k = noPlayers-1; k >= 0; --k) {
sb.op(ScriptOpCodes.OP_SWAP)
.op(ScriptOpCodes.OP_SIZE)
.data(dataMinLength)
.op(ScriptOpCodes.OP_SUB)
.op(ScriptOpCodes.OP_TUCK)
.smallNum(0)
.smallNum(noPlayers)
.op(ScriptOpCodes.OP_WITHIN)
.op(ScriptOpCodes.OP_VERIFY)
.op(BitcoinLotterySettings.hashFunctionOpCode)
.data(hashes.get(k))
.op(ScriptOpCodes.OP_EQUALVERIFY)
.op(ScriptOpCodes.OP_ADD);
if (k < noPlayers-1) {
sb.op(ScriptOpCodes.OP_DUP)
.smallNum(noPlayers)
.op(ScriptOpCodes.OP_GREATERTHANOREQUAL)
.op(ScriptOpCodes.OP_IF)
.smallNum(noPlayers)
.op(ScriptOpCodes.OP_SUB)
.op(ScriptOpCodes.OP_ENDIF);
}
}
for (int k = noPlayers-1; k >= 0; --k) {
sb.data(Utils.sha256hash160(pks.get(k)));
}
sb.smallNum(noPlayers)
.op(ScriptOpCodes.OP_ROLL)
.op(ScriptOpCodes.OP_ROLL)
.smallNum(noPlayers)
.op(ScriptOpCodes.OP_ROLL)
.op(ScriptOpCodes.OP_DUP)
.op(ScriptOpCodes.OP_HASH160)
.op(ScriptOpCodes.OP_ROT)
.op(ScriptOpCodes.OP_EQUALVERIFY);
for (int k = 1; k <= noPlayers-1; ++k) {
sb.op(ScriptOpCodes.OP_SWAP)
.op(ScriptOpCodes.OP_DROP);
}
sb.op(ScriptOpCodes.OP_CHECKSIG);
return sb.build();
}
示例13: pay
import com.google.bitcoin.script.ScriptOpCodes; //导入依赖的package包/类
public void pay(ECKey recipientKey, byte[] request, BigInteger amount) {
try {
Transaction lastTransaction = (this.iSentLast ? this.lastSentTransaction : this.refundTransaction);
this.pendingTransaction = new Transaction(getParentPeer().params());
this.pendingTransaction.setLockTime((this.iSentLast ?
lastTransaction.getLockTime() : lastTransaction.getLockTime()) - this.locktimeStep);
this.pendingTransaction.addInput(this.setupTransaction.getOutput(0));
this.pendingTransaction.getInput(0).setSequenceNumber(this.iSentLast ?
lastTransaction.getInput(0).getSequenceNumber() :
lastTransaction.getInput(0).getSequenceNumber() + 1);
this.pendingTransaction.addOutput(
lastTransaction.getOutput(0).getValue()
.add(this.iAmInitiator ? amount.negate() : amount)
.subtract((this.iAmInitiator && !iSentLast) ? BigInteger.ZERO : this.feeStep),
new ScriptBuilder()
.op(ScriptOpCodes.OP_HASH160)
.data(request)
.op(ScriptOpCodes.OP_EQUALVERIFY)
.data((this.iAmInitiator ? getParentPeerKey() : getPeerKey()).getPubKey())
.op(ScriptOpCodes.OP_CHECKSIG)
.build());
this.pendingTransaction.addOutput(
lastTransaction.getOutput(1).getValue()
.add(this.iAmInitiator ? amount : amount.negate())
.subtract((!this.iAmInitiator && !iSentLast) ? this.feeStep : BigInteger.ZERO),
new ScriptBuilder()
.op(ScriptOpCodes.OP_HASH160)
.data(request)
.op(ScriptOpCodes.OP_EQUALVERIFY)
.data((this.iAmInitiator ? getPeerKey() : getParentPeerKey()).getPubKey())
.op(ScriptOpCodes.OP_CHECKSIG)
.build());
this.pendingTransaction.getInput(0).setScriptSig(
new ScriptBuilder()
.data(this.pendingTransaction.calculateSignature(0, getParentPeerKey(),
this.setupTransaction.getOutput(0).getScriptPubKey(), SigHash.ALL, false)
.encodeToBitcoin())
.build());
this.state = State.PENDING_COMMIT;
this.pendingRequest = request;
this.iSentLast = true;
getPeer().payFor(getParentPeerKey(), getPeerKey(), recipientKey, request, amount, pendingTransaction);
} catch (Exception e) {
// No exception handling for this demo
e.printStackTrace();
}
}