use of it.angelic.mpw.model.jsonpojos.wallet.Wallet in project MPW by shineangelic.
the class KratosInstrumentedTest method testJsonWalletRequest.
@Test
public void testJsonWalletRequest() throws Exception {
final GsonBuilder builder = new GsonBuilder();
JsonObjectRequest jsonObjReq = new JsonObjectRequest(Request.Method.GET, Utils.getWalletStatsUrl(sharedPreferences) + minerAddr, null, new Response.Listener<JSONObject>() {
@Override
public void onResponse(final JSONObject response) {
Log.i(Constants.TAG, response.toString());
Gson gson = builder.create();
// Register an adapter to manage the date types as long values
Wallet retrieved = gson.fromJson(response.toString(), Wallet.class);
assertNotNull(retrieved);
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Log.e(Constants.TAG, "Error: " + error.getMessage());
fail(error.getMessage());
}
});
// Adding request to request queue
JSONClientSingleton.getInstance(appContext).addToRequestQueue(jsonObjReq);
}
use of it.angelic.mpw.model.jsonpojos.wallet.Wallet in project MPW by shineangelic.
the class PoolDbHelper method getAveragePending.
/**
* This HEAVY method can serve stats/charts only, as it is not precise
* The last block pending before payout is not being counted.
*
* @return average 'pending' increase per block
*/
public Long getAveragePending() {
int cnt = 0;
int rec = 0;
Long pendings = 0L;
Long prevPending = 0L;
SQLiteDatabase db = this.getReadableDatabase();
// Cursor cursor = db.rawQuery(selectQuery, null);
Cursor cursor = db.query(DataBaseContract.Wallet_.TABLE_NAME, new String[] { DataBaseContract.Wallet_._ID, DataBaseContract.Wallet_.COLUMN_NAME_DTM, DataBaseContract.Wallet_.COLUMN_NAME_JSON }, null, // String[] selectionArgs
null, null, // HAVING
null, // ORDER BY
DataBaseContract.Wallet_.COLUMN_NAME_DTM + " ASC");
if (cursor.moveToFirst()) {
Gson gson = builder.create();
try {
Wallet camp = gson.fromJson(cursor.getString(cursor.getColumnIndexOrThrow(DataBaseContract.Wallet_.COLUMN_NAME_JSON)), Wallet.class);
prevPending = camp.getStats().getBalance().longValue();
do {
Wallet retrieved = gson.fromJson(cursor.getString(cursor.getColumnIndexOrThrow(DataBaseContract.Wallet_.COLUMN_NAME_JSON)), Wallet.class);
rec++;
Long curPending = retrieved.getStats().getBalance().longValue();
if (curPending > prevPending) {
Log.d(TAG, "Block detected in history. Prev balance: " + prevPending + " current: " + curPending);
cnt++;
// pending increased
pendings += (curPending - prevPending);
}
prevPending = curPending;
} while (cursor.moveToNext());
} catch (Exception caz) {
Log.e(TAG, "Cant read getAveragePending entry: " + caz.getMessage());
}
}
Log.i(TAG, "SELECT DONE. PENDINGS HISTORY SIZE: " + cnt + " FROM RECORDS: " + rec);
cursor.close();
if (cnt == 0)
return 0L;
return pendings / cnt;
}
use of it.angelic.mpw.model.jsonpojos.wallet.Wallet in project MPW by shineangelic.
the class PoolDbHelper method getLastWallets.
public LinkedMap<Date, Wallet> getLastWallets(int limit) {
LinkedMap<Date, Wallet> ret = new LinkedMap<>();
int cnt = 0;
SQLiteDatabase db = this.getReadableDatabase();
Cursor cursor = db.query(DataBaseContract.Wallet_.TABLE_NAME, new String[] { DataBaseContract.Wallet_._ID, DataBaseContract.Wallet_.COLUMN_NAME_DTM, DataBaseContract.Wallet_.COLUMN_NAME_JSON }, null, // String[] selectionArgs
null, null, // HAVING
null, DataBaseContract.Wallet_.COLUMN_NAME_DTM + " DESC", // 2 results to do compare
"" + limit);
// looping through all rows and adding to list
if (cursor.moveToFirst()) {
Gson gson = builder.create();
do {
try {
Wallet retrieved = gson.fromJson(cursor.getString(cursor.getColumnIndexOrThrow(DataBaseContract.Wallet_.COLUMN_NAME_JSON)), Wallet.class);
cnt++;
// Adding contact to list
Date curDate = new Date(cursor.getLong(cursor.getColumnIndexOrThrow(DataBaseContract.Wallet_.COLUMN_NAME_DTM)));
ret.put(curDate, retrieved);
} catch (Exception ce) {
Log.e(TAG, "Cant read wallet entry: " + ce.getMessage());
}
} while (cursor.moveToNext());
}
Log.i(TAG, "SELECT DONE. WALLET HISTORY SIZE: " + cnt);
cursor.close();
return ret;
}
use of it.angelic.mpw.model.jsonpojos.wallet.Wallet in project MPW by shineangelic.
the class MinersActivity method fetchMinerStats.
private void fetchMinerStats(final MinerDBRecord rec) {
JsonObjectRequest jsonObjReq = new JsonObjectRequest(Utils.getWalletStatsUrl(PreferenceManager.getDefaultSharedPreferences(this)) + rec.getAddress(), null, new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
// update known miners TABLE
Log.d(Constants.TAG, response.toString());
Gson gson = builder.create();
// Register an adapter to manage the date types as long values
final Wallet retrieved = gson.fromJson(response.toString(), Wallet.class);
if (retrieved.getWorkersTotal() > (rec.getTopMiners() == null ? -1 : rec.getTopMiners()))
rec.setTopMiners(retrieved.getWorkersTotal());
if (retrieved.getCurrentHashrate() > (rec.getTopHr() == null ? -1 : rec.getTopHr()))
rec.setTopHr(retrieved.getCurrentHashrate());
rec.setPaid(retrieved.getStats().getPaid());
try {
// compute first paymt
Payment pp = retrieved.getPayments().get(retrieved.getPayments().size() - 1);
rec.setFirstSeen(pp.getTimestamp());
} catch (Exception io) {
// dont look back in anger
}
rec.setAvgHr(rec.getAvgHr() == null ? retrieved.getHashrate() : ((rec.getAvgHr() + retrieved.getHashrate()) / 2));
// aggiorna UI
rec.setLastSeen(retrieved.getStats().getLastShare());
rec.setBlocksFound(retrieved.getStats().getBlocksFound());
mDbHelper.updateMiner(rec);
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
VolleyLog.e(Constants.TAG, "Error: " + error.getMessage());
}
});
// Adding request to request queue
JSONClientSingleton.getInstance(this).addToRequestQueue(jsonObjReq);
}
use of it.angelic.mpw.model.jsonpojos.wallet.Wallet in project MPW by shineangelic.
the class Utils method fillEthereumStats.
public static void fillEthereumStats(Context ctx, PoolDbHelper mDbHelper, NavigationView navigationView, PoolEnum activePool, CurrencyEnum cur) {
TextView ethPlaceholder = navigationView.findViewById(R.id.textView10);
TextView ethC = navigationView.findViewById(R.id.textViewEthCourtesy);
TextView textViewWhoPaid = navigationView.findViewById(R.id.textViewWhoPaid);
SharedPreferences settings = ctx.getSharedPreferences("COINMARKETCAP", MODE_PRIVATE);
try {
String val = settings.getString("CURUSD", "---");
String chg = settings.getString("CURCHG", "---");
ethC.setText("Courtesy of coinmarketcap. Last update: " + MainActivity.yearFormatExtended.format(new Date(settings.getLong("CURTIMESTAMP", 0))));
ethPlaceholder.setText(String.format(ctx.getString(R.string.currency_placeholder), cur.name(), val, Double.valueOf(chg)));
} catch (Exception e) {
Log.e(TAG, "Error eth currency panel:" + e.getMessage());
ethC.setVisibility(View.INVISIBLE);
ethPlaceholder.setVisibility(View.INVISIBLE);
}
try {
Wallet last = mDbHelper.getLastWallet();
textViewWhoPaid.setText(String.format(ctx.getString(R.string.paid_out_full), activePool.toString(), "" + Utils.formatCurrency(ctx, last.getStats().getPaid(), cur)));
} catch (Exception e) {
Log.e(TAG, "Errore aggiornamento eth paid panel: " + e.getMessage());
textViewWhoPaid.setVisibility(View.INVISIBLE);
}
}
Aggregations