Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielWeigl committed Oct 1, 2015
2 parents 64b3538 + be97234 commit bae6953
Show file tree
Hide file tree
Showing 16 changed files with 324 additions and 351 deletions.
40 changes: 40 additions & 0 deletions public/bitlib/src/main/java/com/mrd/bitlib/PopBuilder.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.mrd.bitlib;

import com.mrd.bitlib.crypto.IPublicKeyRing;
import com.mrd.bitlib.model.NetworkParameters;
import com.mrd.bitlib.model.TransactionOutput;
import com.mrd.bitlib.model.UnspentTransactionOutput;

import java.util.List;

public class PopBuilder extends StandardTransactionBuilder {
public PopBuilder(NetworkParameters network) {
super(network);
}

private static class UnsignedPop extends UnsignedTransaction {
public static final int MAX_LOCK_TIME = 499999999;
private static final int POP_SEQUENCE_NUMBER = 0;

private UnsignedPop(List<TransactionOutput> outputs, List<UnspentTransactionOutput> funding, IPublicKeyRing keyRing, NetworkParameters network) {
super(outputs, funding, keyRing, network);
}

@Override
public int getDefaultSequenceNumber() {
return POP_SEQUENCE_NUMBER;
}

@Override
public int getLockTime() {
return MAX_LOCK_TIME;
}
}

public UnsignedPop createUnsignedPop(List<TransactionOutput> outputs, List<UnspentTransactionOutput> funding,
IPublicKeyRing keyRing, NetworkParameters network) {
UnsignedPop unsignedPop = new UnsignedPop(outputs, funding, keyRing, network);

return unsignedPop;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import java.util.*;

public class StandardTransactionBuilder {
public static final int MAX_LOCK_TIME = 499999999;

public static class InsufficientFundsException extends Exception {
//todo consider refactoring this into a composite return value instead of an exception. it is not really "exceptional"
Expand Down Expand Up @@ -82,12 +81,12 @@ public SigningRequest(PublicKey publicKey, Sha256Hash toSign) {

public static class UnsignedTransaction implements Serializable {
private static final long serialVersionUID = 1L;
public static final int NO_SEQUENCE = -1;

private TransactionOutput[] _outputs;
private UnspentTransactionOutput[] _funding;
private SigningRequest[] _signingRequests;
private NetworkParameters _network;
private boolean _isPop = false;

public TransactionOutput[] getOutputs(){
return _outputs;
Expand All @@ -97,32 +96,21 @@ public UnspentTransactionOutput[] getFundingOutputs(){
return _funding;
}

private UnsignedTransaction(List<TransactionOutput> outputs, List<UnspentTransactionOutput> funding,
protected UnsignedTransaction(List<TransactionOutput> outputs, List<UnspentTransactionOutput> funding,
IPublicKeyRing keyRing, NetworkParameters network) {
this(outputs, funding, keyRing, false, network);
}

private UnsignedTransaction(List<TransactionOutput> outputs, List<UnspentTransactionOutput> funding,
IPublicKeyRing keyRing, boolean isPop, NetworkParameters network) {
_network = network;
_outputs = outputs.toArray(new TransactionOutput[]{});
_funding = funding.toArray(new UnspentTransactionOutput[]{});
_signingRequests = new SigningRequest[_funding.length];
_isPop = isPop;

// Create empty input scripts pointing at the right out points
TransactionInput[] inputs = new TransactionInput[_funding.length];
for (int i = 0; i < _funding.length; i++) {
inputs[i] = new TransactionInput(_funding[i].outPoint, ScriptInput.EMPTY);
if (isPop) {
// If we're creating an unsigned pop, the sequence numbers must be zero for all inputs.
inputs[i].sequence = 0;
}
inputs[i] = new TransactionInput(_funding[i].outPoint, ScriptInput.EMPTY, getDefaultSequenceNumber());
}

// Create transaction with valid outputs and empty inputs. If PoP, make it invalid by setting
// lock_time to its max block index.
Transaction transaction = new Transaction(1, inputs, _outputs, isPop ? MAX_LOCK_TIME : 0);
// Create transaction with valid outputs and empty inputs
Transaction transaction = new Transaction(1, inputs, _outputs, getLockTime());

for (int i = 0; i < _funding.length; i++) {
UnspentTransactionOutput f = _funding[i];
Expand Down Expand Up @@ -172,6 +160,14 @@ public long calculateFee() {
return in - out;
}

public int getLockTime() {
return 0;
}

public int getDefaultSequenceNumber() {
return NO_SEQUENCE;
}

@Override
public String toString() {
StringBuilder sb = new StringBuilder();
Expand Down Expand Up @@ -266,13 +262,6 @@ public static List<byte[]> generateSignatures(SigningRequest[] requests, IPrivat
return signatures;
}

public UnsignedTransaction createUnsignedPop(List<TransactionOutput> outputs, List<UnspentTransactionOutput> funding,
IPublicKeyRing keyRing, NetworkParameters network) {
UnsignedTransaction unsignedPop = new UnsignedTransaction(outputs, funding, keyRing, true, network);

return unsignedPop;
}

/**
* Create an unsigned transaction and automatically calculate the miner fee.
* <p/>
Expand Down Expand Up @@ -418,14 +407,11 @@ public static Transaction finalizeTransaction(UnsignedTransaction unsigned, List
// Create script from signature and public key
ScriptInputStandard script = new ScriptInputStandard(signatures.get(i),
unsigned._signingRequests[i].publicKey.getPublicKeyBytes());
inputs[i] = new TransactionInput(unsigned._funding[i].outPoint, script);
if (unsigned._isPop) {
inputs[i].sequence = 0;
}
inputs[i] = new TransactionInput(unsigned._funding[i].outPoint, script, unsigned.getDefaultSequenceNumber());
}

// Create transaction with valid outputs and empty inputs
Transaction transaction = new Transaction(1, inputs, unsigned._outputs, unsigned._isPop ? MAX_LOCK_TIME : 0);
Transaction transaction = new Transaction(1, inputs, unsigned._outputs, unsigned.getLockTime());
return transaction;
}

Expand Down
1 change: 0 additions & 1 deletion public/libs/nordpol/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ android {
// we are just embedding the zxing lib here, we are not maintaining it.
lintOptions {
ignoreWarnings true
abortOnError false
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -880,7 +880,7 @@ public boolean handle(StringHandlerActivity handlerActivity, String content) {
try {
popRequest = new PopRequest(content);
} catch (IllegalArgumentException e) {
handlerActivity.finishError(R.string.invalid_pop_uri, content);
handlerActivity.finishError(R.string.pop_invalid_pop_uri, content);
return false;
}

Expand Down
Loading

0 comments on commit bae6953

Please sign in to comment.