Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create app #23

Merged
merged 29 commits into from
Aug 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
0bd1308
Run go mod tidy
orkunkl Jul 29, 2019
628a4b0
Fix protool import path
orkunkl Jul 29, 2019
079f196
Fix codec import paths
orkunkl Jul 29, 2019
375e416
Create init.go
orkunkl Jul 29, 2019
ed76ea2
Add tx.go
orkunkl Jul 29, 2019
fe33654
Add app codec
orkunkl Jul 29, 2019
2fada2c
Compile codec.proto
orkunkl Jul 29, 2019
7162b5f
Add app.go
orkunkl Jul 29, 2019
38b7b27
Rename application to prjct
orkunkl Jul 29, 2019
d653f18
Fix tx codec numbers and add required modules
orkunkl Jul 29, 2019
2c8fc5a
Add required modules to router, query router and organize
orkunkl Jul 29, 2019
07cf469
Add decorators and organize code
orkunkl Jul 29, 2019
db72d8a
Fix codec and compile
orkunkl Jul 29, 2019
1bb4725
Run make mod
orkunkl Aug 9, 2019
2a87aa7
Add x/custom codec messages to app/codec
orkunkl Aug 9, 2019
ccd74cb
Add custom package migration schema
orkunkl Aug 9, 2019
665df47
Register custom package to Router and QueryRouter
orkunkl Aug 9, 2019
9215fd6
Remove app modules comment from app.go
orkunkl Aug 12, 2019
58a5dfc
Creage doc.go and explain app package
orkunkl Aug 12, 2019
de4c130
Remove fmt
orkunkl Aug 12, 2019
8b085f4
Add database error message detail when CommitKVStore fails
orkunkl Aug 12, 2019
a107ccb
Improve commenting on codec
orkunkl Aug 12, 2019
15fefee
Improve app/codec/sum comment
orkunkl Aug 12, 2019
f7fa711
Make requested changes on init.go
orkunkl Aug 12, 2019
36f8075
Add detail to conf/migration/admin
orkunkl Aug 12, 2019
89c9df3
Improve tx.go GetMsg() commenting
orkunkl Aug 12, 2019
431f2a7
Remove weave/errors from init.go
orkunkl Aug 12, 2019
53e0a21
Compile app codec.proto
orkunkl Aug 12, 2019
23dd47f
Run go fmt on all code
orkunkl Aug 12, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
127 changes: 127 additions & 0 deletions app/app.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
package app

import (
"context"
"path/filepath"
"strings"

"github.com/iov-one/weave"
"github.com/iov-one/weave-starter-kit/x/custom"
"github.com/iov-one/weave/app"
"github.com/iov-one/weave/coin"
"github.com/iov-one/weave/errors"
"github.com/iov-one/weave/migration"
"github.com/iov-one/weave/orm"
"github.com/iov-one/weave/store/iavl"
"github.com/iov-one/weave/x"
"github.com/iov-one/weave/x/cash"
"github.com/iov-one/weave/x/currency"
"github.com/iov-one/weave/x/multisig"
"github.com/iov-one/weave/x/sigs"
"github.com/iov-one/weave/x/utils"
"github.com/iov-one/weave/x/validators"
)

// Authenticator returns authentication with multisigs
// and public key signatues
func Authenticator() x.Authenticator {
return x.ChainAuth(sigs.Authenticate{}, multisig.Authenticate{})
}

// CashControl returns a controller for cash functions
func CashControl() cash.Controller {
return cash.NewController(cash.NewBucket())
}

// Chain returns a chain of decorators, to handle authentication,
// fees, logging, and recovery
func Chain(authFn x.Authenticator, minFee coin.Coin) app.Decorators {

return app.ChainDecorators(
utils.NewLogging(),
utils.NewRecovery(),
utils.NewKeyTagger(),
// on CheckTx, bad tx don't affect state
utils.NewSavepoint().OnCheck(),
sigs.NewDecorator(),
multisig.NewDecorator(authFn),
cash.NewFeeDecorator(authFn, CashControl()),
utils.NewSavepoint().OnDeliver(),
)
}

// Router returns a default router
func Router(authFn x.Authenticator, issuer weave.Address) *app.Router {
r := app.NewRouter()

cash.RegisterRoutes(r, authFn, CashControl())
sigs.RegisterRoutes(r, authFn)
multisig.RegisterRoutes(r, authFn)
currency.RegisterRoutes(r, authFn, issuer)
migration.RegisterRoutes(r, authFn)
validators.RegisterRoutes(r, authFn)
custom.RegisterRoutes(r, authFn)
return r
}

// QueryRouter returns a default query router,
// allowing access to "/custom", "/auth", "/contracts", "/wallets", "/validators" and "/"
func QueryRouter() weave.QueryRouter {
r := weave.NewQueryRouter()
r.RegisterAll(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would add cash here, as this is basic to most apps.
And msgfee if you don't remove the decorator above.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought we should keep weave-starter-kit simple as possible. So deleted msgfee

cash.RegisterQuery,
sigs.RegisterQuery,
multisig.RegisterQuery,
currency.RegisterQuery,
migration.RegisterQuery,
orm.RegisterQuery,
validators.RegisterQuery,
custom.RegisterQuery,
)
return r
}

// Stack wires up a standard router with a standard decorator
// chain. This can be passed into BaseApp.
func Stack(issuer weave.Address, minFee coin.Coin) weave.Handler {
authFn := Authenticator()
return Chain(authFn, minFee).WithHandler(Router(authFn, issuer))
}

// CommitKVStore returns an initialized KVStore that persists
// the data to the named path.
func CommitKVStore(dbPath string) (weave.CommitKVStore, error) {
// memory backed case, just for testing
if dbPath == "" {
return iavl.MockCommitStore(), nil
}

// Expand the path fully
path, err := filepath.Abs(dbPath)
if err != nil {
return nil, errors.Wrapf(errors.ErrDatabase, "invalid database name: %s", path)
}

// Some external calls accidentally add a ".db", which is now removed
path = strings.TrimSuffix(path, filepath.Ext(path))

// Split the database name into it's components (dir, name)
dir := filepath.Dir(path)
name := filepath.Base(path)
return iavl.NewCommitStore(dir, name), nil
}

// Application constructs a basic ABCI application with
// the given arguments.
func Application(name string, h weave.Handler,
tx weave.TxDecoder, dbPath string, debug bool) (app.BaseApp, error) {

ctx := context.Background()
kv, err := CommitKVStore(dbPath)
if err != nil {
return app.BaseApp{}, errors.Wrap(err, "cannot create database instance")
}
store := app.NewStoreApp(name, kv, QueryRouter(), ctx)
base := app.NewBaseApp(store, tx, h, nil, debug)
return base, nil
}
Loading