Skip to content

Commit

Permalink
go/roothash: repurpose IncomingMessage.Data
Browse files Browse the repository at this point in the history
  • Loading branch information
pro-wh committed Apr 26, 2022
1 parent eaab525 commit 7084b4e
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion go/roothash/api/message/incoming_message.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package message

import (
"fmt"

"github.com/oasisprotocol/oasis-core/go/common/cbor"
"github.com/oasisprotocol/oasis-core/go/common/crypto/hash"
"github.com/oasisprotocol/oasis-core/go/common/quantity"
staking "github.com/oasisprotocol/oasis-core/go/staking/api"
Expand All @@ -26,10 +29,29 @@ type IncomingMessage struct {
// transferred before the message is processed by the runtime.
Tokens quantity.Quantity `json:"tokens,omitempty"`

// Data is arbitrary runtime-dependent data.
// Data is a serialized IncomingMessageData.
Data []byte `json:"data,omitempty"`
}

const LatestIncomingMessageDataVersion = 1

type IncomingMessageData struct {
cbor.Versioned

// Transaction is an embedded transaction.
Transaction *[]byte `json:"tx,omitempty"`
}

func (d *IncomingMessageData) ValidateBasic() error {
if d.V != LatestIncomingMessageDataVersion {
return fmt.Errorf("invalid incoming message data version (expected: %d got: %d)",
LatestIncomingMessageDataVersion,
d.V,
)
}
return nil
}

// InMessagesHash returns a hash of provided incoming runtime messages.
func InMessagesHash(msgs []*IncomingMessage) (h hash.Hash) {
if len(msgs) == 0 {
Expand Down

0 comments on commit 7084b4e

Please sign in to comment.