Skip to content

Commit

Permalink
initial ShapeShift integration
Browse files Browse the repository at this point in the history
  • Loading branch information
erasmospunk committed Apr 9, 2015
1 parent a049eb3 commit e346227
Show file tree
Hide file tree
Showing 124 changed files with 5,840 additions and 1,307 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ To release the app follow the steps.
* in build.gradle the package from "com.coinomi.wallet.dev" to "com.coinomi.wallet"
* in AndroidManifest.xml the android:icon to "ic_launcher" and all "com.coinomi.wallet.dev.*" to "com.coinomi.wallet.*"
* remove all ic_launcher_dev icons with `rm wallet/src/main/res/drawable*/ic_launcher_dev.png`
* setup ACRA
* setup ACRA and ShapeShift

2) Then in the Android Studio go to:

Expand Down
5 changes: 3 additions & 2 deletions core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,22 @@ dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])

compile 'com.google.guava:guava:17.0'
// compile 'com.google:bitcoinj:0.11.2'
compile 'com.google.code.findbugs:jsr305:1.3.9'
compile 'com.madgag.spongycastle:core:1.51.0.0'

compile 'com.lambdaworks:scrypt:1.4.0'

compile 'com.google.protobuf:protobuf-java:2.5.0'
// compile 'net.jcip:jcip-annotations:1.0'
compile 'org.slf4j:slf4j-jdk14:1.7.6'

// compile 'org.json:json:20140107'
compile 'org.json:json:20080701'

compile 'com.squareup.okhttp:okhttp:2.3.0'

testCompile 'junit:junit:4.11'
testCompile 'org.mockito:mockito-all:1.9.5'
testCompile 'com.squareup.okhttp:mockwebserver:2.3.0'
}

sourceSets {
Expand Down
Binary file not shown.
6 changes: 3 additions & 3 deletions core/src/main/java/com/coinomi/core/coins/BitcoinMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ private BitcoinMain() {
uriScheme = "bitcoin";
bip44Index = 0;
unitExponent = 8;
feePerKb = Coin.valueOf(10000);
minNonDust = Coin.valueOf(5460);
softDustLimit = Coin.valueOf(1000000); // 0.01 BTC
feePerKb = value(10000);
minNonDust = value(5460);
softDustLimit = value(1000000); // 0.01 BTC
softDustPolicy = SoftDustPolicy.AT_LEAST_BASE_FEE_IF_SOFT_DUST_TXO_PRESENT;
}

Expand Down
8 changes: 4 additions & 4 deletions core/src/main/java/com/coinomi/core/coins/BitcoinTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ private BitcoinTest() {
dumpedPrivateKeyHeader = 239;

name = "Bitcoin Test";
symbol = "BTCTEST";
symbol = "BTCt";
uriScheme = "bitcoin";
bip44Index = 1;
unitExponent = 8;
feePerKb = Coin.valueOf(10000);
minNonDust = Coin.valueOf(5460);
softDustLimit = Coin.valueOf(1000000); // 0.01 BTC
feePerKb = value(10000);
minNonDust = value(5460);
softDustLimit = value(1000000); // 0.01 BTC
softDustPolicy = SoftDustPolicy.AT_LEAST_BASE_FEE_IF_SOFT_DUST_TXO_PRESENT;
}

Expand Down
6 changes: 3 additions & 3 deletions core/src/main/java/com/coinomi/core/coins/BlackcoinMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ private BlackcoinMain() {
uriScheme = "blackcoin";
bip44Index = 10;
unitExponent = 8;
feePerKb = Coin.valueOf(10000); // 0.0001 BLK
minNonDust = Coin.valueOf(1);
softDustLimit = Coin.valueOf(1000000); // 0.01 BLK
feePerKb = value(10000); // 0.0001 BLK
minNonDust = value(1);
softDustLimit = value(1000000); // 0.01 BLK
softDustPolicy = SoftDustPolicy.AT_LEAST_BASE_FEE_IF_SOFT_DUST_TXO_PRESENT;
}

Expand Down
6 changes: 3 additions & 3 deletions core/src/main/java/com/coinomi/core/coins/CannacoinMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ private CannacoinMain() {
uriScheme = "cannacoin";
bip44Index = 19;
unitExponent = 8;
feePerKb = Coin.valueOf(100000);
minNonDust = Coin.valueOf(1000000);
softDustLimit = Coin.valueOf(100000000);
feePerKb = value(100000);
minNonDust = value(1000000);
softDustLimit = value(100000000);
softDustPolicy = SoftDustPolicy.BASE_FEE_FOR_EACH_SOFT_DUST_TXO;
}

Expand Down
51 changes: 28 additions & 23 deletions core/src/main/java/com/coinomi/core/coins/CoinID.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.coinomi.core.uri.CoinURIParseException;
import com.google.common.collect.ImmutableList;

import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
Expand All @@ -36,8 +37,10 @@ public enum CoinID {
URO_MAIN(UroMain.get()),
DIGITALCOIN_MAIN(DigitalcoinMain.get()),
CANNACOIN_MAIN(CannacoinMain.get()),
DIGIBYTE_MAIN(DigibyteMain.get())
;
DIGIBYTE_MAIN(DigibyteMain.get()),;

private static HashMap<String, CoinType> idLookup = new HashMap<>();
private static HashMap<String, CoinType> symbolLookup = new HashMap<>();

static {
Set<NetworkParameters> bitcoinjNetworks = Networks.get();
Expand All @@ -49,14 +52,18 @@ public enum CoinID {
Networks.register(id.type);
}

// Test if currency codes are unique
HashSet<String> codes = new HashSet<>();
for (CoinID id : values()) {
if (codes.contains(id.type.symbol)) {
if (symbolLookup.containsKey(id.type.symbol)) {
throw new IllegalStateException(
"Coin currency codes must be unique, double found: " + id.type.symbol);
}
codes.add(id.type.symbol);
symbolLookup.put(id.type.symbol, id.type);

if (idLookup.containsKey(id.type.getId())) {
throw new IllegalStateException(
"Coin IDs must be unique, double found: " + id.type.getId());
}
idLookup.put(id.type.getId(), id.type);
}
}

Expand All @@ -76,29 +83,22 @@ public CoinType getCoinType() {
}

public static List<CoinType> getSupportedCoins() {
ImmutableList.Builder<CoinType> builder = ImmutableList.builder();
for (CoinID id : values()) {
builder.add(id.type);
}
return builder.build();
return ImmutableList.copyOf(idLookup.values());
}

public static CoinType typeFromId(String stringId) {
return fromId(stringId).type;
}

public static CoinID fromId(String stringId) {
for(CoinID id : values()) {
if (id.type.getId().equalsIgnoreCase(stringId)) return id;
if (idLookup.containsKey(stringId)) {
return idLookup.get(stringId);
} else {
throw new IllegalArgumentException("Unsupported ID: " + stringId);
}
throw new IllegalArgumentException("Unsupported ID: " + stringId);
}

public static CoinID fromUri(String input) {
for(CoinID id : values()) {
for (CoinID id : values()) {
if (input.startsWith(id.getCoinType().getUriScheme() + "://")) {
return id;
} else if (input.startsWith(id.getCoinType().getUriScheme()+":")) {
} else if (input.startsWith(id.getCoinType().getUriScheme() + ":")) {
return id;
}
}
Expand All @@ -114,10 +114,15 @@ public static CoinType typeFromAddress(String address) throws AddressFormatExcep
}
}

public static boolean isSymbolSupported(String symbol) {
return symbolLookup.containsKey(symbol);
}

public static CoinType typeFromSymbol(String symbol) {
for(CoinID id : values()) {
if (id.type.getSymbol().equalsIgnoreCase(symbol)) return id.type;
if (symbolLookup.containsKey(symbol.toUpperCase())) {
return symbolLookup.get(symbol.toUpperCase());
} else {
throw new IllegalArgumentException("Unsupported coin symbol: " + symbol);
}
throw new IllegalArgumentException("Unsupported coin symbol: " + symbol);
}
}
51 changes: 44 additions & 7 deletions core/src/main/java/com/coinomi/core/coins/CoinType.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

import com.coinomi.core.util.MonetaryFormat;

import org.bitcoinj.core.Address;
import org.bitcoinj.core.AddressFormatException;
import org.bitcoinj.core.Coin;
import org.bitcoinj.core.NetworkParameters;
import org.bitcoinj.crypto.ChildNumber;
Expand All @@ -28,14 +30,14 @@ abstract public class CoinType extends NetworkParameters implements ValueType, S
protected String uriScheme;
protected Integer bip44Index;
protected Integer unitExponent;
protected Coin feePerKb;
protected Coin minNonDust;
protected Coin softDustLimit;
protected Value feePerKb;
protected Value minNonDust;
protected Value softDustLimit;
protected SoftDustPolicy softDustPolicy;

private MonetaryFormat friendlyFormat;
private MonetaryFormat plainFormat;
private Value oneCoin;
private transient MonetaryFormat friendlyFormat;
private transient MonetaryFormat plainFormat;
private transient Value oneCoin;

@Override
public String getName() {
Expand All @@ -60,15 +62,31 @@ public int getUnitExponent() {
return checkNotNull(unitExponent, "A coin failed to set a unit exponent");
}

@Deprecated
public Coin getFeePerKb() {
return feePerKb().toCoin();
}

public Value feePerKb() {
return checkNotNull(feePerKb, "A coin failed to set a fee per kilobyte");
}

@Deprecated
public Coin getMinNonDust() {
return minNonDust().toCoin();
}

@Override
public Value minNonDust() {
return checkNotNull(minNonDust, "A coin failed to set a minimum amount to be considered not dust");
}

@Deprecated
public Coin getSoftDustLimit() {
return softDustLimit().toCoin();
}

public Value softDustLimit() {
return checkNotNull(softDustLimit, "A coin failed to set a soft dust limit");
}

Expand All @@ -81,6 +99,10 @@ public List<ChildNumber> getBip44Path(int account) {
return HDUtils.parsePath(path);
}

public Address address(String addressStr) throws AddressFormatException {
return new Address(this, addressStr);
}

/**
* Returns a 1 coin of this type with the correct amount of units (satoshis)
* Use {@link com.coinomi.core.coins.CoinType:oneCoin}
Expand All @@ -100,6 +122,21 @@ public Value oneCoin() {
return oneCoin;
}

@Override
public Value value(String string) {
return Value.parse(this, string);
}

@Override
public Value value(Coin coin) {
return Value.valueOf(this, coin);
}

@Override
public Value value(long units) {
return Value.valueOf(this, units);
}

@Override
public String getPaymentProtocolId() {
throw new RuntimeException("Method not implemented");
Expand All @@ -118,7 +155,7 @@ public String toString() {
public MonetaryFormat getMonetaryFormat() {
if (friendlyFormat == null) {
friendlyFormat = new MonetaryFormat()
.shift(0).minDecimals(2).noCode().code(0, symbol).postfixCode();
.shift(0).minDecimals(2).code(0, symbol).postfixCode();
switch (unitExponent) {
case 8:
friendlyFormat = friendlyFormat.optionalDecimals(2, 2, 2);
Expand Down
6 changes: 3 additions & 3 deletions core/src/main/java/com/coinomi/core/coins/DarkcoinMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ private DarkcoinMain() {
uriScheme = "darkcoin";
bip44Index = 5;
unitExponent = 8;
feePerKb = Coin.valueOf(100000);
minNonDust = Coin.valueOf(1000); // 0.00001 DRK mininput
softDustLimit = Coin.valueOf(100000); // 0.001 DRK
feePerKb = value(100000);
minNonDust = value(1000); // 0.00001 DRK mininput
softDustLimit = value(100000); // 0.001 DRK
softDustPolicy = SoftDustPolicy.BASE_FEE_FOR_EACH_SOFT_DUST_TXO;
}

Expand Down
6 changes: 3 additions & 3 deletions core/src/main/java/com/coinomi/core/coins/DarkcoinTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ private DarkcoinTest() {
uriScheme = "darkcoin";
bip44Index = 1;
unitExponent = 8;
feePerKb = Coin.valueOf(100000);
minNonDust = Coin.valueOf(1000); // 0.00001 DRK mininput
softDustLimit = Coin.valueOf(100000); // 0.001 DRK
feePerKb = value(100000);
minNonDust = value(1000); // 0.00001 DRK mininput
softDustLimit = value(100000); // 0.001 DRK
softDustPolicy = SoftDustPolicy.BASE_FEE_FOR_EACH_SOFT_DUST_TXO;
}

Expand Down
6 changes: 3 additions & 3 deletions core/src/main/java/com/coinomi/core/coins/DigibyteMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ private DigibyteMain() {
uriScheme = "digibyte";
bip44Index = 20;
unitExponent = 8;
feePerKb = Coin.valueOf(10000);
minNonDust = Coin.valueOf(5460);
softDustLimit = Coin.valueOf(100000);
feePerKb = value(10000);
minNonDust = value(5460);
softDustLimit = value(100000);
softDustPolicy = SoftDustPolicy.BASE_FEE_FOR_EACH_SOFT_DUST_TXO;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ private DigitalcoinMain() {
uriScheme = "digitalcoin";
bip44Index = 18;
unitExponent = 8;
feePerKb = Coin.valueOf(10000); // 0.0001 DGC
minNonDust = Coin.valueOf(1);
softDustLimit = Coin.valueOf(1000000); // 0.01 DGC
feePerKb = value(10000); // 0.0001 DGC
minNonDust = value(1);
softDustLimit = value(1000000); // 0.01 DGC
softDustPolicy = SoftDustPolicy.BASE_FEE_FOR_EACH_SOFT_DUST_TXO;
}

Expand Down
6 changes: 3 additions & 3 deletions core/src/main/java/com/coinomi/core/coins/DogecoinMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ private DogecoinMain() {
uriScheme = "dogecoin";
bip44Index = 3;
unitExponent = 8;
feePerKb = Coin.valueOf(100000000L);
minNonDust = Coin.valueOf(1);
softDustLimit = Coin.valueOf(100000000L); // 1 DOGE
feePerKb = value(100000000L);
minNonDust = value(1);
softDustLimit = value(100000000L); // 1 DOGE
softDustPolicy = SoftDustPolicy.BASE_FEE_FOR_EACH_SOFT_DUST_TXO;
}

Expand Down
8 changes: 4 additions & 4 deletions core/src/main/java/com/coinomi/core/coins/DogecoinTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ private DogecoinTest() {
spendableCoinbaseDepth = 240; // COINBASE_MATURITY_NEW

name = "Dogecoin Test";
symbol = "DOGETEST";
symbol = "DOGEt";
uriScheme = "dogecoin";
bip44Index = 1;
unitExponent = 8;
feePerKb = Coin.valueOf(100000000L);
minNonDust = Coin.valueOf(1);
softDustLimit = Coin.valueOf(100000000L); // 1 DOGE
feePerKb = value(100000000L);
minNonDust = value(1);
softDustLimit = value(100000000L); // 1 DOGE
softDustPolicy = SoftDustPolicy.BASE_FEE_FOR_EACH_SOFT_DUST_TXO;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ private FeathercoinMain() {
uriScheme = "feathercoin";
bip44Index = 8;
unitExponent = 8;
feePerKb = Coin.valueOf(2000000);
minNonDust = Coin.valueOf(1000); // 0.00001 FTC mininput
softDustLimit = Coin.valueOf(100000); // 0.001 FTC
feePerKb = value(2000000);
minNonDust = value(1000); // 0.00001 FTC mininput
softDustLimit = value(100000); // 0.001 FTC
softDustPolicy = SoftDustPolicy.BASE_FEE_FOR_EACH_SOFT_DUST_TXO;
}

Expand Down
Loading

0 comments on commit e346227

Please sign in to comment.