Skip to content

Commit

Permalink
Merge pull request #2 from FuzzyHobbit/coinomi-0.12.3
Browse files Browse the repository at this point in the history
Coinomi bitcoinj 0.12.3
  • Loading branch information
erasmospunk committed Jan 18, 2015
2 parents 40d8c8a + 07d1e8e commit 4dbce44
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 39 deletions.
2 changes: 1 addition & 1 deletion core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<parent>
<groupId>org.bitcoinj</groupId>
<artifactId>bitcoinj-parent</artifactId>
<version>0.12.2-COINOMI</version>
<version>0.12.3-COINOMI</version>
</parent>

<artifactId>bitcoinj-core</artifactId>
Expand Down
49 changes: 26 additions & 23 deletions core/src/main/java/org/bitcoinj/core/Transaction.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,12 @@
import static org.bitcoinj.core.Utils.*;
import static com.google.common.base.Preconditions.checkState;

import static org.bitcoinj.params.Networks.Family.NUBITS;
import static org.bitcoinj.params.Networks.Family.PEERCOIN;
import static org.bitcoinj.params.Networks.Family.RUBYCOIN;
import static org.bitcoinj.params.Networks.Family.CANNACOIN;
import static org.bitcoinj.params.Networks.Family.BLACKCOIN;
import static org.bitcoinj.params.Networks.Family.REDDCOIN;
import static org.bitcoinj.params.Networks.Family.NUBITS;
import static org.bitcoinj.params.Networks.Family.PEERCOIN;

/**
* <p>A transaction represents the movement of coins from some addresses to some other addresses. It can also represent
Expand Down Expand Up @@ -187,13 +189,14 @@ public Transaction(NetworkParameters params) {
// We don't initialize appearsIn deliberately as it's only useful for transactions stored in the wallet.
length = 8; // 8 for std fields
Networks.Family txFamily = Networks.getFamily(params);
if (txFamily == PEERCOIN || txFamily == NUBITS || txFamily == BLACKCOIN || (txFamily == REDDCOIN && version > 1)) {
if (txFamily == PEERCOIN || txFamily == NUBITS || (txFamily == CANNACOIN && version > 1) ||
txFamily == RUBYCOIN || txFamily == BLACKCOIN || (txFamily == REDDCOIN && version > 1)) {
txTime = new Date().getTime() / 1000; // time is in seconds
length += 4;
}
if (txFamily == NUBITS) {
txTokenId = params.getTokenId();
}
if (txFamily == NUBITS) {
txTokenId = params.getTokenId();
}
}

/**
Expand Down Expand Up @@ -531,7 +534,7 @@ protected int calcLength(byte[] buf, int offset) {
// jump past version (uint32)
int cursor = offset + 4;

if (Networks.isFamily(params, PEERCOIN, NUBITS, BLACKCOIN))
if (Networks.isFamily(params, PEERCOIN, NUBITS, RUBYCOIN, BLACKCOIN))
cursor += 4; // time (uint32)

int i;
Expand Down Expand Up @@ -564,11 +567,11 @@ protected int calcLength(byte[] buf, int offset) {
// 4 = length of lock_time field (uint32)
cursor += 4;

if (Networks.isFamily(params, REDDCOIN) && version > 1)
if (Networks.isFamily(params, CANNACOIN, REDDCOIN) && version > 1)
cursor += 4; // time (uint32)

if (Networks.isFamily(params, NUBITS))
cursor += 1; // token id
if (Networks.isFamily(params, NUBITS))
cursor += 1; // token id

return cursor - offset;
}
Expand All @@ -584,7 +587,7 @@ void parse() throws ProtocolException {
version = readUint32();
optimalEncodingMessageSize = 4;

if (Networks.isFamily(params, PEERCOIN, NUBITS, BLACKCOIN)) {
if (Networks.isFamily(params, PEERCOIN, NUBITS, RUBYCOIN, BLACKCOIN)) {
txTime = readUint32();
optimalEncodingMessageSize = +4;
}
Expand Down Expand Up @@ -614,15 +617,15 @@ void parse() throws ProtocolException {
lockTime = readUint32();
optimalEncodingMessageSize += 4;

if (Networks.isFamily(params, REDDCOIN) && version > 1) {
if (Networks.isFamily(params, CANNACOIN, REDDCOIN) && version > 1) {
txTime = readUint32();
optimalEncodingMessageSize = +4;
}

if (Networks.isFamily(params, NUBITS)) {
txTokenId = readBytes(1)[0];
optimalEncodingMessageSize++;
}
if (Networks.isFamily(params, NUBITS)) {
txTokenId = readBytes(1)[0];
optimalEncodingMessageSize++;
}

length = cursor - offset;
}
Expand All @@ -649,7 +652,7 @@ public boolean isCoinBase() {
}

public boolean isCoinStake() {
if (Networks.isFamily(params, PEERCOIN, NUBITS, BLACKCOIN, REDDCOIN)) {
if (Networks.isFamily(params, PEERCOIN, NUBITS, RUBYCOIN, CANNACOIN, BLACKCOIN, REDDCOIN)) {
maybeParse();
return inputs.size() > 0 && (!inputs.get(0).isCoinBase()) && outputs.size() >= 2 && outputs.get(0).isNull();
} else {
Expand Down Expand Up @@ -1067,7 +1070,7 @@ public synchronized Sha256Hash hashForSignature(int inputIndex, byte[] connected
}

ByteArrayOutputStream bos = new UnsafeByteArrayOutputStream(length == UNKNOWN_LENGTH ? 256 : length + 4);
if (Networks.isFamily(params, REDDCOIN))
if (Networks.isFamily(params, CANNACOIN, REDDCOIN))
bitcoinSerializeToStream(bos, false);
else
bitcoinSerialize(bos);
Expand Down Expand Up @@ -1098,7 +1101,7 @@ protected void bitcoinSerializeToStream(OutputStream stream) throws IOException

protected void bitcoinSerializeToStream(OutputStream stream, boolean includeExtensions) throws IOException {
uint32ToByteStreamLE(version, stream);
if (Networks.isFamily(params, PEERCOIN, NUBITS, BLACKCOIN) && includeExtensions)
if (Networks.isFamily(params, PEERCOIN, NUBITS, RUBYCOIN, BLACKCOIN) && includeExtensions)
uint32ToByteStreamLE(txTime, stream);
stream.write(new VarInt(inputs.size()).encode());
for (TransactionInput in : inputs)
Expand All @@ -1107,10 +1110,10 @@ protected void bitcoinSerializeToStream(OutputStream stream, boolean includeExte
for (TransactionOutput out : outputs)
out.bitcoinSerialize(stream);
uint32ToByteStreamLE(lockTime, stream);
if (Networks.isFamily(params, REDDCOIN) && version > 1 && includeExtensions)
uint32ToByteStreamLE(txTime, stream);
if (Networks.isFamily(params, NUBITS) && includeExtensions)
stream.write(txTokenId);
if (Networks.isFamily(params, CANNACOIN, REDDCOIN) && version > 1 && includeExtensions)
uint32ToByteStreamLE(txTime, stream);
if (Networks.isFamily(params, NUBITS) && includeExtensions)
stream.write(txTokenId);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/org/bitcoinj/core/TransactionOutput.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@

import static com.google.common.base.Preconditions.*;
import static com.google.common.base.Preconditions.checkState;
import static org.bitcoinj.params.Networks.Family.PEERCOIN;
import static org.bitcoinj.params.Networks.Family.REDDCOIN;
import static org.bitcoinj.params.Networks.Family.RUBYCOIN;
import static org.bitcoinj.params.Networks.Family.CANNACOIN;

/**
* A TransactionOutput message contains a scriptPubKey that controls who is able to spend its value. It is a sub-part
Expand Down
42 changes: 30 additions & 12 deletions core/src/main/java/org/bitcoinj/params/Networks.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,20 @@
public class Networks {
public enum Family {
BITCOIN,
PEERCOIN,
NUBITS,
BLACKCOIN,
REDDCOIN
RUBYCOIN,
CANNACOIN,
BLACKCOIN,
REDDCOIN,
PEERCOIN,
NUBITS
}

private static final Pattern cannacoinFamily = Pattern.compile(".*(cannacoin).*");
private static final Pattern rubycoinFamily = Pattern.compile(".*(rubycoin).*");
private static final Pattern blackcoinFamily = Pattern.compile(".*(blackcoin).*");
private static final Pattern reddcoinFamily = Pattern.compile(".*(reddcoin).*");
private static final Pattern peercoinFamily = Pattern.compile(".*(peercoin).*");
private static final Pattern nubitsFamily = Pattern.compile(".*(nubits|nushares).*");
private static final Pattern reddcoinFamily = Pattern.compile(".*(reddcoin).*");
private static final Pattern blackcoinFamily = Pattern.compile(".*(blackcoin).*");

/** Registered networks */
private static Set<NetworkParameters> networks = ImmutableSet.of(TestNet3Params.get(), MainNetParams.get());
Expand Down Expand Up @@ -93,20 +97,34 @@ public static boolean isFamily(NetworkParameters network, Family family1, Family
return networkFamily == family1 || networkFamily == family2 || networkFamily == family3 || networkFamily == family4;
}

public static boolean isFamily(NetworkParameters network, Family family1, Family family2, Family family3, Family family4, Family family5) {
Family networkFamily = getFamily(network);
return networkFamily == family1 || networkFamily == family2 || networkFamily == family3 || networkFamily == family4 || networkFamily == family5;
}

public static boolean isFamily(NetworkParameters network, Family family1, Family family2, Family family3, Family family4, Family family5, Family family6) {
Family networkFamily = getFamily(network);
return networkFamily == family1 || networkFamily == family2 || networkFamily == family3 || networkFamily == family4 || networkFamily == family5 || networkFamily == family6;
}

public static Family getFamily(NetworkParameters network) {
if (network == null || network.getId() == null) {
return Family.BITCOIN; // default is Bitcoin
}

if (peercoinFamily.matcher(network.getId()).matches()) {
return Family.PEERCOIN;
} else if (nubitsFamily.matcher(network.getId()).matches()) {
return Family.NUBITS;
if (rubycoinFamily.matcher(network.getId()).matches()) {
return Family.RUBYCOIN;
} else if (cannacoinFamily.matcher(network.getId()).matches()) {
return Family.CANNACOIN;
} else if (blackcoinFamily.matcher(network.getId()).matches()) {
return Family.BLACKCOIN;
} else if (reddcoinFamily.matcher(network.getId()).matches()) {
} else if (reddcoinFamily.matcher(network.getId()).matches()) {
return Family.REDDCOIN;
} else {
} else if (peercoinFamily.matcher(network.getId()).matches()) {
return Family.PEERCOIN;
} else if (nubitsFamily.matcher(network.getId()).matches()) {
return Family.NUBITS;
} else {
return Family.BITCOIN; // everything else is Bitcoin
}
}
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<groupId>org.bitcoinj</groupId>
<artifactId>bitcoinj-parent</artifactId>
<version>0.12.2-COINOMI</version>
<version>0.12.3-COINOMI</version>
<packaging>pom</packaging>

<modules>
Expand Down

0 comments on commit 4dbce44

Please sign in to comment.