Skip to content
Permalink
Browse files

Merge branch 'mm2-rpcport' into mm2

  • Loading branch information...
ArtemGr committed Apr 1, 2019
2 parents c8a15ad + 5bc63ed commit a7ad38dcf60282511555d8d01a9bfce893488fca
Showing with 41 additions and 20 deletions.
  1. +5 −1 iguana/exchanges/LP_include.h
  2. +17 −12 mm2src/coins/lp_coins.rs
  3. +8 −3 mm2src/coins/utxo.rs
  4. +8 −1 mm2src/common/common.rs
  5. +3 −3 mm2src/mm2_tests.rs
@@ -293,7 +293,11 @@ struct iguana_info
int32_t numutxos,notarized,longestchain,firstrefht,firstscanht,lastscanht,height,txversion; uint16_t busport,did_addrutxo_reset;
uint32_t dPoWtime,lastautosplit,lastresetutxo,loadedcache,electrumlist,lastunspent,importedprivkey,lastpushtime,lastutxosync,addr_listunspent_requested,lastutxos,updaterate,counter,inactive,lastmempool,lastgetinfo,ratetime,heighttime,lastmonitor,obooktime;
uint8_t pubtype,p2shtype,isPoS,wiftype,wiftaddr,taddr,noimportprivkey_flag,userconfirms,isassetchain,maxconfirms;
char symbol[128],smartaddr[64],userpass[1024],serverport[128],instantdex_address[64],estimatefeestr[32],getinfostr[32],etomic[64],validateaddress[64];
char symbol[128],smartaddr[64],userpass[1024];
/// The "$host:$port" address of the coin wallet.
/// Fetched from the wallet config when we can find it.
char serverport[128];
char instantdex_address[64],estimatefeestr[32],getinfostr[32],etomic[64],validateaddress[64];
// portfolio
double price_kmd,force,perc,goal,goalperc,relvolume,rate;
void *electrum; void *ctx;
@@ -637,11 +637,6 @@ fn lp_coininit (ctx: &MmArc, ticker: &str, req: &Json) -> Result<MmCoinEnum, Str
}

let c_ticker = try_s! (CString::new (ticker));
let rpcport = match coins_en["rpcport"].as_u64() {
Some (port) if port > 0 && port < u16::max_value() as u64 => port as u16,
// NB: 0 for anything that's not "BTC" or "KMD".
_ => unsafe {lp::LP_rpcport (c_ticker.as_ptr() as *mut c_char)}
};

let _estimatedrate = coins_en["estimatedrate"].as_f64().unwrap_or (20.);

@@ -675,7 +670,6 @@ fn lp_coininit (ctx: &MmArc, ticker: &str, req: &Json) -> Result<MmCoinEnum, Str
ii.inactive = inactive as u32;
ii.ctx = unsafe {bitcoin_ctx() as *mut c_void};
ii.noimportprivkey_flag = match ticker {"XVG" | "CLOAK" | "PPC" | "BCC" | "ORB" => 1, _ => 0};
if rpcport != 0 {try_s! (safecopy! (ii.serverport, "127.0.0.1:{}", rpcport))}
unsafe {lp::LP_coin_curl_init (&mut *ii)};
ii.decimals = coins_en["decimals"].as_u64().unwrap_or (0) as u8;
ii.overwintered = coins_en["overwintered"].as_u64().unwrap_or (0) as u8;
@@ -703,22 +697,35 @@ fn lp_coininit (ctx: &MmArc, ticker: &str, req: &Json) -> Result<MmCoinEnum, Str
let ii = Box::leak (ii);
common::for_c::LP_coinadd (ii);

let rpcport = unsafe {
let rpc_port = unsafe {
let rpcportₒ = match coins_en["rpcport"].as_u64() {
Some (port) if port > 0 && port < u16::max_value() as u64 => port as u16,
// NB: 0 for anything that's not "BTC" or "KMD".
_ => lp::LP_rpcport (c_ticker.as_ptr() as *mut c_char)
};

let confpathᵖ = try_s! (confpath (coins_en));
let confpathˢ = try_s! (confpathᵖ.to_str().ok_or ("Malformed confpath"));
let confpathᶜ = try_s! (CString::new (confpathˢ));

// Returns the port obtained from the wallet configuration.
// Wallet configuration ports are more likely to work,
// cf. https://github.com/artemii235/SuperNET/issues/359
lp::LP_userpass (
ii.userpass.as_mut_ptr(), // userpass
c_ticker.as_ptr() as *mut c_char, // symbol
null_mut(), // assetname
null_mut(), // confroot
null_mut(), // name
confpathᶜ.as_ptr() as *mut c_char, // confpath
rpcport // origport
rpcportₒ // origport
)
};
if rpcport == 0 {log! ("Warning, coin " (ticker) " doesn't have the 'rpcport' configured")}
if rpc_port == 0 {
log! ("Warning, coin " (ticker) " doesn't have the 'rpcport' configured")
} else {
try_s! (safecopy! (ii.serverport, "127.0.0.1:{}", rpc_port))
}

// TODO: Move the private key into `MmCtx`. Initialize it before `lp_coininit`.
let passphrase = try_s! (ctx.conf["passphrase"].as_str().ok_or ("!passphrase"));
@@ -816,10 +823,8 @@ fn lp_coininit (ctx: &MmArc, ticker: &str, req: &Json) -> Result<MmCoinEnum, Str
return ERR! ("lp_coininit ({}): unknown method {:?}", ticker, method);
};

// TODO: Should pick the correct coin implementation somehow.
// Consider changing the config format to set the coin type `explicitly`.
let coin: MmCoinEnum = if coins_en["etomic"].is_null() {
try_s! (utxo_coin_from_iguana_info (ii, utxo_mode)) .into()
try_s! (utxo_coin_from_iguana_info (ii, utxo_mode, rpc_port)) .into()
} else {
try_s! (eth_coin_from_iguana_info(ii, req)) .into()
};
@@ -123,7 +123,8 @@ pub struct UtxoCoinImpl { // pImpl idiom.
/// Is coin protected by Komodo dPoW?
/// https://komodoplatform.com/security-delayed-proof-of-work-dpow/
notarized: bool,
/// RPC port
/// The local RPC port of the coin wallet.
/// Fetched from the wallet config when we can find it.
rpc_port: u16,
/// RPC username
rpc_user: String,
@@ -981,7 +982,10 @@ pub enum UtxoInitMode {
Electrum(Vec<String>),
}

pub fn utxo_coin_from_iguana_info(info: *mut lp::iguana_info, mode: UtxoInitMode) -> Result<MmCoinEnum, String> {
pub fn utxo_coin_from_iguana_info(
info: *mut lp::iguana_info, mode: UtxoInitMode,
rpc_port: u16,
) -> Result<MmCoinEnum, String> {
let info = unsafe { *info };
let ticker = try_s! (unsafe {CStr::from_ptr (info.symbol.as_ptr())} .to_str()) .into();

@@ -1013,6 +1017,7 @@ pub fn utxo_coin_from_iguana_info(info: *mut lp::iguana_info, mode: UtxoInitMode
let auth_str = unsafe { try_s!(CStr::from_ptr(info.userpass.as_ptr()).to_str()) };
let uri = unsafe { try_s!(CStr::from_ptr(info.serverport.as_ptr()).to_str()) };
UtxoRpcClientEnum::Native(NativeClient {
// Similar to `fomat!("http://127.0.0.1:"(rpc_port))`.
uri: format!("http://{}", uri),
auth: format!("Basic {}", base64_encode(auth_str, URL_SAFE)),
})
@@ -1089,7 +1094,7 @@ pub fn utxo_coin_from_iguana_info(info: *mut lp::iguana_info, mode: UtxoInitMode
pub_t_addr_prefix: info.taddr,
p2sh_t_addr_prefix: info.taddr,
rpc_password: "".to_owned(),
rpc_port: 0,
rpc_port,
rpc_user: "".to_owned(),
segwit: false,
wif_prefix: info.wiftype,
@@ -550,11 +550,18 @@ type SlurpFut = Box<Future<Item=(StatusCode, HeaderMap, Vec<u8>), Error=String>

/// Executes a Hyper request, returning the response status, headers and body.
pub fn slurp_req (request: Request<Body>) -> SlurpFut {
let uri = fomat! ((request.uri()));
let request_f = HYPER.request (request);
let response_f = request_f.then (move |res| -> SlurpFut {
// Can fail with:
// "an IO error occurred: An existing connection was forcibly closed by the remote host. (os error 10054)" (on Windows)
let res = try_fus! (res);
// "an error occurred trying to connect: No connection could be made because the target machine actively refused it. (os error 10061)"
// "an error occurred trying to connect: Connection refused (os error 111)"
let res = match res {
Ok (r) => r,
Err (err) => return Box::new (futures::future::err (
ERRL! ("Error accessing '{}': {}", uri, err)))
};
let status = res.status();
let headers = res.headers().clone();
let body_f = res.into_body().concat2();
@@ -930,9 +930,9 @@ fn trade_base_rel_native(base: &str, rel: &str) {
let alice_userpass = unwrap! (var ("ALICE_USERPASS") .ok().or (alice_file_userpass), "No ALICE_USERPASS or .env.client/USERPASS");

let coins = json! ([
{"coin":"BEER","asset":"BEER","rpcport":8923,"confpath":unwrap!(beer_cfp.to_str())},
{"coin":"PIZZA","asset":"PIZZA","rpcport":11608,"confpath":unwrap!(pizza_cfp.to_str())},
{"coin":"ETOMIC","asset":"ETOMIC","rpcport":10271,"confpath":unwrap!(etomic_cfp.to_str())},
{"coin":"BEER","asset":"BEER","confpath":unwrap!(beer_cfp.to_str())},
{"coin":"PIZZA","asset":"PIZZA","confpath":unwrap!(pizza_cfp.to_str())},
{"coin":"ETOMIC","asset":"ETOMIC","confpath":unwrap!(etomic_cfp.to_str())},
{"coin":"ETH","name":"ethereum","etomic":"0x0000000000000000000000000000000000000000","rpcport":80}
]);

0 comments on commit a7ad38d

Please sign in to comment.
You can’t perform that action at this time.