本文整理汇总了Java中com.google.bitcoin.core.Transaction.addInput方法的典型用法代码示例。如果您正苦于以下问题:Java Transaction.addInput方法的具体用法?Java Transaction.addInput怎么用?Java Transaction.addInput使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.bitcoin.core.Transaction
的用法示例。
在下文中一共展示了Transaction.addInput方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: OpenTx
import com.google.bitcoin.core.Transaction; //导入方法依赖的package包/类
public OpenTx(LotteryTx commitTx, ECKey sk, List<byte[]> pks, Address address,
byte[] secret, BigInteger fee, boolean testnet) throws VerificationException {
NetworkParameters params = getNetworkParameters(testnet);
int noPlayers = commitTx.getOutputs().size();
tx = new Transaction(params);
BigInteger value = BigInteger.ZERO;
for (TransactionOutput out : commitTx.getOutputs()) {
tx.addInput(out);
value = value.add(out.getValue());
}
tx.addOutput(value.subtract(fee), address);
for (int k = 0; k < noPlayers; ++k) {
byte[] sig = sign(k, sk).encodeToBitcoin();
tx.getInput(k).setScriptSig(new ScriptBuilder()
.data(sig)
.data(sk.getPubKey())
.data(sig) // wrong signature in a good format
.data(pks.get(k))
.data(secret)
.build());
tx.getInput(k).verify();
}
tx.verify();
}
示例2: ComputeTx
import com.google.bitcoin.core.Transaction; //导入方法依赖的package包/类
public ComputeTx(List<PutMoneyTx> inputs, List<byte[]> pks, List<byte[]> hashes,
int minLength, BigInteger fee, boolean testnet) throws VerificationException {
this.pks = pks;
this.hashes = hashes;
this.testnet = testnet;
this.minLength = minLength;
this.noPlayers = inputs.size();
tx = new Transaction(getNetworkParameters(testnet));
BigInteger stake = BigInteger.ZERO;
for (int k = 0; k < noPlayers; ++k) {
TransactionOutput in = inputs.get(k).getOut();
tx.addInput(in);
stake = stake.add(in.getValue());
}
tx.addOutput(stake.subtract(fee), calculateOutScript());
signatures = new ArrayList<byte[]>();
for (int k = 0; k < noPlayers; ++k) {
signatures.add(null);
}
tx.verify();
}
示例3: buildRawTx
import com.google.bitcoin.core.Transaction; //导入方法依赖的package包/类
private static String buildRawTx() {
ScriptBuilder builder = new ScriptBuilder();
builder.op(OP_DEPTH).op(OP_1).op(OP_NUMEQUAL).op(OP_IF)
.data("name of nakakamoto".getBytes()).op(OP_DROP)
.op(OP_RIPEMD160).op(OP_RIPEMD160)
.data(doublehash160("satoshi".getBytes())).op(OP_EQUAL)
.op(OP_ELSE).op(OP_DUP).op(OP_HASH160)
.data(doublehash160("Haha".getBytes())).op(OP_EQUALVERIFY)
.op(OP_CHECKSIG).op(OP_ENDIF);
Script outputScript = builder.build();
Transaction tx1 = new Transaction(MainNetParams.get());
tx1.addInput(new TransactionInput(MainNetParams.get(), tx1,
new byte[] {}));
ECKey key = new ECKey();
tx1.addOutput(Bitcoins.toSatoshiEndBully(), key);
Transaction tx2 = new Transaction(MainNetParams.get());
tx2.addInput(tx1.getOutput(0));
tx2.addOutput(Bitcoins.toSatoshiEndBully(), outputScript);
tx2.addOutput(Bitcoins.toSatoshiEndBully(), key);
System.out.println(tx2);
String rawTx = BaseEncoding.base16().encode(
tx2.unsafeBitcoinSerialize());
return rawTx;
}
示例4: buildRawTx
import com.google.bitcoin.core.Transaction; //导入方法依赖的package包/类
private static String buildRawTx() {
ProtoBlue puf = ProtoBlue.newBuilder().setBkbcValue(200855)
.setProtoType(Type.TEST).setExchangeType(ExType.BTC_TWD)
.setVersion(VerType.TEST1).build();
System.out.println(puf);
ScriptBuilder builder = new ScriptBuilder();
builder.op(OP_RETURN).data(puf.toByteArray());
Script outputScript = builder.build();
Transaction tx1 = new Transaction(MainNetParams.get());
tx1.addInput(new TransactionInput(MainNetParams.get(), tx1,
new byte[] {}));
ECKey key = new ECKey();
tx1.addOutput(Bitcoins.toSatoshiEndBully(), key);
Transaction tx2 = new Transaction(MainNetParams.get());
tx2.addInput(tx1.getOutput(0));
tx2.addOutput(Bitcoins.toSatoshiEndBully(), key);
tx2.addOutput(Bitcoins.toSatoshiEndBully(), outputScript);
System.out.println(tx2);
String rawTx = BaseEncoding.base16().encode(
tx2.unsafeBitcoinSerialize());
return rawTx;
}
示例5: CommitTx
import com.google.bitcoin.core.Transaction; //导入方法依赖的package包/类
public CommitTx(TransactionOutput out, ECKey sk, List<byte[]> pks, int position,
byte[] hash, int minLength, BigInteger fee, boolean testnet) throws VerificationException {
this.hash = hash;
this.commiterAddress = sk.getPubKeyHash();
this.minLength = minLength;
this.noPlayers = pks.size();
this.position = position;
this.stake = out.getValue().subtract(fee).divide(BigInteger.valueOf(noPlayers-1));
NetworkParameters params = getNetworkParameters(testnet);
tx = new Transaction(params);
for (int k = 0; k < noPlayers; ++k) {
BigInteger currentStake = stake;
if (k == position) { //TODO: simplier script?
currentStake = BigInteger.ZERO;
}
tx.addOutput(currentStake, getCommitOutScript(Utils.sha256hash160(pks.get(k))));
}
tx.addInput(out);
if (out.getScriptPubKey().isSentToAddress()) {
tx.getInput(0).setScriptSig(ScriptBuilder.createInputScript(sign(0, sk), sk));
}
else if (out.getScriptPubKey().isSentToRawPubKey()) {
tx.getInput(0).setScriptSig(ScriptBuilder.createInputScript(sign(0, sk)));
}
else {
throw new VerificationException("Bad transaction output.");
}
this.addresses = new ArrayList<byte[]>();
for (byte[] pk : pks) {
this.addresses.add(Utils.sha256hash160(pk));
}
tx.verify();
tx.getInput(0).verify();
}
示例6: PayDepositTx
import com.google.bitcoin.core.Transaction; //导入方法依赖的package包/类
public PayDepositTx(CommitTx commitTx, int outNr, ECKey sk, byte[] pk, BigInteger fee,
long timestamp, boolean testnet) throws VerificationException {
TransactionOutput out = commitTx.getOutput(outNr);
NetworkParameters params = getNetworkParameters(testnet);
tx = new Transaction(params);
tx.setLockTime(timestamp);
tx.addOutput(out.getValue().subtract(fee), new Address(params, Utils.sha256hash160(pk)));
tx.addInput(out);
tx.getInput(0).setSequenceNumber(0);
tx.getInput(0).setScriptSig(new ScriptBuilder()
.data(sign(0, sk).encodeToBitcoin())
.data(sk.getPubKey())
.build());
tx.verify();
}
示例7: ClaimTx
import com.google.bitcoin.core.Transaction; //导入方法依赖的package包/类
public ClaimTx(ComputeTx computeTx, List<byte[]> secrets, ECKey sk,
Address address, BigInteger fee, boolean testnet) throws VerificationException {
tx = new Transaction(getNetworkParameters(testnet));
tx.addInput(computeTx.getOutput(0));
tx.addOutput(computeTx.getValue(0).subtract(fee), address);
completeInScript(computeTx, secrets, sk, address);
tx.verify();
}
示例8: addInputs
import com.google.bitcoin.core.Transaction; //导入方法依赖的package包/类
private static void addInputs(Transaction tx, List<TransactionOutPoint> unspents)
{
for(TransactionOutPoint outpoint : unspents)
{
tx.addInput(new TransactionInput(Constants.NETWORK_PARAMETERS, tx, new byte[]{}, outpoint));
}
}
示例9: sweepKey
import com.google.bitcoin.core.Transaction; //导入方法依赖的package包/类
public void sweepKey(ECKey key, long fee,
int accountId, JSONArray outputs) {
mLogger.info("sweepKey starting");
mLogger.info("key addr " + key.toAddress(mParams).toString());
Transaction tx = new Transaction(mParams);
long balance = 0;
ArrayList<Script> scripts = new ArrayList<Script>();
try {
for (int ii = 0; ii < outputs.length(); ++ii) {
JSONObject output;
output = outputs.getJSONObject(ii);
String tx_hash = output.getString("tx_hash");
int tx_output_n = output.getInt("tx_output_n");
String script = output.getString("script");
// Reverse byte order, create hash.
Sha256Hash hash =
new Sha256Hash(WalletUtil.msgHexToBytes(tx_hash));
tx.addInput(new TransactionInput
(mParams, tx, new byte[]{},
new TransactionOutPoint(mParams,
tx_output_n, hash)));
scripts.add(new Script(Hex.decode(script)));
balance += output.getLong("value");
}
} catch (JSONException e) {
e.printStackTrace();
throw new RuntimeException("trouble parsing unspent outputs");
}
// Compute balance - fee.
long amount = balance - fee;
mLogger.info(String.format("sweeping %d", amount));
// Figure out the destination address.
Address to = mHDReceiver.nextReceiveAddress();
mLogger.info("sweeping to " + to.toString());
// Add output.
tx.addOutput(BigInteger.valueOf(amount), to);
WalletUtil.signTransactionInputs(tx, Transaction.SigHash.ALL,
key, scripts);
mLogger.info("tx bytes: " +
new String(Hex.encode(tx.bitcoinSerialize())));
// mKit.peerGroup().broadcastTransaction(tx);
broadcastTransaction(mKit.peerGroup(), tx);
mLogger.info("sweepKey finished");
}