Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update IOTA request URL #4

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 31 additions & 22 deletions IOTA.lua
Original file line number Diff line number Diff line change
@@ -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
--
Expand All @@ -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
Expand All @@ -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" }
}

Expand Down Expand Up @@ -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


Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -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
Expand Down
20 changes: 6 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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)