Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/Fermat-ORG/fermat
Browse files Browse the repository at this point in the history
  • Loading branch information
nattyco committed Oct 5, 2016
2 parents e13651c + 65dd557 commit db8045a
Show file tree
Hide file tree
Showing 2,740 changed files with 20,403 additions and 26,009 deletions.
4 changes: 2 additions & 2 deletions BCH/library/api/fermat-bch-api/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ apply plugin: 'maven-publish'

sourceCompatibility = 1.7
group = "com.bitdubai.bch.api"
version = '4'
version = '2'

jar {
manifest {
attributes 'Implementation-Title': 'bch-api',
'Implementation-Version': '4'
'Implementation-Version': '1'
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
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/26/16.
*/
public class FermatFaucetManager {
/**
*
* @param blockchainNetworkType
* @param cryptoAddress
* @param amount
* @throws CantGetCoinsFromFaucetException
*/
public static void giveMeCoins(BlockchainNetworkType blockchainNetworkType, CryptoAddress cryptoAddress, long amount) throws CantGetCoinsFromFaucetException {
if (cryptoAddress.getCryptoCurrency() != CryptoCurrency.FERMAT)
throw new CantGetCoinsFromFaucetException(null, "Coins requested is not Fermat. This faucet only allows FER request.", "Wrong faucet manager selected.");



if (blockchainNetworkType == BlockchainNetworkType.PRODUCTION){
FermatMainNetFaucetManager mainNetFaucetManager = new FermatMainNetFaucetManager();
System.out.println("***FermatFaucet***requesting coins to faucet...");
mainNetFaucetManager.giveMeCoins(cryptoAddress, amount);
}

//add same behaviour for RegTestNetwork.

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package com.bitdubai.fermat_bch_api.layer.crypto_network.faucet;

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

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/26/16.
*/
public class FermatMainNetFaucetManager {
private final String FAUCET_IP = "52.27.68.19";
private final int FAUCET_PORT = 4499;


/**
*
* @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");


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.");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
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 @@ -179,12 +178,4 @@ 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);
}
Original file line number Diff line number Diff line change
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.getMnemonicCode(), null, "", vaultSeedGenerator.getCreationTimeSeconds());
DeterministicSeed seed = new DeterministicSeed(vaultSeedGenerator.getSeedBytes(), vaultSeedGenerator.getMnemonicCode(), vaultSeedGenerator.getCreationTimeSeconds());
seed.check();
return seed;
} catch (CantLoadExistingVaultSeed cantLoadExistingVaultSeed) {
Expand Down Expand Up @@ -293,29 +293,6 @@ 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.
}

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
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
*/
public enum HierarchyAccountType {
MASTER_ACCOUNT("MASTER"),
IMPORTED_ACCOUNT("IMPORTED"),
REDEEMPOINT_ACCOUNT("RPOINT");

private String code;
Expand All @@ -25,8 +24,6 @@ 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
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,9 @@
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 @@ -97,8 +95,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(MainNetParams.get());
DeterministicSeed seed = new DeterministicSeed(seedWallet.getKeyChainSeed().getMnemonicCode(), null, "", seedWallet.getKeyChainSeed().getCreationTimeSeconds());
Wallet seedWallet = new Wallet(BlockchainNetworkSelector.getNetworkParameter(BitcoinNetworkConfiguration.DEFAULT_NETWORK_TYPE));
DeterministicSeed seed = seedWallet.getKeyChainSeed();

/**
* I set the class values
Expand Down Expand Up @@ -230,7 +228,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 Down Expand Up @@ -266,32 +264,6 @@ public void importSeed(List<String> mnemonicCode, long seedCreationTimeSeconds)
}
}

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");


/**
* 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) {
throw new CantImportSeedException(cantCreateAssetVaultSeed, "unable to save new seed into disk.", "IO Error");
}
}


private void archiveNewSeed() throws CantCreateAssetVaultSeed {
int seedOrder = getNextSeedFileOrder();
Expand Down Expand Up @@ -358,7 +330,7 @@ public List<DeterministicSeed> getImportedSeeds() {
while (true){
try {
load(this.fileName + "_" + i);
DeterministicSeed importedSeed = new DeterministicSeed(this.mnemonicCode, null, "", this.creationTimeSeconds);
DeterministicSeed importedSeed = new DeterministicSeed(this.mnemonicCode, this.seedBytes, "", this.creationTimeSeconds);
importedSeedsList.add(importedSeed);

i++;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,12 @@ public interface CryptoVaultManager extends FermatManager, PlatformCryptoVault {
CryptoVaultSeed exportCryptoVaultSeed();

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


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

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ public enum CryptoVaults {
ASSETS_OVER_BITCOIN("AOB"),
BITCOIN_CURRENCY("BTC"),
BITCOIN_WATCH_ONLY("BWO"),
IMPORTED_SEED("IMS"),
FERMAT_CURRENCY("FER");


Expand All @@ -32,8 +31,6 @@ public static CryptoVaults getByCode(String code) throws InvalidParameterExcepti
return BITCOIN_CURRENCY;
case "BWO":
return BITCOIN_WATCH_ONLY;
case "IMS":
return IMPORTED_SEED;
case "FER":
return FERMAT_CURRENCY;
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
* Created by rodrigo on 7/2/16.
*/
public enum BitcoinFee {
SLOW(20000),
NORMAL(30000),
FAST(50000);
SLOW(2500),
NORMAL(4500),
FAST(8000);

private long fee;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

import com.bitdubai.fermat_api.layer.all_definition.exceptions.InvalidParameterException;

import java.io.Serializable;

/**
* Created by rodrigo on 7/2/16.
* Specifies from where the Fee will be taken. When sending crypto on a transaction, the fee can be deducted from the amount of crypto
Expand All @@ -12,7 +10,7 @@
* If the fee comes from the funds, then we are sending a total of 15000 satothis, 10000 to user and 5000 fee.
*/

public enum FeeOrigin implements Serializable {
public enum FeeOrigin {
SUBSTRACT_FEE_FROM_AMOUNT("AMOUNT"),
SUBSTRACT_FEE_FROM_FUNDS("FUNDS");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public void start() throws CantStartLayerException {
try {

registerPlugin(new BitcoinNetworkPluginSubsystem());
registerPlugin(new FermatNetworkPluginSubsystem(getFermatContext()));
//registerPlugin(new FermatNetworkPluginSubsystem(getFermatContext()));

} catch(CantRegisterPluginException e) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public void start() throws CantStartLayerException {
registerPlugin(new BitcoinAssetVaultPluginSubsystem());
registerPlugin(new BitcoinVaultPluginSubsystem());
registerPlugin(new BitcoinWatchOnlyVaultPluginSubsystem());
registerPlugin(new FermatVaultPluginSubsystem(getFermatContext()));
//registerPlugin(new FermatVaultPluginSubsystem(getFermatContext()));

} catch(CantRegisterPluginException e) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import com.bitdubai.fermat_api.layer.all_definition.enums.VaultType;
import com.bitdubai.fermat_api.layer.all_definition.money.CryptoAddress;
import com.bitdubai.fermat_api.layer.all_definition.util.Version;
import com.bitdubai.fermat_api.layer.core.PluginInfo;
import com.bitdubai.fermat_api.layer.osa_android.database_system.PluginDatabaseSystem;
import com.bitdubai.fermat_api.layer.osa_android.logger_system.LogLevel;
import com.bitdubai.fermat_api.layer.osa_android.logger_system.LogManager;
Expand Down Expand Up @@ -56,6 +55,7 @@
* <p/>
* Created by Leon Acosta (laion.cj91@gmail.com) on 02/09/2015.
*/

public class CryptoAddressBookCryptoModulePluginRoot extends AbstractPlugin implements
Crypto,
CryptoAddressBookManager,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,15 +217,6 @@ public void registerCryptoAddress(CryptoAddressBookRecord cryptoAddressBookRecor
throw new CantRegisterCryptoAddressBookRecordException(CantRegisterCryptoAddressBookRecordException.DEFAULT_MESSAGE, null, "", "cryptoAddressBookRecord, can not be null");
}

try {
CryptoAddressBookRecord existingRecord = getCryptoAddressBookRecordByCryptoAddress(cryptoAddressBookRecord.getCryptoAddress());
if (existingRecord != null)
// the record already exists, won't insert it.
return;
} catch (Exception e) {
//If there was an error, I will continue, because if it already exists, then I won't be able to insert it due to PK constraint.
}

try {
DatabaseTable cryptoAddressBookTable = database.getTable(CryptoAddressBookCryptoModuleDatabaseConstants.CRYPTO_ADDRESS_BOOK_TABLE_NAME);
DatabaseTableRecord entityRecord = buildDatabaseRecord(cryptoAddressBookTable.getEmptyRecord(), cryptoAddressBookRecord);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
import com.bitdubai.fermat_bch_api.layer.crypto_network.bitcoin.exceptions.CantGetBlockchainDownloadProgress;
import com.bitdubai.fermat_bch_api.layer.crypto_network.bitcoin.exceptions.CantGetBroadcastStatusException;
import com.bitdubai.fermat_bch_api.layer.crypto_network.bitcoin.exceptions.CantGetCryptoTransactionException;
import com.bitdubai.fermat_bch_api.layer.crypto_network.bitcoin.exceptions.CantGetImportedAddressesException;
import com.bitdubai.fermat_bch_api.layer.crypto_network.bitcoin.exceptions.CantGetTransactionCryptoStatusException;
import com.bitdubai.fermat_bch_api.layer.crypto_network.bitcoin.exceptions.CantMonitorCryptoNetworkException;
import com.bitdubai.fermat_bch_api.layer.crypto_network.bitcoin.exceptions.CantStoreTransactionException;
Expand Down Expand Up @@ -259,8 +258,4 @@ public BlockchainDownloadProgress getBlockchainDownloadProgress(BlockchainNetwor
return bitcoinCryptoNetworkManager.getBlockchainDownloadProgress(blockchainNetworkType);
}

@Override
public List<CryptoAddress> getImportedAddresses(BlockchainNetworkType blockchainNetworkType) {
return bitcoinCryptoNetworkManager.getImportedAddresses(blockchainNetworkType);
}
}
Loading

0 comments on commit db8045a

Please sign in to comment.