go-nitro

module
Version: v0.0.0-...-942ef11 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2022 License: Apache-2.0, MIT

README


go-nitro

Implementation of the Nitro State Channels Framework in Golang and Solidity.

Usage

Go-nitro is work-in-progress library code with an evolving API.

Our integration tests give the best idea of how to use the API. Another useful resource is the godoc description of the go-nitro.Client API (please check for the latest version).

Broadly, consumers will construct a go-nitro Client, possibly using injected dependencies. Then, they can create channels and send payments:

 import nc "github.com/statechannels/go-nitro/client"

 nitroClient := nc.New(
                    messageservice,
                    chain,
                    storeA,
                    logDestination,
                    nil,
                    nil
                )
response := nitroClient.CreateLedgerChannel(hub.Address, 0, someOutcome)
nitroClient.WaitForCompletedObjective(response.objectiveId)

response = nitroClient.CreateVirtualPaymentChannel([hub.Address],bob.Address, defaultChallengeDuration, someOtherOutcome)
nitroClient.WaitForCompletedObjective(response.objectiveId)

for i := 0; i < len(10); i++ {
    clientA.Pay(response.ChannelId, big.NewInt(int64(5)))
}

response = nitroClient.CloseVirtualChannel(response.ChannelId)
nitroClient.WaitForCompletedObjective(response.objectiveId)

Contributing

Please see contributing.md

ADRs

Architectural decision records may be viewed here.

Roadmap

The following roadmap gives an idea of the various packages that compose the go-nitro module, and their implementation status:

├── abi ✅                     # types for abi encoding and decoding.
├── channel ✅                 # query the latest supported state of a channel
│   ├── consensus_channel ✅    # manage a running ledger channel.
│   └── state ✅               # generate and recover signatures on state updates
│       ├── outcome ✅         # define how funds are dispersed when a channel closes
├── client 🚧                  # exposes an API to the consuming application
│   └── engine ✅              # coordinate the client components, runs the protocols
│       ├── chainservice 🚧    # watch the chain and submit transactions
│       ├── messageservice ✅  # send and receives messages from peers
│       └── store 🚧           # store keys, state updates and other critical data
├── client_test ✅             # integration tests involving multiple clients
├── crypto  ✅                 # create Ethereum accounts, create & recover signatures
├── internal
│   ├── testactors ✅          # peers with vanity addresses (Alice, Bob, Irene, ... )
│   ├── testdata ✅            # literals and utility functions used by other test packages
│   ├── testhelpers ✅         # pretty-print test failures
|
├── protocols ✅               # functional core of the go-nitro client
│   ├── direct-fund ✅         # fund a channel on-chain
│   ├── direct-defund ✅       # defund a channel on-chain
│   ├── virtual-fund ✅        # fund a channel off-chain through one or more  intermediaries
│   └── virtual-defund ✅      # defund a channel off-chain through one or more intermediaries
└── types ✅                   # basic types and utility methods

On-chain code

The on-chain component of Nitro (i.e. the solidity contracts) are housed in the nitro-protocol directory. This directory contains an npm package with a hardhat / typechain / jest toolchain.

License

Dual-licensed under MIT + Apache 2.0

Directories

Path Synopsis
Package abi contains constants which are useful when performing abi encoding and decoding.
Package abi contains constants which are useful when performing abi encoding and decoding.
Package channel defines types and methods for state channels.
Package channel defines types and methods for state channels.
consensus_channel
Package consensus_channel manages a running ledger channel.
Package consensus_channel manages a running ledger channel.
state
Package state defines the data structures which are signed by channel participants.
Package state defines the data structures which are signed by channel participants.
state/outcome
Package outcome defines the data structures for expressing how channel funds are to be distributed on-chain.
Package outcome defines the data structures for expressing how channel funds are to be distributed on-chain.
Package client contains imperative library code for running a go-nitro client inside another application.
Package client contains imperative library code for running a go-nitro client inside another application.
engine
Package engine contains the types and imperative code for the business logic of a go-nitro Client.
Package engine contains the types and imperative code for the business logic of a go-nitro Client.
engine/chainservice
Package chainservice is a chain service responsible for submitting blockchain transactions and relaying blockchain events.
Package chainservice is a chain service responsible for submitting blockchain transactions and relaying blockchain events.
engine/chainservice/adjudicator
package NitroAdjudicator contains bindings generated from the Nitro Adjudicator solidity contract, as well as utilities for converting client types to on-chain types.
package NitroAdjudicator contains bindings generated from the Nitro Adjudicator solidity contract, as well as utilities for converting client types to on-chain types.
engine/messageservice
Package messageservice is a messaging service responsible for routing messages to peers and relaying messages received from peers.
Package messageservice is a messaging service responsible for routing messages to peers and relaying messages received from peers.
engine/store
Package store contains the interface for a go-nitro store.
Package store contains the interface for a go-nitro store.
engine/store/safesync
package safesync provides a type-safe, concurrency-safe Map struct
package safesync provides a type-safe, concurrency-safe Map struct
Package crypto contains types and functions for creating Ethereum private keys and accounts, and creating/recovering signatures made with such keys.
Package crypto contains types and functions for creating Ethereum private keys and accounts, and creating/recovering signatures made with such keys.
Package protocols defines the off-chain protocols for managing channels.
Package protocols defines the off-chain protocols for managing channels.
directdefund
Package directdefund implements an off-chain protocol to defund a directly-funded channel.
Package directdefund implements an off-chain protocol to defund a directly-funded channel.
directfund
Package directfund implements an off-chain protocol to directly fund a channel.
Package directfund implements an off-chain protocol to directly fund a channel.
virtualfund
Package virtualfund implements an off-chain protocol to virtually fund a channel.
Package virtualfund implements an off-chain protocol to virtually fund a channel.
Package types defines common types.
Package types defines common types.
internal
testactors
Package testactors exports peers with vanity addresses: with corresponding keys, names and virtual funding protocol roles.
Package testactors exports peers with vanity addresses: with corresponding keys, names and virtual funding protocol roles.
testhelpers
Package testhelpers contains functions which pretty-print test failures.
Package testhelpers contains functions which pretty-print test failures.

Jump to

Keyboard shortcuts

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