Skip to content

Commit

Permalink
Merge pull request Milerius#1 from KomodoPlatform/update_coins_structure
Browse files Browse the repository at this point in the history
change structures
  • Loading branch information
smk762 authored Jan 12, 2023
2 parents b703e7d + 70eb46c commit 29581ba
Show file tree
Hide file tree
Showing 12 changed files with 54 additions and 26 deletions.
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# Build and config files
mm2_tools_server_bin
coins_config.json

# Binaries for programs and plugins
*.exe
*.exe~
Expand All @@ -19,4 +23,4 @@ cmd/mm2_cli_wasm/data/deps
cmd/mm2_cli_wasm/data/js
cmd/mm2_cli_wasm/data/script.js
cmd/mm2_cli_wasm/data/wasm_exec.js
cmd/mm2_cli_wasm/data/static/assets/mm2_market_maker.json
cmd/mm2_cli_wasm/data/static/assets/mm2_market_maker.json
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ go build -o mm2_tools_server_bin cmd/mm2_tools_server/mm2_tools_server.go
curl --location --request POST 'localhost:1313/api/v1/start_simple_market_maker_bot' \
--header 'Content-Type: application/json' \
--data-raw '{
"desktop_cfg_path": "/Users/milerius/Library/Application Support/AtomicDex Desktop/config/0.5.0-coins.Roman.json",
"desktop_cfg_path": "/Users/milerius/coins/utils/coins_config.json",
"mm2_coins_cfg_path": "/Users/milerius/Library/Application Support/AtomicDex Desktop/0.5.0/configs/coins.json",
"market_maker_cfg_path": "/Users/milerius/GolandProjects/mm2-client/mm2/simple_market_bot.json",
"mm2_userpass": "foobar"
Expand Down
1 change: 1 addition & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
go build -o mm2_tools_server_bin cmd/mm2_tools_server/mm2_tools_server.go
4 changes: 2 additions & 2 deletions cli/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ func processMM2Json() {
func processVersionConfiguration() {
version := mm2http.GetLastDesktopVersion()
targetDir := helpers.GetWorkingDir() + "/mm2"
targetPath := targetDir + "/" + version + "-coins.json"
targetUrl := "https://raw.githubusercontent.com/KomodoPlatform/atomicDEX-Desktop/dev/assets/config/" + version + "-coins.json"
targetPath := targetDir + "/coins_config.json"
targetUrl := "https://raw.githubusercontent.com/KomodoPlatform/coins/master/utils/coins_config.json"
if !helpers.FileExists(targetPath) {
helpers.PrintCheck("Checking if desktop coins json is present", false)
emoji.Printf("Downloading now %s :recycle:\n", targetUrl)
Expand Down
6 changes: 4 additions & 2 deletions cmd/mm2_tools_server/mm2_tools_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,13 @@ func main() {
}
matches, _ := filepath.Glob("*.json")
for _, curMatch := range matches {
if strings.Contains(curMatch, "coins.json") {
if strings.Contains(curMatch, "coins_config.json") {
res := config.ParseDesktopRegistryFromFile(curMatch)
if res {
glg.Info("starting price service from within the server")
glg.Info("Starting price service from within the server")
external_services.LaunchPriceServices()
} else {
glg.Error("Failed to start price service!")
}
}
}
Expand Down
13 changes: 9 additions & 4 deletions config/desktop.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ type ElectrumData struct {
DisableCertVerification *bool `json:"disable_cert_verification,omitempty"`
}

type NodesData struct {
URL string `json:"url"`
GuiAuth *bool `json:"gui_auth,omitempty"`
}

type DesktopCFG struct {
Coin string `json:"coin"`
Name string `json:"name"`
Expand All @@ -31,8 +36,8 @@ type DesktopCFG struct {
NomicsId *string `json:"nomics_id,omitempty"`
ForexId *string `json:"forex_id,omitempty"`
Electrum []ElectrumData `json:"electrum,omitempty"`
Nodes []string `json:"nodes,omitempty"`
ExplorerURL []string `json:"explorer_url"`
Nodes []NodesData `json:"nodes,omitempty"`
ExplorerURL string `json:"explorer_url"`
ExplorerTxURL string `json:"explorer_tx_url,omitempty"`
ExplorerAddressURL string `json:"explorer_address_url,omitempty"`
Type string `json:"type"`
Expand Down Expand Up @@ -159,7 +164,7 @@ func GetDesktopPath(appName string) string {
}

func ParseDesktopRegistry(version string) {
var desktopCoinsPath = constants.GMM2Dir + "/" + version + "-coins.json"
var desktopCoinsPath = constants.GMM2Dir + "/coins_config.json"
file, _ := ioutil.ReadFile(desktopCoinsPath)
err := json.Unmarshal([]byte(file), &GCFGRegistry)
if err != nil {
Expand Down Expand Up @@ -391,7 +396,7 @@ func Update(version string) {
//fmt.Println("Updating cfg")
_ = glg.Infof("Updating cfg")
if runtime.GOARCH != "wasm" {
var desktopCoinsPath = constants.GMM2Dir + "/" + version + "-coins.json"
var desktopCoinsPath = constants.GMM2Dir + "/coins_config.json"
e := os.Remove(desktopCoinsPath)
if e != nil {
fmt.Printf("Err: %v", e)
Expand Down
29 changes: 19 additions & 10 deletions mm2_tools_generics/mm2_data_structure/enable.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,23 @@ import (
)

type EnableRequest struct {
Coin string `json:"coin"`
FallbackSwapContract string `json:"fallback_swap_contract"`
Method string `json:"method"`
SwapContractAddress string `json:"swap_contract_address"`
TxHistory bool `json:"tx_history"`
Urls []string `json:"urls"`
Userpass string `json:"userpass"`
GasStationUrl string `json:"gas_station_url,omitempty"`
GasStationDecimals *int `json:"gas_station_decimals,omitempty"`
Coin string `json:"coin"`
FallbackSwapContract string `json:"fallback_swap_contract"`
Method string `json:"method"`
SwapContractAddress string `json:"swap_contract_address"`
TxHistory bool `json:"tx_history"`
Urls []config.NodesData `json:"urls"`
Userpass string `json:"userpass"`
GasStationUrl string `json:"gas_station_url,omitempty"`
GasStationDecimals *int `json:"gas_station_decimals,omitempty"`
}

func NewEnableRequest(cfg *config.DesktopCFG) *EnableRequest {
genReq := NewGenericRequest("enable")
req := &EnableRequest{Userpass: genReq.Userpass, Method: genReq.Method}
req.Coin = cfg.Coin
req.TxHistory = false
req.Urls = cfg.Nodes
req.Urls = getUrls(cfg)
req.SwapContractAddress, req.FallbackSwapContract = cfg.RetrieveContracts()
req.GasStationUrl = cfg.RetrieveGasStationUrl()
req.GasStationDecimals = cfg.RetrieveGasStationDecimals()
Expand All @@ -38,3 +38,12 @@ func (req *EnableRequest) ToJson() string {
}
return string(b)
}

func getUrls(cfg *config.DesktopCFG) []config.NodesData {
var urls []config.NodesData
for _, value := range cfg.Nodes {
urls = append(urls, value)
}
return urls
}

4 changes: 2 additions & 2 deletions mm2_tools_generics/mm2_data_structure/my_tx_history.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,9 @@ func (answer *MyTxHistoryAnswer) ToTable(coinReq string, page int, tx int, withO
txUrl := ""
if cfgExist {
if cfg.ExplorerTxURL != "" {
txUrl = cfg.ExplorerURL[0] + cfg.ExplorerTxURL + curAnswer.TxHash
txUrl = cfg.ExplorerURL + cfg.ExplorerTxURL + curAnswer.TxHash
} else {
txUrl = cfg.ExplorerURL[0] + "tx/" + curAnswer.TxHash
txUrl = cfg.ExplorerURL + "tx/" + curAnswer.TxHash
}
}

Expand Down
4 changes: 2 additions & 2 deletions mm2_tools_generics/mm2_http_request/broadcast.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ func Broadcast(coin string, txHex string) (*mm2_data_structure.BroadcastAnswer,
}

if val.ExplorerTxURL != "" {
answer.TxUrl = val.ExplorerURL[0] + val.ExplorerTxURL + answer.TxHash
answer.TxUrl = val.ExplorerURL + val.ExplorerTxURL + answer.TxHash
} else {
answer.TxUrl = val.ExplorerURL[0] + "tx/" + answer.TxHash
answer.TxUrl = val.ExplorerURL + "tx/" + answer.TxHash
}
return answer, nil
} else {
Expand Down
4 changes: 2 additions & 2 deletions mm2_tools_generics/mm2_wasm_request/broadcast_js_wasm.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ func Broadcast(coin string, txHex string) (*mm2_data_structure.BroadcastAnswer,
return nil, decodeErr
}
if val.ExplorerTxURL != "" {
answer.TxUrl = val.ExplorerURL[0] + val.ExplorerTxURL + answer.TxHash
answer.TxUrl = val.ExplorerURL + val.ExplorerTxURL + answer.TxHash
} else {
answer.TxUrl = val.ExplorerURL[0] + "tx/" + answer.TxHash
answer.TxUrl = val.ExplorerURL + "tx/" + answer.TxHash
}
return answer, nil
}
Expand Down
5 changes: 5 additions & 0 deletions run_prices.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash

pkill -f mm2_tools_server_bin
sleep 5
./mm2_tools_server_bin -only_price_service=true
2 changes: 2 additions & 0 deletions update_coins.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
rm coins_config.json
wget https://raw.githubusercontent.com/KomodoPlatform/coins/master/utils/coins_config.json

0 comments on commit 29581ba

Please sign in to comment.