diff --git a/IOTA.lua b/IOTA.lua index 3ac7d99..9f60987 100644 --- a/IOTA.lua +++ b/IOTA.lua @@ -1,5 +1,5 @@ -- Inofficial IOTA Extension for MoneyMoney --- Fetches IOTA quantity for addresses via nodes.thetangle.org +-- Fetches IOTA quantity for addresses via explorer-api.iota.org -- Fetches IOTA price in EUR via CoinGecko API -- Returns cryptoassets as securities -- @@ -8,7 +8,7 @@ -- MIT License --- Copyright (c) 2020 PSperber, aaronk6 +-- Copyright (c) 2023 PSperber, aaronk6 -- Permission is hereby granted, free of charge, to any person obtaining a copy -- of this software and associated documentation files (the "Software"), to deal @@ -30,8 +30,8 @@ WebBanking { - version = 0.3, - description = "Include your IOTAs as cryptoportfolio in MoneyMoney by providing IOTA addresses as usernme (comma seperated) and a random Password", + version = 1.0, + description = "Include your IOTAs as securities in MoneyMoney by providing a comma-separated list of IOTA addresses", services = { "IOTA" } } @@ -92,24 +92,21 @@ end -- function requestIOTAQuantitiesForIOTAAddresses(iotaAddresses) - - local iotaAddressesWithoutChecksum = {} - - -- strip checksums and add quotes - for i,v in ipairs(iotaAddresses) do - iotaAddressesWithoutChecksum[i] = '"' .. string.sub(v, 0, 81) .. '"' + local balances = {} + + for i, address in ipairs(iotaAddresses) do + if isLegacy(address) then + content = connection:get(iotaRequestUrl(address, true)) + json = JSON(content):dictionary() + balances[i] = json["balance"] + else + content = connection:get(iotaRequestUrl(address)) + json = JSON(content):dictionary() + balances[i] = json["totalBalance"] + end end - local headers = {} - headers["X-IOTA-API-Version"] = "1" - - local postContent = '{"command":"getBalances","addresses":['.. strjoin(',', iotaAddressesWithoutChecksum) ..'],"threshold":100}' - print(postContent) - content = connection:request("POST", iotaRequestUrl(), postContent, "application/json", headers) - print(content) - - json = JSON(content) - return json:dictionary()["balances"] + return balances end @@ -118,8 +115,20 @@ function cryptocompareRequestUrl() return "https://api.coingecko.com/api/v3/simple/price?ids=iota&vs_currencies=eur" end -function iotaRequestUrl() - return "https://nodes.thetangle.org:443" +function isLegacy(address) + if string.len(address) == 90 then + return true + elseif string.len(address) == 64 then + return false + end + error("Unknown address format: " .. address) +end + +function iotaRequestUrl(address, legacy) + if legacy then + return "https://explorer-api.iota.org/address/legacy-mainnet/" .. address + end + return "https://explorer-api.iota.org/stardust/balance/chronicle/mainnet/" .. address end -- from http://lua-users.org/wiki/SplitJoin diff --git a/LICENSE b/LICENSE index 75c1ada..fb8d73a 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2020 PSperber, aaronk6 +Copyright (c) 2023 PSperber, aaronk6 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index e9992e2..1cecfd2 100644 --- a/README.md +++ b/README.md @@ -1,16 +1,13 @@ # IOTA-MoneyMoney -Fetches amount and value of privately held IOTA address via https://nodes.iota.cafe/ and returns it as a security. -This can be also be used to track your cold storage. - -Do you like this extension? Donation IOTA address: `OUDFKXFDRSWBCTRSJ9MMFGVENOFGHCADQTJUIKTZJPLPGHEQBCLCZPIANOZ9NO9XQVRRHJNOIJNJTPJRWJBWJXHGFW` -This repository is heavily inspired by [Bitcoin-MoneyMoney](https://github.com/Jacubeit/Bitcoin-MoneyMoney). Thanks! +Fetches amount and value of privately held IOTA address via explorer-api.iota.org and returns it as a security. +This can be also be used to track your cold storage. ## Extension Setup You can get a signed version of this extension from -* my [GitHub releases page](https://github.com/psperber/IOTA-MoneyMoney/releases/tag/v0.1), or +* my [GitHub releases page](https://github.com/aaronk6/IOTA-MoneyMoney/releases), or * the [MoneyMoney Extensions](https://moneymoney-app.com/extensions/) page Once downloaded, move `IOTA.lua` to your MoneyMoney Extensions folder. @@ -19,18 +16,13 @@ Once downloaded, move `IOTA.lua` to your MoneyMoney Extensions folder. Add a new account (type "IOTA"). -**Use your IOTA adresses coma seperated as user name** +**You can define multiple IOTA addresses by comma-separating them:** ``` -BLNGFQXMLCZ9VSENI9IVZZMYUHZLUBKHEVYARVHZIKYTTGGFUFNMLZDXJPMQVNHWGM9CQNIWATMLVQSFQ, LLWMD9SFZFOVVXJQDGFHCTGQFWEAJOJSNDCCPHTKULJTBMGNO9WZYIMZFTAOODFBKABVRYIJXK9ZP9F9U +iota1qrp7wn7ag964yh7r6csphg8l47q9ehlpxz8tukhad09x7avjj09s5qunq87, LLWMD9SFZFOVVXJQDGFHCTGQFWEAJOJSNDCCPHTKULJTBMGNO9WZYIMZFTAOODFBKABVRYIJXK9ZP9F9U ``` (example) -**Use whatever you want as password** +Both mainnet (Bech32) and legacy addresses are supported. -``` -123 -``` - -(example)