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


Java Transaction.addOutput方法代码示例

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


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

示例1: 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

示例2: ComputeTx

import com.google.bitcoin.core.Transaction; //导入方法依赖的package包/类
public ComputeTx(List<PutMoneyTx> inputs, List<byte[]> pks, List<byte[]> hashes, 
									int minLength, BigInteger fee, boolean testnet) throws VerificationException {
	this.pks = pks;
	this.hashes = hashes;
	this.testnet = testnet;
	this.minLength = minLength;
	this.noPlayers = inputs.size();
	tx = new Transaction(getNetworkParameters(testnet));
	BigInteger stake = BigInteger.ZERO;
	for (int k = 0; k < noPlayers; ++k) {
		TransactionOutput in = inputs.get(k).getOut();
		tx.addInput(in);
		stake = stake.add(in.getValue());
	}
	
	tx.addOutput(stake.subtract(fee), calculateOutScript());
	signatures = new ArrayList<byte[]>();
	for (int k = 0; k < noPlayers; ++k) {
		signatures.add(null);
	}
	tx.verify();
}
 
开发者ID:lukmaz,项目名称:BitcoinLottery,代码行数:23,代码来源:ComputeTx.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: buildRawTx

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

示例5: CommitTx

import com.google.bitcoin.core.Transaction; //导入方法依赖的package包/类
public CommitTx(TransactionOutput out, ECKey sk, List<byte[]> pks, int position,
		byte[] hash, int minLength, BigInteger fee, boolean testnet) throws VerificationException {
	this.hash = hash;
	this.commiterAddress = sk.getPubKeyHash();
	this.minLength = minLength;
	this.noPlayers = pks.size();
	this.position = position;
	this.stake = out.getValue().subtract(fee).divide(BigInteger.valueOf(noPlayers-1));
	NetworkParameters params = getNetworkParameters(testnet);
	
	tx = new Transaction(params);
	for (int k = 0; k < noPlayers; ++k) {
		BigInteger currentStake = stake;
		if (k == position) { //TODO: simplier script?
			currentStake = BigInteger.ZERO;
		}
		tx.addOutput(currentStake, getCommitOutScript(Utils.sha256hash160(pks.get(k))));
	}
	tx.addInput(out);
	if (out.getScriptPubKey().isSentToAddress()) {
		tx.getInput(0).setScriptSig(ScriptBuilder.createInputScript(sign(0, sk), sk));
	}
	else if (out.getScriptPubKey().isSentToRawPubKey()) {
		tx.getInput(0).setScriptSig(ScriptBuilder.createInputScript(sign(0, sk)));
	} 
	else {
		throw new VerificationException("Bad transaction output.");
	}
	this.addresses = new ArrayList<byte[]>();
	for (byte[] pk : pks) {
		this.addresses.add(Utils.sha256hash160(pk));
	}
	tx.verify();
	tx.getInput(0).verify();
}
 
开发者ID:lukmaz,项目名称:BitcoinLottery,代码行数:36,代码来源:CommitTx.java

示例6: PayDepositTx

import com.google.bitcoin.core.Transaction; //导入方法依赖的package包/类
public PayDepositTx(CommitTx commitTx, int outNr, ECKey sk, byte[] pk, BigInteger fee,
		long timestamp, boolean testnet) throws VerificationException {
	TransactionOutput out = commitTx.getOutput(outNr);
	NetworkParameters params = getNetworkParameters(testnet);
	tx = new Transaction(params);
	tx.setLockTime(timestamp);
	tx.addOutput(out.getValue().subtract(fee), new Address(params, Utils.sha256hash160(pk)));
	tx.addInput(out);
	tx.getInput(0).setSequenceNumber(0);
	tx.getInput(0).setScriptSig(new ScriptBuilder()
										.data(sign(0, sk).encodeToBitcoin())
										.data(sk.getPubKey())
										.build());
	tx.verify();
}
 
开发者ID:lukmaz,项目名称:BitcoinLottery,代码行数:16,代码来源:PayDepositTx.java

示例7: ClaimTx

import com.google.bitcoin.core.Transaction; //导入方法依赖的package包/类
public ClaimTx(ComputeTx computeTx, List<byte[]> secrets, ECKey sk, 
					Address address, BigInteger fee, boolean testnet) throws VerificationException {
	tx = new Transaction(getNetworkParameters(testnet));
	tx.addInput(computeTx.getOutput(0));
	tx.addOutput(computeTx.getValue(0).subtract(fee), address);
	completeInScript(computeTx, secrets, sk, address);
	tx.verify();
}
 
开发者ID:lukmaz,项目名称:BitcoinLottery,代码行数:9,代码来源:ClaimTx.java

示例8: addChangeOutput

import com.google.bitcoin.core.Transaction; //导入方法依赖的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);
        }
    }
}
 
开发者ID:alexkuck,项目名称:ahimsa-app,代码行数:41,代码来源:BulletinBuilder.java

示例9: sweepKey

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

示例10: addBulletinOutputs

import com.google.bitcoin.core.Transaction; //导入方法依赖的package包/类
private static void addBulletinOutputs(Transaction tx, String topic, String message)
{
    // Create protocol buffer builder and set values
    WireBulletin.Builder protobuilder = WireBulletin.newBuilder();
    protobuilder.setBoard(topic);
    protobuilder.setMessage(message);
    protobuilder.setTimestamp(System.currentTimeMillis() / 1000); //seconds since epoch

    // Create a byte array using the builder
    byte[] buffer_bytes = protobuilder.build().toByteArray();

    // Calculate new length of byte array (round up to next factor of char_per_out)
    int msg_len = Constants.AHIMSA_BULLETIN_PREFIX.length + buffer_bytes.length;
    int new_len = msg_len + Constants.CHAR_PER_OUT - (msg_len % Constants.CHAR_PER_OUT);

    Log.d("BB", "msg_len " + msg_len);
    Log.d("BB", "new_len " + new_len);

    // Create array with zeros of length new_len
    byte[] complete_bytes = new byte[new_len];
    Log.d("BB", Arrays.toString( complete_bytes ));

    // Copy ahimsa_bulletin_prefix into first eight bytes
    for(int i = 0; i < Constants.AHIMSA_BULLETIN_PREFIX.length; i++)
    {
        complete_bytes[i] = Constants.AHIMSA_BULLETIN_PREFIX[i];
    }
    Log.d("BB", Arrays.toString( complete_bytes ));

    // Copy buffer_bytes into array
    for(int i = 0; i < buffer_bytes.length; i++)
    {
        complete_bytes[i + Constants.AHIMSA_BULLETIN_PREFIX.length] = buffer_bytes[i];
    }
    Log.d("BB", Arrays.toString( complete_bytes ));

    // Encode 20 byte slices into output addresses, add output to transaction. Rinse and repeat.
    byte[] slice = new byte[Constants.CHAR_PER_OUT];
    for(int i = 0; i < complete_bytes.length; i++)
    {
        slice[i % Constants.CHAR_PER_OUT] = complete_bytes[i];
        if( (i+1) % Constants.CHAR_PER_OUT == 0 )
        {
            Address addr = new Address(Constants.NETWORK_PARAMETERS, slice);
            tx.addOutput(new TransactionOutput(Constants.NETWORK_PARAMETERS, tx, Coin.valueOf(Constants.MIN_DUST), addr));
        }
    }
    Log.d("BB", tx.toString());

}
 
开发者ID:alexkuck,项目名称:ahimsa-app,代码行数:51,代码来源:BulletinBuilder.java


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