Added Bitshares Contants and added all the current smartcoins
Delay the equivalent thread to 1 min pero query
This commit is contained in:
parent
0dd2afd47d
commit
247afeefcd
5 changed files with 98 additions and 56 deletions
|
@ -8,6 +8,7 @@ import java.util.Date;
|
|||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import cy.agorise.crystalwallet.application.constant.BitsharesConstant;
|
||||
import cy.agorise.crystalwallet.dao.BitsharesAssetDao;
|
||||
import cy.agorise.crystalwallet.dao.CryptoCoinBalanceDao;
|
||||
import cy.agorise.crystalwallet.dao.CryptoCurrencyDao;
|
||||
|
@ -58,10 +59,7 @@ import cy.agorise.graphenej.operations.TransferOperation;
|
|||
|
||||
public abstract class GrapheneApiGenerator {
|
||||
|
||||
//TODO network connections
|
||||
//TODO make to work with all Graphene type, not only bitshares
|
||||
public static String faucetUrl = "http://185.208.208.147:5010";
|
||||
private static String equivalentUrl = "wss://bitshares.openledger.info/ws";
|
||||
|
||||
// The message broker for bitshares
|
||||
private static SubscriptionMessagesHub bitsharesSubscriptionHub = new SubscriptionMessagesHub("", "", true, new NodeErrorListener() {
|
||||
|
@ -570,7 +568,7 @@ public abstract class GrapheneApiGenerator {
|
|||
public void onError(BaseResponse.Error error) {
|
||||
request.getListener().fail(request.getId());
|
||||
}
|
||||
}),equivalentUrl);
|
||||
}), BitsharesConstant.EQUIVALENT_URL); //todo change equivalent url for current server url
|
||||
thread.start();
|
||||
}
|
||||
|
||||
|
@ -586,7 +584,7 @@ public abstract class GrapheneApiGenerator {
|
|||
for(BitsharesAsset quoteAsset : quoteAssets){
|
||||
WebSocketThread thread = new WebSocketThread(new GetLimitOrders(baseAsset.getBitsharesId(),
|
||||
quoteAsset.getBitsharesId(), 10, new EquivalentValueListener(baseAsset,
|
||||
quoteAsset,context)),equivalentUrl);
|
||||
quoteAsset,context)), BitsharesConstant.EQUIVALENT_URL); //todo change equivalent url for current server url
|
||||
thread.start();
|
||||
}
|
||||
}
|
||||
|
@ -666,7 +664,7 @@ public abstract class GrapheneApiGenerator {
|
|||
Converter converter = new Converter();
|
||||
order.getSellPrice().base.getAsset().setPrecision(baseAsset.getPrecision());
|
||||
order.getSellPrice().quote.getAsset().setPrecision(quoteAsset.getPrecision());
|
||||
double equiValue = converter.getConversionRate(order.getSellPrice(), Converter.QUOTE_TO_BASE);
|
||||
double equiValue = converter.getConversionRate(order.getSellPrice(), Converter.BASE_TO_QUOTE);
|
||||
CryptoCurrencyEquivalence equivalence = new CryptoCurrencyEquivalence(baseAsset.getId(), quoteAsset.getId(), (int) (Math.pow(10, baseAsset.getPrecision()) * equiValue), new Date());
|
||||
CrystalDatabase.getAppDatabase(context).cryptoCurrencyEquivalenceDao().insertCryptoCurrencyEquivalence(equivalence);
|
||||
break;
|
||||
|
|
|
@ -5,6 +5,7 @@ import android.content.Intent;
|
|||
|
||||
import com.idescout.sql.SqlScoutServer;
|
||||
|
||||
import cy.agorise.crystalwallet.application.constant.BitsharesConstant;
|
||||
import cy.agorise.crystalwallet.dao.CrystalDatabase;
|
||||
import cy.agorise.crystalwallet.enums.CryptoNet;
|
||||
import cy.agorise.crystalwallet.models.BitsharesAsset;
|
||||
|
@ -20,25 +21,6 @@ import cy.agorise.crystalwallet.service.CrystalWalletService;
|
|||
*/
|
||||
|
||||
public class CrystalApplication extends Application {
|
||||
public static String BITSHARES_URL[] =
|
||||
{
|
||||
"wss://de.palmpay.io/ws", // Custom node
|
||||
"wss://bitshares.nu/ws",
|
||||
"wss://dexnode.net/ws", // Dallas, USA
|
||||
"wss://bitshares.crypto.fans/ws", // Munich, Germany
|
||||
"wss://bitshares.openledger.info/ws", // Openledger node
|
||||
"ws://185.208.208.147:8090" // Custom node
|
||||
};
|
||||
|
||||
public static String BITSHARES_TESTNET_URL[] =
|
||||
{
|
||||
"http://185.208.208.147:11012", // Openledger node
|
||||
};
|
||||
|
||||
//This is for testing the equivalent values on the testnet TODO remove
|
||||
public static BitsharesAsset bitUSDAsset = new BitsharesAsset("USD",4,"1.3.121",BitsharesAsset.Type.SMART_COIN);
|
||||
//This is for testing the equivalent values on the testnet TODO remove
|
||||
public static BitsharesAsset bitEURAsset = new BitsharesAsset("EUR",4,"1.3.120",BitsharesAsset.Type.SMART_COIN);
|
||||
|
||||
@Override
|
||||
public void onCreate() {
|
||||
|
@ -48,35 +30,9 @@ public class CrystalApplication extends Application {
|
|||
CrystalDatabase db = CrystalDatabase.getAppDatabase(this.getApplicationContext());
|
||||
SqlScoutServer.create(this, getPackageName());
|
||||
|
||||
//Using Bitshares Agorise Testnet
|
||||
CryptoNetManager.addCryptoNetURL(CryptoNet.BITSHARES,BITSHARES_TESTNET_URL);
|
||||
|
||||
//This is for testing the equivalent values on the testnet TODO remove
|
||||
if(db.bitsharesAssetDao().getBitsharesAssetInfoById(bitEURAsset.getBitsharesId())== null){
|
||||
if(db.cryptoCurrencyDao().getByName(bitEURAsset.getName())== null){
|
||||
db.cryptoCurrencyDao().insertCryptoCurrency(bitEURAsset);
|
||||
}
|
||||
long idCurrency = db.cryptoCurrencyDao().getByName(bitEURAsset.getName()).getId();
|
||||
BitsharesAssetInfo info = new BitsharesAssetInfo(bitEURAsset);
|
||||
info.setCryptoCurrencyId(idCurrency);
|
||||
db.bitsharesAssetDao().insertBitsharesAssetInfo(info);
|
||||
|
||||
}
|
||||
|
||||
//This is for testing the equivalent values on the testnet TODO remove
|
||||
if(db.bitsharesAssetDao().getBitsharesAssetInfoById(bitUSDAsset.getBitsharesId())== null){
|
||||
if(db.cryptoCurrencyDao().getByName(bitUSDAsset.getName())== null){
|
||||
db.cryptoCurrencyDao().insertCryptoCurrency(bitUSDAsset);
|
||||
}
|
||||
long idCurrency = db.cryptoCurrencyDao().getByName(bitUSDAsset.getName()).getId();
|
||||
BitsharesAssetInfo info = new BitsharesAssetInfo(bitUSDAsset);
|
||||
info.setCryptoCurrencyId(idCurrency);
|
||||
db.bitsharesAssetDao().insertBitsharesAssetInfo(info);
|
||||
|
||||
}
|
||||
|
||||
//Next line is for use the bitshares main net
|
||||
//CryptoNetManager.addCryptoNetURL(CryptoNet.BITSHARES,BITSHARES_URL);
|
||||
//BitsharesConstant.addMainNetUrls();
|
||||
BitsharesConstant.addTestNetUrls();
|
||||
BitsharesConstant.addSmartCoins(this.getApplicationContext());
|
||||
|
||||
Intent intent = new Intent(getApplicationContext(), CrystalWalletService.class);
|
||||
startService(intent);
|
||||
|
|
|
@ -0,0 +1,87 @@
|
|||
package cy.agorise.crystalwallet.application.constant;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import java.util.HashSet;
|
||||
|
||||
import cy.agorise.crystalwallet.dao.CrystalDatabase;
|
||||
import cy.agorise.crystalwallet.enums.CryptoNet;
|
||||
import cy.agorise.crystalwallet.models.BitsharesAsset;
|
||||
import cy.agorise.crystalwallet.models.BitsharesAssetInfo;
|
||||
import cy.agorise.crystalwallet.network.CryptoNetManager;
|
||||
|
||||
/**
|
||||
* Created by henry on 15/3/2018.
|
||||
*/
|
||||
|
||||
public abstract class BitsharesConstant {
|
||||
public final static String BITSHARES_URL[] =
|
||||
{
|
||||
"wss://de.palmpay.io/ws", // Custom node
|
||||
"wss://bitshares.nu/ws",
|
||||
"wss://dexnode.net/ws", // Dallas, USA
|
||||
"wss://bitshares.crypto.fans/ws", // Munich, Germany
|
||||
"wss://bitshares.openledger.info/ws", // Openledger node
|
||||
"ws://185.208.208.147:8090" // Custom node
|
||||
};
|
||||
|
||||
public final static String BITSHARES_TESTNET_URL[] =
|
||||
{
|
||||
"http://185.208.208.147:11012", // Openledger node
|
||||
};
|
||||
|
||||
public final static String FAUCET_URL = "http://185.208.208.147:5010";
|
||||
public final static String EQUIVALENT_URL = "wss://bitshares.openledger.info/ws";
|
||||
|
||||
public final static BitsharesAsset[] SMARTCOINS = new BitsharesAsset[]{
|
||||
new BitsharesAsset("USD",4,"1.3.121",BitsharesAsset.Type.SMART_COIN),
|
||||
new BitsharesAsset("EUR",4,"1.3.120",BitsharesAsset.Type.SMART_COIN),
|
||||
new BitsharesAsset("CNY",4,"1.3.113",BitsharesAsset.Type.SMART_COIN),
|
||||
new BitsharesAsset("RUBLE",5,"1.3.1325",BitsharesAsset.Type.SMART_COIN),
|
||||
new BitsharesAsset("AUD",4,"1.3.117",BitsharesAsset.Type.SMART_COIN),
|
||||
new BitsharesAsset("SILVER",4,"1.3.105",BitsharesAsset.Type.SMART_COIN),
|
||||
new BitsharesAsset("GOLD",6,"1.3.106",BitsharesAsset.Type.SMART_COIN),
|
||||
new BitsharesAsset("JPY",2,"1.3.119",BitsharesAsset.Type.SMART_COIN),
|
||||
new BitsharesAsset("CAD",4,"1.3.115",BitsharesAsset.Type.SMART_COIN),
|
||||
new BitsharesAsset("MXN",4,"1.3.114",BitsharesAsset.Type.SMART_COIN),
|
||||
new BitsharesAsset("GBP",4,"1.3.118",BitsharesAsset.Type.SMART_COIN),
|
||||
new BitsharesAsset("ARS",4,"1.3.1017",BitsharesAsset.Type.SMART_COIN),
|
||||
new BitsharesAsset("KRW",4,"1.3.102",BitsharesAsset.Type.SMART_COIN),
|
||||
new BitsharesAsset("CHF",4,"1.3.116",BitsharesAsset.Type.SMART_COIN),
|
||||
new BitsharesAsset("SEK",4,"1.3.111",BitsharesAsset.Type.SMART_COIN),
|
||||
new BitsharesAsset("RUB",4,"1.3.110",BitsharesAsset.Type.SMART_COIN),
|
||||
new BitsharesAsset("NZD",4,"1.3.112",BitsharesAsset.Type.SMART_COIN),
|
||||
new BitsharesAsset("XCD",4,"1.3.2650",BitsharesAsset.Type.SMART_COIN),
|
||||
new BitsharesAsset("TRY",4,"1.3.107",BitsharesAsset.Type.SMART_COIN),
|
||||
new BitsharesAsset("HKD",4,"1.3.109",BitsharesAsset.Type.SMART_COIN),
|
||||
new BitsharesAsset("SGD",4,"1.3.108",BitsharesAsset.Type.SMART_COIN)
|
||||
};
|
||||
|
||||
public static void addMainNetUrls(){
|
||||
for(String url : BITSHARES_URL){
|
||||
CryptoNetManager.addCryptoNetURL(CryptoNet.BITSHARES,url);
|
||||
}
|
||||
}
|
||||
|
||||
public static void addTestNetUrls(){
|
||||
for(String url : BITSHARES_TESTNET_URL){
|
||||
CryptoNetManager.addCryptoNetURL(CryptoNet.BITSHARES,url);
|
||||
}
|
||||
}
|
||||
|
||||
public static void addSmartCoins(Context context){
|
||||
CrystalDatabase db = CrystalDatabase.getAppDatabase(context);
|
||||
for(BitsharesAsset smartcoin : SMARTCOINS){
|
||||
if(db.cryptoCurrencyDao().getByName(smartcoin.getName())== null){
|
||||
db.cryptoCurrencyDao().insertCryptoCurrency(smartcoin);
|
||||
}
|
||||
long idCurrency = db.cryptoCurrencyDao().getByName(smartcoin.getName()).getId();
|
||||
BitsharesAssetInfo info = new BitsharesAssetInfo(smartcoin);
|
||||
info.setCryptoCurrencyId(idCurrency);
|
||||
db.bitsharesAssetDao().insertBitsharesAssetInfo(info);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -17,6 +17,7 @@ import cy.agorise.crystalwallet.apigenerator.ApiRequest;
|
|||
import cy.agorise.crystalwallet.apigenerator.ApiRequestListener;
|
||||
import cy.agorise.crystalwallet.apigenerator.BitsharesFaucetApiGenerator;
|
||||
import cy.agorise.crystalwallet.apigenerator.GrapheneApiGenerator;
|
||||
import cy.agorise.crystalwallet.application.constant.BitsharesConstant;
|
||||
import cy.agorise.crystalwallet.cryptonetinforequests.CryptoNetEquivalentRequest;
|
||||
import cy.agorise.crystalwallet.cryptonetinforequests.CryptoNetInfoRequest;
|
||||
import cy.agorise.crystalwallet.cryptonetinforequests.CryptoNetInfoRequestsListener;
|
||||
|
@ -103,7 +104,7 @@ public class BitsharesAccountManager implements CryptoAccountManager, CryptoNetI
|
|||
new Address(ECKey.fromPublicOnly(grapheneAccount.getOwnerKey(context).getPubKey())).toString(),
|
||||
new Address(ECKey.fromPublicOnly(grapheneAccount.getActiveKey(context).getPubKey())).toString(),
|
||||
new Address(ECKey.fromPublicOnly(grapheneAccount.getMemoKey(context).getPubKey())).toString(),
|
||||
GrapheneApiGenerator.faucetUrl, creationRequest);
|
||||
BitsharesConstant.FAUCET_URL, creationRequest);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -32,7 +32,7 @@ public class EquivalencesThread extends Thread{
|
|||
try {
|
||||
GrapheneApiGenerator.getEquivalenValue(fromAsset, bitsharesAssets, this.service);
|
||||
Log.i("Equivalences Thread", "In loop");
|
||||
Thread.sleep(1000);
|
||||
Thread.sleep(60000);
|
||||
} catch (InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue