multichain-feed

command
v2.10.0+incompatible Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 29, 2024 License: GPL-3.0 Imports: 6 Imported by: 0

README

Multichain-Feed

This project provides a script that can be passed to multichain's runtime variable walletnotify in the blockchain project of Trubudget. The script is executed when a transaction is done. More information how walletnotify works can be found in the runtime-parameter-list of multichain. The script checks the transaction type and executes sideEffects programmed for each recognized type.

Transaction Types

All of Trubudget's events have a certain type. For each event a transaction is created on the blockchain. The multichain feed can perform side effects for specific transactions. An Example for a side effect is the notification_created transaction. On each notification_created transaction a file is saved locally. The different types can be found in Trubudget's api project. In the domain layer of the api all events which create transactions can be found.

The following list shows all recognized transactions with implemented side effects:

  • notification_created
Type: notification_created

This type of event/transaction defines the creation of one notification. The notification id and the recipient can be found in the event defined by Trubudget's api. The notification_transaction_example.json file shows how the structure of such a transaction looks like.

Side Effect of notification_created

Saves the transactions as json file locally. Notification transactions are saved locally into the notifications directory as json files. The files have a timestamp as name. Details about all environment variables can be found in the configuration section of the blockchain project.

Add a new transaction type

New transaction and side effects are implemented in the GO project. Whenever a transaction occurs, the compiled GO binary will be executed. To add a new transaction, simply add the transaction type and the directory (path) to save the transaction as *.json to multichainFeed.go.

Example

As an Example, we want to log every transaction where a new user is created in a *.json file. To achieve this, we need to do following:

  1. Add usertransactionsPath := "./usertransactions/" to multichainFeed.go

    add-usertransactions-path

  2. Add the new transaction type user_created to multichainFeed.go

    add-user-created-transaction

  3. Set the environmental variables MULTICHAIN_FEED_ENABLED to true in blockchain/.env.

  4. Go to the multichain-feed directory (/multichain-feed) and compile the GO project to a binary script file with go build .

cd multichain-feed/
go build .
  1. Now copy the multichain-feed binary script into the docker container using following commands. The docker container name can be found with docker ps. A restart or rebuild is not required. You need to be in the multichain-feed directory (/multichain-feed).
docker cp multichain-feed blockchain_main-node_1:/home/node/src/multichain-feed/multichain-feed

Testing

To test the multichainFeed.go

  • Navigate into the root directory of the mutlichain-feed project.
  • Build the go project.
  • Execute the generated binary with a valid transaction

To test the current implemented transaction type notification_created, use following commands:

cd multichain-feed/
go build .
./multichain-feed "$(cat ./examples/notification_transaction_example.json)"

To see the *.json files in the running MutliChain, view inside the docker container and navigate to the the specific path, for example:

docker exec -it <containerid> bash
cd notifications
ls
cat <somefilename>.json

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL