use of run.wallet.iota.model.Transfer in project run-wallet-android by runplay.
the class NudgeRequestHandler method doNudge.
public static ApiResponse doNudge(RunIotaAPI apiProxy, Context context, ApiRequest inrequest) {
ApiResponse response;
int notificationId = Utils.createNewID();
NudgeRequest request = (NudgeRequest) inrequest;
Transfer nudgeMe = request.getTransfer();
try {
List<Address> alreadyAddress = Store.getAddresses(context, request.getSeed());
// String useAddress="RUN9IOTA9WALLET9NUDGE9PROMOTE9TRANSFER9ADDRESSRUN9IOTA9WALLET9NUDGE9PROMOTE9TRANS";
String random = SeedRandomGenerator.generateNewSeed();
String useAddress = "RUN9IOTA9WALLET9NUDGE9PROMOTE9TRANSFER99" + Sf.restrictLength(random, 41);
NudgeResponse nresp = null;
if (useAddress != null) {
List<Transfer> transfers = new ArrayList<>();
List<Transfer> alreadyTransfers = Store.getTransfers(context, request.getSeed());
Transfer already = Store.isAlreadyTransfer(nudgeMe.getHash(), alreadyTransfers);
if (already != null) {
RunSendTransferResponse rstr = apiProxy.sendNudgeTransfer(String.valueOf(Store.getSeedRaw(context, request.getSeed())), nudgeMe.getHash(), useAddress, 1, 2, request.getDepth(), request.getMinWeightMagnitude());
nresp = new NudgeResponse(rstr);
String gotHash = null;
if (nresp != null && nresp.getSuccessfully()) {
gotHash = nresp.getHashes().get(0);
already.addNudgeHash(gotHash);
} else {
already.addNudgeHash("Failed nudge");
}
jota.dto.response.GetNodeInfoResponse nodeInfo = apiProxy.getNodeInfo();
if (nodeInfo != null) {
already.setMilestone(nodeInfo.getLatestMilestoneIndex());
}
if (gotHash != null) {
Wallet wallet = Store.getWallet(context, request.getSeed());
Audit.setTransfersToAddresses(request.getSeed(), transfers, alreadyAddress, wallet, alreadyTransfers);
Audit.processNudgeAttempts(context, request.getSeed(), transfers);
Store.updateAccountData(context, request.getSeed(), wallet, transfers, alreadyAddress);
}
if (!AppService.isAppStarted()) {
NotificationHelper.responseNotification(context, R.drawable.nudge_orange, context.getString(R.string.notification_nudge_succeeded_title), notificationId);
} else {
NotificationHelper.vibrate(context);
}
return nresp;
}
}
NetworkError error = new NetworkError();
error.setErrorType(NetworkErrorType.INVALID_HASH_ERROR);
return error;
} catch (ArgumentException e) {
Log.e("NUDGE", "error: " + e.getMessage());
NetworkError error = new NetworkError();
error.setErrorType(NetworkErrorType.INVALID_HASH_ERROR);
response = error;
}
return response;
}
use of run.wallet.iota.model.Transfer in project run-wallet-android by runplay.
the class RefreshUsedAddressesHandler method checkUsedAddressForSeed.
private GetAccountDataResponse checkUsedAddressForSeed(Seeds.Seed seed, boolean report) {
Wallet wallet = Store.getWallet(context, seed);
if (wallet != null) {
List<Address> alreadyAddress = Store.getAddresses(context, seed);
GetTransferResponse gtr = null;
StopWatch stopWatch = new StopWatch();
List<Address> checkAddress = new ArrayList<>();
for (Address tmp : alreadyAddress) {
if (tmp.isUsed() && tmp.getValue() == 0) {
checkAddress.add(tmp);
}
}
if (!checkAddress.isEmpty()) {
try {
List<String> checkAddressString = new ArrayList<>();
List<String> checkAddressBal = new ArrayList<>();
for (Address addr : checkAddress) {
checkAddressBal.add(addr.getAddress());
}
GetBalancesResponse gbal = apiProxy.getBalances(100, checkAddressBal);
for (int i = 0; i < gbal.getBalances().length; i++) {
Address addr = checkAddress.get(i);
long gotBalance = Sf.toLong(gbal.getBalances()[i]);
if (gotBalance != 0 || addr.getPendingValue() != 0) {
addr.setValue(gotBalance);
checkAddressString.add(addr.getAddress());
}
if (report) {
if (gotBalance > 0) {
Store.setUsedAddressCheckResult(context.getString(R.string.usedAddressNoOk) + " " + IotaToText.convertRawIotaAmountToDisplayText(gotBalance, true));
} else {
Store.setUsedAddressCheckResult(context.getString(R.string.usedAddressOk));
}
}
}
if (!checkAddressString.isEmpty()) {
Bundle[] bundles = apiProxy.bundlesFromAddresses(checkAddressString.toArray(new String[checkAddressString.size()]), true);
gtr = GetTransferResponse.create(bundles, stopWatch.getElapsedTimeMili());
}
List<Transfer> transfers = new ArrayList<>();
if (gtr != null && gtr.getTransfers().length > 0) {
List<Transfer> alreadyTransfer = Store.getTransfers(context, seed);
Audit.bundlePopulateTransfers(gtr.getTransfers(), transfers, alreadyAddress);
Audit.setTransfersToAddresses(seed, transfers, alreadyAddress, wallet, alreadyTransfer);
Audit.processNudgeAttempts(context, seed, transfers);
Store.updateAccountData(context, seed, wallet, transfers, alreadyAddress);
}
} catch (Exception e) {
Log.e("ERR066", "ERROR: " + e.getMessage());
}
}
}
return new GetAccountDataResponse();
}
use of run.wallet.iota.model.Transfer in project run-wallet-android by runplay.
the class Audit method populateTxToTransfers.
public static void populateTxToTransfers(List<Transaction> inTransactions, NodeInfoResponse nodeInfo, List<Transfer> transfers, List<Address> allAddresses) {
long totalValueTransfer = 0;
long timestamp = 0;
String address = "";
String hash = "";
Boolean persistence = false;
long value = 0;
String tag = Constants.NEW_TRANSFER_TAG;
String destinationAddress = "";
List<TransferTransaction> transactions = new ArrayList<>();
List<TransferTransaction> othertransactions = new ArrayList<>();
String message = defmessage;
for (Transaction trx : inTransactions) {
try {
tag = trx.getTag();
address = trx.getAddress();
persistence = trx.getPersistence();
value = trx.getValue();
Address hasAddress = Store.isAlreadyAddress(address, allAddresses);
if (hasAddress != null) {
hasAddress.setAttached(true);
}
if (value != 0 && hasAddress != null) {
transactions.add(new TransferTransaction(hasAddress.getAddress(), value));
totalValueTransfer += value;
} else if (value != 0) {
othertransactions.add(new TransferTransaction(trx.getAddress(), value));
}
if (trx.getCurrentIndex() == 0) {
message = Utils.removeTrailingNines(trx.getSignatureFragments());
timestamp = trx.getAttachmentTimestamp();
destinationAddress = address;
hash = trx.getHash();
}
if (hasAddress != null) {
boolean isRemainder = (trx.getCurrentIndex() == trx.getLastIndex()) && trx.getLastIndex() != 0;
if (value < 0 && !isRemainder) {
hasAddress.setUsed(true);
} else {
// hasAddress.setUsed(false);
hasAddress.setAttached(true);
}
}
} catch (Exception e) {
Log.e("AUDIT", "exception: " + e.getMessage());
}
}
Transfer addtransfer = new Transfer(timestamp, destinationAddress, hash, persistence, totalValueTransfer, message, tag);
if (nodeInfo != null) {
addtransfer.setMilestone(nodeInfo.getLatestMilestoneIndex());
addtransfer.setMilestoneCreated(nodeInfo.getLatestMilestoneIndex());
}
addtransfer.setTransactions(transactions);
addtransfer.setOtherTransactions(othertransactions);
transfers.add(addtransfer);
}
use of run.wallet.iota.model.Transfer in project run-wallet-android by runplay.
the class Audit method processNudgeAttempts.
public static void processNudgeAttempts(Context context, Seeds.Seed seed, List<Transfer> transfers) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
int nudgeAttempts = Sf.toInt(prefs.getString(Constants.PREF_TRANSFER_NUDGE_ATTEMPTS, "" + Constants.PREF_TRANSFER_NUDGE_ATTEMPTS_VALUE));
Collections.reverse(transfers);
List<NudgeTransfer> alreadyNudge = Store.getNudgeTransfers();
Map<String, Boolean> completedLookup = new HashMap<>();
for (Transfer transfer : transfers) {
if (transfer.isCompleted()) {
completedLookup.put(transfer.getValue() + "" + transfer.getAddress(), true);
}
}
for (Transfer transfer : transfers) {
if (!transfer.isCompleted() && completedLookup.get(transfer.getValue() + "" + transfer.getAddress()) == null) {
if (transfer.getValue() <= 0 && !transfer.isMarkDoubleAddress() && !transfer.isMarkDoubleSpend() && !transfer.getTransactions().isEmpty() && transfer.getNudgeCount() < nudgeAttempts) {
Store.addIfNoNudgeTransfer(context, seed, transfer);
}
} else if (transfer.isCompleted()) {
for (NudgeTransfer nudge : alreadyNudge) {
if (transfer.getHash().equals(nudge.transfer.getHash())) {
List<NudgeTransfer> remove = new ArrayList<>();
remove.add(nudge);
Store.removeNudgeTransfer(context, remove);
}
}
}
}
Store.saveNudgeTransfers(context);
Collections.reverse(transfers);
}
use of run.wallet.iota.model.Transfer in project run-wallet-android by runplay.
the class Audit method setTransfersToAddresses.
public static void setTransfersToAddresses(Seeds.Seed seed, List<Transfer> transfers, List<Address> allAddresses, Wallet wallet, List<Transfer> addinTransfers) {
for (Address add : allAddresses) {
if (add.getValue() != 0 || add.getPendingValue() != 0)
add.setUsed(false);
// add.setValue(0);
add.setPendingValue(0);
if (!add.isPigUser()) {
add.setPigInt(0);
}
}
if (addinTransfers != null) {
List<Transfer> allTransfers = new ArrayList<>();
for (Transfer tran : addinTransfers) {
Transfer already = Store.isAlreadyTransfer(tran, transfers);
if (already == null) {
allTransfers.add(tran);
} else {
already.setLastDoubleCheck(tran.getLastDoubleCheck());
already.setMilestone(tran.getMilestone());
already.setMilestoneCreated(tran.getMilestoneCreated());
already.setNudgeHashes(tran.getNudgeHashes());
}
}
transfers.addAll(allTransfers);
}
if (!transfers.isEmpty()) {
ProcessResult result = processTransfersToAddresses(seed, transfers, allAddresses);
Collections.sort(transfers);
wallet.setBalance(result.seedTotal);
wallet.setBalancePendingIn(result.seedTotalPendingIn);
wallet.setBalancePendingOut(result.seedTotalPendingOut);
}
wallet.setLastUpdate(System.currentTimeMillis());
}
Aggregations