Skip to content
This repository has been archived by the owner on Feb 24, 2021. It is now read-only.

Backends

RmbRT edited this page Mar 9, 2020 · 1 revision

Introduction

We manage all state data in a global matter, tied together in several Backends:

  • Channel: Calculates channel IDs, Signs, Verifies states and decodes asserts
  • Wallet: Decodes addresses, signatures and verifies them
  • App: Decodes apps from their Address

Every backend needs to be set at startup, we automated this process for Channel and Backend so that you only have to use an import. The App backend still needs to be set manually.
All backends can only be set once, trying to set it a second time will panic. Therefore the lifetime of a backend spans over the runtime of the node, restarting the node is the only way of changing a backend.

Using backends

Backends are initialized by importing the concrete implementation of them.
Example for the ethereum backend:

import (
    _ "perun.network/go-perun/backend/ethereum" // backend init

    "perun.network/go-perun/wallet"
    "perun.network/go-perun/channel"
    "perun.network/go-perun/apps/payment"
)

func init() {
    // Sets the address of the ethereum contract that runs the payment app
    payment.SetAppDef(…)
    // Returns the ethereum address of the app.
    payment.AppDef()
}

func Foo() {
    wallet.DecodeAddr(…)
    channel.CalcID(…)
}

This shows how perun is blockchain agnostic; by changing a single line you can change the crypto currency that it uses.

The _ import ensures that the ethereum backend is properly loaded by the init() method upon startup.
All function calls to wallet and channel are then forwarded to the ethereum backend.
Importing apps/payment here is only an example, you could also import your own app. Right now all channels have to use the same app.

Clone this wiki locally