Categorygithub.com/iov-one/weave
modulepackage
1.0.4
Repository: https://github.com/iov-one/weave.git
Documentation: pkg.go.dev

# README

IOV Weave

Build Status TravisCI codecov LoC Go Report Card API Reference ReadTheDocs license

Weave Logo

IOV Weave is a framework for quickly building your custom ABCI application to run a blockchain on top of the best-of-class BFT Proof-of-stake Tendermint consensus engine. It provides much commonly used functionality that can quickly be imported in your custom chain, as well as a simple framework for adding the custom functionality unique to your project.

Join the Weave community channel :loudspeaker:

It is inspired by the routing and middleware model of many web application frameworks, and informed by years of wrestling with blockchain state machines. More directly, it is based on the official cosmos-sdk, both the 0.8 release as well as the future 0.9 rewrite. Naturally, as I was the main author of 0.8.

While both of those are extremely powerful and flexible and contain advanced features, they have a steep learning curve for novice users. Thus, this library aims to favor simplicity over power when there is a choice. If you hit limitations in the design of this library (such as maintaining multiple merkle stores in one app), I highly advise you to use the official cosmos sdk.

On the other hand, if you want to try out tendermint, or have a design that doesn't require an advanced setup, you should try this library and give feedback, especially on ease-of-use. The end goal is to make blockchain development almost as productive as web development (in golang), by providing defaults and best practices for many choices, while allowing extreme flexibility in business logic and data modelling.

For more details on the design goals, see the Design Document

Prerequisites

Instructions

First, make sure you have set up the requirements. If you have a solid go and node developer setup, you may skip this, but good to go through it to be sure.

Once you are set up, you should be able to run something like the following to compile both bnsd (IOV blockchain application) and bnscli (a client side app to interact with bnsd). You will have to install a compatible version of tendermint separately. (Currently we use the v0.31.5 release).

# cd into to your workspace that is not in your $GOPATH
git clone https://github.com/iov-one/weave.git
cd weave
make install

Note that this app relies on a separate tendermint process to drive it. It is helpful to first read a primer on tendermint as well as the documentation on the tendermint cli commands.

Once it compiles, I highly suggest going through the readthedocs

Compatibility

Check out compatibility charts

Protobuf Documentation

We generate documentation from the *.proto files to keep it up to date.

You can view the documentation for all packages used in the bns app.

Or generate it yourself:

make protodocs
open ./docs/proto/index.html

Contributions

When opening a pull request with a change that does not require a CHANGELOG entry, include !nochangelog in the description. This will inform our build system to not fail the build due to a missing CHANGELOG update. This instruction is needed only if you are changing any of the Go source files.

History

The original version, until v0.6.0 was released under confio/weave. The original author, Ethan Frey, had previously worked on the Cosmos SDK and wanted to make a simpler framework he could use to start building demo apps, while the main sdk matured. Thus, confio/weave was born the first few months of 2018. This framework was designed to be open source and shared, but the only real usage and development was by IOV, so it was donated to that organization in August 2018 to be developed further for their BNS blockchain, as well as a companion to iov-core client libraries that deprecated confio/weave-js

Audit

Check out our latest audit report.

Thanks to newfinal100 for designing the weave logo.

# Packages

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
Crypto package is used to build, verify and convert signatures.
Data migration package implements a functionality to declare and execute data migrations.
No description provided by the author
Package gconf provides a toolset for managing an extension configuration.
Package migration provides tooling necessary for working with schema versioned entities.
Package orm provides an easy to use db wrapper Break state space into prefixed sections called Buckets.
No description provided by the author
Package tmtest provides helpers for testing using tendermint server.
Package weavetest provides mocks and functions that makes testing weave functionality easier.
Package x contains some standard extensions Extensions implement common functionality (Handler, Decorator, etc.) and can be combined together to construct an application All sub-packages are various extensions, useful to build applications, but not necessary to use the framework.

# Functions

AsUnixDuration converts given Duration into UnixDuration.
AsUnixTime converts given Time structure into its UNIX time representation.
BlockTime returns current block wall clock time as declared in the context.
CheckOrError returns an abci response for CheckTx, converting the error message if present, or using the successful CheckResult.
CheckTxError converts any error into a abci.ResponseCheckTx, preserving as much info as possible.
DeliverOrError returns an abci response for DeliverTx, converting the error message if present, or using the successful DeliverResult.
DeliverTxError converts any error into a abci.ResponseDeliverTx, preserving as much info as possible.
ExtractMsgFromSum will find a weave message from a tx sum type if it exists.
FromInitChain initialises GenesisParams using abci.RequestInitChain data.
GetChainID returns the current chain id panics if chain id not already set (should never happen).
GetCommitInfo returns the info on validators that signed this block.
GetHeader returns the current block header ok is false if no header set in this Context.
GetHeight returns the current block height ok is false if no height set in this Context.
GetLogger returns the currently set logger, or DefaultLogger if none was set.
GetPath returns the path of the message, or (missing) if no message.
No description provided by the author
InTheFuture returns true if given time is in the future compared to the current time as declared in the context.
InThePast returns true if given time is in the past compared to the current time as declared in the context.
IsExpired returns true if given time is in the past as compared to the "now" as declared for the block.
LoadMsg extracts the message represented by given transaction into given destination.
NewAddress hashes and truncates into the proper size.
NewCheck sets the gas used and the response data but no more info these are the most common info needed to be set by the Handler.
No description provided by the author
NewQueryRouter initializes a QueryRouter with no routes.
Pair constructs a model from a key-value pair.
ParseAddress accepts address in a string format and unmarshals it.
ParseDeliverOrError is the inverse of DeliverOrError It will parse back the abci response to return our internal format, or return an error on failed tx.
ParseFractionString returns a fraction value that is represented by given string.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
ValidatorUpdatesToABCI converts weave validator updates to abci representation.
WithBlockTime sets the block time for the context.
WithChainID sets the chain id for the Context.
WithCommitInfo sets the info on who signed the block in this Context.
WithHeader sets the block header for the Context.
WithHeight sets the block height for the Context.
WithLogger sets the logger for this Context.
WithLogInfo accepts keyvalue pairs, and returns another context like this, after passing all the keyvals to the Logger.

# Constants

KeyQueryMod means to query for exact match (key).
PrefixQueryMod means to query for anything with this prefix.
RangeQueryMod means to expect complex range query.

# Variables

AddressLength is the length of all addresses You can modify it in init() before any addresses are calculated, but it must not change during the lifetime of the kvstore.
DefaultLogger is used for all context that have not set anything themselves.
No description provided by the author
No description provided by the author
IsValidChainID is the RegExp to ensure valid chain IDs.
Version should be set by build flags: `git describe --tags`.

# Structs

CheckResult captures any non-error abci result to make sure people use error for error cases.
CommitID contains the tree version number and its merkle root.
DeliverResult captures any non-error abci result to make sure people use error for error cases.
The Fraction type represents a floating point number without the precision issues that native floating point type has.
GenesisParams represents parameters set in genesis that could be useful for some of the extensions.
Metadata is expected to be the first argument of every message or model.
Model groups together key and value to return.
PubKey represents a validator public key.
QueryRouter allows us to register many query handlers to different paths and then direct each query to the proper handler.
TickResult represents the result of a single tick run.
ValidatorUpdate represents an update to validator set.
ValidatorUpdates represents latest validator state, currently used to validate SetValidatorMsg transactions.

# Interfaces

Batch can write multiple ops atomically to an underlying KVStore.
CacheableKVStore is a KVStore that supports CacheWrapping CacheWrap() should not return a Committer, since Commit() on cache-wraps make no sense.
Checker is a subset of Handler to verify the validity of a transaction.
CommitKVStore is a root store that can make atomic commits to disk.
Decorator wraps a Handler to provide common functionality like authentication, or fee-handling, to many Handlers.
Deliverer is a subset of Handler to execute a transaction.
Handler is a core engine that can process a few specific messages This could represent "coin transfer", or "bonding stake to a validator".
Initializer implementations are used to initialize extensions from genesis file contents.
Iterator allows us to access a set of items within a range of keys.
KVCacheWrap allows us to maintain a scratch-pad of uncommitted data that we can view with all queries.
KVStore is a simple interface to get/set data For simplicity, we require all backing stores to implement this interface.
Marshaller is anything that can be represented in binary Marshall may validate the data before serializing it and unless you previously validated the struct, errors should be expected.
Msg is message for the blockchain to take an action (Make a state transition).
Persistent supports Marshal and Unmarshal This is separated from Marshal, as this almost always requires a pointer, and functions that only need to marshal bytes can use the Marshaller interface to access non-pointers.
QueryHandler is anything that can process ABCI queries.
ReadOnlyKVStore is a simple interface to query data.
Registry is an interface to register your handler, the setup side of a Router.
Scheduler is an interface implemented to allow scheduling message execution.
SetDeleter is a minimal interface for writing, Unifying KVStore and Batch.
Ticker is an interface used to call background tasks scheduled for execution.
Tx represent the data sent from the user to the chain.

# Type aliases

Address represents a collision-free, one-way digest of a Condition It will be of size AddressLength.
CommitInfo is a type alias for now, which allows us to override this type with a custom one at any moment.
Condition is a specially formatted array, containing information on who can authorize an action.
Context is just an alias for the standard implementation.
Options are the app options Each extension can look up it's key and parse the json as desired.
QueryRegister is a function that adds some handlers to this router.
TxDecoder can parse bytes into a Tx.
UnixDuration represents a time duration with granularity of a second.
UnixTime represents a point in time as POSIX time.