当前位置: 首页>>代码示例>>Java>>正文


Java Transaction.verify方法代码示例

本文整理汇总了Java中com.google.bitcoin.core.Transaction.verify方法的典型用法代码示例。如果您正苦于以下问题:Java Transaction.verify方法的具体用法?Java Transaction.verify怎么用?Java Transaction.verify使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.google.bitcoin.core.Transaction的用法示例。


在下文中一共展示了Transaction.verify方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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();
}
 
开发者ID:lukmaz,项目名称:BitcoinLottery,代码行数:25,代码来源:OpenTx.java

示例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();
}
 
开发者ID:lukmaz,项目名称:BitcoinLottery,代码行数:23,代码来源:ComputeTx.java

示例3: 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();
}
 
开发者ID:lukmaz,项目名称:BitcoinLottery,代码行数:36,代码来源:CommitTx.java

示例4: 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();
}
 
开发者ID:lukmaz,项目名称:BitcoinLottery,代码行数:16,代码来源:PayDepositTx.java

示例5: 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();
}
 
开发者ID:lukmaz,项目名称:BitcoinLottery,代码行数:9,代码来源:ClaimTx.java


注:本文中的com.google.bitcoin.core.Transaction.verify方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。