Skip to content

Commit dabaecc

Browse files
authored
Merge pull request #3 from nickabourisk/main
Minor fixes
2 parents e2abb79 + b780a04 commit dabaecc

File tree

8 files changed

+41
-36
lines changed

8 files changed

+41
-36
lines changed

src/main/java/org/twostack/bitcoin4j/script/ScriptFlags.java

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -113,39 +113,39 @@
113113
/// ## SEQUENCE_LOCKTIME_MASK
114114
/// If CTxIn::nSequence encodes a relative lock-time, this mask is applied to
115115
/// extract that lock-time from the sequence field.
116-
class ScriptFlags {
116+
public class ScriptFlags {
117117

118118
/// bitcoind commit: b5d1b1092998bc95313856d535c632ea5a8f9104
119-
static final int SCRIPT_VERIFY_NONE = 0;
119+
public static final int SCRIPT_VERIFY_NONE = 0;
120120

121121
/// Evaluate P2SH subscripts (softfork safe, BIP16).
122-
static final int SCRIPT_VERIFY_P2SH = (1 << 0);
122+
public static final int SCRIPT_VERIFY_P2SH = (1 << 0);
123123

124124

125125
/// Passing a non-strict-DER signature or one with undefined hashtype to a checksig operation causes script failure.
126126
/// Passing a pubkey that is not (0x04 + 64 bytes) or (0x02 or 0x03 + 32 bytes) to checksig causes that pubkey to be
127127
/// skipped (not softfork safe: this flag can widen the validity of OP_CHECKSIG OP_NOT).
128-
static final int SCRIPT_VERIFY_STRICTENC = (1 << 1);
128+
public static final int SCRIPT_VERIFY_STRICTENC = (1 << 1);
129129

130130
/// Passing a non-strict-DER signature to a checksig operation causes script failure (softfork safe, BIP62 rule 1)
131-
static final int SCRIPT_VERIFY_DERSIG = (1 << 2);
131+
public static final int SCRIPT_VERIFY_DERSIG = (1 << 2);
132132

133133
/// Pa non-strict-DER signature or one with S > order/2 to a checksig operation causes script failure
134134
/// (softfork safe, BIP62 rule 5).
135-
static final int SCRIPT_VERIFY_LOW_S = (1 << 3);
135+
public static final int SCRIPT_VERIFY_LOW_S = (1 << 3);
136136

137137
/// verify dummy stack item consumed by CHECKMULTISIG is of zero-length (softfork safe, BIP62 rule 7).
138-
static final int SCRIPT_VERIFY_NULLDUMMY = (1 << 4);
138+
public static final int SCRIPT_VERIFY_NULLDUMMY = (1 << 4);
139139

140140
/// Using a non-push operator in the scriptSig causes script failure (softfork safe, BIP62 rule 2).
141-
static final int SCRIPT_VERIFY_SIGPUSHONLY = (1 << 5);
141+
public static final int SCRIPT_VERIFY_SIGPUSHONLY = (1 << 5);
142142

143143
/// Require minimal encodings for all push operations (OP_0... OP_16, OP_1NEGATE where possible, direct
144144
/// pushes up to 75 bytes, OP_PUSHDATA up to 255 bytes, OP_PUSHDATA2 for anything larger). Evaluating
145145
/// any other push causes the script to fail (BIP62 rule 3).
146146
/// In addition, whenever a stack element is interpreted as a number, it must be of minimal length (BIP62 rule 4).
147147
/// (softfork safe)
148-
static final int SCRIPT_VERIFY_MINIMALDATA = (1 << 6);
148+
public static final int SCRIPT_VERIFY_MINIMALDATA = (1 << 6);
149149

150150
/// Discourage use of NOPs reserved for upgrades (NOP1-10)
151151
///
@@ -155,7 +155,7 @@ class ScriptFlags {
155155
/// discouraged NOPs fails the script. This verification flag will never be
156156
/// a mandatory flag applied to scripts in a block. NOPs that are not
157157
/// executed, e.g. within an unexecuted IF ENDIF block, are *not* rejected.
158-
static final int SCRIPT_VERIFY_DISCOURAGE_UPGRADABLE_NOPS = (1 << 7);
158+
public static final int SCRIPT_VERIFY_DISCOURAGE_UPGRADABLE_NOPS = (1 << 7);
159159

160160
/// Require that only a single stack element remains after evaluation. This
161161
/// changes the success criterion from "At least one stack element must
@@ -164,62 +164,62 @@ class ScriptFlags {
164164
/// be true".
165165
/// (softfork safe, BIP62 rule 6)
166166
/// Note: CLEANSTACK should never be used without P2SH or WITNESS.
167-
static final int SCRIPT_VERIFY_CLEANSTACK = (1 << 8);
167+
public static final int SCRIPT_VERIFY_CLEANSTACK = (1 << 8);
168168

169169
/// Cstatic final LTV See BIP65 for details.
170-
static final int SCRIPT_VERIFY_CHECKLOCKTIMEVERIFY = (1 << 9);
170+
public static final int SCRIPT_VERIFY_CHECKLOCKTIMEVERIFY = (1 << 9);
171171

172172
/// support CHECKSEQUENCEVERIFY opcode
173173
///
174174
/// See BIP112 for details
175-
static final int SCRIPT_VERIFY_CHECKSEQUENCEVERIFY = (1 << 10);
175+
public static final int SCRIPT_VERIFY_CHECKSEQUENCEVERIFY = (1 << 10);
176176

177177
/// Segwit script only: Require the argument of OP_IF/NOTIF to be exactly
178178
/// 0x01 or empty vector
179179
///
180-
static final int SCRIPT_VERIFY_MINIMALIF = (1 << 13);
180+
public static final int SCRIPT_VERIFY_MINIMALIF = (1 << 13);
181181

182182
/// Signature(s) must be empty vector if an CHECK(MULTI)SIG operation failed
183183
///
184-
static final int SCRIPT_VERIFY_NULLFAIL = (1 << 14);
184+
public static final int SCRIPT_VERIFY_NULLFAIL = (1 << 14);
185185

186186
/// Public keys in scripts must be compressed
187-
static final int SCRIPT_VERIFY_COMPRESSED_PUBKEYTYPE = (1 << 15);
187+
public static final int SCRIPT_VERIFY_COMPRESSED_PUBKEYTYPE = (1 << 15);
188188

189189
/// Do we accept signature using SIGHASH_FORKID
190190
///
191-
static final int SCRIPT_ENABLE_SIGHASH_FORKID = (1 << 16);
191+
public static final int SCRIPT_ENABLE_SIGHASH_FORKID = (1 << 16);
192192

193193
/// Do we accept activate replay protection using a different fork id.
194194
///
195-
static final int SCRIPT_ENABLE_REPLAY_PROTECTION = (1 << 17);
195+
public static final int SCRIPT_ENABLE_REPLAY_PROTECTION = (1 << 17);
196196

197197
/// Enable new opcodes.
198198
///
199-
static final int SCRIPT_ENABLE_MONOLITH_OPCODES = (1 << 18);
199+
public static final int SCRIPT_ENABLE_MONOLITH_OPCODES = (1 << 18);
200200

201201
/// Are the Magnetic upgrade opcodes enabled?
202202
///
203-
static final int SCRIPT_ENABLE_MAGNETIC_OPCODES = (1 << 19);
203+
public static final int SCRIPT_ENABLE_MAGNETIC_OPCODES = (1 << 19);
204204

205205
/// *Below flags apply in the context of BIP 68*
206206
///
207207
/// If this flag set, CTxIn::nSequence is NOT interpreted as a relative lock-time.
208208

209-
static final int SEQUENCE_LOCKTIME_DISABLE_FLAG = (1 << 31);
209+
public static final int SEQUENCE_LOCKTIME_DISABLE_FLAG = (1 << 31);
210210

211211

212212
/// If CTxIn::nSequence encodes a relative lock-time and this flag is set,
213213
/// the relative lock-time has units of 512 seconds, otherwise it specifies
214214
/// blocks with a granularity of 1.
215215

216-
static final int SEQUENCE_LOCKTIME_TYPE_FLAG = (1 << 22);
216+
public static final int SEQUENCE_LOCKTIME_TYPE_FLAG = (1 << 22);
217217

218218
///
219219
/// If CTxIn::nSequence encodes a relative lock-time, this mask is applied to
220220
/// extract that lock-time from the sequence field.
221221
///
222-
static final int SEQUENCE_LOCKTIME_MASK = 0x0000ffff;
222+
public static final int SEQUENCE_LOCKTIME_MASK = 0x0000ffff;
223223

224224

225225
}

src/main/java/org/twostack/bitcoin4j/transaction/DefaultUnlockBuilder.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ public class DefaultUnlockBuilder extends UnlockingScriptBuilder {
2525

2626
List<TransactionSignature> signatures = new ArrayList<>();
2727

28-
DefaultUnlockBuilder(){
28+
public DefaultUnlockBuilder(){
2929
super();
3030
}
3131

32-
DefaultUnlockBuilder(Script script){
32+
public DefaultUnlockBuilder(Script script){
3333
super(script);
3434
}
3535

src/main/java/org/twostack/bitcoin4j/transaction/Transaction.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030

3131
public class Transaction {
3232

33-
3433
private long version = 1;
3534
private long nLockTime = 0;
3635
private ArrayList<TransactionInput> inputs = new ArrayList<>();
@@ -40,7 +39,7 @@ public class Transaction {
4039
public static final long NLOCKTIME_MAX_VALUE = 4294967295L;
4140

4241
public static final long MAX_COINS = 21000000;
43-
/// max amount of satoshis in circulation
42+
/// max amount of bitcoins in circulation
4443

4544
private static final int SMALLEST_UNIT_EXPONENT = 8;
4645
private static final long COIN_VALUE = LongMath.pow(10, SMALLEST_UNIT_EXPONENT);
@@ -247,11 +246,11 @@ public List<TransactionOutput> getOutputs() {
247246
}
248247

249248
public String getTransactionId(){
250-
if (txHash == null){
249+
byte[] idBytes = getTransactionIdBytes();
250+
if (idBytes.length == 0) {
251251
return "";
252252
}
253-
254-
return Utils.HEX.encode(txHash.array());
253+
return Utils.HEX.encode(idBytes);
255254
}
256255

257256
public byte[] getTransactionIdBytes(){

src/main/java/org/twostack/bitcoin4j/transaction/TransactionBuilder.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public class TransactionBuilder {
3131
private List<TransactionInput> inputs = new ArrayList<>();
3232
private List<TransactionOutput> outputs = new ArrayList<>();
3333

34-
//Map the transactionIds we're spending from, to the corresponding UXTO amount in the output
34+
//Map the transactionIds we're spending from, to the corresponding UTXO amount in the output
3535
private Map<String, BigInteger> spendingMap = new HashMap();
3636

3737
private LockingScriptBuilder changeScriptBuilder;
@@ -42,7 +42,7 @@ public class TransactionBuilder {
4242

4343
static final BigInteger DUST_AMOUNT = BigInteger.valueOf(256);
4444

45-
/// Margin of error to allow fees in the vecinity of the expected value but doesn't allow a big difference
45+
/// Margin of error to allow fees in the vicinity of the expected value but doesn't allow a big difference
4646
private static final BigInteger FEE_SECURITY_MARGIN = BigInteger.valueOf(150);
4747

4848
private long feePerKb = DEFAULT_FEE_PER_KB;
@@ -62,7 +62,7 @@ public class TransactionBuilder {
6262
private long nLockTime = 0;
6363

6464
/*
65-
utxoMap is expect to have :
65+
utxoMap is expected to have :
6666
6767
{
6868
"transactionId" : [String],

src/main/java/org/twostack/bitcoin4j/transaction/TransactionInput.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public class TransactionInput {
3131
want to indicate that the transaction's [Transaction.nLockTime] should be ignored.
3232
This is a 64-bit value, in range 0 to (2^64) - 1
3333
*/
34-
static long MAX_SEQ_NUMBER = 0xFFFFFFFFL;
34+
public static long MAX_SEQ_NUMBER = 0xFFFFFFFFL;
3535

3636
private long _sequenceNumber;
3737

src/main/java/org/twostack/bitcoin4j/transaction/TransactionOutput.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public static TransactionOutput fromReader(ReadUtils reader) {
4343
return new TransactionOutput(satoshis, script);
4444
}
4545

46-
TransactionOutput(BigInteger satoshis, LockingScriptBuilder builder){
46+
public TransactionOutput(BigInteger satoshis, LockingScriptBuilder builder){
4747
this.satoshis = satoshis;
4848
this._lockingScriptBuilder = builder;
4949
}

src/main/java/org/twostack/bitcoin4j/transaction/TransactionSigner.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public Transaction sign(
4747
byte[] hash = sigHash.createHash(unsignedTxn, sigHashType, inputIndex, subscript, utxo.getAmount());
4848

4949
//FIXME: Revisit this issue surrounding the need to sign a reversed copy of the hash.
50-
/// Right now I've factored this out of signature.dart because 'coupling' & 'seperation of concerns'.
50+
/// Right now I've factored this out of signature.dart because 'coupling' & 'separation of concerns'.
5151
// var reversedHash = Utils.HEX.encode(HEX.decode(hash).reversed.toList());
5252

5353
// generate a signature for the input

src/test/java/org/twostack/bitcoin4j/transaction/TransactionTest.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,12 @@ public void TestSerializeDeserialize() throws IOException {
6767
assertEquals(tx1hex, HEX.encode(transaction.serialize()));
6868
}
6969

70+
@Test
71+
public void TestTransactionIdMatchesTransactionHash() {
72+
Transaction transaction = Transaction.fromHex(tx1hex);
73+
assertEquals(tx1id, transaction.getTransactionId());
74+
}
75+
7076
@Test
7177
public void can_create_and_sign_transaction() throws InvalidKeyException, TransactionException, IOException, SigHashException {
7278

0 commit comments

Comments
 (0)