private static boolean checkTransactionOutputs(TransactionOutput txOutputToCheck, List<TransactionOutput> txOutputs) { // Find the matching transactionOutput, matching by the output script bytes for (TransactionOutput txOutput : txOutputs) { if (txOutputToCheck.getScriptBytes() != null) { if (Arrays.areEqual(txOutputToCheck.getScriptBytes(), txOutput.getScriptBytes())) { return true; } } else { // Script bytes are null log.debug("No script bytes to match on, matching fails"); } } return false; } }
/** * Returns the pubkey script from the connected output. * @throws java.lang.NullPointerException if there is no connected output. */ public byte[] getConnectedPubKeyScript() { byte[] result = checkNotNull(getConnectedOutput()).getScriptBytes(); checkState(result.length > 0); return result; }
/** * Returns the pubkey script from the connected output. * @throws java.lang.NullPointerException if there is no connected output. */ public byte[] getConnectedPubKeyScript() { byte[] result = checkNotNull(getConnectedOutput()).getScriptBytes(); checkState(result.length > 0); return result; }
/** * Returns the pubkey script from the connected output. * @throws java.lang.NullPointerException if there is no connected output. */ public byte[] getConnectedPubKeyScript() { byte[] result = checkNotNull(getConnectedOutput()).getScriptBytes(); checkState(result.length > 0); return result; }
/** * Returns the pubkey script from the connected output. * @throws java.lang.NullPointerException if there is no connected output. */ public byte[] getConnectedPubKeyScript() { byte[] result = checkNotNull(getConnectedOutput()).getScriptBytes(); checkState(result.length > 0); return result; }
public int countSigOps() { return Script.getSigOpCount(getScriptBytes()) * Transaction.WITNESS_SCALE_FACTOR; }
@Override public int compare(TransactionOutput o1, TransactionOutput o2) { long amountDiff = o1.getValue().getValue() - o2.getValue().value; if (amountDiff != 0) { return (int) amountDiff; } else { byte[] hash1 = o1.getScriptBytes(); byte[] hash2 = o2.getScriptBytes(); return LexicographicalComparator.getComparator().compare(hash1, hash2); } } });
public TrimmedOutput(TransactionOutput output, long index, Sha256Hash txHash) { super(output.getParams(), null, output.getValue(), output.getScriptBytes()); this.index = index; this.txHash = txHash; }
public TrimmedOutput(TransactionOutput output, long index, Sha256Hash txHash) { super(output.getParams(), null, output.getValue(), output.getScriptBytes()); this.index = index; this.txHash = txHash; }
public TrimmedOutput(TransactionOutput output, long index, TrimmedTransaction tx) { super(output.getParams(), checkNotNull(tx), output.getValue(), output.getScriptBytes()); this.index = index; this.txHash = null; }
/** * Gets the count of regular SigOps in this transactions */ public int getSigOpCount() throws ScriptException { int sigOps = 0; for (TransactionInput input : inputs) sigOps += Script.getSigOpCount(input.getScriptBytes()); for (TransactionOutput output : outputs) sigOps += Script.getSigOpCount(output.getScriptBytes()); return sigOps; }
public List<TransactionSignature> getPaymentSignatures () { List<Transaction> paymentTransactions = getClientPaymentTransactions(); List<TransactionSignature> signatureList = new ArrayList<>(); int index = 2; for (Transaction t : paymentTransactions) { TransactionSignature sig = Tools.getSignature(t, 0, getClientTransaction().getOutput(index).getScriptBytes(), channel.getKeyServer()); signatureList.add(sig); index++; } return signatureList; }
public TrimmedOutput(TransactionOutput output, long index, TrimmedTransaction tx) { super(output.getParams(), checkNotNull(tx), output.getValue(), output.getScriptBytes()); this.index = index; this.txHash = null; }
/** * Gets the count of regular SigOps in this transactions */ public int getSigOpCount() throws ScriptException { int sigOps = 0; for (TransactionInput input : inputs) sigOps += Script.getSigOpCount(input.getScriptBytes()); for (TransactionOutput output : outputs) sigOps += Script.getSigOpCount(output.getScriptBytes()); return sigOps; }
/** * Gets the count of regular SigOps in this transactions */ public int getSigOpCount() throws ScriptException { int sigOps = 0; for (TransactionInput input : inputs) sigOps += Script.getSigOpCount(input.getScriptBytes()); for (TransactionOutput output : outputs) sigOps += Script.getSigOpCount(output.getScriptBytes()); return sigOps; }
@Override public ChannelSignatures getSignatureObject (Channel channel, Transaction channelTransaction) { ChannelSignatures channelSignatures = new ChannelSignatures(); channelSignatures.channelSignatures = Tools.getChannelSignatures(channel, channelTransaction); List<Transaction> paymentTransactions = getPaymentTransactions(channelTransaction.getHash(), channel.channelStatus, channel.keyServer, channel.keyClient); List<TransactionSignature> signatureList = new ArrayList<>(); int index = 2; for (Transaction t : paymentTransactions) { TransactionSignature sig = Tools.getSignature(t, 0, channelTransaction.getOutput(index).getScriptBytes(), channel.getKeyServer()); signatureList.add(sig); index++; } channelSignatures.paymentSignatures = signatureList; return channelSignatures; }
@Test(expected = PaymentProtocolException.InvalidNetwork.class) public void testWrongNetwork() throws Exception { // Create a PaymentRequest and make sure the correct values are parsed by the PaymentSession. MockPaymentSession paymentSession = new MockPaymentSession(newSimplePaymentRequest("main")); assertEquals(MainNetParams.get(), paymentSession.getNetworkParameters()); // Send the payment and verify that the correct information is sent. // Add a dummy input to tx so it is considered valid. tx.addInput(new TransactionInput(PARAMS, tx, outputToMe.getScriptBytes())); ArrayList<Transaction> txns = new ArrayList<>(); txns.add(tx); Address refundAddr = new Address(PARAMS, serverKey.getPubKeyHash()); paymentSession.sendPayment(txns, refundAddr, paymentMemo); assertEquals(1, paymentSession.getPaymentLog().size()); }
@Test public void testExpiredPaymentRequest() throws Exception { MockPaymentSession paymentSession = new MockPaymentSession(newExpiredPaymentRequest()); assertTrue(paymentSession.isExpired()); // Send the payment and verify that an exception is thrown. // Add a dummy input to tx so it is considered valid. tx.addInput(new TransactionInput(PARAMS, tx, outputToMe.getScriptBytes())); ArrayList<Transaction> txns = new ArrayList<>(); txns.add(tx); try { paymentSession.sendPayment(txns, null, null); } catch(PaymentProtocolException.Expired e) { assertEquals(0, paymentSession.getPaymentLog().size()); assertEquals(e.getMessage(), "PaymentRequest is expired"); return; } fail("Expected exception due to expired PaymentRequest"); }
private Protos.PaymentRequest newSimplePaymentRequest(String netID) { Protos.Output.Builder outputBuilder = Protos.Output.newBuilder() .setAmount(coin.value) .setScript(ByteString.copyFrom(outputToMe.getScriptBytes())); Protos.PaymentDetails paymentDetails = Protos.PaymentDetails.newBuilder() .setNetwork(netID) .setTime(time) .setPaymentUrl(simplePaymentUrl) .addOutputs(outputBuilder) .setMemo(paymentRequestMemo) .setMerchantData(merchantData) .build(); return Protos.PaymentRequest.newBuilder() .setPaymentDetailsVersion(1) .setPkiType("none") .setSerializedPaymentDetails(paymentDetails.toByteString()) .build(); }
@Test public void testDefaults() throws Exception { Protos.Output.Builder outputBuilder = Protos.Output.newBuilder() .setScript(ByteString.copyFrom(outputToMe.getScriptBytes())); Protos.PaymentDetails paymentDetails = Protos.PaymentDetails.newBuilder() .setTime(time) .addOutputs(outputBuilder) .build(); Protos.PaymentRequest paymentRequest = Protos.PaymentRequest.newBuilder() .setSerializedPaymentDetails(paymentDetails.toByteString()) .build(); MockPaymentSession paymentSession = new MockPaymentSession(paymentRequest); assertEquals(Coin.ZERO, paymentSession.getValue()); assertNull(paymentSession.getPaymentUrl()); assertNull(paymentSession.getMemo()); }