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


Java TransactionInput类代码示例

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


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

示例1: isOutpointOneWeOffered

import com.google.bitcoin.core.TransactionInput; //导入依赖的package包/类
private boolean isOutpointOneWeOffered(TransactionInput input) {
	try {
		byte[] bytes = input.getOutpoint().getHash().getBytes();
		String hexHash = new String(Hex.encode(bytes));
						
		long inputIndex = input.getOutpoint().getIndex();

	    Log.d("SharedCoin", "SharedCoin isOutpointOneWeOffered hexHash: " + hexHash);
	    Log.d("SharedCoin", "SharedCoin isOutpointOneWeOffered inputIndex: " + inputIndex);

	    for (int i = 0; i < this.offered_outpoints.size(); i++) {
	    	JSONObject request_outpoint = (JSONObject) this.offered_outpoints.get(i);
	    	String hash = (String) request_outpoint.get("hash");
	    	long index =  SharedCoin.getLongFromLong(request_outpoint, "index");
	    	if (hash.equals(hexHash) && index == inputIndex) {
	    		return true;
	    	}
    	}
	    
	} catch (Exception e) {
		e.printStackTrace();
	}
    
          return false;
}
 
开发者ID:10xEngineer,项目名称:My-Wallet-Android,代码行数:26,代码来源:SharedCoin.java

示例2: CSBalanceTxTransfers

import com.google.bitcoin.core.TransactionInput; //导入依赖的package包/类
public CSBalanceTxTransfers(int AssetID,Transaction Tx)
{
    valid=true;
    inputs=new CSBalanceUpdate[Tx.getInputs().size()];
    int count=0;
    for(TransactionInput input : Tx.getInputs())
    {
        TransactionOutPoint outPoint=input.getOutpoint();
        if(outPoint != null)
        {
            CSBalanceEntry be=new CSBalanceEntry();
            inputs[count]=new CSBalanceUpdate(new CSTransactionOutput(outPoint.getHash(), (int)outPoint.getIndex()), AssetID, new CSBalanceEntry(), -1, null);
        }
        else
        {
            valid=false;
        }
        count++;
    }
            
    outputs=new CSBalanceUpdate[Tx.getOutputs().size()];
    for(int i=0;i<Tx.getOutputs().size();i++)
    {
        outputs[i]=null;
    }
}
 
开发者ID:coinspark,项目名称:sparkbit-bitcoinj,代码行数:27,代码来源:CSBalanceDatabase.java

示例3: computeSecret

import com.google.bitcoin.core.TransactionInput; //导入依赖的package包/类
protected void computeSecret() throws VerificationException {
	for (TransactionInput input : tx.getInputs()) {
		List<ScriptChunk> chunks = input.getScriptSig().getChunks();
		if (chunks.size() == 5) {
			byte[] data = chunks.get(SECRET_POSITION).data;
			if (hash != null) {
				if (Arrays.equals(hash, LotteryUtils.calcDoubleHash(data))) {
					possibleSecrets.add(data);
					return;
				}
			}
			else {
				possibleSecrets.add(data);
			}
		}
	}
	
	if (possibleSecrets.size() == 0) {
		throw new VerificationException("Not an Open transaction.");
	}
}
 
开发者ID:lukmaz,项目名称:BitcoinLottery,代码行数:22,代码来源:OpenTx.java

示例4: getFirstFromAddress

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

示例5: buildRawTx

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

示例6: buildRawTx

import com.google.bitcoin.core.TransactionInput; //导入依赖的package包/类
private static String buildRawTx() {
	ProtoBlue puf = ProtoBlue.newBuilder().setBkbcValue(200855)
			.setProtoType(Type.TEST).setExchangeType(ExType.BTC_TWD)
			.setVersion(VerType.TEST1).build();
	System.out.println(puf);

	ScriptBuilder builder = new ScriptBuilder();
	builder.op(OP_RETURN).data(puf.toByteArray());

	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(), key);
	tx2.addOutput(Bitcoins.toSatoshiEndBully(), outputScript);
	System.out.println(tx2);
	String rawTx = BaseEncoding.base16().encode(
			tx2.unsafeBitcoinSerialize());
	return rawTx;
}
 
开发者ID:y12studio,项目名称:bkbc-tools,代码行数:26,代码来源:ScriptOpReturnBuilder.java

示例7: onCoinsReceived

import com.google.bitcoin.core.TransactionInput; //导入依赖的package包/类
@Override
public void onCoinsReceived(final Transaction tx, final long result)
{
	try {
		System.out.println("onCoinsReceived()");

		if (tx.getInputs() == null || tx.getInputs().size() == 0) {
			notifyCoinbaseReceived(BigInteger.valueOf(result));
		} else {
			final TransactionInput input = tx.getInputs().get(0);

			final Address from = input.getFromAddress();

			handler.post(new Runnable()
			{
				public void run()
				{
					notifyCoinsReceived(from, BigInteger.valueOf(result));

					notifyWidgets();

				}
			});
		}
	} catch (Exception e) {
		e.printStackTrace();
	}
}
 
开发者ID:10xEngineer,项目名称:My-Wallet-Android,代码行数:29,代码来源:WebsocketService.java

示例8: addInputs

import com.google.bitcoin.core.TransactionInput; //导入依赖的package包/类
private static void addInputs(Transaction tx, List<TransactionOutPoint> unspents)
{
    for(TransactionOutPoint outpoint : unspents)
    {
        tx.addInput(new TransactionInput(Constants.NETWORK_PARAMETERS, tx, new byte[]{}, outpoint));
    }
}
 
开发者ID:alexkuck,项目名称:ahimsa-app,代码行数:8,代码来源:BulletinBuilder.java

示例9: onTransaction

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

示例10: newTxInput

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

示例11: chooseOutputs

import com.google.bitcoin.core.TransactionInput; //导入依赖的package包/类
private List<TransactionOutput> chooseOutputs(BigInteger value) {
	SendRequest tempRequest = SendRequest.to(getKey().toAddress(params),
			value);
	this.vWallet.completeTx(tempRequest);
	List<TransactionOutput> outputs = new ArrayList<TransactionOutput>();
	for (TransactionInput in : tempRequest.tx.getInputs()) {
		outputs.add(in.getConnectedOutput());
	}
	return outputs;
}
 
开发者ID:aakselrod,项目名称:libtxchain-java,代码行数:11,代码来源:Peer.java

示例12: signMyInputs

import com.google.bitcoin.core.TransactionInput; //导入依赖的package包/类
void signMyInputs(Transaction tx) {
	// This is to sign only MY OWN inputs in a transaction
	try {
		for (int i = 0; i < tx.getInputs().size(); i++) {
			TransactionInput in = tx.getInput(i);
			TransactionOutput cOut = in.getConnectedOutput();
			Script pubKey = cOut.getScriptPubKey();
			if (cOut.isMine(this.vWallet)) {
				TransactionSignature sig = tx.calculateSignature(i,
						getKey(), pubKey, SigHash.ALL, false);
				if (pubKey.isSentToAddress()
						&& (pubKey.getToAddress(params).equals(getKey()
								.toAddress(params)))) {
					in.setScriptSig(new ScriptBuilder()
							.data(sig.encodeToBitcoin())
							.data(getKey().getPubKey()).build());
				} else if (pubKey.isSentToRawPubKey()
						&& (pubKey.getPubKey().equals(getKey().getPubKey()))) {
					in.setScriptSig(new ScriptBuilder().data(
							sig.encodeToBitcoin()).build());
				}
			}
		}
	} catch (Exception e) {
		// No exception handling for this demo
		e.printStackTrace();
	}
}
 
开发者ID:aakselrod,项目名称:libtxchain-java,代码行数:29,代码来源:Peer.java

示例13: checkExpire

import com.google.bitcoin.core.TransactionInput; //导入依赖的package包/类
void checkExpire() {
	TransactionConfidence conf = getConfidence(this.refundTransaction);
	if ((conf == null) || (conf.getDepthInBlocks() == 0)) {  
		for (WalletTransaction wtx:getParentPeer().wallet().getWalletTransactions()) {
			if (wtx.getTransaction().getHash() == id()) {
				TransactionInput txin = wtx.getTransaction().getOutput(0).getSpentBy();
				if (txin != null) {
					this.refundTransaction = txin.getParentTransaction();
				}
				break;
			}
		}
	}
}
 
开发者ID:aakselrod,项目名称:libtxchain-java,代码行数:15,代码来源:PaymentChannel.java

示例14: getConnectedOutPoint

import com.google.bitcoin.core.TransactionInput; //导入依赖的package包/类
public static TransactionOutPoint getConnectedOutPoint(
        TransactionInput input, Wallet wallet) {
    Sha256Hash id = input.getOutpoint().getHash();
    Transaction t = wallet.getTransaction(id);
    if (t == null) {
        System.out.println("tx " + id + " not found in wallet");
        return null;
    }
    return new TransactionOutPoint(wallet.getNetworkParameters(),
            (int) input.getOutpoint().getIndex(), t);
}
 
开发者ID:dustyneuron,项目名称:bitprivacy,代码行数:12,代码来源:WalletUtils.java

示例15: sweepKey

import com.google.bitcoin.core.TransactionInput; //导入依赖的package包/类
public void sweepKey(ECKey key, long fee,
                     int accountId, JSONArray outputs) {
    mLogger.info("sweepKey starting");

    mLogger.info("key addr " + key.toAddress(mParams).toString());

    Transaction tx = new Transaction(mParams);

    long balance = 0;
    ArrayList<Script> scripts = new ArrayList<Script>();
    try {
        for (int ii = 0; ii < outputs.length(); ++ii) {
            JSONObject output;
output = outputs.getJSONObject(ii);

            String tx_hash = output.getString("tx_hash");
            int tx_output_n = output.getInt("tx_output_n");
            String script = output.getString("script");

            // Reverse byte order, create hash.
            Sha256Hash hash =
                new Sha256Hash(WalletUtil.msgHexToBytes(tx_hash));
        
            tx.addInput(new TransactionInput
                        (mParams, tx, new byte[]{},
                         new TransactionOutPoint(mParams,
                                                 tx_output_n, hash)));

            scripts.add(new Script(Hex.decode(script)));
                
            balance += output.getLong("value");
        }
    } catch (JSONException e) {
        e.printStackTrace();
        throw new RuntimeException("trouble parsing unspent outputs");
    }

    // Compute balance - fee.
    long amount = balance - fee;
    mLogger.info(String.format("sweeping %d", amount));

    // Figure out the destination address.
    Address to = mHDReceiver.nextReceiveAddress();
    mLogger.info("sweeping to " + to.toString());

    // Add output.
    tx.addOutput(BigInteger.valueOf(amount), to);

    WalletUtil.signTransactionInputs(tx, Transaction.SigHash.ALL,
                                     key, scripts);

    mLogger.info("tx bytes: " +
                 new String(Hex.encode(tx.bitcoinSerialize())));

    // mKit.peerGroup().broadcastTransaction(tx);
    broadcastTransaction(mKit.peerGroup(), tx);

    mLogger.info("sweepKey finished");
}
 
开发者ID:ksedgwic,项目名称:BTCReceive,代码行数:60,代码来源:WalletService.java


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