How to register an effect
Date | Responsible | Changes |
---|---|---|
November 29, 2022 | @Tomislav Herman | Initial version |
January 20, 2023 | @Tomislav Herman | Updated code example to match latest signing api from ledger-sdk. |
February 10, 2023 | @Omar Monterrey | SDK Options refactoring (url to server and key to signer ) |
February 17, 2023 | @Tomislav Herman | Updated webhook urls to bridge interface convention: v2/effects/:handle |
February 27, 2023 | @Omar Monterrey | Refactored signer.schema → signer.format |
March 9, 2023 | @Tomislav Herman | Refactored ledger → sdk |
November 16, 2023 | @Luis Fidelis | Add bridge action schema |
Effects are used to extend the ledger core functionalities by observing and reacting on events raised when a change occurs with ledger data.
We will register an effect which is triggered by an event with signal balance-received
, but only when wallet with handle bank1
receives a balance in usd
symbol. When triggered, the effect will execute webhook
action which sends a HTTP POST request with event payload to the endpoint defined in webhook action, or to the server defined in a bridge if the effect action schema if bridge
. We will assume that there is a local HTTP server which listens on http://localhost:3000/v2/effects/bank1-balance-received
endpoint.
Registering a webhook effect
Example in Node.js by using @minka/ledger-sdk
:
Or by using @minka/cli
:
Registering a bridge effect
Firstly, we need to setup a bridge in the ledger to receive an event when a balance is changed - received - in the system.
Via @minka/ledger-sdk
:
Or via @minka/cli
:
The bridge should implement at least events
trait to be able to receive effect calls.
Now we have our bridge, we can proceed and register the effect targeting the bridge created previously.
By using @minka/ledger-sdk
:
Or by using @minka/cli
:
After that, the bridge will start to receive those events at
POST http://localhost:3000/v2/effects/bank2-balance-received
.
Notice that bank2-balance-received
is the handle of the effect created, so the endpoint
on the other side should be registered with same value.