• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java ScriptException类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: getWalletAddressOfReceived

import org.bitcoinj.core.ScriptException; //导入依赖的package包/类
@Nullable
public static Address getWalletAddressOfReceived(final Transaction tx, final Wallet wallet) {
    for (final TransactionOutput output : tx.getOutputs()) {
        try {
            if (output.isMine(wallet)) {
                final Script script = output.getScriptPubKey();
                return script.getToAddress(Constants.NETWORK_PARAMETERS, true);
            }
        } catch (final ScriptException x) {
            // swallow
        }
    }

    return null;
}
 
开发者ID:ehanoc,项目名称:xwallet,代码行数:16,代码来源:WalletUtils.java


示例2: markKeysAsUsed

import org.bitcoinj.core.ScriptException; //导入依赖的package包/类
/**
 * Marks all keys used in the transaction output as used in the wallet.
 * See {@link org.bitcoinj.wallet.DeterministicKeyChain#markKeyAsUsed(DeterministicKey)} for more info on this.
 */
private void markKeysAsUsed(Transaction tx) {
    keyChainGroupLock.lock();
    try {
        for (TransactionOutput o : tx.getOutputs()) {
            try {
                Script script = o.getScriptPubKey();
                if (script.isSentToRawPubKey()) {
                    byte[] pubkey = script.getPubKey();
                    keyChainGroup.markPubKeyAsUsed(pubkey);
                } else if (script.isSentToAddress()) {
                    byte[] pubkeyHash = script.getPubKeyHash();
                    keyChainGroup.markPubKeyHashAsUsed(pubkeyHash);
                } else if (script.isPayToScriptHash()) {
                    Address a = Address.fromP2SHScript(tx.getParams(), script);
                    keyChainGroup.markP2SHAddressAsUsed(a);
                }
            } catch (ScriptException e) {
                // Just means we didn't understand the output of this transaction: ignore it.
                log.warn("Could not parse tx output script: {}", e.toString());
            }
        }
    } finally {
        keyChainGroupLock.unlock();
    }
}
 
开发者ID:Grant-Redmond,项目名称:cryptwallet,代码行数:30,代码来源:Wallet.java


示例3: isPendingTransactionRelevant

import org.bitcoinj.core.ScriptException; //导入依赖的package包/类
/**
 * This method is used by a {@link Peer} to find out if a transaction that has been announced is interesting,
 * that is, whether we should bother downloading its dependencies and exploring the transaction to decide how
 * risky it is. If this method returns true then {@link Wallet#receivePending(Transaction, java.util.List)}
 * will soon be called with the transactions dependencies as well.
 */
public boolean isPendingTransactionRelevant(Transaction tx) throws ScriptException {
    lock.lock();
    try {
        // Ignore it if we already know about this transaction. Receiving a pending transaction never moves it
        // between pools.
        EnumSet<Pool> containingPools = getContainingPools(tx);
        if (!containingPools.equals(EnumSet.noneOf(Pool.class))) {
            log.debug("Received tx we already saw in a block or created ourselves: " + tx.getHashAsString());
            return false;
        }
        // We only care about transactions that:
        //   - Send us coins
        //   - Spend our coins
        //   - Double spend a tx in our wallet
        if (!isTransactionRelevant(tx)) {
            log.debug("Received tx that isn't relevant to this wallet, discarding.");
            return false;
        }
        return true;
    } finally {
        lock.unlock();
    }
}
 
开发者ID:Grant-Redmond,项目名称:cryptwallet,代码行数:30,代码来源:Wallet.java


示例4: getWatchedOutputs

import org.bitcoinj.core.ScriptException; //导入依赖的package包/类
/**
 * Returns all the outputs that match addresses or scripts added via {@link #addWatchedAddress(Address)} or
 * {@link #addWatchedScripts(java.util.List)}.
 * @param excludeImmatureCoinbases Whether to ignore outputs that are unspendable due to being immature.
 */
public List<TransactionOutput> getWatchedOutputs(boolean excludeImmatureCoinbases) {
    lock.lock();
    keyChainGroupLock.lock();
    try {
        LinkedList<TransactionOutput> candidates = Lists.newLinkedList();
        for (Transaction tx : Iterables.concat(unspent.values(), pending.values())) {
            if (excludeImmatureCoinbases && !tx.isMature()) continue;
            for (TransactionOutput output : tx.getOutputs()) {
                if (!output.isAvailableForSpending()) continue;
                try {
                    Script scriptPubKey = output.getScriptPubKey();
                    if (!watchedScripts.contains(scriptPubKey)) continue;
                    candidates.add(output);
                } catch (ScriptException e) {
                    // Ignore
                }
            }
        }
        return candidates;
    } finally {
        keyChainGroupLock.unlock();
        lock.unlock();
    }
}
 
开发者ID:Grant-Redmond,项目名称:cryptwallet,代码行数:30,代码来源:Wallet.java


示例5: calcBloomOutPointsLocked

import org.bitcoinj.core.ScriptException; //导入依赖的package包/类
private void calcBloomOutPointsLocked() {
    // TODO: This could be done once and then kept up to date.
    bloomOutPoints.clear();
    Set<Transaction> all = new HashSet<Transaction>();
    all.addAll(unspent.values());
    all.addAll(spent.values());
    all.addAll(pending.values());
    for (Transaction tx : all) {
        for (TransactionOutput out : tx.getOutputs()) {
            try {
                if (isTxOutputBloomFilterable(out))
                    bloomOutPoints.add(out.getOutPointFor());
            } catch (ScriptException e) {
                // If it is ours, we parsed the script correctly, so this shouldn't happen.
                throw new RuntimeException(e);
            }
        }
    }
}
 
开发者ID:Grant-Redmond,项目名称:cryptwallet,代码行数:20,代码来源:Wallet.java


示例6: estimateBytesForSigning

import org.bitcoinj.core.ScriptException; //导入依赖的package包/类
private int estimateBytesForSigning(CoinSelection selection) {
    int size = 0;
    for (TransactionOutput output : selection.gathered) {
        try {
            Script script = output.getScriptPubKey();
            ECKey key = null;
            Script redeemScript = null;
            if (script.isSentToAddress()) {
                key = findKeyFromPubHash(script.getPubKeyHash());
                checkNotNull(key, "Coin selection includes unspendable outputs");
            } else if (script.isPayToScriptHash()) {
                redeemScript = findRedeemDataFromScriptHash(script.getPubKeyHash()).redeemScript;
                checkNotNull(redeemScript, "Coin selection includes unspendable outputs");
            }
            size += script.getNumberOfBytesRequiredToSpend(key, redeemScript);
        } catch (ScriptException e) {
            // If this happens it means an output script in a wallet tx could not be understood. That should never
            // happen, if it does it means the wallet has got into an inconsistent state.
            throw new IllegalStateException(e);
        }
    }
    return size;
}
 
开发者ID:Grant-Redmond,项目名称:cryptwallet,代码行数:24,代码来源:Wallet.java


示例7: isInputMine

import org.bitcoinj.core.ScriptException; //导入依赖的package包/类
private boolean isInputMine(TransactionInput input) {
    lock.lock();
    try {
        try {
            Script script = input.getScriptSig();
            // TODO check multi sig scripts
            return isPubKeyMine(script.getPubKey());
        } catch (ScriptException e) {
            // We didn't understand this input ScriptSig: ignore it.
            log.debug("Could not parse tx input script: {}", e.toString());
            return false;
        }
    }
    finally {
        lock.unlock();
    }
}
 
开发者ID:filipnyquist,项目名称:lbry-android,代码行数:18,代码来源:TransactionWatcherWallet.java


示例8: getToAddressOfSent

import org.bitcoinj.core.ScriptException; //导入依赖的package包/类
@Nullable
public static Address getToAddressOfSent(final Transaction tx, final Wallet wallet)
{
    for (final TransactionOutput output : tx.getOutputs())
    {
        try
        {
            if (!output.isMine(wallet))
            {
                final Script script = output.getScriptPubKey();
                return script.getToAddress(Constants.NETWORK_PARAMETERS, true);
            }
        }
        catch (final ScriptException x)
        {
            // swallow
        }
    }

    return null;
}
 
开发者ID:soapboxsys,项目名称:ombuds-android,代码行数:22,代码来源:WalletUtils.java


示例9: getWalletAddressOfReceived

import org.bitcoinj.core.ScriptException; //导入依赖的package包/类
@Nullable
public static Address getWalletAddressOfReceived(final Transaction tx, final Wallet wallet)
{
    for (final TransactionOutput output : tx.getOutputs())
    {
        try
        {
            if (output.isMine(wallet))
            {
                final Script script = output.getScriptPubKey();
                return script.getToAddress(Constants.NETWORK_PARAMETERS, true);
            }
        }
        catch (final ScriptException x)
        {
            // swallow
        }
    }

    return null;
}
 
开发者ID:soapboxsys,项目名称:ombuds-android,代码行数:22,代码来源:WalletUtils.java


示例10: pshTx

import org.bitcoinj.core.ScriptException; //导入依赖的package包/类
@Test
public void pshTx() {

    final List<TransactionInput> inputs = tx1.getInputs();
    for (TransactionInput input : inputs) {
        try {
            Address current = input.getScriptSig().getFromAddress(MainNetParams.get());
            System.out.println(current.toString());
        } catch (ScriptException e) {
            System.out.println("exception");
        }

    }

}
 
开发者ID:RCasatta,项目名称:EternityWallAndroid,代码行数:16,代码来源:BitcoinTest.java


示例11: signStandardTx

import org.bitcoinj.core.ScriptException; //导入依赖的package包/类
private Transaction signStandardTx(Transaction tx, Map<String,ECKey> keys){
	// sign
	for(int index=0;index < tx.getInputs().size(); index++){
		TransactionInput in = tx.getInput(index);
		TransactionOutput connectedOutput = in.getConnectedOutput();
		String addFrom = connectedOutput.getScriptPubKey().getToAddress(getNetworkParams()).toString();
		TransactionSignature sig = tx.calculateSignature(index, keys.get(addFrom), 
				connectedOutput.getScriptPubKey(), 
				Transaction.SigHash.ALL, 
				false);
		Script inputScript = ScriptBuilder.createInputScript(sig, keys.get(addFrom));
		in.setScriptSig(inputScript);
		
		try {
			in.getScriptSig().correctlySpends(tx, (long)index, connectedOutput.getScriptPubKey());
		} catch (ScriptException e) {
            return null;
        }
	}
	
	return tx;
}
 
开发者ID:BitcoinAuthenticator,项目名称:Wallet,代码行数:23,代码来源:WalletOperation.java


示例12: getUnspentOutputsForAccount

import org.bitcoinj.core.ScriptException; //导入依赖的package包/类
public ArrayList<TransactionOutput> getUnspentOutputsForAccount(int accountIndex) throws ScriptException, CannotGetAddressException{
	ArrayList<TransactionOutput> ret = new ArrayList<TransactionOutput>();
	List<TransactionOutput> all = mWalletWrapper.getWatchedOutputs();
	for(TransactionOutput unspentOut:all){
		ATAddress add = findAddressInAccounts(unspentOut.getScriptPubKey().getToAddress(getNetworkParams()).toString());
		/*
		 * could happen if an unspent address belongs to a deleted account, it will not find it
		 */
		if(add == null)
			continue;
		
		if(add.getAccountIndex() == accountIndex)
			ret.add(unspentOut);
	}
	return ret;
}
 
开发者ID:BitcoinAuthenticator,项目名称:Wallet,代码行数:17,代码来源:WalletOperation.java


示例13: getToAddressOfSent

import org.bitcoinj.core.ScriptException; //导入依赖的package包/类
@Nullable
public static Address getToAddressOfSent(final Transaction tx, final Wallet wallet) {
    for (final TransactionOutput output : tx.getOutputs()) {
        try {
            if (!output.isMine(wallet)) {
                final Script script = output.getScriptPubKey();
                return script.getToAddress(Constants.NETWORK_PARAMETERS, true);
            }
        } catch (final ScriptException x) {
            // swallow
        }
    }

    return null;
}
 
开发者ID:ehanoc,项目名称:xwallet,代码行数:16,代码来源:WalletUtils.java


示例14: valueOf

import org.bitcoinj.core.ScriptException; //导入依赖的package包/类
public static Output valueOf(final PaymentProtocol.Output output)
        throws PaymentProtocolException.InvalidOutputs {
    try {
        final Script script = new Script(output.scriptData);
        return new PaymentIntent.Output(output.amount, script);
    } catch (final ScriptException x) {
        throw new PaymentProtocolException.InvalidOutputs(
                "unparseable script in output: " + Constants.HEX.encode(output.scriptData));
    }
}
 
开发者ID:guodroid,项目名称:okwallet,代码行数:11,代码来源:PaymentIntent.java


示例15: isTransactionRelevant

import org.bitcoinj.core.ScriptException; //导入依赖的package包/类
/**
 * <p>Returns true if the given transaction sends coins to any of our keys, or has inputs spending any of our outputs,
 * and also returns true if tx has inputs that are spending outputs which are
 * not ours but which are spent by pending transactions.</p>
 *
 * <p>Note that if the tx has inputs containing one of our keys, but the connected transaction is not in the wallet,
 * it will not be considered relevant.</p>
 */
public boolean isTransactionRelevant(Transaction tx) throws ScriptException {
    lock.lock();
    try {
        return tx.getValueSentFromMe(this).signum() > 0 ||
               tx.getValueSentToMe(this).signum() > 0 ||
               !findDoubleSpendsAgainst(tx, transactions).isEmpty();
    } finally {
        lock.unlock();
    }
}
 
开发者ID:Grant-Redmond,项目名称:cryptwallet,代码行数:19,代码来源:Wallet.java


示例16: toStringHelper

import org.bitcoinj.core.ScriptException; //导入依赖的package包/类
private void toStringHelper(StringBuilder builder, Map<Sha256Hash, Transaction> transactionMap,
                            @Nullable AbstractBlockChain chain, @Nullable Comparator<Transaction> sortOrder) {
    checkState(lock.isHeldByCurrentThread());

    final Collection<Transaction> txns;
    if (sortOrder != null) {
        txns = new TreeSet<Transaction>(sortOrder);
        txns.addAll(transactionMap.values());
    } else {
        txns = transactionMap.values();
    }

    for (Transaction tx : txns) {
        try {
            builder.append(tx.getValue(this).toFriendlyString());
            builder.append(" total value (sends ");
            builder.append(tx.getValueSentFromMe(this).toFriendlyString());
            builder.append(" and receives ");
            builder.append(tx.getValueSentToMe(this).toFriendlyString());
            builder.append(")\n");
        } catch (ScriptException e) {
            // Ignore and don't print this line.
        }
        if (tx.hasConfidence())
            builder.append("  confidence: ").append(tx.getConfidence()).append('\n');
        builder.append(tx.toString(chain));
    }
}
 
开发者ID:Grant-Redmond,项目名称:cryptwallet,代码行数:29,代码来源:Wallet.java


示例17: estimateBytesForSigning

import org.bitcoinj.core.ScriptException; //导入依赖的package包/类
private int estimateBytesForSigning(CoinSelection selection) {
        int size = 0;
        for (OutPointOutput utxo : selection.gathered) {
            try {
                TransactionOutput output = utxo.getOutput();
                Script script = output.getScriptPubKey();
                ECKey key = null;
                Script redeemScript = null;
                if (script.isSentToAddress()) {
                    key = account.findKeyFromPubHash(script.getPubKeyHash());
                    if (key == null) {
                        log.error("output.getIndex {}", output.getIndex());
                        log.error("output.getAddressFromP2SH {}", output.getAddressFromP2SH(coinType));
                        log.error("output.getAddressFromP2PKHScript {}", output.getAddressFromP2PKHScript(coinType));
                        log.error("output.getParentTransaction().getHash() {}", output.getParentTransaction().getHash());
                    }
                    Preconditions.checkNotNull(key, "Coin selection includes unspendable outputs");
                } else if (script.isPayToScriptHash()) {
                    throw new ScriptException("Wallet does not currently support PayToScriptHash");
//                    redeemScript = keychain.findRedeemScriptFromPubHash(script.getPubKeyHash());
//                    checkNotNull(redeemScript, "Coin selection includes unspendable outputs");
                }
                size += script.getNumberOfBytesRequiredToSpend(key, redeemScript);
            } catch (ScriptException e) {
                // If this happens it means an output script in a wallet tx could not be understood. That should never
                // happen, if it does it means the wallet has got into an inconsistent state.
                throw new IllegalStateException(e);
            }
        }
        return size;
    }
 
开发者ID:filipnyquist,项目名称:lbry-android,代码行数:32,代码来源:TransactionCreator.java


示例18: valueOf

import org.bitcoinj.core.ScriptException; //导入依赖的package包/类
public static Output valueOf(final PaymentProtocol.Output output) throws PaymentProtocolException.InvalidOutputs
{
    try
    {
        final Script script = new Script(output.scriptData);
        return new PaymentIntent.Output(output.amount, script);
    }
    catch (final ScriptException x)
    {
        throw new PaymentProtocolException.InvalidOutputs("unparseable script in output: " + Constants.HEX.encode(output.scriptData));
    }
}
 
开发者ID:soapboxsys,项目名称:ombuds-android,代码行数:13,代码来源:PaymentIntent.java


示例19: receiveFromBlock

import org.bitcoinj.core.ScriptException; //导入依赖的package包/类
@Override
public void receiveFromBlock(Transaction tx, StoredBlock block, AbstractBlockChain.NewBlockType blockType, int relativityOffset) throws VerificationException {
    // TODO: use BIP 113 timestamps
    if ( (new Date().getTime() / 1000 ) - block.getHeader().getTimeSeconds() > 366 * 24 * 60 * 60) {
        log.debug("NameDB skipping new transaction at height " + block.getHeight() + " due to timestamp " + block.getHeader().getTimeSeconds());
        return;
    }
    
    for (TransactionOutput output : tx.getOutputs()) {
        try {
            Script scriptPubKey = output.getScriptPubKey();
            NameScript ns = new NameScript(scriptPubKey);
            // Always save the coinbase, because it lets us identify that we've received the contents of the block, even if it has no name_anyupdate operations.
            // TODO: maybe save a null reference instead of the actual coinbase tx, since this would cut down on memory usage very slightly.
            if(tx.isCoinBase() || ( ns.isNameOp() && ns.isAnyUpdate() ) ) {
                log.debug("NameDB temporarily storing name transaction until it gets more confirmations.");
                pendingBlockTransactions.put(block.getHeader().getHash(), tx);
            }
        } catch (ScriptException e) {
            // Our threat model is lightweight SPV, which means we
            // don't attempt to reject a blockchain due to a single
            // invalid transaction.  As such, if we see a
            // ScriptException, we just discard the transaction
            // (and log a warning) rather than rejecting the block.
            log.warn("Error checking TransactionOutput for name_anyupdate script!", e);
            continue;
        }
    }
}
 
开发者ID:dogecoin,项目名称:libdohj,代码行数:30,代码来源:NameLookupLatestLevelDBTransactionCache.java


示例20: isNameOp

import org.bitcoinj.core.ScriptException; //导入依赖的package包/类
public boolean isNameOp() {
    switch(op) {
        case OP_NAME_NEW:
        case OP_NAME_FIRSTUPDATE:
        case OP_NAME_UPDATE:
            return true;
        
        case OP_NOP:
            return false;
        
        default:
            throw new ScriptException("Invalid name op");
    }
}
 
开发者ID:dogecoin,项目名称:libdohj,代码行数:15,代码来源:NameScript.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java GLFWMouseButtonCallback类代码示例发布时间:2022-05-21
下一篇:
Java NameEnvironmentAnswer类代码示例发布时间:2022-05-21
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap