本文整理汇总了Java中org.bitcoinj.core.TransactionOutput.getScriptPubKey方法的典型用法代码示例。如果您正苦于以下问题:Java TransactionOutput.getScriptPubKey方法的具体用法?Java TransactionOutput.getScriptPubKey怎么用?Java TransactionOutput.getScriptPubKey使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.bitcoinj.core.TransactionOutput
的用法示例。
在下文中一共展示了TransactionOutput.getScriptPubKey方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getWalletAddressOfReceived
import org.bitcoinj.core.TransactionOutput; //导入方法依赖的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;
}
示例2: markKeysAsUsed
import org.bitcoinj.core.TransactionOutput; //导入方法依赖的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();
}
}
示例3: getWatchedOutputs
import org.bitcoinj.core.TransactionOutput; //导入方法依赖的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();
}
}
示例4: estimateBytesForSigning
import org.bitcoinj.core.TransactionOutput; //导入方法依赖的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;
}
示例5: getToAddressOfSent
import org.bitcoinj.core.TransactionOutput; //导入方法依赖的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;
}
示例6: getWalletAddressOfReceived
import org.bitcoinj.core.TransactionOutput; //导入方法依赖的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;
}
示例7: getNameNewNameScript
import org.bitcoinj.core.TransactionOutput; //导入方法依赖的package包/类
NameScript getNameNewNameScript() throws IOException {
byte[] payload;
final Transaction tx;
final TransactionOutput out;
final Script outScript;
final NameScript ns;
// https://namecoin.webbtc.com/tx/6047ce28a076118403aa960909c9c4d0056f97ee0da4d37d109515f8367e2ccb
payload = Util.getBytes(getClass().getResourceAsStream("namecoin_name_new_d_bitcoin.bin"));
tx = new Transaction(params, payload);
out = tx.getOutputs().get(1);
outScript = out.getScriptPubKey();
ns = new NameScript(outScript);
return ns;
}
示例8: getNameFirstUpdateNameScript
import org.bitcoinj.core.TransactionOutput; //导入方法依赖的package包/类
NameScript getNameFirstUpdateNameScript() throws IOException {
byte[] payload;
final Transaction tx;
final TransactionOutput out;
final Script outScript;
final NameScript ns;
// https://namecoin.webbtc.com/tx/ab1207bd605af57ed0b5325ac94d19578cff3bce668ebe8dda2f42a00b001f5d
payload = Util.getBytes(getClass().getResourceAsStream("namecoin_name_firstupdate_d_bitcoin.bin"));
tx = new Transaction(params, payload);
out = tx.getOutputs().get(1);
outScript = out.getScriptPubKey();
ns = new NameScript(outScript);
return ns;
}
示例9: getNameUpdateNameScript
import org.bitcoinj.core.TransactionOutput; //导入方法依赖的package包/类
NameScript getNameUpdateNameScript() throws IOException {
byte[] payload;
final Transaction tx;
final TransactionOutput out;
final Script outScript;
final NameScript ns;
// https://namecoin.webbtc.com/tx/3376c5e0e5b69d0a104863de8432d7c13f891065e7628a72487b770c6418d397
payload = Util.getBytes(getClass().getResourceAsStream("namecoin_name_update_d_bitcoin.bin"));
tx = new Transaction(params, payload);
out = tx.getOutputs().get(1);
outScript = out.getScriptPubKey();
ns = new NameScript(outScript);
return ns;
}
示例10: getCurrencyNameScript
import org.bitcoinj.core.TransactionOutput; //导入方法依赖的package包/类
NameScript getCurrencyNameScript() throws IOException {
byte[] payload;
final Transaction tx;
final TransactionOutput out;
final Script outScript;
final NameScript ns;
// https://namecoin.webbtc.com/tx/4ea5d679d63ef46449a44ca056584a986412676641bdaf13d44a7c7c2e32cca1
payload = Util.getBytes(getClass().getResourceAsStream("namecoin_p2pkh.bin"));
tx = new Transaction(params, payload);
out = tx.getOutputs().get(0);
outScript = out.getScriptPubKey();
ns = new NameScript(outScript);
return ns;
}
示例11: getReturnNameScript
import org.bitcoinj.core.TransactionOutput; //导入方法依赖的package包/类
NameScript getReturnNameScript() throws IOException {
byte[] payload;
final Transaction tx;
final TransactionOutput out;
final Script outScript;
final NameScript ns;
// https://namecoin.webbtc.com/tx/ab1207bd605af57ed0b5325ac94d19578cff3bce668ebe8dda2f42a00b001f5d
payload = Util.getBytes(getClass().getResourceAsStream("namecoin_name_firstupdate_d_bitcoin.bin"));
tx = new Transaction(params, payload);
out = tx.getOutputs().get(2);
outScript = out.getScriptPubKey();
ns = new NameScript(outScript);
return ns;
}
示例12: getToAddressOfSent
import org.bitcoinj.core.TransactionOutput; //导入方法依赖的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;
}
示例13: estimateBytesForSigning
import org.bitcoinj.core.TransactionOutput; //导入方法依赖的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;
}
示例14: receiveFromBlock
import org.bitcoinj.core.TransactionOutput; //导入方法依赖的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;
}
}
}
示例15: getNameAnyUpdateScript
import org.bitcoinj.core.TransactionOutput; //导入方法依赖的package包/类
public static NameScript getNameAnyUpdateScript(Transaction tx, String name) {
TransactionOutput output = getNameAnyUpdateOutput(tx, name);
if (output == null) {
return null;
}
Script scriptPubKey = output.getScriptPubKey();
return new NameScript(scriptPubKey);
}