-
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
3 changed files
with
46 additions
and
33 deletions.
There are no files selected for viewing
37 changes: 4 additions & 33 deletions
37
src/main/java/com/allmycoins/balance/avalanche/AvalancheProvider.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,39 +1,10 @@ | ||
package com.allmycoins.balance.avalanche; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import com.allmycoins.balance.covalent.CovalentProvider; | ||
|
||
import com.allmycoins.balance.PublicAddressBalanceProvider; | ||
import com.allmycoins.balance.etherscan.SingleBalanceJson; | ||
import com.allmycoins.balance.etherscan.TokenTxResultJson; | ||
import com.allmycoins.balance.etherscan.TxToBalances; | ||
import com.allmycoins.json.BalanceJson; | ||
import com.allmycoins.utils.BigDecimalUtils; | ||
import com.allmycoins.utils.RequestUtils; | ||
public final class AvalancheProvider extends CovalentProvider { | ||
|
||
public final class AvalancheProvider implements PublicAddressBalanceProvider { | ||
|
||
@Override | ||
public List<BalanceJson> balance(String publicAddress) { | ||
|
||
// Single AVAX balance | ||
SingleBalanceJson avalancheBalance = RequestUtils.sendRequest(new AvalancheBalanceRequest(publicAddress)); | ||
float qty = BigDecimalUtils.decimal18(avalancheBalance.getResult()); | ||
BalanceJson balance = new BalanceJson("AVAX", qty, "Avalanche C"); | ||
|
||
// Tokens | ||
TokenTxResultJson tokenTxResultJson = RequestUtils.sendRequest(new AvalancheTokenTxRequest(publicAddress)); | ||
List<BalanceJson> tokenBalances = TxToBalances.txToBalances(tokenTxResultJson, publicAddress, "Avalanche C"); | ||
|
||
List<BalanceJson> balances = new ArrayList<>(); | ||
balances.add(balance); | ||
balances.addAll(tokenBalances); | ||
return balances; | ||
public AvalancheProvider() { | ||
super("Avalanche C wallet", "avalanche-mainnet", "AVALANCHE_C_ADDRESS"); | ||
} | ||
|
||
@Override | ||
public String privateConfigKey() { | ||
return "AVALANCHE_C_ADDRESS"; | ||
} | ||
|
||
} |
39 changes: 39 additions & 0 deletions
39
src/test/java/com/allmycoins/balance/AvalancheProviderTest.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,39 @@ | ||
package com.allmycoins.balance; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
import java.util.List; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import com.allmycoins.PrivateConfig; | ||
import com.allmycoins.balance.avalanche.AvalancheProvider; | ||
import com.allmycoins.json.BalanceJson; | ||
|
||
class AvalancheProviderTest { | ||
|
||
@Test | ||
void testBalances() { | ||
PrivateConfig.loadConfigurationFromClassLoader(); | ||
|
||
AvalancheProvider avalancheProvider = new AvalancheProvider(); | ||
List<BalanceJson> balance = avalancheProvider.balances(); | ||
assertTrue(balance.size() >= 1); | ||
BalanceJson balanceJson = balance.get(0); | ||
|
||
assertEquals("AVAX", balanceJson.getAsset()); | ||
assertEquals("Avalanche C wallet", balanceJson.getSrc()); | ||
assertTrue(balanceJson.getQty() >= 0.0f); | ||
} | ||
|
||
@Test | ||
void testNoBalances() { | ||
PrivateConfig.clearConfiguration(); | ||
|
||
AvalancheProvider avalancheProvider = new AvalancheProvider(); | ||
List<BalanceJson> balance = avalancheProvider.balances(); | ||
assertTrue(balance.isEmpty()); | ||
} | ||
|
||
} |
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