本文整理汇总了Java中com.google.bitcoin.core.ScriptException类的典型用法代码示例。如果您正苦于以下问题:Java ScriptException类的具体用法?Java ScriptException怎么用?Java ScriptException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ScriptException类属于com.google.bitcoin.core包,在下文中一共展示了ScriptException类的16个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: isRelevant
import com.google.bitcoin.core.ScriptException; //导入依赖的package包/类
public boolean isRelevant(TransactionOutput out)
{
try {
Script script = out.getScriptPubKey();
if (script.isSentToRawPubKey())
{
return Arrays.equals(key.getPubKey(), script.getPubKey());
}
if (script.isPayToScriptHash())
{
// return wallet.isPayToScriptHashMine(script.getPubKeyHash());
return false; // unsupported. todo: support
}
else
{
return Arrays.equals(key.getPubKeyHash(), script.getPubKeyHash());
}
}
catch (ScriptException e)
{
// Just means we didn't understand the output of this transaction: ignore it.
Log.e(TAG, "Could not parse tx output script: {}", e);
return false;
}
}
开发者ID:alexkuck,项目名称:ahimsa-app,代码行数:26,代码来源:AhimsaWallet.java
示例2: loadInBackground
import com.google.bitcoin.core.ScriptException; //导入依赖的package包/类
@Override
public List<Transaction> loadInBackground()
{
final Set<Transaction> transactions = wallet.getTransactions(true);
final List<Transaction> filteredTransactions = new ArrayList<Transaction>(transactions.size());
try
{
for (final Transaction tx : transactions)
{
final boolean sent = tx.getValue(wallet).signum() < 0;
if ((direction == Direction.RECEIVED && !sent) || direction == null || (direction == Direction.SENT && sent))
filteredTransactions.add(tx);
}
}
catch (final ScriptException x)
{
throw new RuntimeException(x);
}
Collections.sort(filteredTransactions, TRANSACTION_COMPARATOR);
return filteredTransactions;
}
开发者ID:9cat,项目名称:templecoin-android-wallet,代码行数:25,代码来源:TransactionsListFragment.java
示例3: getFirstFromAddress
import com.google.bitcoin.core.ScriptException; //导入依赖的package包/类
@CheckForNull
public static Address getFirstFromAddress(@Nonnull final Transaction tx)
{
if (tx.isCoinBase())
return null;
try
{
for (final TransactionInput input : tx.getInputs())
{
return input.getFromAddress();
}
throw new IllegalStateException();
}
catch (final ScriptException x)
{
// this will happen on inputs connected to coinbase transactions
return null;
}
}
开发者ID:9cat,项目名称:templecoin-android-wallet,代码行数:22,代码来源:WalletUtils.java
示例4: getFirstToAddress
import com.google.bitcoin.core.ScriptException; //导入依赖的package包/类
@CheckForNull
public static Address getFirstToAddress(@Nonnull final Transaction tx)
{
try
{
for (final TransactionOutput output : tx.getOutputs())
{
return output.getScriptPubKey().getToAddress(Constants.NETWORK_PARAMETERS);
}
throw new IllegalStateException();
}
catch (final ScriptException x)
{
return null;
}
}
开发者ID:9cat,项目名称:templecoin-android-wallet,代码行数:18,代码来源:WalletUtils.java
示例5: isInternal
import com.google.bitcoin.core.ScriptException; //导入依赖的package包/类
public static boolean isInternal(@Nonnull final Transaction tx)
{
if (tx.isCoinBase())
return false;
final List<TransactionOutput> outputs = tx.getOutputs();
if (outputs.size() != 1)
return false;
try
{
final TransactionOutput output = outputs.get(0);
final Script scriptPubKey = output.getScriptPubKey();
if (!scriptPubKey.isSentToRawPubKey())
return false;
return true;
}
catch (final ScriptException x)
{
return false;
}
}
开发者ID:9cat,项目名称:templecoin-android-wallet,代码行数:24,代码来源:WalletUtils.java
示例6: select
import com.google.bitcoin.core.ScriptException; //导入依赖的package包/类
public CoinSelection select(BigInteger biTarget,
LinkedList<TransactionOutput> candidates) {
// Filter the candidates so only coins from this account
// are considered. Let the Wallet.DefaultCoinSelector do
// all the remaining work.
LinkedList<TransactionOutput> filtered =
new LinkedList<TransactionOutput>();
for (TransactionOutput to : candidates) {
try {
byte[] pubkey = null;
byte[] pubkeyhash = null;
Script script = to.getScriptPubKey();
if (script.isSentToRawPubKey())
pubkey = script.getPubKey();
else
pubkeyhash = script.getPubKeyHash();
if (mReceiveChain.hasPubKey(pubkey, pubkeyhash))
filtered.add(to);
else if (mChangeChain.hasPubKey(pubkey, pubkeyhash))
filtered.add(to);
else
// Not in this account ...
continue;
} catch (ScriptException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
// Does all the real work ...
return mDefaultCoinSelector.select(biTarget, filtered);
}
开发者ID:ksedgwic,项目名称:BTCReceive,代码行数:35,代码来源:HDAccount.java
示例7: getPkHash
import com.google.bitcoin.core.ScriptException; //导入依赖的package包/类
public byte[] getPkHash() {
try {
return tx.getOutput(outNr).getScriptPubKey().getPubKeyHash();
} catch (ScriptException e) {
return null; //do nothing - can not happen
}
}
开发者ID:lukmaz,项目名称:BitcoinLottery,代码行数:8,代码来源:PutMoneyTx.java
示例8: computeInScript
import com.google.bitcoin.core.ScriptException; //导入依赖的package包/类
protected void computeInScript(ECKey sk) throws ScriptException {
List<ScriptChunk> chunks = tx.getInput(0).getScriptSig().getChunks();
byte[] sig = sign(0, sk).encodeToBitcoin();
ScriptBuilder sb = new ScriptBuilder()
.data(chunks.get(0).data)
.data(chunks.get(1).data)
.data(sig)
.data(sk.getPubKey())
.data(sig); // dummy secret
tx.getInput(0).setScriptSig(sb.build());
}
开发者ID:lukmaz,项目名称:BitcoinLottery,代码行数:12,代码来源:PayDepositTx.java
示例9: onCoinsReceived
import com.google.bitcoin.core.ScriptException; //导入依赖的package包/类
@Override
public void onCoinsReceived(final Wallet wallet, final Transaction tx, final BigInteger prevBalance, final BigInteger newBalance)
{
transactionsReceived.incrementAndGet();
final int bestChainHeight = blockChain.getBestChainHeight();
try
{
final Address from = WalletUtils.getFirstFromAddress(tx);
final BigInteger amount = tx.getValue(wallet);
final ConfidenceType confidenceType = tx.getConfidence().getConfidenceType();
handler.post(new Runnable()
{
@Override
public void run()
{
final boolean isReceived = amount.signum() > 0;
final boolean replaying = bestChainHeight < bestChainHeightEver;
final boolean isReplayedTx = confidenceType == ConfidenceType.BUILDING && replaying;
if (isReceived && !isReplayedTx)
notifyCoinsReceived(from, amount);
}
});
}
catch (final ScriptException x)
{
throw new RuntimeException(x);
}
}
开发者ID:9cat,项目名称:templecoin-android-wallet,代码行数:33,代码来源:BlockchainServiceImpl.java
示例10: onTransaction
import com.google.bitcoin.core.ScriptException; //导入依赖的package包/类
@Override
public void onTransaction(Peer peer, Transaction tx) {
try {
log.info("TxLockTime {}", tx.getLockTime());
log.info("TxIn{}/Out{}", tx.getInputs().size(), tx
.getOutputs().size());
log.info("Saw Tx {}", tx);
if (_debug) {
for (TransactionInput tin : tx.getInputs()) {
log.info("InputSequenceNumber {}",
tin.getSequenceNumber());
if (tin.getSequenceNumber() == TransactionInput.NO_SEQUENCE) {
log.info("InputSequenceNumber==UINT_MAX lock time ignored");
}
log.info("InputScriptSig {}", tin.getScriptSig()
.toString());
log.info("InputOutpoint previous output hash {}",
tin.getOutpoint().getHash());
log.info("InputOutpoint previous output index {}",
tin.getOutpoint().getIndex());
TransactionOutput tout = tin.getOutpoint()
.getConnectedOutput();
// Map<Sha256Hash, Integer> appearInHashes =
// preTx.getAppearsInHashes();
log.info("OutpointTx output", tout);
}
}
} catch (ScriptException e) {
e.printStackTrace();
}
}
开发者ID:y12studio,项目名称:bkbc-tools,代码行数:34,代码来源:DebugPeerEventListener.java
示例11: newTxInput
import com.google.bitcoin.core.ScriptException; //导入依赖的package包/类
/**
* <p>Construct a TxInput message based on the given transaction </p>
*
* @param tx The Bitcoinj transaction
* @param index The index of the input transaction to work with
*
* @return A TxInput message representing the transaction input
*/
public static TrezorMessage.TxInput newTxInput(Transaction tx, int index) {
Preconditions.checkNotNull(tx, "Transaction must be present");
Preconditions.checkElementIndex(index, tx.getInputs().size(), "TransactionInput not present at index " + index);
// Input index is valid
TransactionInput txInput = tx.getInput(index);
TrezorMessage.TxInput.Builder builder = TrezorMessage.TxInput.newBuilder();
builder.setIndex(index);
// Fill in the input addresses
long prevIndex = txInput.getOutpoint().getIndex();
byte[] prevHash = txInput.getOutpoint().getHash().getBytes();
// In Bitcoinj "nanocoins" are Satoshis
long satoshiAmount = txInput.getConnectedOutput().getValue().longValue();
builder.setAmount(satoshiAmount);
try {
byte[] scriptSig = txInput.getScriptSig().toString().getBytes();
builder.setScriptSig(ByteString.copyFrom(scriptSig));
builder.setPrevIndex((int) prevIndex);
builder.setPrevHash(ByteString.copyFrom(prevHash));
builder.addAddressN(0);
builder.addAddressN(index);
return builder.build();
} catch (ScriptException e) {
throw new IllegalStateException(e);
}
}
开发者ID:Multibit-Legacy,项目名称:trezorj,代码行数:44,代码来源:TrezorMessageUtils.java
示例12: newTxOutput
import com.google.bitcoin.core.ScriptException; //导入依赖的package包/类
/**
* <p>Construct a TxOutput message based on the given transaction</p>
*
* @param tx The Bitcoinj transaction
* @param index The index of the output transaction to work with
*
* @return A TxOutput message representing the transaction output
*/
public static TrezorMessage.TxOutput newTxOutput(Transaction tx, int index) {
Preconditions.checkNotNull(tx, "Transaction must be present");
Preconditions.checkElementIndex(index, tx.getOutputs().size(), "TransactionOutput not present at index " + index);
// Output index is valid
TransactionOutput txOutput = tx.getOutput(index);
TrezorMessage.TxOutput.Builder builder = TrezorMessage.TxOutput.newBuilder();
builder.setIndex(index);
// In Bitcoinj "nanocoins" are Satoshis
long satoshiAmount = txOutput.getValue().longValue();
builder.setAmount(satoshiAmount);
// Extract the receiving address from the output
try {
builder.setAddress(txOutput.getScriptPubKey().getToAddress(MainNetParams.get()).toString());
} catch (ScriptException e) {
throw new IllegalArgumentException("Transaction script pub key invalid", e);
}
//builder.setAddressBytes(ByteString.copyFrom("".getBytes()));
// Bitcoinj only support Pay to Address
builder.setScriptType(TrezorMessage.ScriptType.PAYTOADDRESS);
// TODO (GR) Verify what ScriptArgs is doing (array of script arguments?)
//builder.setScriptArgs(0,0);
// AddressN encodes the branch co-ordinates of the receiving/change public keys
// Leave it unset if the Trezor does not control the output address
if (index == 1) {
builder.addAddressN(0); // Depth of receiving address was
builder.addAddressN(1); // 0 is recipient address, 1 is change address
}
return builder.build();
}
开发者ID:Multibit-Legacy,项目名称:trezorj,代码行数:47,代码来源:TrezorMessageUtils.java
示例13: computePks
import com.google.bitcoin.core.ScriptException; //导入依赖的package包/类
protected void computePks() throws ScriptException {
pks = new ArrayList<byte[]>();
for (int k = 0; k < noPlayers; ++k) {
pks.add(tx.getInput(k).getScriptSig().getChunks().get(1).data);
}
}
开发者ID:lukmaz,项目名称:BitcoinLottery,代码行数:7,代码来源:ComputeTx.java
示例14: computeSignatures
import com.google.bitcoin.core.ScriptException; //导入依赖的package包/类
protected void computeSignatures() throws ScriptException {
signatures = new ArrayList<byte[]>();
for (int k = 0; k < noPlayers; ++k) {
signatures.add(tx.getInput(k).getScriptSig().getChunks().get(0).data);
}
}
开发者ID:lukmaz,项目名称:BitcoinLottery,代码行数:7,代码来源:ComputeTx.java
示例15: generate
import com.google.bitcoin.core.ScriptException; //导入依赖的package包/类
@Command
public synchronized void generate() throws IOException, ScriptException {
wallet.addKey(new ECKey());
addresses();
}
开发者ID:dustyneuron,项目名称:bitprivacy,代码行数:7,代码来源:WalletMgr.java
示例16: addresses
import com.google.bitcoin.core.ScriptException; //导入依赖的package包/类
@Command
public void addresses() throws ScriptException {
BigInteger estimateTotalBalance = new BigInteger("0");
Iterator<ECKey> it = wallet.getKeys().iterator();
while (it.hasNext()) {
ECKey key = it.next();
byte[] pubKeyHash = key.getPubKeyHash();
Address address = new Address(params, pubKeyHash);
String output = "address: " + address.toString() + "\n";
List<Transaction> transactions = wallet.getTransactionsByTime();
BigInteger estimateAddressBalance = new BigInteger("0");
BigInteger confirmedAddressBalance = new BigInteger("0");
int worstDepth = Integer.MAX_VALUE;
for (Transaction t : transactions) {
for (TransactionOutput o : t.getOutputs()) {
if (o.isAvailableForSpending()) {
if (Arrays.equals(o.getScriptPubKey().getPubKeyHash(), address.getHash160())) {
estimateAddressBalance = estimateAddressBalance
.add(o.getValue());
if (t.getConfidence().getConfidenceType() == ConfidenceType.BUILDING) {
int depth = t.getConfidence()
.getDepthInBlocks();
worstDepth = (depth < worstDepth ? depth
: worstDepth);
confirmedAddressBalance = confirmedAddressBalance
.add(o.getValue());
}
}
}
}
}
estimateTotalBalance = estimateTotalBalance
.add(estimateAddressBalance);
output += " balance estimate: "
+ Utils.bitcoinValueToFriendlyString(estimateAddressBalance)
+ " confirmed: "
+ Utils.bitcoinValueToFriendlyString(confirmedAddressBalance);
if (worstDepth != Integer.MAX_VALUE) {
output += " (worst depth " + worstDepth + ")";
}
System.out.println(output);
}
System.out.println("Total balance estimate: "
+ Utils.bitcoinValueToFriendlyString(estimateTotalBalance)
+ ", Total available: "
+ Utils.bitcoinValueToFriendlyString(wallet.getBalance()));
}
开发者ID:dustyneuron,项目名称:bitprivacy,代码行数:51,代码来源:WalletMgr.java
注:本文中的com.google.bitcoin.core.ScriptException类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论