-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Update scripting for cryptocurrency management
Here is the summary of the commit: **Update Blockchain Components** - Implement price feed script for Orbs network. - Enhance bitcoin script to display transaction details, transfer cryptocurrency, and improve API request error handling. Note: The most significant changes are highlighted, and the file summaries are not repeated in the commit message. The description and bullet points provide a high-level overview of the changes made in the commit.
- Loading branch information
Showing
2 changed files
with
191 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
local json = require("json") | ||
|
||
_0RBIT = "BaMK1dfayo75s3q1ow6AO64UDpD9SEFbeE8xYrY2fyQ" | ||
_0RBT_TOKEN = "BUhZLMwQ6yZHguLtJYA5lLUa9LQzLXMXRfaq9FVcPJc" | ||
|
||
BASE_URL = "https://api.coingecko.com/api/v3/simple/price" | ||
FEE_AMOUNT = "1000000000000" -- 1 $0RBT | ||
|
||
TOKEN_PRICES = TOKEN_PRICES or { | ||
BTC = { | ||
coingecko_id = "bitcoin", | ||
price = 0, | ||
last_update_timestamp = 0 | ||
}, | ||
ETH = { | ||
coingecko_id = "ethereum", | ||
price = 0, | ||
last_update_timestamp = 0 | ||
}, | ||
SOL = { | ||
coingecko_id = "solana", | ||
price = 0, | ||
last_update_timestamp = 0 | ||
} | ||
} | ||
ID_TOKEN = ID_TOKEN or { | ||
bitcoin = "BTC", | ||
ethereum = "ETH", | ||
solana = "SOL" | ||
} | ||
LOGS = LOGS or {} | ||
|
||
function fetchPrice() | ||
local url; | ||
local token_ids; | ||
|
||
for _, v in pairs(TOKEN_PRICES) do | ||
token_ids = token_ids .. v.coingecko_id .. "," | ||
end | ||
|
||
url = BASE_URL .. "?ids=" .. token_ids .. "&vs_currencies=usd" | ||
|
||
Send({ | ||
Target = _0RBT_TOKEN, | ||
Action = "Transfer", | ||
Recipient = _0RBIT, | ||
Quantity = FEE_AMOUNT, | ||
["X-Url"] = url, | ||
["X-Action"] = "Get-Real-Data" | ||
}) | ||
print(Colors.green .. "GET Request sent to the 0rbit process.") | ||
end | ||
|
||
function receiveData(msg) | ||
local res = json.decode(msg.Data) | ||
for k, v in pairs(res) do | ||
TOKEN_PRICES[ID_TOKEN[k]].price = tonumber(v.usd) | ||
TOKEN_PRICES[ID_TOKEN[k]].last_update_timestamp = msg.Timestamp | ||
end | ||
end | ||
|
||
function getTokenPrice(msg) | ||
local token = msg.Tags.Token | ||
local price = TOKEN_PRICES[token].price | ||
if price == 0 then | ||
Handlers.utils.reply("Price not available!!!")(msg) | ||
else | ||
Handlers.utils.reply(tostring(price))(msg) | ||
end | ||
end | ||
|
||
Handlers.add("GetTokenPrice", Handlers.utils.hasMatchingTag("Action", "Get-Token-Price"), getTokenPrice) | ||
|
||
Handlers.add("FetchPrice", Handlers.utils.hasMatchingTag("Action", "Fetch-Price"), fetchPrice) | ||
|
||
Handlers.add("ReceiveData", Handlers.utils.hasMatchingTag("Action", "Receive-Response"), receiveData) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters