-
Notifications
You must be signed in to change notification settings - Fork 331
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
Generate a MsgWirePayForMessage
via CLI
#32
Conversation
Codecov Report
@@ Coverage Diff @@
## master #32 +/- ##
==========================================
+ Coverage 15.04% 15.66% +0.62%
==========================================
Files 14 14
Lines 1888 1909 +21
==========================================
+ Hits 284 299 +15
- Misses 1588 1591 +3
- Partials 16 19 +3
Continue to review full report at Codecov.
|
80afc2a
to
7adb975
Compare
// MsgServer is the server API for Msg service. | ||
type MsgServer interface { | ||
// PayForMessage allows the user to post data to made be available. | ||
PayForMessage(context.Context, *types.MsgWirePayForMessage) (*types.MsgPayForMessageResponse, error) | ||
// PayForMessage allows the user to post data to made be available. | ||
SignedTransactionDataPayForMessage(context.Context, *types.SignedTransactionDataPayForMessage) (*types.SignedTransactionDataPayForMessageResponse, error) | ||
} | ||
|
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.
What is the relation of this interface to the MsgServer interface
in x/lazyledgerapp/types/tx.pb.go
?
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.
The MsgServer
interface in x/lazyledgerapp/types/tx.pb.go
only accounts for rpc endpoints, as the generated code assumes that there will always be 1 enpoint per 1 handler. That is not the case in our situation, where we need 2 handlers, but only 1 endpoint.
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.
What was the reason again to only have one endpoint 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.
because each MsgWirePayForMessage
will have the information for multiple SignedTransactionDataPayForMessage
s in it, and one SignedTransactionDataPayForMessage
is picked during PreprocessTxs
, so having an endpoint for SignedTransactionDataPayForMessage
could be confusing.
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.
That makes sense!
// PayForMessage allows the user to post data to made be available. | ||
SignedTransactionDataPayForMessage(context.Context, *SignedTransactionDataPayForMessage) (*SignedTransactionDataPayForMessageResponse, error) |
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.
Why are there changes in this file with no changes in the corresponding proto file?
// Code generated by protoc-gen-gogo. DO NOT EDIT.
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 had manually changed them in the last PR when I added the handler for SignedTransactionDataPayForMessage
😬 , which was definitely the wrong approach to change MsgServer
without adding an rpc endpoint. It was also my fault for force pushing the repo, otherwise someone would have probably caught it and informed me that it was a bad idea.
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.
does this need to be a separate PR?
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.
No worries! Thanks for the explanation. Hmm, yeah probably a good idea to rip out the rpc/endpoint/handler changes and clean that up in a separate PR.
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.
Actually, if that means self-contained small changes, feel free to address this in this PR. Probably good to open a tiny issue explaining the changes for reference though (amend a closes #XXX
referencing that issue too in the opening comment).
// transaction. | ||
func CmdCreatePayForMessage() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "payForMessage [hexNamespace] [hexMessage]", |
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.
Other Tx are in JSON encoding or hex, too? (I mean on the cli)
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.
That is a good question. I'm not sure. In other tx, each argument is parsed individually, and the only ones handling raw bytes are using either amino or the Bech32 address encoding. For example lazyledger-appd tx decode [amino-byte-string] [flags]
uses the amino byte string, and all addresses are inputted as a Bech32 string. Should it use amino? Something else to handle bytes?
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.
Should it use amino?
NOOOOOOO! please don't :-D
But seriously, let's go with hex bytes for now. Let's open an issue about the UX/UI of the CLI. I'm also not sure what would be best here. We can address this much later anyway (before mainnet). Probably the main usage won't be over the CLI but from other chains too.
And I find payForMessage [hexNamespace] [hexMessage]
clear and simple enough.
func (msg *MsgWirePayForMessage) SignShareCommitments(accName string, ring keyring.Keyring) error { | ||
for i, commit := range msg.MessageShareCommitment { | ||
bytesToSign, err := msg.GetCommitmentSignBytes(commit.K) | ||
if err != nil { | ||
return err | ||
} | ||
sig, _, err := ring.Sign(accName, bytesToSign) | ||
if err != nil { | ||
return err | ||
} | ||
msg.MessageShareCommitment[i].Signature = sig | ||
} | ||
return nil | ||
} |
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.
Dope! Can we create at least a small unit test for this method?
…ternal method for checking/adding padding.
msg.Message = PadMessage(msg.Message) | ||
msg.padMessage() |
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.
Shouldn't this be obsolete if the MsgWirePayForMessage
was constructed via NewMsgWirePayForMessage
?
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.
yes it is redundant, and it reminded me of why I put it there in the first place. The last PR #21 uses MsgWirePayForMessage
s in the tests but obviously doesn't use the new NewMsgWirePayForMessage
function, so those tests need a quick refactor along with getting rid of this msg.padMessage
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.
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.
✅ 🎉 👍🏼
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.
Looks good. I have only one tiny comment.
// decode the message | ||
message, err := hex.DecodeString(args[1]) | ||
if err != nil { | ||
return 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.
For better UX, maybe you can wrap error and provide info what argument (namespace or message) is wrong?
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 catch! You just saved someone some time 🙂 not all heroes wear capes 😉
resolved db5a91c
…ment could not be decoded
Co-authored-by: Ismail Khoffi <[email protected]>
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.
Left some nit about error wrapping.
See "Wrapping errors with %w": https://blog.golang.org/go1.13-errors
Co-authored-by: Ismail Khoffi <[email protected]>
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.
Description
This PR adds a sub command to the cli to generate a
MsgWirePayForMessage
transaction.Breaking down the above command,
lazyledgerappd
is the root command for everything lazyledger-app, including starting the node and generating transactions, but of this can change.tx
sub-command contains other sub-commands related to generating transactionslazyledgerapp
sub-command specifies the module that is being usedpayForMessage
is the sub-command to generate aMsgWirePayForMessage
The only necessary inputs are the namespace and the message, where everything else can be optional with sane defaults.
This PR should not be merged until #21 is merged.✔️the full --help message:
closes: #31 #35
TODO:
docs/
) or specification (x/<module>/spec/
)Unreleased
section inCHANGELOG.md
Files changed
in the Github PR explorerCodecov Report
in the comment section below once CI passes