@Override public Channel saveToChannel (Channel channel) { channel.anchorTx = new Transaction(Constants.getNetwork(), anchorSigned); return channel; }
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; }
/** * 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; }
/** * 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; }
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; }
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; }
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; }
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); }
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; }
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(); }
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; }
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); }
@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); }
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); }
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); }
@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); }
@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(); }
@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)); }
@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); }
@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); }