Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6431 from nattyco/develop
Last code version
- Loading branch information
Showing
2,949 changed files
with
77,566 additions
and
71,905 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
...at_bch_api/layer/crypto_network/bitcoin/exceptions/CantGetImportedAddressesException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
..._bch_api/layer/crypto_network/bitcoin/exceptions/NetworkMonitorIsNotRunningException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
...in/java/com/bitdubai/fermat_bch_api/layer/crypto_network/faucet/BitcoinFaucetManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. | ||
|
||
} | ||
} |
75 changes: 75 additions & 0 deletions
75
.../com/bitdubai/fermat_bch_api/layer/crypto_network/faucet/BitcoinTestNetFaucetManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
|
||
} |
19 changes: 19 additions & 0 deletions
19
.../bitdubai/fermat_bch_api/layer/crypto_network/faucet/CantGetCoinsFromFaucetException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.