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


Java ScriptException类代码示例

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


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


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