This repository has been archived by the owner on Feb 8, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
242 additions
and
36 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
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
27 changes: 27 additions & 0 deletions
27
src/main/java/io/keyko/nevermined/api/helper/AccountsHelper.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,27 @@ | ||
package io.keyko.nevermined.api.helper; | ||
|
||
import org.web3j.crypto.CipherException; | ||
import org.web3j.crypto.WalletUtils; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.security.InvalidAlgorithmParameterException; | ||
import java.security.NoSuchAlgorithmException; | ||
import java.security.NoSuchProviderException; | ||
|
||
public abstract class AccountsHelper { | ||
|
||
public static String createAccount(String password, String destination) throws NoSuchAlgorithmException, NoSuchProviderException, InvalidAlgorithmParameterException, CipherException, IOException { | ||
return WalletUtils.generateNewWalletFile(password, new File(destination)); | ||
} | ||
|
||
public static String getAddressFromFilePath(String walletFileName) { | ||
try { | ||
String[] fetchAddress = walletFileName.split("--"); | ||
return "0x" + fetchAddress[fetchAddress.length - 1].split("\\.")[0]; | ||
} catch (Exception e) { | ||
return null; | ||
} | ||
} | ||
|
||
} |
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
53 changes: 53 additions & 0 deletions
53
src/main/java/io/keyko/nevermined/external/FaucetService.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,53 @@ | ||
package io.keyko.nevermined.external; | ||
|
||
import com.fasterxml.jackson.core.type.TypeReference; | ||
import io.keyko.common.helpers.HttpHelper; | ||
import io.keyko.common.models.HttpResponse; | ||
import io.keyko.nevermined.exceptions.ServiceException; | ||
import io.keyko.nevermined.models.faucet.FaucetRequest; | ||
import io.keyko.nevermined.models.faucet.FaucetResponse; | ||
import org.apache.http.HttpStatus; | ||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
|
||
import java.util.ArrayList; | ||
|
||
/** | ||
* Service for Gateway's Integration | ||
*/ | ||
public class FaucetService { | ||
|
||
private static final Logger log = LogManager.getLogger(FaucetService.class); | ||
|
||
private static final String FAUCET_URI = "/faucet"; | ||
|
||
|
||
/** | ||
* Requests Network ETH to the faucet for paying the transactions gas | ||
* | ||
* @param address address requesting ETH from the faucet | ||
* @return boolean | ||
* @throws ServiceException if there is an error communicating with the Faucet | ||
*/ | ||
public static FaucetResponse requestEthFromFaucet(String faucetUrl, String address) throws ServiceException { | ||
try { | ||
|
||
final FaucetRequest faucetRequest = new FaucetRequest(address); | ||
HttpResponse response = HttpHelper.httpClientPost( | ||
faucetUrl + FAUCET_URI, new ArrayList<>(), faucetRequest.toJson()); | ||
|
||
if (response.getStatusCode() != HttpStatus.SC_OK && response.getStatusCode() != HttpStatus.SC_CREATED) { | ||
log.warn("Error getting funds from faucet " + response.getBody()); | ||
} | ||
|
||
return FaucetResponse.fromJSON(new TypeReference<>() { | ||
}, response.getBody()); | ||
|
||
} catch (Exception ex) { | ||
String msg = "Error requesting eth from faucet for address " + address; | ||
log.error(msg + ": " + ex.getMessage()); | ||
throw new ServiceException("Exception getting ETH from faucet: " + ex.getMessage()); | ||
} | ||
} | ||
|
||
} |
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.