-
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.
Refactoring to make covalent provider generic
- Loading branch information
Showing
6 changed files
with
58 additions
and
36 deletions.
There are no files selected for viewing
2 changes: 1 addition & 1 deletion
2
...nce/ethereum/CovalentBalanceItemJson.java → ...nce/covalent/CovalentBalanceItemJson.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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package com.allmycoins.balance.ethereum; | ||
package com.allmycoins.balance.covalent; | ||
|
||
import java.math.BigDecimal; | ||
|
||
|
2 changes: 1 addition & 1 deletion
2
...ce/ethereum/CovalentBalancesDataJson.java → ...ce/covalent/CovalentBalancesDataJson.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
2 changes: 1 addition & 1 deletion
2
...alance/ethereum/CovalentBalancesJson.java → ...alance/covalent/CovalentBalancesJson.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
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
44 changes: 44 additions & 0 deletions
44
src/main/java/com/allmycoins/balance/covalent/CovalentProvider.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,44 @@ | ||
package com.allmycoins.balance.covalent; | ||
|
||
import java.util.List; | ||
import java.util.concurrent.Future; | ||
import java.util.stream.Collectors; | ||
|
||
import com.allmycoins.balance.PublicAddressBalanceProvider; | ||
import com.allmycoins.json.BalanceJson; | ||
import com.allmycoins.utils.BigDecimalUtils; | ||
import com.allmycoins.utils.FutureUtils; | ||
import com.allmycoins.utils.RequestUtils; | ||
|
||
public class CovalentProvider implements PublicAddressBalanceProvider { | ||
|
||
private String balanceSource; | ||
private String network; | ||
private String configKey; | ||
|
||
public CovalentProvider(final String pBalanceSource, final String pNetwork, final String pConfigKey) { | ||
balanceSource = pBalanceSource; | ||
network = pNetwork; | ||
configKey = pConfigKey; | ||
} | ||
|
||
@Override | ||
public final List<BalanceJson> balance(String publicAddress) { | ||
Future<CovalentBalancesJson> futureAmberdataEthTokensJson = RequestUtils | ||
.sendRequestFuture(new CovalentBalancesRequest(network, publicAddress)); | ||
|
||
CovalentBalancesJson covalentBalancesJson = FutureUtils.futureResult(futureAmberdataEthTokensJson); | ||
|
||
List<CovalentBalanceItemJson> list = List.of(covalentBalancesJson.getData().getItems()); | ||
|
||
return list.stream() | ||
.map(i -> new BalanceJson(i.getContract_ticker_symbol(), | ||
BigDecimalUtils.decimal(i.getBalance(), i.getContract_decimals()), balanceSource)) | ||
.collect(Collectors.toList()); | ||
} | ||
|
||
@Override | ||
public final String privateConfigKey() { | ||
return configKey; | ||
} | ||
} |
32 changes: 4 additions & 28 deletions
32
src/main/java/com/allmycoins/balance/ethereum/EthProvider.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 |
---|---|---|
@@ -1,34 +1,10 @@ | ||
package com.allmycoins.balance.ethereum; | ||
|
||
import java.util.List; | ||
import java.util.concurrent.Future; | ||
import java.util.stream.Collectors; | ||
import com.allmycoins.balance.covalent.CovalentProvider; | ||
|
||
import com.allmycoins.balance.PublicAddressBalanceProvider; | ||
import com.allmycoins.json.BalanceJson; | ||
import com.allmycoins.utils.BigDecimalUtils; | ||
import com.allmycoins.utils.FutureUtils; | ||
import com.allmycoins.utils.RequestUtils; | ||
public final class EthProvider extends CovalentProvider { | ||
|
||
public final class EthProvider implements PublicAddressBalanceProvider { | ||
|
||
@Override | ||
public List<BalanceJson> balance(String publicAddress) { | ||
Future<CovalentBalancesJson> futureAmberdataEthTokensJson = RequestUtils | ||
.sendRequestFuture(new CovalentBalancesRequest(publicAddress)); | ||
|
||
CovalentBalancesJson covalentBalancesJson = FutureUtils.futureResult(futureAmberdataEthTokensJson); | ||
|
||
List<CovalentBalanceItemJson> list = List.of(covalentBalancesJson.getData().getItems()); | ||
|
||
return list.stream() | ||
.map(i -> new BalanceJson(i.getContract_ticker_symbol(), | ||
BigDecimalUtils.decimal(i.getBalance(), i.getContract_decimals()), "ETH wallet")) | ||
.collect(Collectors.toList()); | ||
} | ||
|
||
@Override | ||
public String privateConfigKey() { | ||
return "ETH_ADDRESS"; | ||
public EthProvider() { | ||
super("ETH wallet", "eth-mainnet", "ETH_ADDRESS"); | ||
} | ||
} |