-
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
Create app #23
Conversation
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.
Nice start. Made some comments to clean up app.
Clearly docs need to exist to explain this. Thanks for figuring this out without proper docs.
app/app.go
Outdated
// Router returns a default router | ||
func Router(authFn x.Authenticator) *app.Router { | ||
r := app.NewRouter() | ||
// TODO implement orderbook router |
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.
Replace this TODO with the multisig and cash router at least.
app/app.go
Outdated
sigs.NewDecorator(), | ||
multisig.NewDecorator(authFn), | ||
utils.NewSavepoint().OnDeliver(), | ||
msgfee.NewFeeDecorator(), |
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.
msgfee can probably be removed from base app.
And the cash.StaticFeeDecorator can be used above (this is the simplest case when the product fee doesn't depend on the output from the Handler)
// allowing access to "/auth", "/contracts" and "/" | ||
func QueryRouter() weave.QueryRouter { | ||
r := weave.NewQueryRouter() | ||
r.RegisterAll( |
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
repeated bytes multisig = 4; | ||
// msg is a sum type over all allowed messages on this chain. | ||
oneof sum { | ||
cash.SendMsg cash_send_msg = 51; |
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.
You can also add the create/update multisig msgs here
app/codec.proto
Outdated
// space here to allow many more.... | ||
|
||
custom.CreateCustomStateIndexedMsg custom_create_state_indexed_msg = 100; | ||
custom.CreateCustomStateMsg create_custom_state_msg = 101; |
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.
If you add these, please update the Router and QueryHandler set in the app to include these
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 still need to implement handler and buckets. Lets keep this PR on until I finish and merge them
app/init.go
Outdated
// DecorateApp adds initializers and Logger to an Application | ||
func DecorateApp(application app.BaseApp, logger log.Logger) app.BaseApp { | ||
application.WithInit(app.ChainInitializers( | ||
&migration.Initializer{}, |
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.
Please update this to be in-line with the router/query/etc.
There are a few places that need to be kept in sync - good to add this to the docs.
When adding a package:
Stack
if it has a DecoratorRouter
if it has a HandlerQueryRouter
if it has any BucketsDecorateApp
/init if it has any Initializer.
Best to write down a list of all modules to use first, then make them all the same. As discussed above, I think the minimal set is:
- cash
- sigs
- multisig
- currency
- migration (as a runtime dependency of above modules)
validators
is a nice to have to run a PoA testnet and good to have as a demo.
--
msgfee
is a bit more complex and requires more complex Fee handling. I would not use this for default app.
@@ -2,7 +2,7 @@ syntax = "proto3"; | |||
|
|||
package custom; | |||
|
|||
import "github.com/iov-one/weave/codec.proto"; | |||
import "codec.proto"; |
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.
This didn't work the other way?
I actually thought we wanted short paths for references in the same repo, and full for outside.
But if needed for protoc, then do it like this.
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 tried to make it work as it was but no chance 😞 The only thing worked is to make x/codec
imports refer to weave codec without the prefix.
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.
Okay, then we just document that. Maybe someone (maybe me?) has time to look into it. Otherwise we just explain how to work with this.
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 appreciate it if somebody takes a look at it. I spent quite a time on the issue and this is the solution I come up with ¯_(ツ)_/¯
About protoc... these are key lines in prototool.yaml.
That is - customapp imports modules from same repo with short path. customapp imports weave protobuf from spec with full path. weave protobuf inside spec imports other weave protobuf with short path. Does this make sense? It was how I got it to work once (how it still does). But I really should have documented this better. Sorry. |
Blocked by #31 |
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.
If you want to make this crips, please update the comments to follow https://github.com/golang/go/wiki/CodeReviewComments#comment-sentences
app/app.go
Outdated
) | ||
} | ||
|
||
/* custom app uses below weave modules apart from x/custom |
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 am not sure why this comment is here. I think if at all, it should be part of general application documentation or package level comment. This place seems quite random for this listing.
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.
Nice advise 👍 I really enjoy writing go because only language itself covers and enforces structuring and documenting your code.
app/app.go
Outdated
// Expand the path fully | ||
path, err := filepath.Abs(dbPath) | ||
if err != nil { | ||
return nil, fmt.Errorf("Invalid Database Name: %s", path) |
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.
Error string should not be capitalized https://github.com/golang/go/wiki/CodeReviewComments#error-strings
Maybe it is worth using weave/errors
package to produce a better error instance?
app/app.go
Outdated
ctx := context.Background() | ||
kv, err := CommitKVStore(dbPath) | ||
if err != nil { | ||
return app.BaseApp{}, err |
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 think it is better to wrap error with additional information. Such context information is useful during debugging. For example:
return app.BaseApp{}, errors.Wrap(err, "cannot create database instance")
// Tx contains the message | ||
message Tx { | ||
// fee info, autogenerates GetFees() | ||
cash.FeeInfo cash_fees = 1; |
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.
Is the above comment true? This attribute will generate GetCashFees
method. 🤔
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.
https://github.com/iov-one/weave/blob/master/x/cash/codec.pb.go#L220-L225 Auto-generation does not cover the concept though.
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.
It is not necessary to add comments for autogeneration. Just remove it to not create confusion with all the other fields where it is not added.
app/codec.proto
Outdated
repeated sigs.StdSignature sigs_signatures = 2; | ||
// ID of a multisig contract. | ||
repeated bytes multisig = 4; | ||
// msg is a sum type over all allowed messages on this chain. |
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.
This attribute is called sum
not msg
🚓
app/init.go
Outdated
dict map[string]interface{} | ||
array []interface{} | ||
) | ||
collectorAddr, err := hex.DecodeString("3b11c732b8fc1f09beb34031302fe2ab347c5c14") |
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 think it is worth adding a comment what collector address is (to whom it belongs to?) and why it is hardcoded here.
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.
Nice point. I will take bnsd/init
as an example because mycoind/init
seems too much outdated
app/init.go
Outdated
// You can give coins to this address and return the recovery | ||
// phrase to the user to access them. | ||
func GenerateCoinKey() (weave.Address, string, error) { | ||
// TODO implement BIP39 recovery phrases |
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 think a TODO does not belong in a good codebase. Either implement it or leave a good comment explaining why below functionality works in this certain way and what was the reason for choosing this implementation.
Leaving TODO like this will give an impression that the code is not finished and lacking, therefore cannot be trusted. No one will address this comment as well.
app/tx.go
Outdated
// make sure tx fulfills all interfaces | ||
var _ weave.Tx = (*Tx)(nil) | ||
|
||
// GetMsg switches over all types defined in the protobuf file |
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 think a much better comment explaining the functionality would be
GetMsg returns a single message instance that is represented by this transaction.
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.
Only had a very brief look:
- Please run
go fmt $(go list ./... | grep -v "/vendor/")
make protoc
fails on my box
<input>:1:1:Import "x/custom/codec.proto" was not found.
app/codec.proto:29:5:"custom.CreateTimedStateMsg" is not defined.
app/codec.proto:30:5:"custom.CreateStateMsg" is not defined.
make test
fails on my box:
app/app.go:23:2: unknown import path "github.com/iov-one/weave-starter-kit/x/custom": import lookup disabled by -mod=readonly
// Tx contains the message | ||
message Tx { | ||
// fee info, autogenerates GetFees() | ||
cash.FeeInfo cash_fees = 1; |
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.
It is not necessary to add comments for autogeneration. Just remove it to not create confusion with all the other fields where it is not added.
@alpe really weird you are having errors on |
Waiting for response from gogo/protobuf#601 |
I have fixed harmless |
Closes #4
This is basically a copy-paste from the tutorial. If you think if there is an unnecessary chain decorator, let me know