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


Java Transaction类代码示例

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


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

示例1: analyzeIsStandard

import com.google.bitcoin.core.Transaction; //导入依赖的package包/类
private Result analyzeIsStandard() {
    if (!wallet.getNetworkParameters().getId().equals(NetworkParameters.ID_MAINNET))
        return Result.OK;

    nonStandard = isStandard(tx);
    if (nonStandard != null)
        return Result.NON_STANDARD;

    for (Transaction dep : dependencies) {
        nonStandard = isStandard(dep);
        if (nonStandard != null)
            return Result.NON_STANDARD;
    }

    return Result.OK;
}
 
开发者ID:coinspark,项目名称:sparkbit-bitcoinj,代码行数:17,代码来源:DefaultRiskAnalysis.java

示例2: OpenTx

import com.google.bitcoin.core.Transaction; //导入依赖的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();
}
 
开发者ID:lukmaz,项目名称:BitcoinLottery,代码行数:25,代码来源:OpenTx.java

示例3: buildRawTx

import com.google.bitcoin.core.Transaction; //导入依赖的package包/类
private static String buildRawTx() {
	ScriptBuilder builder = new ScriptBuilder();
	builder.op(OP_DEPTH).op(OP_1).op(OP_NUMEQUAL).op(OP_IF)
			.data("name of nakakamoto".getBytes()).op(OP_DROP)
			.op(OP_RIPEMD160).op(OP_RIPEMD160)
			.data(doublehash160("satoshi".getBytes())).op(OP_EQUAL)
			.op(OP_ELSE).op(OP_DUP).op(OP_HASH160)
			.data(doublehash160("Haha".getBytes())).op(OP_EQUALVERIFY)
			.op(OP_CHECKSIG).op(OP_ENDIF);

	Script outputScript = builder.build();
	Transaction tx1 = new Transaction(MainNetParams.get());
	tx1.addInput(new TransactionInput(MainNetParams.get(), tx1,
			new byte[] {}));
	ECKey key = new ECKey();
	tx1.addOutput(Bitcoins.toSatoshiEndBully(), key);
	Transaction tx2 = new Transaction(MainNetParams.get());

	tx2.addInput(tx1.getOutput(0));
	tx2.addOutput(Bitcoins.toSatoshiEndBully(), outputScript);
	tx2.addOutput(Bitcoins.toSatoshiEndBully(), key);
	System.out.println(tx2);
	String rawTx = BaseEncoding.base16().encode(
			tx2.unsafeBitcoinSerialize());
	return rawTx;
}
 
开发者ID:y12studio,项目名称:bkbc-tools,代码行数:27,代码来源:HintScriptBuilder.java

示例4: invokeOnCoinsSent

import com.google.bitcoin.core.Transaction; //导入依赖的package包/类
public static void invokeOnCoinsSent(final Transaction tx, final long result) {
	new Thread(new Runnable() {
		@Override
		public void run() {
			synchronized (listeners) {
				for (final ListenerWeakContainer listener : listeners) {
					if (listener.get() == null)
						return;

					handler.post(new Runnable() {
						@Override
						public void run() {
							EventListener _listener = listener.get();
							if (_listener != null) {
								_listener.onCoinsSent(tx, result);
							}
						}
					});
				}
			}	
		}
	}).start();
}
 
开发者ID:10xEngineer,项目名称:My-Wallet-Android,代码行数:24,代码来源:EventListeners.java

示例5: analyzeIsFinal

import com.google.bitcoin.core.Transaction; //导入依赖的package包/类
private Result analyzeIsFinal() {
    // Transactions we create ourselves are, by definition, not at risk of double spending against us.
    if (tx.getConfidence().getSource() == TransactionConfidence.Source.SELF)
        return Result.OK;

    final int height = wallet.getLastBlockSeenHeight();
    final long time = wallet.getLastBlockSeenTimeSecs();
    // If the transaction has a lock time specified in blocks, we consider that if the tx would become final in the
    // next block it is not risky (as it would confirm normally).
    final int adjustedHeight = height + 1;

    if (!tx.isFinal(adjustedHeight, time)) {
        nonFinal = tx;
        return Result.NON_FINAL;
    }
    for (Transaction dep : dependencies) {
        if (!dep.isFinal(adjustedHeight, time)) {
            nonFinal = dep;
            return Result.NON_FINAL;
        }
    }
    return Result.OK;
}
 
开发者ID:cannabiscoindev,项目名称:cannabiscoinj,代码行数:24,代码来源:DefaultRiskAnalysis.java

示例6: importBlock

import com.google.bitcoin.core.Transaction; //导入依赖的package包/类
public void importBlock(Block block, Integer blockHeight) {
	statusMessage = "Importing block "+blockHeight;
	logger.info(statusMessage);
	Database db = Database.getInstance();
	ResultSet rs = db.executeQuery("select * from blocks where block_hash='"+block.getHashAsString()+"';");
	try {
		if (!rs.next()) {
			db.executeUpdate("INSERT INTO blocks(block_index,block_hash,block_time,block_nonce) VALUES('"+blockHeight.toString()+"','"+block.getHashAsString()+"','"+block.getTimeSeconds()+"','"+block.getNonce()+"')");
		}
		Integer txSnInBlock=0;
		for (Transaction tx : block.getTransactions()) {
			importTransaction(tx,txSnInBlock, block, blockHeight);
			txSnInBlock++;
		}
		//Bet.resolve(blockHeight);  //pengding test
		//BetWorldCup.resolve(blockHeight,new Long(block.getTimeSeconds()).intValue());
		//Order.expire();
	} catch (SQLException e) {
	}
}
 
开发者ID:newbiecoin,项目名称:newbiecoinj,代码行数:21,代码来源:Blocks.java

示例7: getFirstToAddress

import com.google.bitcoin.core.Transaction; //导入依赖的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

示例8: PayDepositTx

import com.google.bitcoin.core.Transaction; //导入依赖的package包/类
public PayDepositTx(byte[] rawTx, TransactionOutput out, ECKey sk, boolean testnet) throws VerificationException {
	tx = new Transaction(getNetworkParameters(testnet), rawTx);
	validateIsIncopletePayDeposit(sk);
	tx.getInput(0).connect(out);
	computeInScript(sk);
	tx.verify();
	tx.getInput(0).verify();
}
 
开发者ID:lukmaz,项目名称:BitcoinLottery,代码行数:9,代码来源:PayDepositTx.java

示例9: isEncodingCanonical

import com.google.bitcoin.core.Transaction; //导入依赖的package包/类
/**
 * Returns true if the given signature is has canonical encoding, and will thus be accepted as standard by
 * the reference client. DER and the SIGHASH encoding allow for quite some flexibility in how the same structures
 * are encoded, and this can open up novel attacks in which a man in the middle takes a transaction and then
 * changes its signature such that the transaction hash is different but it's still valid. This can confuse wallets
 * and generally violates people's mental model of how Bitcoin should work, thus, non-canonical signatures are now
 * not relayed by default.
 */
public static boolean isEncodingCanonical(byte[] signature) {
    // See reference client's IsCanonicalSignature, https://bitcointalk.org/index.php?topic=8392.msg127623#msg127623
    // A canonical signature exists of: <30> <total len> <02> <len R> <R> <02> <len S> <S> <hashtype>
    // Where R and S are not negative (their first byte has its highest bit not set), and not
    // excessively padded (do not start with a 0 byte, unless an otherwise negative number follows,
    // in which case a single 0 byte is necessary and even required).
    if (signature.length < 9 || signature.length > 73)
        return false;

    int hashType = signature[signature.length-1] & ((int)(~Transaction.SIGHASH_ANYONECANPAY_VALUE));
    if (hashType < (Transaction.SigHash.ALL.ordinal() + 1) || hashType > (Transaction.SigHash.SINGLE.ordinal() + 1))
        return false;

    //                   "wrong type"                  "wrong length marker"
    if ((signature[0] & 0xff) != 0x30 || (signature[1] & 0xff) != signature.length-3)
        return false;

    int lenR = signature[3] & 0xff;
    if (5 + lenR >= signature.length || lenR == 0)
        return false;
    int lenS = signature[5+lenR] & 0xff;
    if (lenR + lenS + 7 != signature.length || lenS == 0)
        return false;

    //    R value type mismatch          R value negative
    if (signature[4-2] != 0x02 || (signature[4] & 0x80) == 0x80)
        return false;
    if (lenR > 1 && signature[4] == 0x00 && (signature[4+1] & 0x80) != 0x80)
        return false; // R value excessively padded

    //       S value type mismatch                    S value negative
    if (signature[6 + lenR - 2] != 0x02 || (signature[6 + lenR] & 0x80) == 0x80)
        return false;
    if (lenS > 1 && signature[6 + lenR] == 0x00 && (signature[6 + lenR + 1] & 0x80) != 0x80)
        return false; // S value excessively padded

    return true;
}
 
开发者ID:HashEngineering,项目名称:megacoinj,代码行数:47,代码来源:TransactionSignature.java

示例10: sigHashMode

import com.google.bitcoin.core.Transaction; //导入依赖的package包/类
public Transaction.SigHash sigHashMode() {
    final int mode = sighashFlags & 0x1f;
    if (mode == Transaction.SigHash.NONE.ordinal() + 1)
        return Transaction.SigHash.NONE;
    else if (mode == Transaction.SigHash.SINGLE.ordinal() + 1)
        return Transaction.SigHash.SINGLE;
    else
        return Transaction.SigHash.ALL;
}
 
开发者ID:testzcrypto,项目名称:animecoinj,代码行数:10,代码来源:TransactionSignature.java

示例11: handlePasteClipboard

import com.google.bitcoin.core.Transaction; //导入依赖的package包/类
private void handlePasteClipboard()
{
	if (clipboardManager.hasText())
	{
		final String input = clipboardManager.getText().toString().trim();

		new StringInputParser(input)
		{
			@Override
			protected void bitcoinRequest(final Address address, final String addressLabel, final BigInteger amount, final String bluetoothMac)
			{
				EditAddressBookEntryFragment.edit(getFragmentManager(), address.toString());
			}

			@Override
			protected void directTransaction(final Transaction transaction)
			{
				cannotClassify(input);
			}

			@Override
			protected void error(final int messageResId, final Object... messageArgs)
			{
				dialog(activity, null, R.string.address_book_options_paste_from_clipboard_title, messageResId, messageArgs);
			}
		}.parse();
	}
	else
	{
		activity.toast(R.string.address_book_options_copy_from_clipboard_msg_empty);
	}
}
 
开发者ID:9cat,项目名称:templecoin-android-wallet,代码行数:33,代码来源:SendingAddressesFragment.java

示例12: onCoinsSent

import com.google.bitcoin.core.Transaction; //导入依赖的package包/类
@Override
public void onCoinsSent(final Transaction tx, final long result) {
	btSend.setVisibility(View.GONE);
       summary3.setVisibility(View.VISIBLE);
       tvSentPrompt.setVisibility(View.VISIBLE);

       if(sendingProgressDialog != null) {
        sendingProgressDialog.dismiss();
       }

       clearSend();
}
 
开发者ID:10xEngineer,项目名称:My-Wallet-Android,代码行数:13,代码来源:SendFragment.java

示例13: onTransactionConfidenceChanged

import com.google.bitcoin.core.Transaction; //导入依赖的package包/类
@Override
public void onTransactionConfidenceChanged(Wallet wallet, Transaction transaction) {
    if (controller.getCurrentView() == View.TRANSACTIONS_VIEW) {
        ShowTransactionsPanel.updateTransactions(); 
    } else if (controller.getCurrentView() == View.SEND_BITCOIN_VIEW) {
        final int numberOfPeers = (transaction == null || transaction.getConfidence() == null) ? 0 : transaction.getConfidence().getBroadcastByCount();
        //log.debug("numberOfPeers = " + numberOfPeers);
        final Sha256Hash transactionHash = (transaction == null) ? null : transaction.getHash();
        //log.debug((transaction != null && transaction.getConfidence() != null) ? transaction.getConfidence().toString() : "No transaction confidence for tx");
        SendBitcoinConfirmPanel.updatePanelDueToTransactionConfidenceChange(transactionHash, numberOfPeers); 
    }
}
 
开发者ID:coinspark,项目名称:sparkbit,代码行数:13,代码来源:MultiBitFrame.java

示例14: isSelectable

import com.google.bitcoin.core.Transaction; //导入依赖的package包/类
public static boolean isSelectable(Transaction tx, int requiredNumBroadcastPeers) {
    // Only pick chain-included transactions, or transactions that are ours and pending.
    TransactionConfidence confidence = tx.getConfidence();
    TransactionConfidence.ConfidenceType type = confidence.getConfidenceType();
    return type.equals(TransactionConfidence.ConfidenceType.BUILDING) ||

           type.equals(TransactionConfidence.ConfidenceType.PENDING) &&
           confidence.getSource().equals(TransactionConfidence.Source.SELF) &&
           // In regtest mode we expect to have only one peer, so we won't see transactions propagate.
           // TODO: The value 1 below dates from a time when transactions we broadcast *to* were counted, set to 0
           (confidence.numBroadcastPeers() >= requiredNumBroadcastPeers || tx.getParams() == RegTestParams.get());
}
 
开发者ID:coinspark,项目名称:sparkbit-bitcoinj,代码行数:13,代码来源:DefaultCoinSelector.java

示例15: onLoadFinished

import com.google.bitcoin.core.Transaction; //导入依赖的package包/类
@Override
public void onLoadFinished(final Loader<List<StoredBlock>> loader, final List<StoredBlock> blocks)
{
	adapter.replace(blocks);

	final Loader<Set<Transaction>> transactionLoader = loaderManager.getLoader(ID_TRANSACTION_LOADER);
	if (transactionLoader != null && transactionLoader.isStarted())
		transactionLoader.forceLoad();
}
 
开发者ID:9cat,项目名称:templecoin-android-wallet,代码行数:10,代码来源:BlockListFragment.java


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