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


Java VerificationException类代码示例

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

VerificationException类属于com.google.bitcoin.core包,在下文中一共展示了VerificationException类的24个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: decodeFromBitcoin

import com.google.bitcoin.core.VerificationException; //导入依赖的package包/类
/**
 * Returns a decoded signature.
 * @throws RuntimeException if the signature is invalid or unparseable in some way.
 */
public static TransactionSignature decodeFromBitcoin(byte[] bytes, boolean requireCanonical) throws VerificationException {
    // Bitcoin encoding is DER signature + sighash byte.
    if (requireCanonical && !isEncodingCanonical(bytes))
        throw new VerificationException("Signature encoding is not canonical.");
    ECKey.ECDSASignature sig;
    try {
        sig = ECKey.ECDSASignature.decodeFromDER(bytes);
    } catch (IllegalArgumentException e) {
        throw new VerificationException("Could not decode DER", e);
    }
    TransactionSignature tsig = new TransactionSignature(sig.r, sig.s);
    // In Bitcoin, any value of the final byte is valid, but not necessarily canonical. See javadocs for
    // isEncodingCanonical to learn more about this.
    tsig.sighashFlags = bytes[bytes.length - 1];
    return tsig;
}
 
开发者ID:HashEngineering,项目名称:megacoinj,代码行数:21,代码来源:TransactionSignature.java


示例2: OpenTx

import com.google.bitcoin.core.VerificationException; //导入依赖的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


示例3: computeSecret

import com.google.bitcoin.core.VerificationException; //导入依赖的package包/类
protected void computeSecret() throws VerificationException {
	for (TransactionInput input : tx.getInputs()) {
		List<ScriptChunk> chunks = input.getScriptSig().getChunks();
		if (chunks.size() == 5) {
			byte[] data = chunks.get(SECRET_POSITION).data;
			if (hash != null) {
				if (Arrays.equals(hash, LotteryUtils.calcDoubleHash(data))) {
					possibleSecrets.add(data);
					return;
				}
			}
			else {
				possibleSecrets.add(data);
			}
		}
	}
	
	if (possibleSecrets.size() == 0) {
		throw new VerificationException("Not an Open transaction.");
	}
}
 
开发者ID:lukmaz,项目名称:BitcoinLottery,代码行数:22,代码来源:OpenTx.java


示例4: ComputeTx

import com.google.bitcoin.core.VerificationException; //导入依赖的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


示例5: validateIsIncopletePayDeposit

import com.google.bitcoin.core.VerificationException; //导入依赖的package包/类
protected void validateIsIncopletePayDeposit(ECKey sk) throws VerificationException {
	if (tx.getInputs().size() != 1) {
		throw new VerificationException("Wrong number of inputs.");
	}
	else if (tx.getOutputs().size() != 1) {
		throw new VerificationException("Wrong number of outputs.");
	}
	else if (tx.getInput(0).getSequenceNumber() != 0) {
		throw new VerificationException("Wrong sequence number.");
	}
	else if (tx.getLockTime() < Transaction.LOCKTIME_THRESHOLD) {
		throw new VerificationException("Wrong lock time.");
	}
	else if (tx.getInput(0).getScriptSig().getChunks().size() != 2) {
		throw new VerificationException("Wrong script sig.");
	}
	else if (!tx.getOutput(0).getScriptPubKey().isSentToAddress()) {
		throw new VerificationException("Wrong out script.");
	}
	else if (!Arrays.equals(tx.getOutput(0).getScriptPubKey().getPubKeyHash(), sk.getPubKeyHash())) {
		throw new VerificationException("Wrong transaction's recipient.");
	}
}
 
开发者ID:lukmaz,项目名称:BitcoinLottery,代码行数:24,代码来源:PayDepositTx.java


示例6: processDirectTransaction

import com.google.bitcoin.core.VerificationException; //导入依赖的package包/类
protected void processDirectTransaction(@Nonnull final Transaction tx)
{
	final Wallet wallet = getWalletApplication().getWallet();

	try
	{
		if (wallet.isTransactionRelevant(tx))
		{
			wallet.receivePending(tx, null);

			final WalletApplication application = (WalletApplication) getApplication();
			application.broadcastTransaction(tx);
		}
		else
		{
			longToast("Direct transaction is not relevant for you.");
		}
	}
	catch (final VerificationException x)
	{
		longToast("Direct transaction is not valid.");
	}
}
 
开发者ID:9cat,项目名称:templecoin-android-wallet,代码行数:24,代码来源:AbstractOnDemandServiceActivity.java


示例7: verify

import com.google.bitcoin.core.VerificationException; //导入依赖的package包/类
public ComputeTx verify(String input) throws WrongInputException {
	byte[] rawTx = parseHexString(input);
	try {
		return new ComputeTx(rawTx, null, testnet);
	} catch (VerificationException e) {
		throw new WrongInputException(e.getMessage());
	}
}
 
开发者ID:lukmaz,项目名称:BitcoinLottery,代码行数:9,代码来源:InputVerifiers.java


示例8: claimMoney

import com.google.bitcoin.core.VerificationException; //导入依赖的package包/类
public void claimMoney() throws IOException {
	boolean testnet = parameters.isTestnet();
	ComputeTx computeTx = ioHandler.askCompute(new InputVerifiers.ComputeTxVerifier(testnet));
	memoryStorage.saveTransaction(parameters, computeTx);
	
	List<byte[]> hashes = computeTx.getSecretsHashes();
	int minLength = computeTx.getMinLength();
	List<byte[]> secrets = ioHandler.askSecrets(hashes, 
			new InputVerifiers.SecretListVerifier(null, hashes, minLength, testnet));
	memoryStorage.saveSecrets(parameters, secrets);
	
	int winner = 0;
	Address winersAddress = null;
	try {
		winner = computeTx.getWinner(secrets);
		winersAddress = computeTx.getAddress(winner);
	} catch (VerificationException e1) {// can not happen
		e1.printStackTrace();
	}
	ioHandler.showWinner(winner, winersAddress);
	byte[] pkHash = winersAddress.getHash160();
	NetworkParameters params = LotteryTx.getNetworkParameters(testnet);
	ECKey sk = ioHandler.askSK(new InputVerifiers.SkVerifier(pkHash, testnet));
	Address address = ioHandler.askAddress(sk.toAddress(params), new InputVerifiers.AddressVerifier(testnet));
	BigInteger fee = ioHandler.askFee(new InputVerifiers.FeeVerifier(computeTx.getValue(0)));
	ClaimTx claimMoneyTx = null;
	try {
		claimMoneyTx = new ClaimTx(computeTx, secrets, sk, address, fee, testnet);
	} catch (VerificationException e) {// can not happen
		e.printStackTrace();
	}
	File claimMoneyFile = memoryStorage.saveTransaction(parameters, claimMoneyTx);
	ioHandler.showClaimMoney(claimMoneyTx, claimMoneyFile.getParent());
}
 
开发者ID:lukmaz,项目名称:BitcoinLottery,代码行数:35,代码来源:MoneyClaimer.java


示例9: executionPhase

import com.google.bitcoin.core.VerificationException; //导入依赖的package包/类
protected void executionPhase() throws IOException {
	ioHandler.showLotteryPhase(LotteryPhases.EXECUTION_PHASE);
	boolean testnet = parameters.isTestnet();
	List<PutMoneyTx> putMoneyTxs = ioHandler.askPutMoney(noPlayers, stake, 
			new InputVerifiers.PutMoneyVerifier(pks, stake, testnet));
	memoryStorage.saveTransactions(parameters, putMoneyTxs);
	try {
		computeTx = new ComputeTx(putMoneyTxs, pks, hashes, minLength, fee, testnet);
	} catch (VerificationException e1) { //cannot happen
		e1.printStackTrace();
	}
	byte[] computeSig = null;
	try {
		computeSig = computeTx.addSignature(position, sk);
	} catch (VerificationException e) {
		// TODO should not happen
		e.printStackTrace();
	}

	if (position == 0) {
		SignaturesVerifier sigVerifier = new InputVerifiers.SignaturesVerifier(computeTx);
		ioHandler.askSignatures(noPlayers, position, sigVerifier);
		ioHandler.showCompute(computeTx);
	}
	else {
		ioHandler.showSignature(computeSig);
		computeTx = ioHandler.askCompute(new InputVerifiers.SignedComputeTxVerifier(computeTx, pks, putMoneyTxs, testnet));
	}
	memoryStorage.saveTransaction(parameters, computeTx);
}
 
开发者ID:lukmaz,项目名称:BitcoinLottery,代码行数:31,代码来源:Lottery.java


示例10: claimMoneyPhase

import com.google.bitcoin.core.VerificationException; //导入依赖的package包/类
protected void claimMoneyPhase() throws IOException { //TODO: extract common part with MoneyClaimer ?
	ioHandler.showLotteryPhase(LotteryPhases.CLAIM_MONEY_PHASE);
	boolean testnet = parameters.isTestnet();
	List<byte[]> secrets = ioHandler.askSecretsOrOpens(noPlayers, position, 
			new InputVerifiers.SecretListVerifier(position, hashes, minLength, testnet));
	secrets.set(position, secret);
	memoryStorage.saveSecrets(parameters, secrets);
	
	int winner = 0;
	try {
		winner = computeTx.getWinner(secrets);
	} catch (VerificationException e1) {// can not happen
		e1.printStackTrace();
	}
	if (winner == position) {
		ioHandler.showWin();
		NetworkParameters params = LotteryTx.getNetworkParameters(testnet);
		Address address = ioHandler.askAddress(sk.toAddress(params), new InputVerifiers.AddressVerifier(testnet));
		ClaimTx claimMoneyTx = null;
		try {
			claimMoneyTx = new ClaimTx(computeTx, secrets, sk, address, fee, testnet);
		} catch (VerificationException e) {// can not happen
			e.printStackTrace();
		}
		File claimMoneyFile = memoryStorage.saveTransaction(parameters, claimMoneyTx);
		ioHandler.showClaimMoney(claimMoneyTx, claimMoneyFile.getParent());
	}
	else {
		ioHandler.showLost(winner, computeTx.getAddress(winner));
	}
}
 
开发者ID:lukmaz,项目名称:BitcoinLottery,代码行数:32,代码来源:Lottery.java


示例11: validateIsPutMoney

import com.google.bitcoin.core.VerificationException; //导入依赖的package包/类
protected int validateIsPutMoney(byte[] pkHash, BigInteger stake) throws VerificationException {
	tx.verify();
	for (int k = 0; k < tx.getOutputs().size(); ++k) {
		TransactionOutput out = tx.getOutput(k);
		if (out.getValue().equals(stake) && out.getScriptPubKey().isSentToAddress()) {
			if (Arrays.equals(out.getScriptPubKey().getPubKeyHash(), pkHash)) {
				return k;
			}
		}
	}
	throw new VerificationException("No output of a proper value corresponding to the expected public key.");
}
 
开发者ID:lukmaz,项目名称:BitcoinLottery,代码行数:13,代码来源:PutMoneyTx.java


示例12: getWinner

import com.google.bitcoin.core.VerificationException; //导入依赖的package包/类
public int getWinner(List<byte[]> secrets) throws VerificationException {
	if (!checkSecrets(secrets)) {
		throw new VerificationException("Wrong secrets");
	}
	int winner = 0;
	for (byte[] secret : secrets) {
		winner += secret.length - minLength;
	}
	
	winner = (winner % getNoPlayers());
	return winner;
}
 
开发者ID:lukmaz,项目名称:BitcoinLottery,代码行数:13,代码来源:ComputeTx.java


示例13: addSignature

import com.google.bitcoin.core.VerificationException; //导入依赖的package包/类
public byte[] addSignature(int k, byte[] signature) throws VerificationException {
	tx.getInput(k).setScriptSig(new ScriptBuilder()
											.data(signature)
											.data(pks.get(k))
											.build());
	tx.getInput(k).verify();
	signatures.set(k, signature);
	return signature;
}
 
开发者ID:lukmaz,项目名称:BitcoinLottery,代码行数:10,代码来源:ComputeTx.java


示例14: computeSecretsHashes

import com.google.bitcoin.core.VerificationException; //导入依赖的package包/类
protected void computeSecretsHashes() throws VerificationException {
	Script outScript = tx.getOutput(0).getScriptPubKey();
	hashes = new ArrayList<byte[]>();
	List<ScriptChunk> chunks = outScript.getChunks();
	ListIterator<ScriptChunk> it = chunks.listIterator();
	while(it.hasNext()) {
		if (it.next().equalsOpCode(BitcoinLotterySettings.hashFunctionOpCode)) {
			hashes.add(it.next().data);
		}
	}
	Collections.reverse(hashes);
	if (hashes.size() != noPlayers) {
		throw new VerificationException("Wrong out script.");
	}
}
 
开发者ID:lukmaz,项目名称:BitcoinLottery,代码行数:16,代码来源:ComputeTx.java


示例15: computeMinLength

import com.google.bitcoin.core.VerificationException; //导入依赖的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.");
}
 
开发者ID:lukmaz,项目名称:BitcoinLottery,代码行数:13,代码来源:ComputeTx.java


示例16: CommitTx

import com.google.bitcoin.core.VerificationException; //导入依赖的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


示例17: validateIsCommit

import com.google.bitcoin.core.VerificationException; //导入依赖的package包/类
protected void validateIsCommit() throws VerificationException {
	noPlayers = tx.getOutputs().size();
	if (noPlayers < 2) {
		throw new VerificationException("Wrong number of outputs.");
	}
	addresses = new ArrayList<byte[]>();
	for (int k = 0; k < noPlayers; ++k) {
		if (tx.getOutput(k).getValue().equals(BigInteger.ZERO)) {
			position = k;
		}
		else {
			stake = tx.getOutput(k).getValue();
		}
		if (tx.getOutput(k).getScriptPubKey().getChunks().size() < 23) {
			throw new VerificationException("Wrong outputs.");
		}
		addresses.add(tx.getOutput(k).getScriptPubKey().getChunks().get(13).data);
	}
	minLength = Integer.valueOf(Utils.bytesToHexString(tx.getOutput(0).getScriptPubKey().getChunks().get(1).data), 16);
	hash = tx.getOutput(0).getScriptPubKey().getChunks().get(6).data;
	commiterAddress = tx.getOutput(0).getScriptPubKey().getChunks().get(20).data;
	
	for (int k = 0; k < noPlayers; ++k) {
		if (!Arrays.equals(tx.getOutput(k).getScriptPubKey().getProgram(), getCommitOutScript(addresses.get(k)).getProgram())) {
			throw new VerificationException("Wrong outputs.");
		}
		if (k == position && !tx.getOutput(k).getValue().equals(BigInteger.ZERO)) {
			throw new VerificationException("Wrong outputs.");
		}
		else if (k != position && !tx.getOutput(k).getValue().equals(stake)) {
			throw new VerificationException("Wrong outputs.");
		} 
	}
	
	tx.verify();
}
 
开发者ID:lukmaz,项目名称:BitcoinLottery,代码行数:37,代码来源:CommitTx.java


示例18: PayDepositTx

import com.google.bitcoin.core.VerificationException; //导入依赖的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


示例19: ClaimTx

import com.google.bitcoin.core.VerificationException; //导入依赖的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


示例20: completeInScript

import com.google.bitcoin.core.VerificationException; //导入依赖的package包/类
protected void completeInScript(ComputeTx computeTx, List<byte[]> secrets, 
									ECKey sk, Address address)  throws VerificationException {
	ScriptBuilder scriptBuilder = new ScriptBuilder();
	scriptBuilder.data(sign(0,sk).encodeToBitcoin())
			      	 .data(sk.getPubKey());
	for (byte[] secret : secrets) {
		scriptBuilder.data(secret);
	}
	tx.getInput(0).setScriptSig(scriptBuilder.build());
	tx.getInput(0).verify();
}
 
开发者ID:lukmaz,项目名称:BitcoinLottery,代码行数:12,代码来源:ClaimTx.java


示例21: decodeFromBitcoin

import com.google.bitcoin.core.VerificationException; //导入依赖的package包/类
/**
 * Returns a decoded signature.
 * @throws RuntimeException if the signature is invalid or unparseable in some way.
 */
public static TransactionSignature decodeFromBitcoin(byte[] bytes, boolean requireCanonical) throws VerificationException {
    // Bitcoin encoding is DER signature + sighash byte.
    if (requireCanonical && !isEncodingCanonical(bytes))
        throw new VerificationException("Signature encoding is not canonical.");
    ECKey.ECDSASignature sig;
    try {
        sig = ECKey.ECDSASignature.decodeFromDER(bytes);
    } catch (IllegalArgumentException e) {
        throw new VerificationException("Could not decode DER", e);
    }
    // In Bitcoin, any value of the final byte is valid, but not necessarily canonical. See javadocs for
    // isEncodingCanonical to learn more about this. So we must store the exact byte found.
    return new TransactionSignature(sig.r, sig.s, bytes[bytes.length - 1]);
}
 
开发者ID:HashEngineering,项目名称:quarkcoinj,代码行数:19,代码来源:TransactionSignature.java


示例22: onNewConnection

import com.google.bitcoin.core.VerificationException; //导入依赖的package包/类
@Override
public ServerConnectionEventHandler onNewConnection(final SocketAddress clientAddress) {
    // Each connection needs a handler which is informed when that payment channel gets adjusted. Here we just log
    // things. In a real app this object would be connected to some business logic.
    return new ServerConnectionEventHandler() {
        @Override
        public void channelOpen(Sha256Hash channelId) {
            log.info("Channel open for {}: {}.", clientAddress, channelId);

            // Try to get the state object from the stored state set in our wallet
            PaymentChannelServerState state = null;
            try {
                state = storedStates.getChannel(channelId).getOrCreateState(appKit.wallet(), appKit.peerGroup());
            } catch (VerificationException e) {
                // This indicates corrupted data, and since the channel was just opened, cannot happen
                throw new RuntimeException(e);
            }
            log.info("   with a maximum value of {}, expiring at UNIX timestamp {}.",
                    // The channel's maximum value is the value of the multisig contract which locks in some
                    // amount of money to the channel
                    state.getMultisigContract().getOutput(0).getValue(),
                    // The channel expires at some offset from when the client's refund transaction becomes
                    // spendable.
                    state.getRefundTransactionUnlockTime() + StoredPaymentChannelServerStates.CHANNEL_EXPIRE_OFFSET);
        }

        @Override
        public void paymentIncrease(BigInteger by, BigInteger to) {
            log.info("Client {} paid increased payment by {} for a total of " + to.toString(), clientAddress, by);
        }

        @Override
        public void channelClosed(PaymentChannelCloseException.CloseReason reason) {
            log.info("Client {} closed channel for reason {}", clientAddress, reason);
        }
    };
}
 
开发者ID:9cat,项目名称:templecoin-java,代码行数:38,代码来源:ExamplePaymentChannelServer.java


示例23: getCheckpointBeforeOrAtHeight

import com.google.bitcoin.core.VerificationException; //导入依赖的package包/类
/**
 * Returns a {@link StoredBlock} representing the last checkpoint before the given block height, for example, normally
 * you would want to know the checkpoint before the last block the wallet had seen.
 */
public StoredBlock getCheckpointBeforeOrAtHeight(int height) {
    Map.Entry<Long, StoredBlock> highestCheckpointBeforeHeight = null;
    
    for (Map.Entry<Long, StoredBlock> loop : checkpoints.entrySet()) {
        if (loop.getValue().getHeight() < height) {
            // This checkpoint is before the specified height.
            if (highestCheckpointBeforeHeight == null) {
                highestCheckpointBeforeHeight = loop;
            } else {
                if (highestCheckpointBeforeHeight.getValue().getHeight() < loop.getValue().getHeight()) {
                    // This entry is later.
                    highestCheckpointBeforeHeight = loop;
                }
            }
        }
    }
    
    if (highestCheckpointBeforeHeight == null) {
        try {
            return new StoredBlock(params.getGenesisBlock(), params.getGenesisBlock().getWork(), 0);
        } catch (VerificationException e) {
            e.printStackTrace();
        }
    }
    return highestCheckpointBeforeHeight.getValue();
}
 
开发者ID:coinspark,项目名称:sparkbit,代码行数:31,代码来源:MultiBitCheckpointManager.java


示例24: decodeFromBitcoin

import com.google.bitcoin.core.VerificationException; //导入依赖的package包/类
/**
 * Returns a decoded signature.
 * @throws RuntimeException if the signature is invalid or unparseable in some way.
 */
public static TransactionSignature decodeFromBitcoin(byte[] bytes, boolean requireCanonical) throws VerificationException {
    // Bitcoin encoding is DER signature + sighash byte.
    if (requireCanonical && !isEncodingCanonical(bytes))
        throw new VerificationException("Signature encoding is not canonical.");
    ECKey.ECDSASignature sig = ECKey.ECDSASignature.decodeFromDER(bytes);
    if (sig == null)
        throw new VerificationException("Could not decode DER component.");
    TransactionSignature tsig = new TransactionSignature(sig.r, sig.s);
    // In Bitcoin, any value of the final byte is valid, but not necessarily canonical. See javadocs for
    // isEncodingCanonical to learn more about this.
    tsig.sighashFlags = bytes[bytes.length - 1];
    return tsig;
}
 
开发者ID:sserrano44,项目名称:bitcoinj-watcher-service,代码行数:18,代码来源:TransactionSignature.java



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