本文整理汇总了Java中com.google.bitcoin.core.VerificationException类的典型用法代码示例。如果您正苦于以下问题:Java VerificationException类的具体用法?Java VerificationException怎么用?Java VerificationException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
VerificationException类属于com.google.bitcoin.core包,在下文中一共展示了VerificationException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
示例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();
}
示例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.");
}
}
示例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();
}
示例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.");
}
}
示例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.");
}
}
示例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());
}
}
示例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());
}
示例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);
}
示例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));
}
}
示例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.");
}
示例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;
}
示例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;
}
示例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.");
}
}
示例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.");
}