alexbosy / go-nitro

Implementation of nitro-protocol in Go

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool


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

About

Implementation of nitro-protocol in Go

License:Other


Languages

Language:Go 60.5%Language:TypeScript 26.4%Language:Solidity 12.2%Language:JavaScript 0.4%Language:Python 0.3%Language:Shell 0.2%