YourMoneroRequests::import_recent_wallet_request added

pull/30/head
moneroexamples 7 years ago
parent f7c01fe9cb
commit 68dfadbb2a

@ -33,6 +33,7 @@
},
"refresh_block_status_every_seconds" : 10,
"search_thread_life_in_seconds" : 300,
"max_number_of_blocks_to_import" : 8000,
"ssl" :
{
"enable" : false,

@ -1268,6 +1268,15 @@ p {
font-weight: 500;
text-align: center;
}
.success-backing {
padding-top: 15px;
border-radius: 3px;
background-color: #008331;
font-family: Proximanova, sans-serif;
color: white;
font-weight: 500;
text-align: center;
}
.support-block {
display: inline-block;
margin-left: 12px;

@ -26,13 +26,14 @@
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
thinwalletCtrls.controller("ImportWalletCtrl", function($scope, $location, $http, AccountService, ModalService, $interval) {
thinwalletCtrls.controller("ImportWalletCtrl", function($scope, $location, $http, AccountService, ModalService, $interval, $timeout) {
"use strict";
$scope.payment_address = '';
$scope.payment_id = '';
$scope.import_fee = JSBigInt.ZERO;
$scope.status = '';
$scope.command = '';
$scope.success = '';
$scope.no_blocks_to_import = "1000";
function get_import_request() {
@ -57,15 +58,34 @@ thinwalletCtrls.controller("ImportWalletCtrl", function($scope, $location, $http
});
}
var getRequestInterval = $interval(get_import_request, 10 * 1000);
get_import_request();
// var getRequestInterval = $interval(get_import_request, 10 * 1000);
// get_import_request();
//
// $scope.$on('$destroy', function() {
// $interval.cancel(getRequestInterval);
// });
$scope.$on('$destroy', function() {
$interval.cancel(getRequestInterval);
});
$scope.importLast = function()
{
if ($scope.no_blocks_to_import > 8000) {
ModalService.hide('imported-account');
return;
}
$http.post(config.apiUrl + "import_recent_wallet_request", {
address: AccountService.getAddress(),
view_key: AccountService.getViewKey(),
no_blocks_to_import: $scope.no_blocks_to_import
}).success(function(data) {
$scope.status = data.status;
$scope.importLast = function(no_blocks) {
alert($scope.no_blocks_to_import);
if (data.request_fulfilled) {
$scope.success = "Request successful. Import will start shortly. This window will close in few seconds.";
$timeout(function(){ModalService.hide('imported-account')}, 5000);
}
}).error(function(err) {
$scope.error = err.Error || err || "An unexpected server error occurred";
});
}
});

@ -25,7 +25,7 @@
</div>
<div class="submit-div small-top-margin">
<a class="login-btn modals pointer" hide-modal="" ng-click="importLast('10000')">Import recent transactions</a>
<a class="login-btn modals pointer" ng-click="importLast()">Import recent transactions</a>
</div>
@ -34,6 +34,12 @@
<div class="submit-div small-top-margin">
<a class="login-btn modals pointer" hide-modal="">Don't import transactions</a>
</div>
<div class="w-form-fail error-backing" style="display: block;" ng-show="!!error">
<p>{{error}}</p>
</div>
<div class="w-form-done success-backing" style="display: block;" ng-show="!!success">
<p>{{success}}</p>
</div>
</div>
</div>
</div>

@ -104,6 +104,8 @@ xmreg::CurrentBlockchainStatus::deamon_url
= deamon_url;
xmreg::CurrentBlockchainStatus::refresh_block_status_every_seconds
= config_json["refresh_block_status_every_seconds"];
xmreg::CurrentBlockchainStatus::max_number_of_blocks_to_import
= config_json["max_number_of_blocks_to_import"];
xmreg::CurrentBlockchainStatus::search_thread_life_in_seconds
= config_json["search_thread_life_in_seconds"];
xmreg::CurrentBlockchainStatus::import_fee
@ -159,9 +161,9 @@ MAKE_RESOURCE(get_unspent_outs);
MAKE_RESOURCE(get_random_outs);
MAKE_RESOURCE(submit_raw_tx);
MAKE_RESOURCE(import_wallet_request);
MAKE_RESOURCE(import_recent_wallet_request);
MAKE_RESOURCE(get_version);
// restbed service
Service service;
@ -173,6 +175,7 @@ service.publish(get_unspent_outs);
service.publish(get_random_outs);
service.publish(submit_raw_tx);
service.publish(import_wallet_request);
service.publish(import_recent_wallet_request);
service.publish(get_version);
auto settings = make_shared<Settings>( );

@ -29,6 +29,7 @@ bool CurrentBlockchainStatus::do_not_relay{false};
bool CurrentBlockchainStatus::is_running{false};
std::thread CurrentBlockchainStatus::m_thread;
uint64_t CurrentBlockchainStatus::refresh_block_status_every_seconds{20};
uint64_t CurrentBlockchainStatus::max_number_of_blocks_to_import{8000};
uint64_t CurrentBlockchainStatus::search_thread_life_in_seconds {600}; // 10 minutes
vector<pair<uint64_t, transaction>> CurrentBlockchainStatus::mempool_txs;
string CurrentBlockchainStatus::import_payment_address;

@ -49,6 +49,8 @@ struct CurrentBlockchainStatus
static uint64_t refresh_block_status_every_seconds;
static uint64_t max_number_of_blocks_to_import;
static uint64_t search_thread_life_in_seconds;
static string import_payment_address;

@ -614,18 +614,27 @@ YourMoneroRequests::get_random_outs(const shared_ptr< Session > session, const B
uint64_t count = j_request["count"];
json j_response {
{"amount_outs", json::array()}
};
vector<uint64_t> amounts;
// populate amounts vector so that we can pass it directly to
// daeamon to get random outputs for these amounts
for (json amount: j_request["amounts"])
try
{
amounts.push_back(boost::lexical_cast<uint64_t>(amount.get<string>()));
// populate amounts vector so that we can pass it directly to
// daeamon to get random outputs for these amounts
for (json amount: j_request["amounts"])
{
amounts.push_back(boost::lexical_cast<uint64_t>(amount.get<string>()));
}
}
catch (boost::bad_lexical_cast& e)
{
cerr << "Bed lexical cast" << '\n';
session_close(session, j_response.dump());
return;
}
json j_response {
{"amount_outs", json::array()}
};
vector<COMMAND_RPC_GET_RANDOM_OUTPUTS_FOR_AMOUNTS::outs_for_amount> found_outputs;
@ -832,6 +841,96 @@ YourMoneroRequests::import_wallet_request(const shared_ptr< Session > session, c
}
void
YourMoneroRequests::import_recent_wallet_request(const shared_ptr< Session > session, const Bytes & body)
{
json j_response;
json j_request;
vector<string> requested_values {"address" , "view_key", "no_blocks_to_import"};
if (!parse_request(body, requested_values, j_request, j_response))
{
session_close(session, j_response.dump());
return;
}
string xmr_address = j_request["address"];
string view_key = j_request["view_key"];
uint64_t no_blocks_to_import {1000};
try
{
no_blocks_to_import = boost::lexical_cast<uint64_t>(j_request["no_blocks_to_import"].get<string>());
}
catch (boost::bad_lexical_cast& e)
{
cerr << "Cant cast " << j_request["no_blocks_to_import"] << " into number."
<< " Using default value of " << no_blocks_to_import << '\n';
}
// make sure that we dont import more that the maximum alowed no of blocks
no_blocks_to_import = std::min(no_blocks_to_import,
CurrentBlockchainStatus::max_number_of_blocks_to_import);
bool request_fulfilled {false};
XmrAccount acc;
if (xmr_accounts->select(xmr_address, acc))
{
XmrAccount updated_acc = acc;
// make sure scanned_block_height is larger than no_blocks_to_import so we dont
// end up with overflowing uint64_t.
if (updated_acc.scanned_block_height > no_blocks_to_import)
{
// repetead calls to import_recent_wallet_request will be moving the scanning backward.
// not sure yet if any protection is needed to make sure that a user does not
// go back too much back by importing his/hers wallet multiple times in a row.
updated_acc.scanned_block_height = updated_acc.scanned_block_height - no_blocks_to_import;
if (xmr_accounts->update(acc, updated_acc))
{
// change search blk number in the search thread
if (!CurrentBlockchainStatus::set_new_searched_blk_no(xmr_address,
updated_acc.scanned_block_height))
{
cerr << "Updating searched_blk_no failed!" << endl;
j_response["status"] = "Updating searched_blk_no failed!";
}
else
{
// if success, set acc to updated_acc;
request_fulfilled = true;
}
}
} // if (updated_acc.scanned_block_height > no_blocks_to_import)
}
else
{
cerr << "Updating account with new scanned_block_height failed! " << endl;
j_response["status"] = "Updating account with new scanned_block_height failed!";
}
if (request_fulfilled)
{
j_response["request_fulfilled"] = request_fulfilled;
j_response["status"] = "Updating account with for importing recent txs successeful.";
}
string response_body = j_response.dump();
auto response_headers = make_headers({{ "Content-Length", to_string(response_body.size())}});
session->close( OK, response_body, response_headers);
}
void
YourMoneroRequests::get_version(const shared_ptr< Session > session, const Bytes & body)
{
@ -876,8 +975,6 @@ YourMoneroRequests::generic_options_handler( const shared_ptr< Session > session
size_t content_length = request->get_header( "Content-Length", 0);
//cout << "generic_options_handler" << endl;
session->fetch(content_length, [](const shared_ptr< Session > session, const Bytes & body)
{
session->close( OK, string{}, make_headers());

@ -87,6 +87,9 @@ public:
void
import_wallet_request(const shared_ptr< Session > session, const Bytes & body);
void
import_recent_wallet_request(const shared_ptr< Session > session, const Bytes & body);
void
get_version(const shared_ptr< Session > session, const Bytes & body);

Loading…
Cancel
Save