use of run.wallet.iota.api.responses.ApiResponse 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.api.responses.ApiResponse 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.api.responses.ApiResponse in project run-wallet-android by runplay.
the class RefreshUsedAddressesHandler method handle.
@Override
public ApiResponse handle(ApiRequest inrequest) {
RefreshUsedAddressesRequest request = (RefreshUsedAddressesRequest) inrequest;
NodeInfoRequestHandler.getNodeInfo(apiProxy, context);
if (Store.isNodeSynced()) {
if (request.getSeed() != null) {
// Log.e("CHK-USED","SINGLE");
checkUsedAddressForSeed(request.getSeed(), true);
} else {
Store.updateLastUsedCheck(context);
for (int i = 0; i < Store.getSeedList().size(); i++) {
// Log.e("CHK-USED","MULTI: "+i);
checkUsedAddressForSeed(Store.getSeedList().get(i), false);
}
}
}
return new ApiResponse();
}
use of run.wallet.iota.api.responses.ApiResponse in project run-wallet-android by runplay.
the class IotaApiProvider method processRequest.
@Override
public ApiResponse processRequest(ApiRequest apiRequest) {
ApiResponse response = null;
try {
// Log.e("iotaApiProv",apiRequest.getClass()+" - "+this.requestHandlerMap.containsKey(apiRequest.getClass()));
if (this.requestHandlerMap.containsKey(apiRequest.getClass())) {
RequestHandler requestHandler = this.requestHandlerMap.get(apiRequest.getClass());
response = requestHandler.handle(apiRequest);
}
} catch (IllegalAccessError e) {
NetworkError error = new NetworkError();
error.setErrorType(NetworkErrorType.ACCESS_ERROR);
error.setMessage(e.getMessage());
response = error;
// if(error.getErrorType()==401 && e.getMessage().contains("getNeighbours"))
Log.e("ERR-API1", "" + e.getMessage());
} catch (Exception e) {
Log.e("ERR-API2", e.toString() + " -- " + e.getMessage());
response = new NetworkError();
}
return response == null ? new NetworkError() : response;
}
use of run.wallet.iota.api.responses.ApiResponse in project run-wallet-android by runplay.
the class IotaRequestTask method doInBackground.
@Override
protected ApiResponse doInBackground(ApiRequest... params) {
Context context = this.context.get();
if (context != null) {
// SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
// String protocol = prefs.getString(Constants.PREFERENCE_NODE_PROTOCOL, Constants.PREFERENCE_NODE_DEFAULT_PROTOCOL);
// String host = prefs.getString(Constants.PREFERENCE_NODE_IP, Constants.PREFERENCE_NODE_DEFAULT_IP);
// int port = Integer.parseInt(prefs.getString(Constants.PREFERENCE_NODE_PORT, Constants.PREFERENCE_NODE_DEFAULT_PORT));
Nodes.Node node = Store.getNode();
// Log.e("NODE ON:",node.protocol+":"+node.ip+":"+node.port);
if (node != null) {
String protocol = node.protocol;
String host = node.ip;
int port = node.port;
if (IOTA.DEBUG) {
// Log.e("ApiRequest", params[0].toString());
start = new Date();
// Log.e("started req at", start.getTime() + "");
}
ApiRequest apiRequest = params[0];
tag = apiRequest.getClass().getCanonicalName();
ApiProvider apiProvider = new IotaApiProvider(protocol, host, port, context);
ApiResponse response = apiProvider.processRequest(apiRequest);
return response;
}
}
// TaskManager.removeTask(tag);
return null;
}
Aggregations