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

Generate a MsgWirePayForMessage via CLI #32

Merged
merged 11 commits into from
Feb 26, 2021
Merged
13 changes: 12 additions & 1 deletion x/lazyledgerapp/types/payformessage.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ var _ sdk.Msg = &MsgWirePayForMessage{}
// Note that the share commitments generated still need to be signed using the Sign
// method
func NewMsgWirePayForMessage(namespace, message, pubK []byte, fee *TransactionFee, sizes ...uint64) (*MsgWirePayForMessage, error) {
message = PadMessage(message)
out := &MsgWirePayForMessage{
Fee: fee,
Nonce: 0,
Expand Down Expand Up @@ -166,7 +167,7 @@ func (msg *MsgWirePayForMessage) GetCommitmentSignBytes(k uint64) ([]byte, error
// to create a new SignedTransactionDataPayForMessage
func (msg *MsgWirePayForMessage) SignedTransactionDataPayForMessage(k uint64) (*SignedTransactionDataPayForMessage, error) {
// add padding to message if necessary
msg.Message = PadMessage(msg.Message)
msg.padMessage()
Copy link
Member

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?

Copy link
Member Author

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 MsgWirePayForMessages 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

Copy link
Member Author

Choose a reason for hiding this comment

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

resolved by de38b72 and e15b95b


// create the commitment using the padded message
commit, err := CreateCommitment(k, msg.MessageNameSpaceId, msg.Message)
Expand All @@ -187,6 +188,16 @@ func (msg *MsgWirePayForMessage) SignedTransactionDataPayForMessage(k uint64) (*
return &sTxMsg, nil
}

// padMessage adds padding to a message while also changing the declared message
// length
func (msg *MsgWirePayForMessage) padMessage() {
msg.Message = PadMessage(msg.Message)

if uint64(len(msg.Message)) != msg.MessageSize {
msg.MessageSize = uint64(msg.MessageSize)
}
}

///////////////////////////////////////
// SignedTransactionDataPayForMessage
///////////////////////////////////////
Expand Down