本文整理汇总了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;
}
示例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;
}
}
示例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.");
}
}
示例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;
}
}
示例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;
}
示例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;
}
示例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();
}
}
示例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));
}
}
示例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();
}
}
示例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);
}
}
示例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;
}
示例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();
}
}
示例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;
}
}
}
}
示例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);
}
示例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");
}