go-nitro

command module
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2023 License: Apache-2.0, MIT Imports: 17 Imported by: 0

README


go-nitro

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

go-nitro is an implementation of a node in a nitro state channel network. It is software that:

  • manages a secret "channel" key
  • crafts blockchain transactions (to allow the user to join and exit the network)
  • crafts, signs, and sends state channel updates to counterparties in the network
  • listens to blockchain events
  • listens for counterparty messages
  • stores important data to allow for recovery from counterparty inactivity / malice
  • understands how to perform these functions safely without risking any funds

Usage

⚠️ Go-nitro is pre-production software ⚠️

Go-nitro can be consumed either as library code or started in an independent process and interfaced with remote procedure calls (recommended).

Contributing

Please see contributing.md

ADRs

Architectural decision records may be viewed here.

Testing

To run unit tests locally, you will need to generate a TLS certificate. Details are here.

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 yarn workspace with a hardhat / typechain / jest toolchain.

License

Dual-licensed under MIT + Apache 2.0

Documentation

Overview

Go-nitro can be run as a system service with an RPC api. Go-nitro's default configuration looks for a local blockchain network on port 8545 with chainid 1337. If such a network is available is running, go-nitro can be started from the root directory with

go run .

Or, built to an executable binary with

go build -o gonitro

Either command may be augmented with a build tag like so:

go build -o gonitro -tags embed-ui

which will cause a static website located at packages/nitro-gui/dist to be served over the rpcPort (see below). If no such site has been built, there will be a compiler error.

Go nitro accepts the following command flags, which can also be displayed via `go run . -help` (or `gonitro -help` for the build binary). Usage of ./nitro-rpc-server:

-chainid int
      Specifies the chain id of the chain. (default 1337)
-chainurl string
      Specifies the url of a RPC endpoint for the chain. (default "ws://127.0.0.1:8545")
-deploycontracts
      Specifies whether to deploy the adjudicator and create2deployer contracts.
-msgport int
      Specifies the tcp port for the  message service. (default 3005)
-naaddress string
      Specifies the address of the nitro adjudicator contract. Default is the address computed by the Create2Deployer contract. (default "0xC6A55E07566416274dBF020b5548eecEdB56290c")
-pk string
      Specifies the private key used by the node. Default is Alice's private key. (default "2d999770f7b5d49b694080f987b82bbc9fc9ac2b4dcc10b0f8aba7d700f69c6d")
-rpcport int
      Specifies the tcp port for the rpc server. (default 4005)
-usedurablestore
      Specifies whether to use a durable store or an in-memory store.
-usenats
      Specifies whether to use NATS or http/ws for the rpc server.

You can make remote procedure calls like so:

curl -X POST \
  -H 'Content-Type: application/json' \
  -d '{"jsonrpc":"2.0","id":1,"method":"get_address","params":{}}' \
  http://localhost:4005/api/v1

but see github.com/statechannels/go-nitro/rpc or https://github.com/statechannels/go-nitro/tree/main/packages/nitro-rpc-client for an RPC client to do so programmatically.

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.
cmd
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.
internal
rpc
safesync
package safesync provides a type-safe, concurrency-safe Map struct
package safesync provides a type-safe, concurrency-safe Map struct
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.
Package node contains imperative library code for running a go-nitro node inside another application.
Package node contains imperative library code for running a go-nitro node inside another application.
engine
Package engine contains the types and imperative code for the business logic of a go-nitro Node.
Package engine contains the types and imperative code for the business logic of a go-nitro Node.
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.
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 rand is a convenience wrapper aroung golang rand go math/rand is deterministic unless a random seed is provided see https://gobyexample.com/random-numbers
Package rand is a convenience wrapper aroung golang rand go math/rand is deterministic unless a random seed is provided see https://gobyexample.com/random-numbers
rpc
Package types defines common types.
Package types defines common types.

Jump to

Keyboard shortcuts

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