KomodoPlatform / komodo-defi-framework

This is the official Komodo DeFi Framework repository
https://komodoplatform.com/en/docs/komodo-defi-framework/
104 stars 95 forks source link

Enable Coin Not Reading Correct Directory #498

Closed mattt21 closed 5 years ago

mattt21 commented 5 years ago

Running macOS. Launching mm2 with native daemon instead of electrum does not read proper directory of ~/Library/Application Support/$name. Launching coin returns:

{"error":"lp_coins:695] lp_coins:662] utxo:1606] utxo:1559] No such file or directory.

https://github.com/KomodoPlatform/atomicDEX-API/blob/mm2/mm2src/coins/utxo.rs#L1530

Should not use home_dir() for darwin as it returns "/Users/Alice" folder for mac.

mattt21 commented 5 years ago

Consider using app dirs:

https://docs.rs/app_dirs/1.2.1/app_dirs/

ArtemGr commented 5 years ago

@mattt21 , which native daemon it is? komodod or another one? Different daemons would sometimes have different algorithms regarding the configuration path, not all of them adhere to the Apple hier.

P.S. Also what is the coin and what is the actual listing of ~/Library/Application Support/ for that coin? The case might be different as well (Litecoin, litecoin, .litecoin).

mattt21 commented 5 years ago

@ArtemGr This is regarding mm2 reading coin directories for all btc native coins using darwin, the coin directory is in ~/Library/Application Support/$name for all coins BTC,NIX,LTC etc.

The current setup checks for /Users/Alice/.$name which is the reason the directory cannot be found by the mm2 daemon.

If I move my coin .conf to /Users/Alice/.$name/$name.conf everything is fine and mm2 reads my coin config, but that is not the standard directory for btc based coins on darwin, so it is important that is changed.

ArtemGr commented 5 years ago

I've asked three questions (the coin, the daemon, the listing) and I don't see an answer for any of them, give me something specific please.

mattt21 commented 5 years ago

This is regarding mm2 reading coin directories for all btc native coins using darwin. Does this not answer any of your questions if not all? I do not think you understand fully what I am saying.

ArtemGr commented 5 years ago

I do not think you understand fully what I am saying.

I wrote this code in mm2 and I've researched the respective code in komodod. I understand what you're saying, but I want specific examples to proceed.

mattt21 commented 5 years ago

For example, if I run BTC QT, my native directory is in ~/Library/Application Support/bitcoin.

When I run mm2 and set up BTC as a coin, it will throw the error that the conf & directory is not found. This is because mm2 searches in the wrong directory. Should be searching the appdata folder for the bitcoin folder. Not userdata.

ArtemGr commented 5 years ago

For example, if I run BTC QT, my native directory is in ~/Library/Application Support/bitcoin.

See, this is different from what's documented at https://github.com/jl777/coins#bitcoin-protocol-specific-json (the case is wrong). That's why I asked for an example. Thanks.

mattt21 commented 5 years ago

How is that different?

"~/Library/Application Support/Litecoin/" for LTC. MM2 does not search that path. It searches the user directory.

ArtemGr commented 5 years ago

How is that different?

According to https://github.com/jl777/coins#bitcoin-protocol-specific-json it should be "Bitcoin", not "bitcoin".

mattt21 commented 5 years ago

Ok. If it is Bitcoin, it would still be wrong though. As mm2 does not even search that directory.

mattt21 commented 5 years ago

even if it is xyz coin. mm2 is not searching appdata and that is the issue. It will never find the conf when it is searching the userdata directory even if the names are correct.

ArtemGr commented 5 years ago

Ok. If it is Bitcoin, it would still be wrong though.

Exactly! That's why I want a specific example. What coin are you trying to use and how is it listed under ~/Library/Application Support/? And what coin daemon are you using?

mattt21 commented 5 years ago

Ok let me explain this one more time....

I run XYZ coin. The native directory is ~/Library/Application Support/XYZ

The coin config is in ~/Library/Application Support/XYZ/XYZ.conf

I run MM2 and enable XYZ coin. MM2 searches for the XYZ.conf in /USER/ALICE/.XYZ/XYZ.conf

It will never find the conf there as it is searching in the wrong directory.

ArtemGr commented 5 years ago

XYZ is a ticker, not a coin name. Don't generalize, give me a specific use case.

mattt21 commented 5 years ago

Since you are having a hard time understanding, I will make the PR when I have time. For now, mm2 is broken for Darwin users.

ArtemGr commented 5 years ago

Like I said, the coin path might be different for different coin daemons (it is implementation-specific). Please provide the information about the daemon and the coin you're using with the PR.

Both HFS+ and APFS might be case sensitive and we need to research the actual use cases before we change the path resolution there.

artemii235 commented 5 years ago

In some of our automated (and currently unused tests) we were already using ~/Library/Application Support for Darwin, but in the MM2 code it's not used so KMD and assetchains and likely all other UTXO coins won't work in native mode not only on Darwin, but on Windows too. app_dirs crate is worth to consider, but it might be sufficient to merge the unused tests code to MM2 utxo support codebase.

It will be done together with https://github.com/KomodoPlatform/atomicDEX-API/issues/499.

ArtemGr commented 5 years ago

@artemii235 , keep in mind that the test code you've mentioned matched the behavior of komodod but doesn't adhere to Apple guidelines.

That is, on the Apple operating systems we ought to be using the Apple libraries to determine the application library path: "Consider that these directories may be in different locations if your app is sandboxed. As a result, always use the NSFileManager method URLsForDirectory:inDomains: with the NSUserDomainMask as the domain to locate the specific directory that you should use to store this data."
But that's not what the komodod is doing and hence neither do we.

I suspect that other native wallet implementations might use different methods of locating the library path. If you have some practical data on this, I'd appreciate if you'd share it.

P.S. On Windows the situation is reversed, komodod is using SHGetSpecialFolderPathA, which is different from how the app_dirs works.

artemii235 commented 5 years ago

Bitcoin code doesn't use specific MacOS APIs to retrieve the data directory path, it's using ~/Library/Application Support/Bitcoin: https://github.com/bitcoin/bitcoin/blob/master/src/util/system.cpp#L704. Same for litecoin, except the coin name

All UTXO coins are actually Bitcoin forks as of now, so using the ~/Library/Application Support/ path will be valid for like 99.9% cases. Of course, some coins may use another path, but we already have the confpath field for this in coins file.

artemii235 commented 5 years ago

@mattt21 It should be fixed now, could you test please when you have time?

artemii235 commented 5 years ago

Closing as it seems to be fixed.