Skip to content

Commit

Permalink
Merge pull request #6431 from nattyco/develop
Browse files Browse the repository at this point in the history
Last code version
  • Loading branch information
nattyco committed Oct 18, 2016
2 parents 65dd557 + 09d7ce5 commit 6be736d
Show file tree
Hide file tree
Showing 2,949 changed files with 77,566 additions and 71,905 deletions.
Expand Up @@ -24,7 +24,7 @@
/**
* Created by Gabriel Araujo (gabe_512@hotmail.com) on 08/04/16.
*/
public class ArtistCommunityNavigationViewPainter implements NavigationViewPainter {
public class ArtistCommunityNavigationViewPainter extends NavigationViewPainter {

private WeakReference<Context> activity;
private ActiveActorIdentityInformation actorIdentity;
Expand Down
Expand Up @@ -25,7 +25,7 @@
/**
* Created by Manuel Perez (darkpriestrelative@gmail.com) on 05/04/16.
*/
public class FanCommunityNavigationViewPainter implements NavigationViewPainter {
public class FanCommunityNavigationViewPainter extends NavigationViewPainter {

private WeakReference<Context> activity;
private ActiveActorIdentityInformation actorIdentity;
Expand Down
4 changes: 3 additions & 1 deletion BCH/library/api/fermat-bch-api/build.gradle
Expand Up @@ -16,7 +16,9 @@ jar {

dependencies {
// compile fileTree(dir: 'libs', include: ['*.jar'])
compile project(':fermat-api') }
// compile project(':fermat-api')
compile project(':fermat-pip-api')
}

task bchApiFatJar(type: Jar) {
manifest {
Expand Down
@@ -0,0 +1,18 @@
package com.bitdubai.fermat_bch_api.layer.crypto_network.bitcoin.exceptions;

import com.bitdubai.fermat_api.FermatException;

/**
* Created by rodrigo on 7/13/16.
*/
public class CantGetImportedAddressesException extends FermatException {
public static final String DEFAULT_MESSAGE = "There was an error getting the list of imported addresses";

public CantGetImportedAddressesException(Exception cause, String context, String possibleReason) {
super(DEFAULT_MESSAGE, cause, context, possibleReason);
}

public CantGetImportedAddressesException(String message, Exception cause, String context, String possibleReason) {
super(message, cause, context, possibleReason);
}
}
@@ -0,0 +1,35 @@
package com.bitdubai.fermat_bch_api.layer.crypto_network.bitcoin.exceptions;

import com.bitdubai.fermat_api.FermatException;

/**
* Created by rodrigo on 7/15/16.
*/
public class NetworkMonitorIsNotRunningException extends FermatException {

private static final String DEFAULT_MESSAGE = "The crypto network monitor is not running for the specified network.";

private static final String DEFAULT_REASON = "The network is not activated or is being reset just now.";

private static final String DEFAULT_CONTEXT = "CryptoNetworkManager";

public NetworkMonitorIsNotRunningException() {
super(DEFAULT_MESSAGE, null, DEFAULT_CONTEXT, DEFAULT_REASON);
}

public NetworkMonitorIsNotRunningException(String context) {
super(DEFAULT_MESSAGE, null, context, DEFAULT_REASON);
}

public NetworkMonitorIsNotRunningException(Exception cause, String context) {
super(DEFAULT_MESSAGE, cause, context, DEFAULT_REASON);
}

public NetworkMonitorIsNotRunningException(String context, String possibleReason) {
super(DEFAULT_MESSAGE, null, context, possibleReason);
}

public NetworkMonitorIsNotRunningException(String message, Exception cause, String context, String possibleReason) {
super(message, cause, context, possibleReason);
}
}
@@ -0,0 +1,34 @@
package com.bitdubai.fermat_bch_api.layer.crypto_network.faucet;

import com.bitdubai.fermat_api.layer.all_definition.enums.BlockchainNetworkType;
import com.bitdubai.fermat_api.layer.all_definition.enums.CryptoCurrency;
import com.bitdubai.fermat_api.layer.all_definition.money.CryptoAddress;

/**
* Created by rodrigo on 7/11/16.
*/
public class BitcoinFaucetManager {

/**
*
* @param blockchainNetworkType
* @param cryptoAddress
* @param amount
* @throws CantGetCoinsFromFaucetException
*/
public static void giveMeCoins(BlockchainNetworkType blockchainNetworkType, CryptoAddress cryptoAddress, long amount) throws CantGetCoinsFromFaucetException {
if (cryptoAddress.getCryptoCurrency() != CryptoCurrency.BITCOIN)
throw new CantGetCoinsFromFaucetException(null, "Coins requested is not Bitcoin. This faucet only allows BTC request.", "Wrong faucet manager selected.");



if (blockchainNetworkType == BlockchainNetworkType.TEST_NET){
BitcoinTestNetFaucetManager testNetFaucetManager = new BitcoinTestNetFaucetManager();
System.out.println("***BitcoinFaucet***requesting coins to faucet...");
testNetFaucetManager.giveMeCoins(cryptoAddress, amount);
}

//add same behaviour for RegTestNetwork.

}
}
@@ -0,0 +1,75 @@
package com.bitdubai.fermat_bch_api.layer.crypto_network.faucet;

import com.bitdubai.fermat_api.layer.all_definition.money.CryptoAddress;

import org.bitcoinj.core.Address;
import org.bitcoinj.core.AddressFormatException;
import org.bitcoinj.core.Coin;
import org.bitcoinj.params.TestNet3Params;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.net.SocketAddress;

/**
* Created by rodrigo on 7/11/16.
*/
public class BitcoinTestNetFaucetManager {

private final String FAUCET_IP = "52.27.68.19";
private final int FAUCET_PORT = 4488;


/**
*
* @param cryptoAddress
* @param amount
* @throws CantGetCoinsFromFaucetException
*/
public void giveMeCoins(CryptoAddress cryptoAddress, long amount) throws CantGetCoinsFromFaucetException {
if (cryptoAddress == null)
throw new CantGetCoinsFromFaucetException(null, "Address can't be null", "invalid parameters");

if (!isAddressValid(cryptoAddress))
throw new CantGetCoinsFromFaucetException(null, "Address is not valid on TestNet network.", cryptoAddress.getAddress());

if (amount == 0)
amount = Coin.COIN.getValue();

Socket faucetSocket = null;
DataOutputStream os = null;
DataInputStream is = null;

try {
SocketAddress faucetServer = new InetSocketAddress(FAUCET_IP, FAUCET_PORT);
faucetSocket = new Socket(FAUCET_IP, FAUCET_PORT);

os = new DataOutputStream(faucetSocket.getOutputStream());
is = new DataInputStream(faucetSocket.getInputStream());

if (faucetSocket != null && os != null && is != null) {

os.writeBytes(cryptoAddress.getAddress() + "\n");
os.writeBytes(String.valueOf(amount) + "\n");

os.close();
is.close();
faucetSocket.close();
}
} catch (Exception e) {
throw new CantGetCoinsFromFaucetException(e, "error requesting coins to faucet." , "cant connect.");
}
}

private boolean isAddressValid(CryptoAddress cryptoAddress) {
try {
Address address = new Address(TestNet3Params.get(), cryptoAddress.getAddress());
} catch (AddressFormatException e) {
return false;
}
return true;
}

}
@@ -0,0 +1,19 @@
package com.bitdubai.fermat_bch_api.layer.crypto_network.faucet;

import com.bitdubai.fermat_api.FermatException;

/**
* Created by rodrigo on 7/11/16.
*/
public class CantGetCoinsFromFaucetException extends FermatException {
public static final String DEFAULT_MESSAGE = "There was an error getting the requested coins from the faucet";


public CantGetCoinsFromFaucetException(String message, Exception cause, String context, String possibleReason) {
super(message, cause, context, possibleReason);
}

public CantGetCoinsFromFaucetException(Exception cause, String context, String possibleReason) {
super(DEFAULT_MESSAGE, cause, context, possibleReason);
}
}
Expand Up @@ -6,6 +6,7 @@
import com.bitdubai.fermat_api.layer.all_definition.transaction_transference_protocol.crypto_transactions.CryptoStatus;
import com.bitdubai.fermat_api.layer.all_definition.transaction_transference_protocol.crypto_transactions.CryptoTransaction;
import com.bitdubai.fermat_api.layer.all_definition.transaction_transference_protocol.crypto_transactions.CryptoTransactionType;
import com.bitdubai.fermat_bch_api.layer.crypto_network.bitcoin.exceptions.CantGetImportedAddressesException;
import com.bitdubai.fermat_bch_api.layer.crypto_network.util.BlockchainConnectionStatus;
import com.bitdubai.fermat_bch_api.layer.crypto_network.util.BlockchainDownloadProgress;
import com.bitdubai.fermat_bch_api.layer.crypto_network.util.BroadcastStatus;
Expand Down Expand Up @@ -178,4 +179,12 @@ public interface BlockchainManager <T1, T2> extends TransactionSender<CryptoTran
BlockchainDownloadProgress getBlockchainDownloadProgress(BlockchainNetworkType blockchainNetworkType) throws CantGetBlockchainDownloadProgress;


/**
* When a seed is imported into a vault, a bunch of addresses are generated from that seed.
* This method returns that list if any.
* @param blockchainNetworkType the network to get the list from.
* @return a list of CryptoAddresses
* @throws CantGetImportedAddressesException
*/
List<CryptoAddress> getImportedAddresses(BlockchainNetworkType blockchainNetworkType);
}
Expand Up @@ -249,7 +249,7 @@ public DeterministicSeed getVaultSeed() throws InvalidSeedException{
vaultSeedGenerator.load(CRYPTO_VAULT_SEED_FILENAME);
} else
vaultSeedGenerator.load(CRYPTO_VAULT_SEED_FILENAME);
DeterministicSeed seed = new DeterministicSeed(vaultSeedGenerator.getSeedBytes(), vaultSeedGenerator.getMnemonicCode(), vaultSeedGenerator.getCreationTimeSeconds());
DeterministicSeed seed = new DeterministicSeed(vaultSeedGenerator.getMnemonicCode(), null, "", vaultSeedGenerator.getCreationTimeSeconds());
seed.check();
return seed;
} catch (CantLoadExistingVaultSeed cantLoadExistingVaultSeed) {
Expand Down Expand Up @@ -293,6 +293,30 @@ public void importSeedFromMnemonicCode(String mNemonicCode, long seedCreationTim
* @throws CantImportSeedException
*/
public void importSeedFromMnemonicCode(List<String> mNemonicCode, long seedCreationTimeInSeconds) throws CantImportSeedException{
//Make sure we are not importing the same seed we are currently using.
try {
DeterministicSeed currentSeed = this.getVaultSeed();
if (currentSeed.getCreationTimeSeconds() == seedCreationTimeInSeconds && currentSeed.getMnemonicCode().equals(mNemonicCode))
throw new CantImportSeedException(null, "Seed to be imported is the same as the actual seed we are using.", "User input error");
} catch (InvalidSeedException e) {
//if for some reason I couldn't get it, I will continue.
System.out.println("--- importSeedFromMnemonicCode ERROR InvalidSeedException ---");
}

VaultSeedGenerator vaultSeedGenerator = new VaultSeedGenerator(this.pluginFileSystem, this.pluginId, CRYPTO_VAULT_SEED_FILEPATH, CRYPTO_VAULT_SEED_FILENAME);
vaultSeedGenerator.importSeed(mNemonicCode, seedCreationTimeInSeconds);
}

public void importSeedFromMnemonicCode(List<String> mNemonicCode, long seedCreationTimeInSeconds, byte[] bytes) throws CantImportSeedException{
//Make sure we are not importing the same seed we are currently using.
try {
DeterministicSeed currentSeed = this.getVaultSeed();
if (currentSeed.getCreationTimeSeconds() == seedCreationTimeInSeconds && currentSeed.getMnemonicCode().equals(mNemonicCode))
throw new CantImportSeedException(null, "Seed to be imported is the same as the actual seed we are using.", "User input error");
} catch (InvalidSeedException e) {
//if for some reason I couldn't get it, I will continue.
}

VaultSeedGenerator vaultSeedGenerator = new VaultSeedGenerator(this.pluginFileSystem, this.pluginId, CRYPTO_VAULT_SEED_FILEPATH, CRYPTO_VAULT_SEED_FILENAME);
vaultSeedGenerator.importSeed(mNemonicCode, seedCreationTimeInSeconds);
}
Expand Down
Expand Up @@ -7,6 +7,7 @@
*/
public enum HierarchyAccountType {
MASTER_ACCOUNT("MASTER"),
IMPORTED_ACCOUNT("IMPORTED"),
REDEEMPOINT_ACCOUNT("RPOINT");

private String code;
Expand All @@ -24,6 +25,8 @@ public static HierarchyAccountType getByCode(String code) throws InvalidParamete
switch (code) {
case "MASTER":
return MASTER_ACCOUNT;
case "IMPORTED":
return IMPORTED_ACCOUNT;
case "RPOINT":
return REDEEMPOINT_ACCOUNT;
default:
Expand Down
Expand Up @@ -17,9 +17,11 @@
import com.bitdubai.fermat_bch_api.layer.crypto_vault.exceptions.CantImportSeedException;
import com.google.common.base.Splitter;

import org.apache.commons.codec.binary.Hex;
import org.bitcoinj.core.Wallet;
import org.bitcoinj.crypto.MnemonicCode;
import org.bitcoinj.crypto.MnemonicException;
import org.bitcoinj.params.MainNetParams;
import org.bitcoinj.store.UnreadableWalletException;
import org.bitcoinj.wallet.DeterministicSeed;

Expand Down Expand Up @@ -95,8 +97,8 @@ public void create() throws CantCreateAssetVaultSeed {
/**
* The Wallet class of bitcoinJ has a great entrophy level to generate a random seed.
*/
Wallet seedWallet = new Wallet(BlockchainNetworkSelector.getNetworkParameter(BitcoinNetworkConfiguration.DEFAULT_NETWORK_TYPE));
DeterministicSeed seed = seedWallet.getKeyChainSeed();
Wallet seedWallet = new Wallet(MainNetParams.get());
DeterministicSeed seed = new DeterministicSeed(seedWallet.getKeyChainSeed().getMnemonicCode(), null, "", seedWallet.getKeyChainSeed().getCreationTimeSeconds());

/**
* I set the class values
Expand Down Expand Up @@ -228,7 +230,7 @@ public static String getmNemonicAsString(List<String> mnemonicCode){
}

//remove the last space
return phrase.substring(0, phrase.length()-1);
return phrase.substring(0, phrase.length() - 1);
}


Expand All @@ -242,6 +244,37 @@ public void importSeed(List<String> mnemonicCode, long seedCreationTimeSeconds)
DeterministicSeed importedSeed = null;
importedSeed = new DeterministicSeed(mnemonicCode, null, "", seedCreationTimeSeconds);

if (!isSeedValid(importedSeed))
{
System.out.println("--- Import Seed ERROR --- Importing new seed from incorrect seed format");
throw new CantImportSeedException(null, "Importing new seed from " + mnemonicCode, "incorrect seed format");
}



/**
* I set the seed values of the class
*/
this.mnemonicCode = importedSeed.getMnemonicCode();
this.creationTimeSeconds = importedSeed.getCreationTimeSeconds();
this.seedBytes = importedSeed.getSeedBytes();

/**
* and Store the new seed.
*/
try {
String newSeedFileName = this.fileName + "_" + this.getNextSeedFileOrder();
storeSeedInFile(newSeedFileName);
} catch (CantCreateAssetVaultSeed cantCreateAssetVaultSeed) {
System.err.println("--- CantCreateAssetVaultSeed ERROR ---");
throw new CantImportSeedException(cantCreateAssetVaultSeed, "unable to save new seed into disk.", "IO Error");
}
}

public void importSeed(List<String> mnemonicCode, long seedCreationTimeSeconds, byte[] bytes) throws CantImportSeedException{
DeterministicSeed importedSeed = null;
importedSeed = new DeterministicSeed(mnemonicCode, bytes, "", seedCreationTimeSeconds);

if (!isSeedValid(importedSeed))
throw new CantImportSeedException(null, "Importing new seed from " + mnemonicCode, "incorrect seed format");

Expand Down Expand Up @@ -330,7 +363,7 @@ public List<DeterministicSeed> getImportedSeeds() {
while (true){
try {
load(this.fileName + "_" + i);
DeterministicSeed importedSeed = new DeterministicSeed(this.mnemonicCode, this.seedBytes, "", this.creationTimeSeconds);
DeterministicSeed importedSeed = new DeterministicSeed(this.mnemonicCode, null, "", this.creationTimeSeconds);
importedSeedsList.add(importedSeed);

i++;
Expand Down
Expand Up @@ -84,12 +84,14 @@ public interface CryptoVaultManager extends FermatManager, PlatformCryptoVault {
CryptoVaultSeed exportCryptoVaultSeed();

/**
* Imports the passed seed into the vault.
* @param mnemonicCode the mnemonic Code passed by the user
* @param date the date this seed was generated.
* * Imports the passed seed into the vault.
* @param destinationAddress
* @param blockchainNetworkType
* @param mnemonicCode
* @param date
* @throws CantImportSeedException
*/
void importSeedFromMnemonicCode(List<String> mnemonicCode,long date) throws CantImportSeedException;
void importSeedFromMnemonicCode(CryptoAddress destinationAddress, BlockchainNetworkType blockchainNetworkType, List<String> mnemonicCode,long date) throws CantImportSeedException;


/**
Expand Down Expand Up @@ -125,4 +127,5 @@ public interface CryptoVaultManager extends FermatManager, PlatformCryptoVault {
* @throws CantStoreBitcoinTransactionException
*/
void saveTransaction(DraftTransaction draftTransaction) throws CantStoreBitcoinTransactionException;

}

0 comments on commit 6be736d

Please sign in to comment.