本文整理汇总了Java中com.google.bitcoin.core.TransactionOutPoint类的典型用法代码示例。如果您正苦于以下问题:Java TransactionOutPoint类的具体用法?Java TransactionOutPoint怎么用?Java TransactionOutPoint使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TransactionOutPoint类属于com.google.bitcoin.core包,在下文中一共展示了TransactionOutPoint类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: CSBalanceTxTransfers
import com.google.bitcoin.core.TransactionOutPoint; //导入依赖的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;
}
}
示例2: createTx
import com.google.bitcoin.core.TransactionOutPoint; //导入依赖的package包/类
public static Transaction createTx(ECKey key, List<TransactionOutPoint> unspents, String topic, String message) throws Exception
{
//create new transaction
Transaction bulletin = new Transaction(Constants.NETWORK_PARAMETERS);
//add inputs and message outputs
addInputs(bulletin, unspents);
addBulletinOutputs(bulletin, topic, message);
//add change output to transaction
addChangeOutput(key, bulletin, unspents);
//sign the inputs
BasicKeyChain keychain = new BasicKeyChain();
keychain.importKey(key);
bulletin.signInputs(SigHash.ALL, false, keychain);
return bulletin;
}
示例3: getUnspentOutPoints
import com.google.bitcoin.core.TransactionOutPoint; //导入依赖的package包/类
public List<TransactionOutPoint> getUnspentOutPoints(Long min_coin_necessary)
{
//get unspent transactions sorted in descending order
List<TransactionOutPoint> db_unspent = getAllUnspentOutPoints();
Coin min = Coin.valueOf( min_coin_necessary );
ArrayList<TransactionOutPoint> unspents = new ArrayList<TransactionOutPoint>();
Coin bal = Coin.ZERO;
for(TransactionOutPoint outpoint : db_unspent)
{
if(bal.compareTo(min) >= 0)
break;
unspents.add(outpoint);
bal = bal.add(outpoint.getConnectedOutput().getValue());
}
return unspents;
}
示例4: getAllUnspentOutPoints
import com.google.bitcoin.core.TransactionOutPoint; //导入依赖的package包/类
public List<TransactionOutPoint> getAllUnspentOutPoints()
{
//return all confirmed and unspent/pending transaction outputs in descending order by value
String sql = "SELECT txouts.vout, transactions.raw FROM txouts JOIN transactions ON transactions.txid == txouts.txid " +
"WHERE transactions.confirmed == 1 AND (txouts.status == 'unspent' OR txouts.status == 'pending') ORDER BY txouts.value DESC;";
Cursor cursor = db.rawQuery(sql, null);
ArrayList<TransactionOutPoint> result = new ArrayList<TransactionOutPoint>();
while(cursor.moveToNext())
{
int vout = cursor.getInt(0);
byte[] raw_tx = cursor.getBlob(1);
Transaction parent_tx = new Transaction(Constants.NETWORK_PARAMETERS, cursor.getBlob(1));
TransactionOutPoint outpoint = new TransactionOutPoint(Constants.NETWORK_PARAMETERS, vout, parent_tx);
result.add( outpoint );
}
return result;
}
示例5: addInputs
import com.google.bitcoin.core.TransactionOutPoint; //导入依赖的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));
}
}
示例6: addChangeOutput
import com.google.bitcoin.core.TransactionOutPoint; //导入依赖的package包/类
private static void addChangeOutput(ECKey key, Transaction tx, List<TransactionOutPoint> unspents) throws Exception
{
Coin fee = Coin.valueOf(Constants.MIN_FEE);
Coin in_coin = totalInCoin(unspents);
Coin out_coin = totalOutCoin(tx);
Coin total = Coin.ZERO.add(in_coin).subtract(out_coin).subtract(fee);
String TAG = "BulletinBuilder";
Log.d(TAG, "fee |" + fee.toString());
Log.d(TAG, "in_coin |" + in_coin.toString());
Log.d(TAG, "out_coin |" + out_coin.toString());
Log.d(TAG, "total |" + total.toString());
switch ( total.compareTo(Coin.ZERO) )
{
case 0:
case 1: break;
case -1: Log.d(TAG, Utils.bytesToHex(tx.bitcoinSerialize()) );
throw new Exception("out_coin + fee exceeds in_coin | " + total.toString());
}
Coin min = Coin.valueOf( Constants.getStandardCoin() );
Address default_addr = key.toAddress(Constants.NETWORK_PARAMETERS);
while(total.compareTo(Coin.ZERO) == 1)
{
if(total.subtract(min).compareTo(min) >= 0)
{
tx.addOutput( new TransactionOutput(Constants.NETWORK_PARAMETERS, tx, min, default_addr) );
total = total.subtract(min);
}
else
{
tx.addOutput( new TransactionOutput(Constants.NETWORK_PARAMETERS, tx, total, default_addr) );
total = total.subtract(total);
}
}
}
示例7: totalInCoin
import com.google.bitcoin.core.TransactionOutPoint; //导入依赖的package包/类
private static Coin totalInCoin(List<TransactionOutPoint> db_unspent)
{
Coin in_coin = Coin.ZERO;
for(TransactionOutPoint output : db_unspent)
{
in_coin = in_coin.add(output.getConnectedOutput().getValue());
}
return in_coin;
}
示例8: createAndAddBulletin
import com.google.bitcoin.core.TransactionOutPoint; //导入依赖的package包/类
public Transaction createAndAddBulletin(String topic, String message, Long fee) throws Exception
{
if(topic == null || topic.equals("") )
{
// Ensure topic and message content is proper
//todo remove this
topic = Constants.DEFAULT_TOPIC;
}
if(message == null)
{
message = "";
}
// Get the right amount of unspent transaction outputs to spend from
List<TransactionOutPoint> unspents = db.getUnspentOutPoints(Constants.getStandardCoin());
Log.d(TAG, "UNSPENT.TOSTRING() from CREATEANDADDBULLETIN()");
Log.d(TAG, unspents.toString());
// Create a bulletin using system's configuration file, a bitcoinj wallet, the unspent
// txouts gathered, and the topic and message.
Transaction bulletin = BulletinBuilder.createTx(key, unspents, topic, message);
// Add this bulletin to the bulletin table
// todo | atomicity (include with commit of transaction)
db.addBulletin(bulletin.getHashAsString(), topic, message, fee);
return bulletin;
}
示例9: getConnectedOutPoint
import com.google.bitcoin.core.TransactionOutPoint; //导入依赖的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);
}
示例10: MyTransactionInput
import com.google.bitcoin.core.TransactionOutPoint; //导入依赖的package包/类
public MyTransactionInput(NetworkParameters params, Transaction parentTransaction, byte[] scriptBytes, TransactionOutPoint outpoint) {
super(params, parentTransaction, scriptBytes, outpoint);
this.params = params;
}
示例11: sweepKey
import com.google.bitcoin.core.TransactionOutPoint; //导入依赖的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");
}