use webasm and core.js from mymonero.cor

new_rpc
moneroexamples 5 years ago
parent 10e54f66d5
commit 764e45420e

@ -0,0 +1,159 @@
# Generated by YCM Generator at 2019-01-02 17:01:50.568923
# This file is NOT licensed under the GPLv3, which is the license for the rest
# of YouCompleteMe.
#
# Here's the license text for this file:
#
# This is free and unencumbered software released into the public domain.
#
# Anyone is free to copy, modify, publish, use, compile, sell, or
# distribute this software, either in source code form or as a compiled
# binary, for any purpose, commercial or non-commercial, and by any
# means.
#
# In jurisdictions that recognize copyright laws, the author or authors
# of this software dedicate any and all copyright interest in the
# software to the public domain. We make this dedication for the benefit
# of the public at large and to the detriment of our heirs and
# successors. We intend this dedication to be an overt act of
# relinquishment in perpetuity of all present and future rights to this
# software under copyright law.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
# IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
# OTHER DEALINGS IN THE SOFTWARE.
#
# For more information, please refer to <http://unlicense.org/>
import os
import ycm_core
flags = [
'-x',
'c++',
'-DASIO_STANDALONE=YES',
'-DBUILD_SSL=TRUE',
'-I/home/mwo2/monero/build',
'-I/home/mwo2/monero/contrib/epee/include',
'-I/home/mwo2/monero/external',
'-I/home/mwo2/monero/external/db_drivers/liblmdb',
'-I/home/mwo2/monero/external/easylogging++',
'-I/home/mwo2/monero/src',
'-I/home/mwo2/openmonero/ext/restbed/source',
'-I/tmp/tmp9cWyau/gen',
'-I/usr/include/mysql',
'-I/usr/local/include',
'-I/usr/local/include/mysql',
'-I/usr/local/opt/openssl/include',
'-Wall',
'-Weffc++',
'-Wextra',
'-Wno-unknown-pragmas',
'-std=c++11',
'-std=gnu++14',
'-isystem', '/home/mwo2/openmonero/ext/restbed/dependency/asio/asio/include',
'-isystem', '/home/mwo2/openmonero/ext/restbed/dependency/kashmir',
]
# Set this to the absolute path to the folder (NOT the file!) containing the
# compile_commands.json file to use that instead of 'flags'. See here for
# more details: http://clang.llvm.org/docs/JSONCompilationDatabase.html
#
# You can get CMake to generate this file for you by adding:
# set( CMAKE_EXPORT_COMPILE_COMMANDS 1 )
# to your CMakeLists.txt file.
#
# Most projects will NOT need to set this to anything; you can just change the
# 'flags' list of compilation flags. Notice that YCM itself uses that approach.
compilation_database_folder = ''
if os.path.exists( compilation_database_folder ):
database = ycm_core.CompilationDatabase( compilation_database_folder )
else:
database = None
SOURCE_EXTENSIONS = [ '.C', '.cpp', '.cxx', '.cc', '.c', '.m', '.mm' ]
def DirectoryOfThisScript():
return os.path.dirname( os.path.abspath( __file__ ) )
def MakeRelativePathsInFlagsAbsolute( flags, working_directory ):
if not working_directory:
return list( flags )
new_flags = []
make_next_absolute = False
path_flags = [ '-isystem', '-I', '-iquote', '--sysroot=' ]
for flag in flags:
new_flag = flag
if make_next_absolute:
make_next_absolute = False
if not flag.startswith( '/' ):
new_flag = os.path.join( working_directory, flag )
for path_flag in path_flags:
if flag == path_flag:
make_next_absolute = True
break
if flag.startswith( path_flag ):
path = flag[ len( path_flag ): ]
new_flag = path_flag + os.path.join( working_directory, path )
break
if new_flag:
new_flags.append( new_flag )
return new_flags
def IsHeaderFile( filename ):
extension = os.path.splitext( filename )[ 1 ]
return extension in [ '.H', '.h', '.hxx', '.hpp', '.hh' ]
def GetCompilationInfoForFile( filename ):
# The compilation_commands.json file generated by CMake does not have entries
# for header files. So we do our best by asking the db for flags for a
# corresponding source file, if any. If one exists, the flags for that file
# should be good enough.
if IsHeaderFile( filename ):
basename = os.path.splitext( filename )[ 0 ]
for extension in SOURCE_EXTENSIONS:
replacement_file = basename + extension
if os.path.exists( replacement_file ):
compilation_info = database.GetCompilationInfoForFile(
replacement_file )
if compilation_info.compiler_flags_:
return compilation_info
return None
return database.GetCompilationInfoForFile( filename )
def FlagsForFile( filename, **kwargs ):
if database:
# Bear in mind that compilation_info.compiler_flags_ does NOT return a
# python list, but a "list-like" StringVec object
compilation_info = GetCompilationInfoForFile( filename )
if not compilation_info:
return None
final_flags = MakeRelativePathsInFlagsAbsolute(
compilation_info.compiler_flags_,
compilation_info.compiler_working_dir_ )
else:
relative_to = DirectoryOfThisScript()
final_flags = MakeRelativePathsInFlagsAbsolute( flags, relative_to )
return {
'flags': final_flags,
'do_cache': True
}

@ -36,34 +36,14 @@ class HostedMoneroAPIClient
throw "self.$http required"
}
}
//
// Getting outputs for sending funds
UnspentOuts(
address,
view_key__private,
spend_key__public,
spend_key__private,
mixinNumber,
sweeping,
fn
) { // -> RequestHandle
UnspentOuts(parameters, fn)
{ // -> RequestHandle
const self = this
mixinNumber = parseInt(mixinNumber) // jic
//
var parameters =
{
address: address,
view_key: view_key__private
};
parameters.amount = '0'
parameters.mixin = mixinNumber
parameters.use_dust = true // Client now filters unmixable by dustthreshold amount (unless sweeping) + non-rct
parameters.dust_threshold = mymonero_core_js.monero_config.dustThreshold.toString()
const endpointPath = 'get_unspent_outs'
self.$http.post(config.apiUrl + endpointPath, parameters).then(
function(data)
{
__proceedTo_parseAndCallBack(data.data)
fn(null, data.data)
}
).catch(
function(data)
@ -71,31 +51,6 @@ class HostedMoneroAPIClient
fn(data && data.Error ? data.Error : "Something went wrong with getting your available balance for spending");
}
);
function __proceedTo_parseAndCallBack(data)
{
mymonero_core_js.monero_utils_promise.then(function(monero_utils)
{
mymonero_core_js.api_response_parser_utils.Parsed_UnspentOuts__keyImageManaged(
data,
address,
view_key__private,
spend_key__public,
spend_key__private,
monero_utils,
function(err, retVals)
{
if (err) {
fn(err)
return
}
fn(null, retVals.unspentOutputs, retVals.per_byte_fee__string)
}
)
}).catch(function(err)
{
fn(err)
})
}
const requestHandle =
{
abort: function()
@ -105,37 +60,14 @@ class HostedMoneroAPIClient
}
return requestHandle
}
//
RandomOuts(
using_outs,
mixinNumber,
fn
) { // -> RequestHandle
RandomOuts(parameters, fn)
{ // -> RequestHandle
const self = this
//
mixinNumber = parseInt(mixinNumber)
if (mixinNumber < 0 || isNaN(mixinNumber)) {
const errStr = "Invalid mixin - must be >= 0"
const err = new Error(errStr)
fn(err)
return
}
//
var amounts = [];
for (var l = 0; l < using_outs.length; l++) {
amounts.push(using_outs[l].rct ? "0" : using_outs[l].amount.toString())
}
//
var parameters =
{
amounts: amounts,
count: mixinNumber + 1 // Add one to mixin so we can skip real output key if necessary
}
const endpointPath = 'get_random_outs'
self.$http.post(config.apiUrl + endpointPath, parameters).then(
function(data)
{
__proceedTo_parseAndCallBack(data.data)
fn(null, data.data)
}
).catch(
function(data)
@ -143,13 +75,6 @@ class HostedMoneroAPIClient
fn(data && data.Error ? data.Error : "Something went wrong while getting decoy outputs");
}
);
function __proceedTo_parseAndCallBack(data)
{
console.log("debug: info: random outs: data", data)
const amount_outs = data.amount_outs
//
fn(null, amount_outs)
}
const requestHandle =
{
abort: function()
@ -159,46 +84,21 @@ class HostedMoneroAPIClient
}
return requestHandle
}
//
// Runtime - Imperatives - Public - Sending funds
SubmitSerializedSignedTransaction(
address,
view_key__private,
serializedSignedTx,
fn // (err?) -> RequestHandle
) {
SubmitRawTx(parameters, fn)
{
const self = this
//
var parameters =
{
address: address,
view_key: view_key__private
};
parameters.tx = serializedSignedTx
const endpointPath = 'submit_raw_tx'
self.$http.post(config.apiUrl + endpointPath, parameters).then(
function(data)
{
if (data.data.error)
{
const errStr = "Invalid mixin - must be >= 0";
const err = new Error(data.data.error);
fn(err);
return;
}
__proceedTo_parseAndCallBack(data.data)
fn(null, data.data)
}
).catch(
function(data)
{
fn(data && data.Error ? data.Error : "Something went wrong with getting your available balance for spending");
fn(data && data.Error ? data.Error : "Something went wrong while submitting your transaction");
}
);
function __proceedTo_parseAndCallBack(data)
{
console.log("debug: info: submit_raw_tx: data", data)
fn(null)
}
const requestHandle =
{
abort: function()
@ -282,7 +182,7 @@ thinwalletCtrls.controller('SendCoinsCtrl', function($scope, $http, $q, AccountS
$scope.error = "";
$scope.submitting = true;
//
mymonero_core_js.monero_utils_promise.then(function(monero_utils)
mymonero_core_js.monero_utils_promise.then(function(coreBridge_instance)
{
if (targets.length > 1) {
throw "MyMonero currently only supports one target"
@ -296,7 +196,7 @@ thinwalletCtrls.controller('SendCoinsCtrl', function($scope, $http, $q, AccountS
if (err) {
console.error("Err:", err)
$scope.status = "";
$scope.error = "Something unexpected occurred when submitting your transaction: " + (err.Error || err);
$scope.error = "Something unexpected occurred when sending funds: " + (err.Error || err);
$scope.submitting = false;
return
}
@ -327,6 +227,7 @@ thinwalletCtrls.controller('SendCoinsCtrl', function($scope, $http, $q, AccountS
$http.post(config.apiUrl + "get_txt_records", {
domain: domain
}).then(function(data) {
var data = data.data;
var records = data.records;
var oaRecords = [];
console.log(domain + ": ", data.records);
@ -359,7 +260,7 @@ thinwalletCtrls.controller('SendCoinsCtrl', function($scope, $http, $q, AccountS
console.log("OpenAlias record: ", oaRecords[0]);
var oaAddress = oaRecords[0].address;
try {
monero_utils.decode_address(oaAddress, config.nettype);
coreBridge_instance.decode_address(oaAddress, config.nettype);
confirmOpenAliasAddress(
domain,
oaAddress,
@ -390,12 +291,12 @@ thinwalletCtrls.controller('SendCoinsCtrl', function($scope, $http, $q, AccountS
// xmr address (incl subaddresses):
try {
// verify that the address is valid
monero_utils.decode_address(target.address, config.nettype);
sendTo(target.address, amount, null /*domain*/);
coreBridge_instance.decode_address(target.address, config.nettype);
} catch (e) {
fn("Failed to decode address (#" + i + "): " + e);
fn("Failed to decode address with error: " + e);
return;
}
sendTo(target.address, amount, null /*domain*/);
//
function sendTo(target_address, amount, domain/*may be null*/)
{
@ -409,40 +310,76 @@ thinwalletCtrls.controller('SendCoinsCtrl', function($scope, $http, $q, AccountS
//
_configureWith_statusUpdate(statusUpdate_messageBase);
//
const monero_sendingFunds_utils = mymonero_core_js.monero_sendingFunds_utils
monero_sendingFunds_utils.SendFunds(
target_address,
config.nettype,
amount,
sweeping,
AccountService.getAddress(),
AccountService.getSecretKeys(),
AccountService.getPublicKeys(),
new HostedMoneroAPIClient({ $http: $http }),
payment_id, // passed in
1, /* priority */
function(code)
const sec_keys = AccountService.getSecretKeys()
const pub_keys = AccountService.getPublicKeys()
const apiClient = new HostedMoneroAPIClient({ $http: $http })
var parsed_amount;
try {
parsed_amount = mymonero_core_js.monero_amount_format_utils.parseMoney(target.amount);
} catch (e) {
fn("Please enter a valid amount");
return
}
const send_args =
{
is_sweeping: sweeping,
payment_id_string: payment_id, // passed in
sending_amount: sweeping ? 0 : parsed_amount.toString(), // sending amount
from_address_string: AccountService.getAddress(),
sec_viewKey_string: sec_keys.view,
sec_spendKey_string: sec_keys.spend,
pub_spendKey_string: pub_keys.spend,
to_address_string: target_address,
priority: 1,
unlock_time: 0, // unlock_time
nettype: config.nettype,
//
get_unspent_outs_fn: function(req_params, cb)
{
apiClient.UnspentOuts(req_params, function(err_msg, res)
{
cb(err_msg, res);
});
},
get_random_outs_fn: function(req_params, cb)
{
let suffix = monero_sendingFunds_utils.SendFunds_ProcessStep_MessageSuffix[code]
apiClient.RandomOuts(req_params, function(err_msg, res)
{
cb(err_msg, res);
});
},
submit_raw_tx_fn: function(req_params, cb)
{
apiClient.SubmitRawTx(req_params, function(err_msg, res)
{
cb(err_msg, res);
});
},
//
status_update_fn: function(params)
{
let suffix = mymonero_core_js.monero_sendingFunds_utils.SendFunds_ProcessStep_MessageSuffix[params.code]
_configureWith_statusUpdate(
statusUpdate_messageBase + " " + suffix, // TODO: localize this concatenation
code
params.code
)
},
function(
currencyReady_targetDescription_address,
sentAmount, final__payment_id,
tx_hash, tx_fee, tx_key, mixin
) {
let total_sent__JSBigInt = sentAmount.add(tx_fee)
let total_sent__atomicUnitString = total_sent__JSBigInt.toString()
let total_sent__floatString = mymonero_core_js.monero_amount_format_utils.formatMoney(total_sent__JSBigInt)
let total_sent__float = parseFloat(total_sent__floatString)
error_fn: function(params)
{
fn(params.err_msg)
},
success_fn: function(params)
{
const total_sent__JSBigInt = new JSBigInt(params.total_sent)
const tx_fee = new JSBigInt(params.used_fee)
const total_sent__atomicUnitString = total_sent__JSBigInt.toString()
const total_sent__floatString = mymonero_core_js.monero_amount_format_utils.formatMoney(total_sent__JSBigInt)
const total_sent__float = parseFloat(total_sent__floatString)
//
const mockedTransaction =
{
hash: tx_hash,
mixin: "" + mixin,
hash: params.tx_hash,
mixin: "" + params.mixin,
coinbase: false,
mempool: true, // is that correct?
//
@ -459,20 +396,24 @@ thinwalletCtrls.controller('SendCoinsCtrl', function($scope, $http, $q, AccountS
approx_float_amount: -1 * total_sent__float, // -1 cause it's outgoing
// amount: new JSBigInt(sentAmount), // not really used (note if you uncomment, import JSBigInt)
//
payment_id: final__payment_id, // b/c `payment_id` may be nil of short pid was used to fabricate an integrated address
payment_id: params.final_payment_id, // b/c `payment_id` may be nil of short pid was used to fabricate an integrated address
//
// info we can only preserve locally
tx_fee: tx_fee,
tx_key: tx_key,
tx_key: params.tx_key,
tx_pub_key: params.tx_pub_key,
target_address: target_address, // only we here are saying it's the target
};
fn(null, mockedTransaction, domain)
},
function(err)
{ // failed-fn
fn(err)
}
)
}
try {
// verify that the address is valid
coreBridge_instance.async__send_funds(send_args);
} catch (e) {
fn("Failed to send with exception: " + e);
return;
}
}
})
};

File diff suppressed because one or more lines are too long
Loading…
Cancel
Save