use of run.wallet.iota.model.Address in project run-wallet-android by runplay.
the class MessageFirstLoadRequestHandler method handle.
@Override
public ApiResponse handle(ApiRequest request) {
try {
// Log.e("FIRST-TIME-MSG","called");
StopWatch stopWatch = new StopWatch();
MessageFirstLoadRequest firstLoadRequest = (MessageFirstLoadRequest) request;
GetTransferResponse gtr = null;
List<Address> allAddresses = new ArrayList<>();
int start = 0;
final int addcount = 5;
while (true) {
GetNewAddressResponse gnr = apiProxy.getNewAddress(String.valueOf(Store.getSeedRaw(context, MsgStore.getSeed())), firstLoadRequest.getSecurity(), start, false, start + addcount, true);
for (String add : gnr.getAddresses()) {
// Log.e("FIRST-TIME-MSG","CALC ADDRESS: "+allAddresses+" -- "+stopWatch.getElapsedTimeSecs());
final FindTransactionResponse tr = apiProxy.findTransactionsByAddresses(add);
Address newaddress = new Address(add, false, true);
if (tr.getHashes().length == 0) {
newaddress.setAttached(false);
}
allAddresses.add(newaddress);
}
int countempty = 0;
for (int i = allAddresses.size() - 1; i >= 0 && i >= allAddresses.size() - 4; i--) {
if (!allAddresses.get(i).isAttached()) {
countempty++;
}
}
if (countempty >= 2) {
break;
}
start += addcount;
}
List<String> transactionaddresses = new ArrayList<>();
for (Address add : allAddresses) {
if (add.isAttached())
transactionaddresses.add(add.getAddress());
}
if (!transactionaddresses.isEmpty()) {
try {
Bundle[] bundles = apiProxy.bundlesFromAddresses(transactionaddresses.toArray(new String[transactionaddresses.size()]), true);
gtr = GetTransferResponse.create(bundles, stopWatch.getElapsedTimeMili());
} catch (Exception e) {
Log.e("FIRST-LOAD-MSG", "ex: " + e.getMessage());
}
} else {
gtr = GetTransferResponse.create(new Bundle[] {}, stopWatch.getElapsedTimeMili());
}
List<Transfer> transfers = new ArrayList<>();
long seedTotal = 0;
Wallet wallet = new Wallet(MsgStore.getSeed().id, seedTotal, System.currentTimeMillis());
// Audit.setTransfersToAddresses(firstLoadRequest.getSeed(),gtr,transfers,allAddresses,wallet);
MsgStore.updateMessageData(context, wallet, transfers, allAddresses);
// AppService.generateMessageNewAddress(context);
// if()
} catch (ArgumentException e) {
Log.e("FIRST-TIME-MSG", "ex: " + e.getMessage());
return new NetworkError();
}
return new ApiResponse();
}
use of run.wallet.iota.model.Address 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.Address 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.Address 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.Address 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