-
Notifications
You must be signed in to change notification settings - Fork 2
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
Create app #23
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 628a4b0
Fix protool import path
orkunkl 079f196
Fix codec import paths
orkunkl 375e416
Create init.go
orkunkl ed76ea2
Add tx.go
orkunkl fe33654
Add app codec
orkunkl 2fada2c
Compile codec.proto
orkunkl 7162b5f
Add app.go
orkunkl 38b7b27
Rename application to prjct
orkunkl d653f18
Fix tx codec numbers and add required modules
orkunkl 2c8fc5a
Add required modules to router, query router and organize
orkunkl 07cf469
Add decorators and organize code
orkunkl db72d8a
Fix codec and compile
orkunkl 1bb4725
Run make mod
orkunkl 2a87aa7
Add x/custom codec messages to app/codec
orkunkl ccd74cb
Add custom package migration schema
orkunkl 665df47
Register custom package to Router and QueryRouter
orkunkl 9215fd6
Remove app modules comment from app.go
orkunkl 58a5dfc
Creage doc.go and explain app package
orkunkl de4c130
Remove fmt
orkunkl 8b085f4
Add database error message detail when CommitKVStore fails
orkunkl a107ccb
Improve commenting on codec
orkunkl 15fefee
Improve app/codec/sum comment
orkunkl f7fa711
Make requested changes on init.go
orkunkl 36f8075
Add detail to conf/migration/admin
orkunkl 89c9df3
Improve tx.go GetMsg() commenting
orkunkl 431f2a7
Remove weave/errors from init.go
orkunkl 53e0a21
Compile app codec.proto
orkunkl 23dd47f
Run go fmt on all code
orkunkl File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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( | ||
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 | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.There was a problem hiding this comment.
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