mirror of
https://github.com/fluencelabs/gitbook-docs
synced 2025-06-14 23:41:32 +00:00
Merge branch 'main' into docs
This commit is contained in:
@ -6,5 +6,6 @@ Without diving too deep into the Fluence security framework, you should be aware
|
||||
|
||||
For the purposes of this tutorial, there is a caveat you need to keep in mind: Every reader of this document inevitably ends up using the same sample service with the same ownership control. In the highly, highly unlikely event you're getting funky results, it's most likely due to someone else doing the very same tutorial at the very same time. \[Jinx\]\([https://en.wikipedia.org/wiki/Jinx\_\(game](https://en.wikipedia.org/wiki/Jinx_%28game)\)\) ! Buy me a Coke, drink the Coke, slowly, try again and you should be fine.
|
||||
|
||||
|
||||
The next sections explore both the setup and the use of our database: Sqlite as a Service.
|
||||
|
||||
|
@ -106,6 +106,7 @@ The new service components called are:
|
||||
* _get\_reward\_block_, which takes a miner address and in this cae the one produced by `get_block`, and finally
|
||||
* _get\_miner\_rewards_, which returns a list of miner rewards for a particular miner address; in this case, the one provided by the `get_reward_block` result. Note the `$` operator to access the `block_miner` field in the return struct and the `!` operator to flatten the response
|
||||
|
||||
|
||||
From the previous section we know that
|
||||
|
||||
* service\_1: 74d5c5da-4c83-4af9-9371-2ab5d31f8019 , node\_1: 12D3KooWGzNvhSDsgFoHwpWHAyPf1kcTYCGeRBPfznL8J6qdyu2H
|
||||
|
@ -1,6 +1,6 @@
|
||||
# Building An Application From Multiple Services
|
||||
|
||||
In this section, we compose multiple services into an application to catalog block miner addresses and block rewards for the latest block created on the [Ethereum](https://ethereum.org/en/) mainnet. This block reward data is useful to track miner and pool dominance as well ETH supply and related indexes. For convenience purposes, we use the [Etherscan API](https://etherscan.io/apis) for this portion of the tutorial and in order to proceed, you should have an Etherscan API Key or get one from [Etherscan](https://etherscan.io/apis).
|
||||
In this section, we compose multiple services into an application to catalog block miner addresses and block rewards for the latest block created on the \[Ethereum\[\([https://ethereum.org/en/](https://ethereum.org/en/)\) mainnet. This block reward data is useful to track miner and pool dominance as well ETH supply and related indexes. For convenience purposes, we use the \[Etherscan API\]\([https://etherscan.io/apis](https://etherscan.io/apis)\) for this portion of the tutorial and in order to proceed, you should have an Etherscan API Key or get one from [Etherscan](https://etherscan.io/apis).
|
||||
|
||||
Since we are composing our application from first principles, we use the following services to compose our app:
|
||||
|
||||
@ -53,7 +53,7 @@ _call_ is the _execution_ instruction to launch distributed service methods and
|
||||
**\(**_call_ **node-id \(service-id service-method\) \[input parameters\] result\)**
|
||||
{% endhint %}
|
||||
|
||||
As with the previous AIR script, the _xor_ takes care of capturing errors in case things don't pan out the way we've planned. Other than that, we are calling the `hex_to_int` method and we need to supply the service and node ids as well as the hex value. Save the above script to a local file called _hex2int.clj_ and use `fldist` to deploy the script:
|
||||
As with the previous AIR script, the _xor_ takes care of capturing errors in case things don't pan out the way we've planned. Other than that, we are calling the `hex_to_int` method and we need to supply the service and node ids as well the the hex value. Save the above script to a local file called _hex2int.clj_ and use `fldist` to deploy the script:
|
||||
|
||||
```bash
|
||||
fldist run_air -p hex2int.clj -d '{"hex_service":"285e2a5e-e505-475f-a99d-15c16c7253f9", "hex_node": "12D3KooWKnRcsTpYx9axkJ6d69LPfpPXrkVLe96skuPTAo76LLVH", "hex_string":"0xF"}'
|
||||
@ -85,7 +85,7 @@ Particle id: c0f44da7-3bfb-445b-896a-537c10143392. Waiting for results... Press
|
||||
|
||||
We input the hex string 0xF and, as expected, got 15 radius 10 back. Whoever implemented the hex conversion service seemingly got it right. So let's keep using it as we coordinate an application from multiple services.
|
||||
|
||||
Beware but do not fear the nesting and parenthesis!! As we're building a more complex application, our script of course grows a bit. Next, we use the get\__latest\_block_ function and feed the result, a hex string, into the _hex\_to\_int c_onversion function and feed its output, an integer, to the _get\_block_ function to arrive at the reward block data. Of course, we wrap it all into the trusty XOR just in case something goes wrong.
|
||||
Beware but do not fear the nesting and parenthesis!! As we're building a more complex application, our script of course grows a bit. Next, we use the get\__latest\_block_ function and feed the result, a hex string, into the _hex\_to\_int c\_onversion function and feed its output, an integer, to the \_get\_block_ function to arrive at the reward block data. Of course, we wrap it all into the trusty XOR just in case something goes wrong.
|
||||
|
||||
```text
|
||||
(xor
|
||||
@ -132,7 +132,7 @@ Beware but do not fear the nesting and parenthesis!! As we're building a more co
|
||||
|
||||
Before we deploy the script, notice that we made explicit provisions for service and node id associated with each method and we used the output, i.e., result, as input parameters for subsequent method calls. This further illustrates how Aquamarine allows developers to efficiently write applications from distributed network services.
|
||||
|
||||
Save the script locally to a file named _block\_geter_.clj and deploy it with `fldist`:
|
||||
Save the script locally to a file named _block\_geter_.clj and deploy it with `fldist`:
|
||||
|
||||
```bash
|
||||
fldist run_air -p block_getter.clj -d '{"service_1":"74d5c5da-4c83-4af9-9371-2ab5d31f8019", "service_2":"285e2a5e-e505-475f-a99d-15c16c7253f9", "node_1": "12D3KooWGzNvhSDsgFoHwpWHAyPf1kcTYCGeRBPfznL8J6qdyu2H","node_2": "12D3KooWKnRcsTpYx9axkJ6d69LPfpPXrkVLe96skuPTAo76LLVH", "api_key":<your api key}'
|
||||
@ -194,7 +194,7 @@ Particle id: 50f54bad-03f3-41ba-9950-9f18b47fbdee. Waiting for results... Press
|
||||
|
||||
Very cool. Our coordinated service flow generates the expected latest block hex string, which serves as an input to the hex conversion and the resulting integer value is used as an input in the get\_block method, which returns the associated reward block information. Just as planned. Beautiful.
|
||||
|
||||
Of course, that leaves us wanting as our goal was to get the reward miner address. Not to worry, we incorporate the missing _extract\_miner\_address_ service call into our AIR script:
|
||||
Of course, that leaves us wanting as our goal was to get the reward miner address. Not to worry, we incorporate the missing _extract\_miner\_address_ service call into our AIR script:
|
||||
|
||||
```text
|
||||
(xor
|
||||
|
@ -1,6 +1,6 @@
|
||||
# Using a Service
|
||||
|
||||
Let's dive right into peer-to-peer awesomeness by harnessing a distributed curl service, which pretty much keeps with its namesake: pass it a url and collect the response. Instead of developing our service from scratch, we reuse one already deployed to the [Fluence testnet](https://dash.fluence.dev/nodes).
|
||||
Let's dive right into peer-to-peer awesomeness by harnessing a distributed curl service, which pretty much keeps with its namesake: pass it a url and collect the response. Instead of developing our service from scratch, we reuse one already deployed to the \[Fluence testnet\]\([https://dash.fluence.dev/nodes](https://dash.fluence.dev/nodes)\).
|
||||
|
||||
The [Fluence Dashboard](https://dash.fluence.dev/) facilitates the discovery of available services, such as the [Curl Adapter](https://dash.fluence.dev/blueprint/b7d2454e-2a75-408c-a23a-fe35de3beeb9) service, which allows us to harness http\(s\) requests as a service. Drilling down on the metadata provides a few useful parameters such as _service id_, _node id_ and _ip address_, which we need to execute our distributed curl service.
|
||||
|
||||
@ -29,13 +29,13 @@ The "magic" happens by handing the script to the `fldist` CLI tool, which then s
|
||||
Throughout the document, we utilize service and node ids, which in most cases may be different for you.
|
||||
{% endhint %}
|
||||
|
||||
With the service id parameter obtained from the dashboard lookup above, e.g., `"f92ce98b-1ed6-4ce3-9864-11f4e93a478f"`, and some Fluence goodness at both the local and remote levels enables us to:
|
||||
With the service id parameter obtained from the dashboard lookup above, e.g., "f92ce98b-1ed6-4ce3-9864-11f4e93a478f", and some Fluence goodness at both the local and remote levels enables us to:
|
||||
|
||||
1. find the p2p node hosting the curl service with above service id ,
|
||||
2. execute the service and
|
||||
3. collect the response
|
||||
|
||||
In your directory of choice, save the above script as `curl_request.clj` and run:
|
||||
In your directory of choice, save the above script as _curl\_request.clj_ and run:
|
||||
|
||||
```bash
|
||||
$ fldist run_air -p curl_request.clj -d '{"service_id": "f92ce98b-1ed6-4ce3-9864-11f4e93a478f", "url":"https://api.duckduckgo.com/?q=homotopy&format=json"}'
|
||||
@ -82,7 +82,7 @@ To recap, we:
|
||||
* executed the \(remote\) curl service request, and
|
||||
* collected the result
|
||||
|
||||
With essentially a two-line script and a couple of parameters, we executed a search request as a service on a peer-to-peer network. Even this small example should impress the ease afforded by Aquamarine to compose applications from portable, reusable and distributed services not only taken serverless to the next level by greatly reducing devops requirements but also empowering developers with a composition and coordination medium second to none.
|
||||
With essentially a two line script and a couple of parameters we executed a search request as a service on a peer-to-peer network. Even this small example should impress the ease afforded by Aquamarine to compose applications from portable, reusable and distributed services not only taken serverless to the next level by greatly reducing devops requirements but also empowering developers with a composition and coordination medium second to none.
|
||||
|
||||
In the next section, we build an Ethereum block getter application by coordinating multiple services into an application.
|
||||
|
||||
|
Reference in New Issue
Block a user