diff --git a/core/src/bitcoin.proto b/core/src/bitcoin.proto index 374719b5..baadec76 100644 --- a/core/src/bitcoin.proto +++ b/core/src/bitcoin.proto @@ -1,4 +1,5 @@ /** Copyright 2013 Google Inc. + * Copyright 2014 Andreas Schildbach * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,7 +15,7 @@ */ /* - * Authors: Jim Burton, Miron Cuperman + * Authors: Jim Burton, Miron Cuperman, Andreas Schildbach */ /* Notes: @@ -94,6 +95,8 @@ message TransactionInput { required bytes script_bytes = 3; // Sequence number. Currently unused, but intended for contracts in future. optional uint32 sequence = 4; + // Value of connected output, if known + optional int64 value = 5; } message TransactionOutput { diff --git a/core/src/main/java/com/google/bitcoin/core/Transaction.java b/core/src/main/java/com/google/bitcoin/core/Transaction.java index 9fbb25b1..dc250027 100644 --- a/core/src/main/java/com/google/bitcoin/core/Transaction.java +++ b/core/src/main/java/com/google/bitcoin/core/Transaction.java @@ -1,5 +1,6 @@ /** * Copyright 2011 Google Inc. + * Copyright 2014 Andreas Schildbach * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -375,6 +376,25 @@ public class Transaction extends ChildMessage implements Serializable { return getValueSentToMe(wallet).subtract(getValueSentFromMe(wallet)); } + /** + * The transaction fee is the difference of the value of all inputs and the value of all outputs. Currently, the fee + * can only be determined for transactions created by us. + * + * @return fee, or null if it cannot be determined + */ + public BigInteger getFee() { + BigInteger fee = BigInteger.ZERO; + for (TransactionInput input : inputs) { + if (input.getValue() == null) + return null; + fee = fee.add(input.getValue()); + } + for (TransactionOutput output : outputs) { + fee = fee.subtract(output.getValue()); + } + return fee; + } + boolean disconnectInputs() { boolean disconnected = false; maybeParse(); @@ -635,6 +655,8 @@ public class Transaction extends ChildMessage implements Serializable { try { Script scriptSig = in.getScriptSig(); s.append(scriptSig); + if (in.getValue() != null) + s.append(" ").append(bitcoinValueToFriendlyString(in.getValue())).append(" BTC"); s.append("\n "); s.append("outpoint:"); final TransactionOutPoint outpoint = in.getOutpoint(); diff --git a/core/src/main/java/com/google/bitcoin/core/TransactionInput.java b/core/src/main/java/com/google/bitcoin/core/TransactionInput.java index 962d1f95..08525c59 100644 --- a/core/src/main/java/com/google/bitcoin/core/TransactionInput.java +++ b/core/src/main/java/com/google/bitcoin/core/TransactionInput.java @@ -1,5 +1,6 @@ /** * Copyright 2011 Google Inc. + * Copyright 2014 Andreas Schildbach * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -24,6 +25,7 @@ import java.io.ObjectOutputStream; import java.io.OutputStream; import java.io.Serializable; import java.lang.ref.WeakReference; +import java.math.BigInteger; import java.util.Arrays; import java.util.Map; @@ -54,28 +56,32 @@ public class TransactionInput extends ChildMessage implements Serializable { // The Script object obtained from parsing scriptBytes. Only filled in on demand and if the transaction is not // coinbase. transient private WeakReference