本文整理了Java中org.bitcoinj.core.Transaction.<init>()
方法的一些代码示例,展示了Transaction.<init>()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Transaction.<init>()
方法的具体详情如下:
包路径:org.bitcoinj.core.Transaction
类名称:Transaction
方法名:<init>
[英]Creates a transaction from the given serialized bytes, eg, from a block or a tx network message.
[中]从给定的序列化字节创建事务,例如,从块或tx网络消息。
代码示例来源:origin: blockchain/thunder
@Override
public Channel saveToChannel (Channel channel) {
channel.anchorTx = new Transaction(Constants.getNetwork(), anchorSigned);
return channel;
}
代码示例来源:origin: blockchain/thunder
public Transaction getAnchorTransactionServer (WalletHelper walletHelper) {
//TODO test if anchor is complete and just return it..
if (anchorTx == null) {
anchorTx = new Transaction(Constants.getNetwork());
}
fillAnchorTransactionWithoutSignatures(walletHelper);
return anchorTx;
}
代码示例来源:origin: cash.bitcoinj/bitcoinj-core
/**
* Make a transaction from the payload. Extension point for alternative
* serialization format support.
*/
@Override
public Transaction makeTransaction(byte[] payloadBytes, int offset,
int length, byte[] hash) throws ProtocolException {
Transaction tx = new Transaction(params, payloadBytes, offset, null, this, length);
if (hash != null)
tx.setHash(Sha256Hash.wrapReversed(hash));
return tx;
}
代码示例来源:origin: HashEngineering/dashj
/**
* Make a transaction from the payload. Extension point for alternative
* serialization format support.
*/
@Override
public Transaction makeTransaction(byte[] payloadBytes, int offset,
int length, byte[] hash) throws ProtocolException {
Transaction tx = new Transaction(params, payloadBytes, offset, null, this, length);
if (hash != null)
tx.setHash(Sha256Hash.wrapReversed(hash));
return tx;
}
代码示例来源:origin: fr.acinq/bitcoinj-core
public static SendRequest emptyWallet(Address destination) {
SendRequest req = new SendRequest();
final NetworkParameters parameters = destination.getParameters();
checkNotNull(parameters, "Address is for an unknown network");
req.tx = new Transaction(parameters);
req.tx.addOutput(Coin.ZERO, destination);
req.emptyWallet = true;
return req;
}
代码示例来源:origin: blockchain/thunder
public void addAnchorOutputToAnchor () {
List<TransactionOutput> outputList = new ArrayList<>();
outputList.add(new TransactionOutput(
Constants.getNetwork(),
null,
Coin.valueOf(channelStatus.amountClient + channelStatus.amountServer),
getAnchorScript().getProgram()));
outputList.addAll(anchorTx.getOutputs());
Transaction tx = new Transaction(Constants.getNetwork());
anchorTx.getInputs().stream().forEach(tx::addInput);
outputList.stream().forEach(tx::addOutput);
this.anchorTx = tx;
}
代码示例来源:origin: fr.acinq/bitcoinj-core
public static SendRequest toCLTVPaymentChannel(NetworkParameters params, BigInteger time, ECKey from, ECKey to, Coin value) {
SendRequest req = new SendRequest();
Script output = ScriptBuilder.createCLTVPaymentChannelOutput(time, from, to);
req.tx = new Transaction(params);
req.tx.addOutput(value, output);
return req;
}
代码示例来源:origin: blockchain/thunder
public org.bitcoinj.core.Transaction getBitcoinJTransaction (String txHash) throws APIException, IOException {
String response = HttpClient.getInstance().get("rawtx/" + txHash + "?api_code=" + apiCode + "&format=hex", null);
byte[] raw = Tools.hexStringToByteArray(response);
return new org.bitcoinj.core.Transaction(Constants.getNetwork(), raw);
}
代码示例来源:origin: Coinomi/coinomi-android
public static BitSendRequest emptyWallet(BitAddress destination) {
checkNotNull(destination.getType(), "Address is for an unknown network");
checkTypeCompatibility(destination.getType());
BitSendRequest req = new BitSendRequest(destination.getType());
Transaction tx = new Transaction(req.type);
tx.addOutput(Coin.ZERO, destination);
req.tx = new BitTransaction(tx);
req.emptyWallet = true;
return req;
}
代码示例来源:origin: blockchain/thunder
public void fillAnchorTransactionWithoutSignatures (WalletHelper walletHelper) {
long totalAmount = channelStatus.amountServer + channelStatus.amountClient;
if (anchorTx == null) {
Script anchorScriptServer = getAnchorScriptOutput();
Script anchorScriptServerP2SH = ScriptBuilder.createP2SHOutputScript(anchorScriptServer);
anchorTx = new Transaction(Constants.getNetwork());
anchorTx.addOutput(Coin.valueOf(totalAmount), anchorScriptServerP2SH);
}
anchorTx = walletHelper.addInputs(anchorTx, channelStatus.amountServer, channelStatus.feePerByte);
anchorTxHash = anchorTx.getHash();
}
代码示例来源:origin: greenaddress/GreenBits
private synchronized Transaction makeUnsignedChannelContract(Coin valueToMe) throws ValueOutOfRangeException {
Transaction tx = new Transaction(wallet.getParams());
tx.addInput(getContractInternal().getOutput(0));
// Our output always comes first.
// TODO: We should drop myKey in favor of output key + multisig key separation
// (as its always obvious who the client is based on T2 output order)
tx.addOutput(valueToMe, myKey.toAddress(wallet.getParams()));
return tx;
}
代码示例来源:origin: blockchain/thunder
public Transaction getClosingTransaction (ChannelStatus channelStatus, float feePerByte) {
//For the sake of privacy (and simplicity) we use lexicographically ordering here, as defined in BIP69
Transaction transaction = new Transaction(Constants.getNetwork());
transaction.addInput(channel.anchorTxHash, 0, Tools.getDummyScript());
//TODO deduct the transaction fee correctly from both amounts
//TODO would be better to have another address on file that we can use here..
long feePerParty = (Tools.getTransactionFees(2, 2, feePerByte) / 2);
transaction.addOutput(Coin.valueOf(channelStatus.amountClient - feePerParty), channel.channelStatus.addressClient);
transaction.addOutput(Coin.valueOf(channelStatus.amountServer - feePerParty), channel.channelStatus.addressServer);
return Tools.applyBIP69(transaction);
}
代码示例来源:origin: greenaddress/GreenBits
@Test
public void opReturnOneOutputWithValueTest() throws Exception {
// Tests basic send of transaction with one output that destroys coins and has an OP_RETURN.
receiveATransaction(wallet, myAddress);
Transaction tx = new Transaction(PARAMS);
Coin messagePrice = CENT;
Script script = ScriptBuilder.createOpReturnScript("hello world!".getBytes());
tx.addOutput(messagePrice, script);
SendRequest request = SendRequest.forTx(tx);
wallet.completeTx(request);
}
代码示例来源:origin: fr.acinq/bitcoinj-core
protected synchronized SendRequest makeUnsignedChannelContract(Coin valueToMe) {
Transaction tx = new Transaction(wallet.getParams());
if (!getTotalValue().subtract(valueToMe).equals(Coin.ZERO)) {
tx.addOutput(getTotalValue().subtract(valueToMe), getClientKey().toAddress(wallet.getParams()));
}
tx.addInput(contract.getOutput(0));
return SendRequest.forTx(tx);
}
代码示例来源:origin: greenaddress/GreenBits
protected synchronized SendRequest makeUnsignedChannelContract(Coin valueToMe) {
Transaction tx = new Transaction(wallet.getParams());
if (!getTotalValue().subtract(valueToMe).equals(Coin.ZERO)) {
tx.addOutput(getTotalValue().subtract(valueToMe), getClientKey().toAddress(wallet.getParams()));
}
tx.addInput(contract.getOutput(0));
return SendRequest.forTx(tx);
}
代码示例来源:origin: greenaddress/GreenBits
@Test
public void roundtripVersionTwoTransaction() throws Exception {
Transaction tx = new Transaction(PARAMS, Utils.HEX.decode(
"0200000001d7902864af9310420c6e606b814c8f89f7902d40c130594e85df2e757a7cc301070000006b483045022100ca1757afa1af85c2bb014382d9ce411e1628d2b3d478df9d5d3e9e93cb25dcdd02206c5d272b31a23baf64e82793ee5c816e2bbef251e733a638b630ff2331fc83ba0121026ac2316508287761befbd0f7495ea794b396dbc5b556bf276639f56c0bd08911feffffff0274730700000000001976a91456da2d038a098c42390c77ef163e1cc23aedf24088ac91062300000000001976a9148ebf3467b9a8d7ae7b290da719e61142793392c188ac22e00600"));
assertEquals(tx.getVersion(), 2);
assertEquals(tx.getHashAsString(), "0321b1413ed9048199815bd6bc2650cab1a9e8d543f109a42c769b1f18df4174");
myWallet.addWalletTransaction(new WalletTransaction(Pool.UNSPENT, tx));
Wallet wallet1 = roundTrip(myWallet);
Transaction tx2 = wallet1.getTransaction(tx.getHash());
assertEquals(checkNotNull(tx2).getVersion(), 2);
}
代码示例来源:origin: greenaddress/GreenBits
@Test(expected = IllegalStateException.class)
public void analysisCantBeUsedTwice() {
Transaction tx = new Transaction(PARAMS);
DefaultRiskAnalysis analysis = DefaultRiskAnalysis.FACTORY.create(wallet, tx, NO_DEPS);
assertEquals(RiskAnalysis.Result.OK, analysis.analyze());
assertNull(analysis.getNonFinal());
// Verify we can't re-use a used up risk analysis.
analysis.analyze();
}
代码示例来源:origin: greenaddress/GreenBits
@Test
public void getAddressTests() throws Exception {
Transaction tx = new Transaction(MainNetParams.get());
tx.addOutput(Coin.CENT, ScriptBuilder.createOpReturnScript("hello world!".getBytes()));
assertNull(tx.getOutput(0).getAddressFromP2SH(PARAMS));
assertNull(tx.getOutput(0).getAddressFromP2PKHScript(PARAMS));
}
代码示例来源:origin: Coinomi/coinomi-android
@Test
public void serializeTransactionsBtc() throws Exception, Bip44KeyLookAheadExceededException {
WalletPocketHD account = new WalletPocketHD(rootKey, BTC, null, null);
Transaction tx = new Transaction(BTC);
tx.addOutput(BTC.oneCoin().toCoin(), account.getReceiveAddress());
account.addNewTransactionIfNeeded(tx);
testWalletSerializationForCoin(account);
}
代码示例来源:origin: Coinomi/coinomi-android
@Test
public void serializeTransactionsNbt() throws Exception, Bip44KeyLookAheadExceededException {
WalletPocketHD account = new WalletPocketHD(rootKey, NBT, null, null);
Transaction tx = new Transaction(NBT);
tx.addOutput(NBT.oneCoin().toCoin(), account.getReceiveAddress());
account.addNewTransactionIfNeeded(tx);
testWalletSerializationForCoin(account);
}
内容来源于网络,如有侵权,请联系作者删除!