mirror of
https://github.com/fluencelabs/gitbook-docs
synced 2025-04-25 16:02:17 +00:00
GitBook: [docs] 54 pages modified
This commit is contained in:
parent
271edda449
commit
ae8f93dba0
@ -1,6 +1,6 @@
|
|||||||
# Building An Application From Multiple Services
|
# 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/](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).
|
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).
|
||||||
|
|
||||||
Since we are composing our application from first principles, we use the following services to compose our app:
|
Since we are composing our application from first principles, we use the following services to compose our app:
|
||||||
|
|
||||||
@ -9,17 +9,17 @@ Since we are composing our application from first principles, we use the followi
|
|||||||
* _get\_block_: takes an api key and block number as int and returns the reward block info
|
* _get\_block_: takes an api key and block number as int and returns the reward block info
|
||||||
* _extract\_miner\_address_: takes a json string and return the miner address
|
* _extract\_miner\_address_: takes a json string and return the miner address
|
||||||
|
|
||||||
Let's find these services on the [Fluence Dashboard](https://dash.fluence.dev/) and make a note of the corresponding associated the service and network ids:
|
Let's find these services on the [Fluence Dashboard](https://dash.fluence.dev/) and make a note of the corresponding associated service and network ids:
|
||||||
|
|
||||||
* [Ethereum Block Getter](https://dash.fluence.dev/blueprint/801037186238469ce354d2eb6d884091aaf9622ba7b1a83816cc45d39ab2000d) provides methods to retrieve the latest, most recent Ethereum block number as a hex string and a reward block getter method, which gets the block information for a given integer block number. And yes, this service exposes two methods
|
* [Ethereum Block Getter](https://dash.fluence.dev/blueprint/801037186238469ce354d2eb6d884091aaf9622ba7b1a83816cc45d39ab2000d) provides methods to retrieve the latest, most recent Ethereum block number as a hex string and a reward block getter method, which gets the block information for a given integer block number. And yes, this service exposes two methods
|
||||||
* service id: 74d5c5da-4c83-4af9-9371-2ab5d31f8019
|
* service id: `74d5c5da-4c83-4af9-9371-2ab5d31f8019`
|
||||||
* node id: 12D3KooWGzNvhSDsgFoHwpWHAyPf1kcTYCGeRBPfznL8J6qdyu2H
|
* node id: `12D3KooWGzNvhSDsgFoHwpWHAyPf1kcTYCGeRBPfznL8J6qdyu2H`
|
||||||
* [Hex Converter](https://dash.fluence.dev/blueprint/63ff63360ef64651f712a2ecf08868d1a71f9dff0af04e234e4d543a66872806), which exposes the hex\_to\_int method to convert a hex string \(starting with 0x\) to an integer value
|
* [Hex Converter](https://dash.fluence.dev/blueprint/63ff63360ef64651f712a2ecf08868d1a71f9dff0af04e234e4d543a66872806), which exposes the hex\_to\_int method to convert a hex string \(starting with 0x\) to an integer value
|
||||||
* service id: 285e2a5e-e505-475f-a99d-15c16c7253f9
|
* service id: `285e2a5e-e505-475f-a99d-15c16c7253f9`
|
||||||
* node id: 12D3KooWKnRcsTpYx9axkJ6d69LPfpPXrkVLe96skuPTAo76LLVH
|
* node id: `12D3KooWKnRcsTpYx9axkJ6d69LPfpPXrkVLe96skuPTAo76LLVH`
|
||||||
* [Extract Miner Address](https://dash.fluence.dev/blueprint/16a22a4033b6e98c45ac603fb520db77f4dcf42bf143f0d935262cb43136647e) extracts the miner address from a reward block json string
|
* [Extract Miner Address](https://dash.fluence.dev/blueprint/16a22a4033b6e98c45ac603fb520db77f4dcf42bf143f0d935262cb43136647e) extracts the miner address from a reward block json string
|
||||||
* service id: d13da294-004a-4c71-8631-a351c5f3489b
|
* service id: `d13da294-004a-4c71-8631-a351c5f3489b`
|
||||||
* node id: 12D3KooWCKCeqLPSgMnDjyFsJuWqREDtKNHx1JEBiwaMXhCLNTRb
|
* node id: `12D3KooWCKCeqLPSgMnDjyFsJuWqREDtKNHx1JEBiwaMXhCLNTRb`
|
||||||
|
|
||||||
Let's test the hex conversion test in isolation with the following AIR script:
|
Let's test the hex conversion test in isolation with the following AIR script:
|
||||||
|
|
||||||
@ -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\)**
|
**\(**_call_ **node-id \(service-id service-method\) \[input parameters\] result\)**
|
||||||
{% endhint %}
|
{% 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 the 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 as the hex value. Save the above script to a local file called _hex2int.clj_ and use `fldist` to deploy the script:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
fldist run_air -p hex2int.clj -d '{"hex_service":"285e2a5e-e505-475f-a99d-15c16c7253f9", "hex_node": "12D3KooWKnRcsTpYx9axkJ6d69LPfpPXrkVLe96skuPTAo76LLVH", "hex_string":"0xF"}'
|
fldist run_air -p hex2int.clj -d '{"hex_service":"285e2a5e-e505-475f-a99d-15c16c7253f9", "hex_node": "12D3KooWKnRcsTpYx9axkJ6d69LPfpPXrkVLe96skuPTAo76LLVH", "hex_string":"0xF"}'
|
||||||
|
@ -6,36 +6,29 @@ The [Fluence Dashboard](https://dash.fluence.dev/) facilitates the discovery of
|
|||||||
|
|
||||||
In order to execute the cUrl service and collect the result, i.e., response, we call upon our composition and coordination medium Aquamarine via an Aquamarine Intermediate Representation \(AIR\) script.
|
In order to execute the cUrl service and collect the result, i.e., response, we call upon our composition and coordination medium Aquamarine via an Aquamarine Intermediate Representation \(AIR\) script.
|
||||||
|
|
||||||
```scheme
|
```text
|
||||||
;; handle possible errors via xor
|
|
||||||
(xor
|
(xor
|
||||||
(seq
|
(seq
|
||||||
;; call function 'service_id.request' on node 'relay'
|
|
||||||
(call relay (service_id "request") [url] result)
|
(call relay (service_id "request") [url] result)
|
||||||
|
|
||||||
;; return result back to the client
|
|
||||||
(call %init_peer_id% (returnService "run") [result])
|
(call %init_peer_id% (returnService "run") [result])
|
||||||
)
|
)
|
||||||
;; if error, return it to the client
|
|
||||||
(call %init_peer_id% (returnService "run") [%last_error%])
|
(call %init_peer_id% (returnService "run") [%last_error%])
|
||||||
)
|
)
|
||||||
```
|
```
|
||||||
|
|
||||||
Without going too deep into Aquamarine and AIR, this script specifies that we call a public peer-to-peer relay \(node\) on the network, ask to run the \(curl\) _request_ function with data parameter _url_ and _service\_id_ parameter, and collect the _result_ **xor** the _error message_ in case of execution failure. We also promise to pass the _service\_id_ and _url_ parameters to the scripts.
|
Without going too deep into Aquamarine and AIR, this script specifies that we call a public peer-to-peer relay \(node\) on the network, ask to run the \(curl\) _request_ function with data parameter _url_ and _service\_id_ parameter, and collect the _result_ **xor** the _error message_ in case of execution failure. We also promise to pass the _service\_id_ and _url_ parameters to the scripts. The "magic" happens by handing the script to the `fldist` CLI tool, which then sends the script for execution to the specified p2p network and locally shadows the execution. Please note that Instead of developing full-fledged frontend applications, we use the `fldist` CLI tool. However, a [JS SDK](https://github.com/fluencelabs/fluence-js) is available to accelerate the development of more complex frontend applications.
|
||||||
|
|
||||||
The "magic" happens by handing the script to the `fldist` CLI tool, which then sends the script for execution to the specified p2p network and locally shadows the execution. Please note that Instead of developing full-fledged frontend applications, we use the `fldist` CLI tool. However, a [JS SDK](https://github.com/fluencelabs/fluence-js) is available to accelerate the development of more complex frontend applications.
|
|
||||||
|
|
||||||
{% hint style="info" %}
|
{% hint style="info" %}
|
||||||
Throughout the document, we utilize service and node ids, which in most cases may be different for you.
|
Throughout the document, we utilize service and node ids, which in most cases may be different for you.
|
||||||
{% endhint %}
|
{% 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 ,
|
1. find the p2p node hosting the curl service with above service id ,
|
||||||
2. execute the service and
|
2. execute the service and
|
||||||
3. collect the response
|
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
|
```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"}'
|
$ 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 +75,7 @@ To recap, we:
|
|||||||
* executed the \(remote\) curl service request, and
|
* executed the \(remote\) curl service request, and
|
||||||
* collected the result
|
* 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.
|
In the next section, we build an Ethereum block getter application by coordinating multiple services into an application.
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user