mirror of
https://github.com/fluencelabs/examples
synced 2024-12-04 19:20:17 +00:00
add ETH price getter
This commit is contained in:
parent
3c95cfb815
commit
7fea5d3263
BIN
ether-price-getter/.DS_Store
vendored
Normal file
BIN
ether-price-getter/.DS_Store
vendored
Normal file
Binary file not shown.
19
ether-price-getter/.repl_history
Normal file
19
ether-price-getter/.repl_history
Normal file
@ -0,0 +1,19 @@
|
||||
#V2
|
||||
help
|
||||
l eth_getter artifacts/ether_price_getter.wasm
|
||||
l curl_adapter artifacts/curl_adapter.wasm
|
||||
interface
|
||||
call ether_price_getter ["042baa7d-2e2a-4664-b767-5bdc7988c572", "GBP"]
|
||||
call ether_price_getter ether_price_getter ["042baa7d-2e2a-4664-b767-5bdc7988c572", "GBP"]
|
||||
call ether_price_getter ether_price_getter ["42fc4b0e-59cf-4182-8f22-d4095cf0a738", "GBP"]
|
||||
call ether_price_getter ether_price_getter ["42fc4b0e-59cf-4182-8f22-d4095cf0a738", "USD"]
|
||||
call ether_price_getter ether_price_getter ["42fc4b0e-59cf-4182-8f22-d4095cf0a738", "GBP"]
|
||||
call ether_price_getter ether_price_getter ["42fc4b0e-59cf-4182-8f22-d4095cf0a738", "USD"]
|
||||
call ether_price_getter ether_price_getter ["42fc4b0e-59cf-4182-8f22-d4095cf0a738", "GBP"]
|
||||
call ether_price_getter ether_price_getter ["42fc4b0e-59cf-4182-8f22-d4095cf0a738", "EUR"]
|
||||
interface
|
||||
call ether_price_getter ether_price_getter ["42fc4b0e-59cf-4182-8f22-d4095cf0a738", "EUR"]
|
||||
inte
|
||||
interface
|
||||
call ether_price_getter ether_price_getter ["42fc4b0e-59cf-4182-8f22-d4095cf0a738", "GBP"]
|
||||
interface
|
12
ether-price-getter/Config.toml
Normal file
12
ether-price-getter/Config.toml
Normal file
@ -0,0 +1,12 @@
|
||||
modules_dir = "artifacts/"
|
||||
|
||||
[[module]]
|
||||
name = "curl_adapter"
|
||||
# logger_enabled = false
|
||||
|
||||
[module.mounted_binaries]
|
||||
curl = "/usr/bin/curl"
|
||||
|
||||
[[module]]
|
||||
name = "ether_price_getter"
|
||||
# logger_enabled = true
|
127
ether-price-getter/Readme.md
Normal file
127
ether-price-getter/Readme.md
Normal file
@ -0,0 +1,127 @@
|
||||
# Ether Price Quotation Service
|
||||
|
||||
## Overview
|
||||
This module utilizes curl and the [Coinmarketcap API](https://coinmarketcap.com/api/) to allow the query of the latest Ether (ETH) price relative to some 120 currencies. The service requires a valid Coinmarketcap API key, which is freely available with [registration](https://pro.coinmarketcap.com/signup/). The query function wraps this API call: https://coinmarketcap.com/api/documentation/v1/#operation/getV2CryptocurrencyQuotesLatest:
|
||||
|
||||
```bash
|
||||
ether_price_getter(api_key: String, currency_symbol: String)
|
||||
```
|
||||
|
||||
which expects the [Coinmarketcap API key] and the three letter currency symbol, e.g.:
|
||||
|
||||
```
|
||||
call ether_price_getter ether_price_getter ["32fd4c0f-59cf-4182-8f22-d4083df0a738", "EUR"]
|
||||
```
|
||||
|
||||
Please note that you need to supply a valid Coinmarketcap API key and that the free account limits the
|
||||
number of conversions to one. The result from the Fluence service call is the raw json string, e.g.:
|
||||
|
||||
```
|
||||
result: String("{\"status\":{\"timestamp\":\"2021-02-22T20:47:59.960Z\",\"error_code\":0,\"error_message\":null,\"elapsed\":225,\"credit_count\":1,\"notice\":null},\"data\":{\"ETH\":{\"id\":1027,\"name\":\"Ethereum\",\"symbol\":\"ETH\",\"slug\":\"ethereum\",\"num_market_pairs\":5986,\"date_added\":\"2015-08-07T00:00:00.000Z\",\"tags\":[\"mineable\",\"pow\",\"smart-contracts\",\"coinbase-ventures-portfolio\",\"three-arrows-capital-portfolio\",\"polychain-capital-portfolio\"],\"max_supply\":null,\"circulating_supply\":114779907.124,\"total_supply\":114779907.124,\"is_active\":1,\"platform\":null,\"cmc_rank\":2,\"is_fiat\":0,\"last_updated\":\"2021-02-22T20:46:06.000Z\",\"quote\":{\"EUR\":{\"price\":1464.4187545109621,\"volume_24h\":34069036322.326084,\"percent_change_1h\":3.41360427,\"percent_change_24h\":-10.32669439,\"percent_change_7d\":-3.70439114,\"percent_change_30d\":41.39754247,\"market_cap\":168085848633.412,\"last_updated\":\"2021-02-22T20:47:05.000Z\"}}}}}")
|
||||
```
|
||||
|
||||
## Where to Find The Service
|
||||
The service is discoverable at [Fluence](https://dash.fluence.dev/), e.g., https://dash.fluence.dev/blueprint/a7959f53-a70b-4183-83e0-649f4f91160c, and ready for use.
|
||||
|
||||
## How to Build The Service
|
||||
machine setup instructions
|
||||
|
||||
In the `eth-price-getter` dir,
|
||||
```bash
|
||||
# if needed
|
||||
chmod +x .build.sh
|
||||
|
||||
./build.sh
|
||||
```
|
||||
|
||||
That compiles both the curl and the price getter code and places the resulting wasm code into the `artifacts` dir. For local testing run `fce-repl Config.toml` to initiate the repl:
|
||||
|
||||
```bash
|
||||
fce-repl Config.toml
|
||||
Welcome to the FCE REPL (version 0.1.33)
|
||||
app service was created with service id = b0cc4d0d-fb3e-49e1-8532-54d77e03cdaa
|
||||
elapsed time 82.757883ms
|
||||
|
||||
1> interface
|
||||
Loaded modules interface:
|
||||
|
||||
curl_adapter:
|
||||
fn curl_request(url: String) -> String
|
||||
|
||||
ether_price_getter:
|
||||
fn ether_price_getter(api_key: String, currency_symbol: String) -> String
|
||||
|
||||
2> call ether_price_getter ether_price_getter ["35fd4b0e-56cf-4182-8f22-d4095cf0a738", "EUR"]
|
||||
INFO: Running "/usr/bin/curl -H X-CMC_PRO_API_KEY: 35fd4b0e-56cf-4182-8f22-d4095cf0a738 -H Accept: application/json -d symbol=ETH&convert=EUR -G https://pro-api.coinmarketcap.com/v1/cryptocurrency/quotes/latest" ...
|
||||
% Total % Received % Xferd Average Speed Time Time Time Current
|
||||
Dload Upload Total Spent Left Speed
|
||||
100 868 0 868 0 0 2755 0 --:--:-- --:--:-- --:--:-- 2755
|
||||
result: String("{\"status\":{\"timestamp\":\"2021-02-22T21:06:42.598Z\",\"error_code\":0,\"error_message\":null,\"elapsed\":18,\"credit_count\":1,\"notice\":null},\"data\":{\"ETH\":{\"id\":1027,\"name\":\"Ethereum\",\"symbol\":\"ETH\",\"slug\":\"ethereum\",\"num_market_pairs\":5986,\"date_added\":\"2015-08-07T00:00:00.000Z\",\"tags\":[\"mineable\",\"pow\",\"smart-contracts\",\"coinbase-ventures-portfolio\",\"three-arrows-capital-portfolio\",\"polychain-capital-portfolio\"],\"max_supply\":null,\"circulating_supply\":114779907.124,\"total_supply\":114779907.124,\"is_active\":1,\"platform\":null,\"cmc_rank\":2,\"is_fiat\":0,\"last_updated\":\"2021-02-22T21:05:03.000Z\",\"quote\":{\"EUR\":{\"price\":1459.5551152082585,\"volume_24h\":33903071552.817226,\"percent_change_1h\":2.64386327,\"percent_change_24h\":-10.46990835,\"percent_change_7d\":-4.37412016,\"percent_change_30d\":41.26794407,\"market_cap\":167527600565.963,\"last_updated\":\"2021-02-22T21:06:05.000Z\"}}}}}")
|
||||
elapsed time: 323.584665ms
|
||||
|
||||
3>
|
||||
```
|
||||
|
||||
Calling `interface` lists both the curl_adapter and ether_price_getter interfaces. Calling the `ether_price_getter` service function with the API key and conversion currency symbol, `"35fd4b0e-56cf-4182-8f22-d4095cf0a738", "EUR"`, yields the raw json string result expected.
|
||||
|
||||
## How to Deploy The Service
|
||||
ToDo: fldist installation instructions
|
||||
|
||||
|
||||
If you don't have a seed ready to use:
|
||||
|
||||
```bash
|
||||
fldist create_keypair
|
||||
{
|
||||
id: '12D3KooWQy61BZ4P1DeJzhvsQ76uQAQc7N8tDk6NDz5BFnnhwuPP',
|
||||
privKey: 'CAESYI9nA79xXH9yYeuU4UDPiaa7C84U0OKnihdSkSdbMOIV4RtA5l9dooR41cO8lCz3okYpEboK6maL7yk1ABgCvrLhG0DmX12ihHjVw7yULPeiRikRugrqZovvKTUAGAK+sg==',
|
||||
pubKey: 'CAESIOEbQOZfXaKEeNXDvJQs96JGKRG6Cupmi+8pNQAYAr6y',
|
||||
seed: 'AenQdfKCRrh1sajNFkKKV1iojgVnLWyatdaqwzEMopje'
|
||||
}
|
||||
```
|
||||
|
||||
which yields a fresh keypair and derived seed and allows us to create a new service. The `fldist new_service` is a convenience method that takes care the module uploads to the node, the creation of the blueprint, and finally, the instantiation of the services.
|
||||
|
||||
```bash
|
||||
fldist new_service --env testnet -n "Ether Price Getter" -s AenQdfKCRrh1sajNFkKKV1iojgVnLWyatdaqwzEMopje --ms artifacts/curl_adapter.wasm:curl_cfg.json artifacts/ether_price_getter.wasm:ether_price_getter_cfg.json
|
||||
```
|
||||
|
||||
specifies that we are creating a new service comprised of two modules, the curl_adapter module and the ether_price_getter module, and generates the confirmation with service id:
|
||||
|
||||
```bash
|
||||
client seed: AenQdfKCRrh1sajNFkKKV1iojgVnLWyatdaqwzEMopje
|
||||
client peerId: 12D3KooWQy61BZ4P1DeJzhvsQ76uQAQc7N8tDk6NDz5BFnnhwuPP
|
||||
node peerId: 12D3KooWBUJifCTgaxAUrcM9JysqCcS4CS8tiYH5hExbdWCAoNwb
|
||||
uploading blueprint Ether Price Getter to node 12D3KooWBUJifCTgaxAUrcM9JysqCcS4CS8tiYH5hExbdWCAoNwb via client 12D3KooWQy61BZ4P1DeJzhvsQ76uQAQc7N8tDk6NDz5BFnnhwuPP
|
||||
creating service a7959f53-a70b-4183-83e0-649f4f91160c
|
||||
service id: 9840c6be-11c8-47e2-98e0-88d758b5a456
|
||||
service created successfully
|
||||
```
|
||||
|
||||
We can now discover the service on the [Fluenced dashboard](https://dash.fluence.dev/blueprint/a7959f53-a70b-4183-83e0-649f4f91160c) and put it to use. Whether we want to write a frontend application or use the `fldist` tool to execute the remote service, we need an AIR script. Using the prepared [AIR script](../air-scripts/get_eth_price.js) for which you need to supply your own API key:
|
||||
|
||||
```bash
|
||||
fldist run_air -p get_eth_price.clj -d '{"service":"9840c6be-11c8-47e2-98e0-88d758b5a456"}'
|
||||
|
||||
client seed: 6w6j5yiPU7pMj86XSoLwesoSxhM2fzNNKF6DDtqm3WCH
|
||||
client peerId: 12D3KooWAwwuy9mz1w14JhznVo1cA4UKtvVv1Gy4EKRywVRwKQ1w
|
||||
node peerId: 12D3KooWBUJifCTgaxAUrcM9JysqCcS4CS8tiYH5hExbdWCAoNwb
|
||||
Particle id: 9eb6c275-8f1a-4bae-b457-747546b3daaf. Waiting for results... Press Ctrl+C to stop the script.
|
||||
===================
|
||||
[
|
||||
"{\"status\":{\"timestamp\":\"2021-02-24T07:11:26.493Z\",\"error_code\":0,\"error_message\":null,\"elapsed\":14,\"credit_count\":1,\"notice\":null},\"data\":{\"ETH\":{\"id\":1027,\"name\":\"Ethereum\",\"symbol\":\"ETH\",\"slug\":\"ethereum\",\"num_market_pairs\":6018,\"date_added\":\"2015-08-07T00:00:00.000Z\",\"tags\":[\"mineable\",\"pow\",\"smart-contracts\",\"coinbase-ventures-portfolio\",\"three-arrows-capital-portfolio\",\"polychain-capital-portfolio\"],\"max_supply\":null,\"circulating_supply\":114799158.0615,\"total_supply\":114799158.0615,\"is_active\":1,\"platform\":null,\"cmc_rank\":2,\"is_fiat\":0,\"last_updated\":\"2021-02-24T07:10:03.000Z\",\"quote\":{\"EUR\":{\"price\":1338.6331723430615,\"volume_24h\":40823704838.16298,\"percent_change_1h\":-1.44088165,\"percent_change_24h\":-0.24837544,\"percent_change_7d\":-8.52364557,\"percent_change_30d\":13.62330192,\"market_cap\":153673961138.17825,\"last_updated\":\"2021-02-24T07:11:06.000Z\"}}}}}"
|
||||
]
|
||||
[
|
||||
[
|
||||
{
|
||||
peer_pk: '12D3KooWBUJifCTgaxAUrcM9JysqCcS4CS8tiYH5hExbdWCAoNwb',
|
||||
service_id: '9840c6be-11c8-47e2-98e0-88d758b5a456',
|
||||
function_name: 'ether_price_getter',
|
||||
json_path: ''
|
||||
}
|
||||
]
|
||||
]
|
||||
===================
|
||||
```
|
||||
|
||||
yields the expected raw pricing response. Please note that with the free account, only one currency conversion target can be supplied per query.
|
166
ether-price-getter/Readme.md.bk
Normal file
166
ether-price-getter/Readme.md.bk
Normal file
@ -0,0 +1,166 @@
|
||||
# Ether Price Quotation Service
|
||||
|
||||
## Overview
|
||||
This module utilizes curl and the Coinbase API to allow the query of the latest Ether (ETH) price relative to some 120 currencies. The service requires a valid Coinmarketcap API key, which is freely available with [registration](). The query function wraps this API call: https://coinmarketcap.com/api/documentation/v1/#operation/getV2CryptocurrencyQuotesLatest:
|
||||
|
||||
```bash
|
||||
ether_price_getter(api_key: String, currency_symbol: String)
|
||||
```
|
||||
|
||||
which expects the Coinmarketcap API key and the three letter currency symbol, e.g.:
|
||||
|
||||
```
|
||||
call ether_price_getter ether_price_getter ["32fd4c0f-59cf-4182-8f22-d4083df0a738", "EUR"]
|
||||
```
|
||||
|
||||
Please note that you need to supply a valid Coinmarketcap API key and that the free account limits the
|
||||
number of conversions to one. The result from the Fluence service call is the raw json string, e.g.:
|
||||
|
||||
```
|
||||
result: String("{\"status\":{\"timestamp\":\"2021-02-22T20:47:59.960Z\",\"error_code\":0,\"error_message\":null,\"elapsed\":225,\"credit_count\":1,\"notice\":null},\"data\":{\"ETH\":{\"id\":1027,\"name\":\"Ethereum\",\"symbol\":\"ETH\",\"slug\":\"ethereum\",\"num_market_pairs\":5986,\"date_added\":\"2015-08-07T00:00:00.000Z\",\"tags\":[\"mineable\",\"pow\",\"smart-contracts\",\"coinbase-ventures-portfolio\",\"three-arrows-capital-portfolio\",\"polychain-capital-portfolio\"],\"max_supply\":null,\"circulating_supply\":114779907.124,\"total_supply\":114779907.124,\"is_active\":1,\"platform\":null,\"cmc_rank\":2,\"is_fiat\":0,\"last_updated\":\"2021-02-22T20:46:06.000Z\",\"quote\":{\"EUR\":{\"price\":1464.4187545109621,\"volume_24h\":34069036322.326084,\"percent_change_1h\":3.41360427,\"percent_change_24h\":-10.32669439,\"percent_change_7d\":-3.70439114,\"percent_change_30d\":41.39754247,\"market_cap\":168085848633.412,\"last_updated\":\"2021-02-22T20:47:05.000Z\"}}}}}")
|
||||
```
|
||||
|
||||
## Where to Find The Service
|
||||
The service is discoverable at [Fluence](https://dash.fluence.dev/) and ready for use.
|
||||
|
||||
## How to Build The Service
|
||||
machine setup instructions
|
||||
|
||||
In the `eth-price-getter` dir,
|
||||
```bash
|
||||
# if needed
|
||||
chmod +x .build.sh
|
||||
|
||||
./build.sh
|
||||
```
|
||||
|
||||
That compiles both the curl and the price getter code and places the resulting wasm code into the `artifacts` dir. For local testing run `fce-repl Config.toml` to initiate the repl:
|
||||
|
||||
```bash
|
||||
mbp16~/localdev/ethdenver-hackathon/ether-price-getter(eth-price-getter|…) % fce-repl Config.toml
|
||||
Welcome to the FCE REPL (version 0.1.33)
|
||||
app service was created with service id = b0cc4d0d-fb3e-49e1-8532-54d77e03cdaa
|
||||
elapsed time 82.757883ms
|
||||
|
||||
1> interface
|
||||
Loaded modules interface:
|
||||
|
||||
curl_adapter:
|
||||
fn curl_request(url: String) -> String
|
||||
|
||||
ether_price_getter:
|
||||
fn ether_price_getter(api_key: String, currency_symbol: String) -> String
|
||||
|
||||
2> call ether_price_getter ether_price_getter ["35fd4b0e-56cf-4182-8f22-d4095cf0a738", "EUR"]
|
||||
INFO: Running "/usr/bin/curl -H X-CMC_PRO_API_KEY: 35fd4b0e-56cf-4182-8f22-d4095cf0a738 -H Accept: application/json -d symbol=ETH&convert=EUR -G https://pro-api.coinmarketcap.com/v1/cryptocurrency/quotes/latest" ...
|
||||
% Total % Received % Xferd Average Speed Time Time Time Current
|
||||
Dload Upload Total Spent Left Speed
|
||||
100 868 0 868 0 0 2755 0 --:--:-- --:--:-- --:--:-- 2755
|
||||
result: String("{\"status\":{\"timestamp\":\"2021-02-22T21:06:42.598Z\",\"error_code\":0,\"error_message\":null,\"elapsed\":18,\"credit_count\":1,\"notice\":null},\"data\":{\"ETH\":{\"id\":1027,\"name\":\"Ethereum\",\"symbol\":\"ETH\",\"slug\":\"ethereum\",\"num_market_pairs\":5986,\"date_added\":\"2015-08-07T00:00:00.000Z\",\"tags\":[\"mineable\",\"pow\",\"smart-contracts\",\"coinbase-ventures-portfolio\",\"three-arrows-capital-portfolio\",\"polychain-capital-portfolio\"],\"max_supply\":null,\"circulating_supply\":114779907.124,\"total_supply\":114779907.124,\"is_active\":1,\"platform\":null,\"cmc_rank\":2,\"is_fiat\":0,\"last_updated\":\"2021-02-22T21:05:03.000Z\",\"quote\":{\"EUR\":{\"price\":1459.5551152082585,\"volume_24h\":33903071552.817226,\"percent_change_1h\":2.64386327,\"percent_change_24h\":-10.46990835,\"percent_change_7d\":-4.37412016,\"percent_change_30d\":41.26794407,\"market_cap\":167527600565.963,\"last_updated\":\"2021-02-22T21:06:05.000Z\"}}}}}")
|
||||
elapsed time: 323.584665ms
|
||||
|
||||
3>
|
||||
```
|
||||
|
||||
Calling `interface` lists both the curl_adapter and ether_price_getter interfaces. Calling the `ether_price_getter` service function with the API key and conversion currency symbol, `"35fd4b0e-56cf-4182-8f22-d4095cf0a738", "EUR"`, yields the raw json string result expected.
|
||||
|
||||
## How to Deploy The Service
|
||||
ToDo: fldist installatin instructions
|
||||
|
||||
|
||||
If you don't have a seed ready to use:
|
||||
|
||||
```bash
|
||||
mbp16~/localdev/ethdenver-hackathon/ether-price-getter(eth-price-getter|…) % fldist create_keypair
|
||||
{
|
||||
id: '12D3KooWQy61BZ4P1DeJzhvsQ76uQAQc7N8tDk6NDz5BFnnhwuPP',
|
||||
privKey: 'CAESYI9nA79xXH9yYeuU4UDPiaa7C84U0OKnihdSkSdbMOIV4RtA5l9dooR41cO8lCz3okYpEboK6maL7yk1ABgCvrLhG0DmX12ihHjVw7yULPeiRikRugrqZovvKTUAGAK+sg==',
|
||||
pubKey: 'CAESIOEbQOZfXaKEeNXDvJQs96JGKRG6Cupmi+8pNQAYAr6y',
|
||||
seed: 'AenQdfKCRrh1sajNFkKKV1iojgVnLWyatdaqwzEMopje'
|
||||
}
|
||||
```
|
||||
|
||||
which yields the keypair and seed and allows us to create a new service:
|
||||
|
||||
```bash
|
||||
fldist new_service --env testnet -n "Ether Price Getter" -s AenQdfKCRrh1sajNFkKKV1iojgVnLWyatdaqwzEMopje --ms artifacts/curl_adapter.wasm:curl_cfg.json artifacts/ether_price_getter.wasm:ether_price_getter_cfg.json
|
||||
client seed: AenQdfKCRrh1sajNFkKKV1iojgVnLWyatdaqwzEMopje
|
||||
client peerId: 12D3KooWQy61BZ4P1DeJzhvsQ76uQAQc7N8tDk6NDz5BFnnhwuPP
|
||||
node peerId: 12D3KooWBUJifCTgaxAUrcM9JysqCcS4CS8tiYH5hExbdWCAoNwb
|
||||
uploading blueprint Ether Price Getter to node 12D3KooWBUJifCTgaxAUrcM9JysqCcS4CS8tiYH5hExbdWCAoNwb via client 12D3KooWQy61BZ4P1DeJzhvsQ76uQAQc7N8tDk6NDz5BFnnhwuPP
|
||||
creating service c77f4b0f-b9e2-47ca-8358-7add50bab280
|
||||
|
||||
```
|
||||
|
||||
```
|
||||
mbp16~/localdev/ethdenver-hackathon/ether-price-getter(eth-price-getter|✚1…) % fldist new_service --env testnet -n "Ether Price Getter" -s AenQdfKCRrh1sajNFkKKV1iojgVnLWyatdaqwzEMopje --ms artifacts/curl_adapter.wasm:curl_cfg.json artifacts/ether_price_getter.wasm:ether_price_getter_cfg.json --ttl 120000
|
||||
client seed: AenQdfKCRrh1sajNFkKKV1iojgVnLWyatdaqwzEMopje
|
||||
client peerId: 12D3KooWQy61BZ4P1DeJzhvsQ76uQAQc7N8tDk6NDz5BFnnhwuPP
|
||||
node peerId: 12D3KooWBUJifCTgaxAUrcM9JysqCcS4CS8tiYH5hExbdWCAoNwb
|
||||
uploading blueprint Ether Price Getter to node 12D3KooWBUJifCTgaxAUrcM9JysqCcS4CS8tiYH5hExbdWCAoNwb via client 12D3KooWQy61BZ4P1DeJzhvsQ76uQAQc7N8tDk6NDz5BFnnhwuPP
|
||||
creating service a7959f53-a70b-4183-83e0-649f4f91160c
|
||||
service id: 9840c6be-11c8-47e2-98e0-88d758b5a456
|
||||
service created successfully
|
||||
```
|
||||
|
||||
|
||||
|
||||
|
||||
## Timeout Error:
|
||||
```
|
||||
fldist new_service --env testnet -n "Ether Price Getter" -s AenQdfKCRrh1sajNFkKKV1iojgVnLWyatdaqwzEMopje --ms artifacts/curl_adapter.wasm:curl_cfg.json artifacts/ether_price_getter.wasm:ether_price_getter_cfg.json
|
||||
client seed: AenQdfKCRrh1sajNFkKKV1iojgVnLWyatdaqwzEMopje
|
||||
client peerId: 12D3KooWQy61BZ4P1DeJzhvsQ76uQAQc7N8tDk6NDz5BFnnhwuPP
|
||||
node peerId: 12D3KooWBUJifCTgaxAUrcM9JysqCcS4CS8tiYH5hExbdWCAoNwb
|
||||
uploading blueprint Ether Price Getter to node 12D3KooWBUJifCTgaxAUrcM9JysqCcS4CS8tiYH5hExbdWCAoNwb via client 12D3KooWQy61BZ4P1DeJzhvsQ76uQAQc7N8tDk6NDz5BFnnhwuPP
|
||||
creating service c77f4b0f-b9e2-47ca-8358-7add50bab280
|
||||
Particle expired. Now: 1614029919574, ttl: 60000, ts: 1614029859570
|
||||
Particle expired. Now: 1614029922669, ttl: 60000, ts: 1614029862668
|
||||
Particle expired. Now: 1614029925656, ttl: 60000, ts: 1614029865653
|
||||
Particle expired. Now: 1614029926178, ttl: 60000, ts: 1614029866176
|
||||
Something went wrong!
|
||||
Error: callback for _callback/createService timed out after 60000
|
||||
at Timeout._onTimeout (/Users/bebo/.nvm/versions/node/v12.16.3/lib/node_modules/@fluencelabs/fldist/node_modules/@fluencelabs/fluence/dist/api.js:169:28)
|
||||
at listOnTimeout (internal/timers.js:549:17)
|
||||
at processTimers (internal/timers.js:492:7)
|
||||
```
|
||||
|
||||
and:
|
||||
|
||||
```
|
||||
mbp16~/localdev/ethdenver-hackathon/ether-price-getter(eth-price-getter|✚1…) % fldist new_service --env testnet -n "Ether Price Getter" -s AenQdfKCRrh1sajNFkKKV1iojgVnLWyatdaqwzEMopje --ms artifacts/curl_adapter.wasm:curl_cfg.json artifacts/ether_price_getter.wasm:ether_price_getter_cfg.json --ttl 90000
|
||||
client seed: AenQdfKCRrh1sajNFkKKV1iojgVnLWyatdaqwzEMopje
|
||||
client peerId: 12D3KooWQy61BZ4P1DeJzhvsQ76uQAQc7N8tDk6NDz5BFnnhwuPP
|
||||
node peerId: 12D3KooWBUJifCTgaxAUrcM9JysqCcS4CS8tiYH5hExbdWCAoNwb
|
||||
uploading blueprint Ether Price Getter to node 12D3KooWBUJifCTgaxAUrcM9JysqCcS4CS8tiYH5hExbdWCAoNwb via client 12D3KooWQy61BZ4P1DeJzhvsQ76uQAQc7N8tDk6NDz5BFnnhwuPP
|
||||
creating service 95abbf2b-cf4f-4560-b3a5-2717b340ead8
|
||||
Particle expired. Now: 1614030097045, ttl: 90000, ts: 1614030007040
|
||||
Particle expired. Now: 1614030100739, ttl: 90000, ts: 1614030010735
|
||||
Particle expired. Now: 1614030104327, ttl: 90000, ts: 1614030014325
|
||||
Particle expired. Now: 1614030104850, ttl: 90000, ts: 1614030014846
|
||||
Something went wrong!
|
||||
Error: callback for _callback/createService timed out after 90000
|
||||
at Timeout._onTimeout (/Users/bebo/.nvm/versions/node/v12.16.3/lib/node_modules/@fluencelabs/fldist/node_modules/@fluencelabs/fluence/dist/api.js:169:28)
|
||||
at listOnTimeout (internal/timers.js:549:17)
|
||||
at processTimers (internal/timers.js:492:7)
|
||||
mbp16~/localdev/ethdenver-hackathon/ether-price-getter(eth-price-getter|✚1…) %
|
||||
```
|
||||
|
||||
```
|
||||
mbp16~/localdev/ethdenver-hackathon/ether-price-getter(eth-price-getter|✚1…) % fldist new_service --env testnet -n "Ether Price Getter" -s AenQdfKCRrh1sajNFkKKV1iojgVnLWyatdaqwzEMopje --ms artifacts/curl_adapter.wasm:curl_cfg.json artifacts/ether_price_getter.wasm:ether_price_getter_cfg.json --ttl 180000
|
||||
client seed: AenQdfKCRrh1sajNFkKKV1iojgVnLWyatdaqwzEMopje
|
||||
client peerId: 12D3KooWQy61BZ4P1DeJzhvsQ76uQAQc7N8tDk6NDz5BFnnhwuPP
|
||||
node peerId: 12D3KooWBUJifCTgaxAUrcM9JysqCcS4CS8tiYH5hExbdWCAoNwb
|
||||
uploading blueprint Ether Price Getter to node 12D3KooWBUJifCTgaxAUrcM9JysqCcS4CS8tiYH5hExbdWCAoNwb via client 12D3KooWQy61BZ4P1DeJzhvsQ76uQAQc7N8tDk6NDz5BFnnhwuPP
|
||||
creating service 5f7497e8-1140-44e4-ad93-87d52e7cb359
|
||||
Particle expired. Now: 1614030312210, ttl: 180000, ts: 1614030132205
|
||||
Particle expired. Now: 1614030315338, ttl: 180000, ts: 1614030135336
|
||||
Particle expired. Now: 1614030318206, ttl: 180000, ts: 1614030138203
|
||||
Particle expired. Now: 1614030318738, ttl: 180000, ts: 1614030138732
|
||||
Something went wrong!
|
||||
Error: callback for _callback/createService timed out after 180000
|
||||
at Timeout._onTimeout (/Users/bebo/.nvm/versions/node/v12.16.3/lib/node_modules/@fluencelabs/fldist/node_modules/@fluencelabs/fluence/dist/api.js:169:28)
|
||||
at listOnTimeout (internal/timers.js:549:17)
|
||||
at processTimers (internal/timers.js:492:7)
|
||||
mbp16~/localdev/ethdenver-hackathon/ether-price-getter(eth-price-getter|✚1…) %
|
||||
```
|
10
ether-price-getter/air-scripts/get_eth_price.clj
Normal file
10
ether-price-getter/air-scripts/get_eth_price.clj
Normal file
@ -0,0 +1,10 @@
|
||||
(xor
|
||||
(seq
|
||||
(call relay (service "ether_price_getter") ["32fc4c0e-59cf-4245-8f22-d4095de0f738" "EUR"] result)
|
||||
(call %init_peer_id% (returnService "run") [result])
|
||||
)
|
||||
(seq
|
||||
(call relay ("op" "identity") [])
|
||||
(call %init_peer_id% (returnService "run") ["XOR FAILED" %last_error%])
|
||||
)
|
||||
)
|
10
ether-price-getter/air-scripts/get_eth_price.clj.bk
Normal file
10
ether-price-getter/air-scripts/get_eth_price.clj.bk
Normal file
@ -0,0 +1,10 @@
|
||||
(xor
|
||||
(seq
|
||||
(call relay (service "ether_price_getter") ["42fc4b0e-59cf-4182-8f22-d4095cf0a738" "EUR"] result)
|
||||
(call %init_peer_id% (returnService "run") [result])
|
||||
)
|
||||
(seq
|
||||
(call relay ("op" "identity") [])
|
||||
(call %init_peer_id% (returnService "run") ["XOR FAILED" %last_error%])
|
||||
)
|
||||
)
|
15
ether-price-getter/build.sh
Executable file
15
ether-price-getter/build.sh
Executable file
@ -0,0 +1,15 @@
|
||||
#!/bin/sh
|
||||
|
||||
mkdir -p artifacts
|
||||
|
||||
cd curl_adapter
|
||||
fce build --release
|
||||
cd ..
|
||||
|
||||
cd ether_price_getter
|
||||
fce build --release
|
||||
cd ..
|
||||
|
||||
rm -f artifacts/*
|
||||
cp curl_adapter/target/wasm32-wasi/release/curl_adapter.wasm artifacts/
|
||||
cp ether_price_getter/target/wasm32-wasi/release/ether_price_getter.wasm artifacts/
|
BIN
ether-price-getter/curl_adapter/.DS_Store
vendored
Normal file
BIN
ether-price-getter/curl_adapter/.DS_Store
vendored
Normal file
Binary file not shown.
6
ether-price-getter/curl_adapter/.gitignore
vendored
Normal file
6
ether-price-getter/curl_adapter/.gitignore
vendored
Normal file
@ -0,0 +1,6 @@
|
||||
DS_Store
|
||||
.repl_history
|
||||
/target
|
||||
**/**.bak
|
||||
**/**.bk
|
||||
Cargo.lock
|
14
ether-price-getter/curl_adapter/Cargo.toml
Normal file
14
ether-price-getter/curl_adapter/Cargo.toml
Normal file
@ -0,0 +1,14 @@
|
||||
[package]
|
||||
name = "curl_adapter"
|
||||
version = "0.1.0"
|
||||
authors = ["Fluence Labs"]
|
||||
edition = "2018"
|
||||
publish = false
|
||||
|
||||
[[bin]]
|
||||
path = "src/main.rs"
|
||||
name = "curl_adapter"
|
||||
|
||||
[dependencies]
|
||||
fluence = { version = "=0.2.18", features = ["logger"]}
|
||||
log = "0.4.8"
|
55
ether-price-getter/curl_adapter/src/main.rs
Normal file
55
ether-price-getter/curl_adapter/src/main.rs
Normal file
@ -0,0 +1,55 @@
|
||||
/*
|
||||
* Copyright 2021 Fluence Labs Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
use fluence::fce;
|
||||
use fluence::WasmLoggerBuilder;
|
||||
|
||||
/// Log level can be changed by `RUST_LOG` env as well.
|
||||
pub fn main() {
|
||||
WasmLoggerBuilder::new().build().unwrap();
|
||||
}
|
||||
|
||||
#[fce]
|
||||
pub fn curl_request(url: String) -> String {
|
||||
// log::info!("get called with url {}", url);
|
||||
|
||||
unsafe { curl(url) }
|
||||
}
|
||||
|
||||
/// Permissions in `Config.toml` should exist to use host functions.
|
||||
#[fce]
|
||||
#[link(wasm_import_module = "host")]
|
||||
extern "C" {
|
||||
fn curl(cmd: String) -> String;
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn curl_test() {
|
||||
let args = r#"-X POST --data '{"jsonrpc":"2.0","method":"eth_getBlockByNumber","params":["0x1b4", true],"id":1}'"#;
|
||||
let url = "https://kovan.infura.io/v3//0cc023286cae4ab886598ecd14e256fd";
|
||||
|
||||
let cmd = format!("{} {}", args, url);
|
||||
println!("cmd: {}", cmd);
|
||||
|
||||
let res = curl_request(cmd);
|
||||
println!("res: {}", res);
|
||||
assert!(true);
|
||||
}
|
||||
}
|
6
ether-price-getter/curl_cfg.json
Normal file
6
ether-price-getter/curl_cfg.json
Normal file
@ -0,0 +1,6 @@
|
||||
{
|
||||
"name": "curl_adapter",
|
||||
"mountedBinaries": {
|
||||
"curl": "/usr/bin/curl"
|
||||
}
|
||||
}
|
BIN
ether-price-getter/ether_price_getter/.DS_Store
vendored
Normal file
BIN
ether-price-getter/ether_price_getter/.DS_Store
vendored
Normal file
Binary file not shown.
6
ether-price-getter/ether_price_getter/.gitignore
vendored
Normal file
6
ether-price-getter/ether_price_getter/.gitignore
vendored
Normal file
@ -0,0 +1,6 @@
|
||||
DS_Store
|
||||
.repl_history
|
||||
/target
|
||||
**/**.bak
|
||||
**/**.bk
|
||||
Cargo.lock
|
15
ether-price-getter/ether_price_getter/Cargo.toml
Normal file
15
ether-price-getter/ether_price_getter/Cargo.toml
Normal file
@ -0,0 +1,15 @@
|
||||
[package]
|
||||
name = "ether_price_getter"
|
||||
version = "0.1.0"
|
||||
authors = ["Fluence Labs"]
|
||||
edition = "2018"
|
||||
publish = false
|
||||
|
||||
[[bin]]
|
||||
name = "ether_price_getter"
|
||||
path = "src/main.rs"
|
||||
|
||||
[dependencies]
|
||||
fluence = { version = "0.2.18", features = ["logger"]}
|
||||
log = "0.4.8"
|
||||
fstrings = { version="0.2.3" }
|
@ -0,0 +1,29 @@
|
||||
/*
|
||||
* Copyright 2021 Fluence Labs Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
use fluence::fce;
|
||||
use crate::curl_request;
|
||||
|
||||
static URL_LATEST: &'static str = "https://pro-api.coinmarketcap.com/v1/cryptocurrency/quotes/latest";
|
||||
|
||||
|
||||
#[fce]
|
||||
pub fn ether_price_getter(api_key: String, currency_symbol: String) -> String {
|
||||
let curl_args = f!(r#"-H "X-CMC_PRO_API_KEY: {api_key}" -H "Accept: application/json" -d "symbol=ETH&convert={currency_symbol}" -G {URL_LATEST}"#);
|
||||
let response: String = unsafe { curl_request(curl_args) };
|
||||
response
|
||||
}
|
||||
|
82
ether-price-getter/ether_price_getter/src/fce_results.rs
Normal file
82
ether-price-getter/ether_price_getter/src/fce_results.rs
Normal file
@ -0,0 +1,82 @@
|
||||
/*
|
||||
* Copyright 2021 Fluence Labs Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
use crate::jsonrpc_helpers::JSON_RPC;
|
||||
use crate::Result;
|
||||
use fluence::fce;
|
||||
use serde_json::Value;
|
||||
|
||||
#[fce]
|
||||
#[derive(Debug)]
|
||||
pub struct JsonRpcResult {
|
||||
pub jsonrpc: String,
|
||||
pub result: String,
|
||||
pub error: String,
|
||||
pub id: u64,
|
||||
}
|
||||
|
||||
impl From<Result<String>> for JsonRpcResult {
|
||||
fn from(result: Result<String>) -> Self {
|
||||
let jsonrpc = JSON_RPC.into();
|
||||
match result {
|
||||
Ok(res) => {
|
||||
let result_obj: Value = serde_json::from_str(&res).unwrap();
|
||||
let id: u64 = serde_json::from_value(result_obj["id"].clone()).unwrap();
|
||||
let result: String = serde_json::from_value(result_obj["result"].clone()).unwrap();
|
||||
|
||||
Self {
|
||||
jsonrpc,
|
||||
id,
|
||||
result,
|
||||
error: "".to_string(),
|
||||
}
|
||||
}
|
||||
Err(err) => {
|
||||
let result_obj: Value = serde_json::from_str(&err).unwrap();
|
||||
let id: u64 = serde_json::from_value(result_obj["id"].clone()).unwrap();
|
||||
|
||||
Self {
|
||||
jsonrpc,
|
||||
id,
|
||||
result: "".to_string(),
|
||||
error: err,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[fce]
|
||||
#[derive(Debug)]
|
||||
pub struct TestResult {
|
||||
pub test_passed: bool,
|
||||
pub error: String,
|
||||
}
|
||||
|
||||
impl From<Result<String>> for TestResult {
|
||||
fn from(result: Result<String>) -> Self {
|
||||
match result {
|
||||
Ok(res) => Self {
|
||||
test_passed: true,
|
||||
error: res,
|
||||
},
|
||||
Err(err) => Self {
|
||||
test_passed: false,
|
||||
error: err,
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
36
ether-price-getter/ether_price_getter/src/main.rs
Normal file
36
ether-price-getter/ether_price_getter/src/main.rs
Normal file
@ -0,0 +1,36 @@
|
||||
/*
|
||||
* Copyright 2021 Fluence Labs Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#![allow(non_snake_case, unused_variables, unused_imports, unused_parens, unused_mut)]
|
||||
|
||||
#[macro_use]
|
||||
extern crate fstrings;
|
||||
|
||||
use fluence::fce;
|
||||
use fluence::WasmLoggerBuilder;
|
||||
|
||||
mod eth_price_getter;
|
||||
|
||||
pub(crate) type Result<T> = std::result::Result<T, T>;
|
||||
|
||||
pub fn main() {
|
||||
WasmLoggerBuilder::new().build().ok();
|
||||
}
|
||||
|
||||
#[fce]
|
||||
#[link(wasm_import_module = "curl_adapter")]
|
||||
extern "C" {
|
||||
pub fn curl_request(url: String) -> String;
|
||||
}
|
3
ether-price-getter/ether_price_getter_cfg.json
Normal file
3
ether-price-getter/ether_price_getter_cfg.json
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"name": "Ether-Price-Getter"
|
||||
}
|
Loading…
Reference in New Issue
Block a user