Skip to content

Commit

Permalink
Change Go TP SDK FamilyVersion to FamilyVersions
Browse files Browse the repository at this point in the history
Signed-off-by: Nick Drozd <[email protected]>
  • Loading branch information
nick-drozd committed Nov 13, 2017
1 parent a9f4e46 commit 3639d9e
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 26 deletions.
5 changes: 3 additions & 2 deletions families/seth/src/sawtooth_seth/processor/handler/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,9 @@ func NewBurrowEVMHandler() *BurrowEVMHandler {
func (self *BurrowEVMHandler) FamilyName() string {
return FAMILY_NAME
}
func (self *BurrowEVMHandler) FamilyVersion() string {
return FAMILY_VERSION

func (self *BurrowEVMHandler) FamilyVersions() []string {
return []string{FAMILY_VERSION}
}

func (self *BurrowEVMHandler) Namespaces() []string {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@ type SmallbankHandler struct {
func (self *SmallbankHandler) FamilyName() string {
return "smallbank"
}
func (self *SmallbankHandler) FamilyVersion() string {
return "1.0"

func (self *SmallbankHandler) FamilyVersions() []string {
return []string{"1.0"}
}

func (self *SmallbankHandler) Namespaces() []string {
Expand Down
5 changes: 3 additions & 2 deletions sdk/examples/intkey_go/src/sawtooth_intkey/handler/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,9 @@ const (
func (self *IntkeyHandler) FamilyName() string {
return FAMILY_NAME
}
func (self *IntkeyHandler) FamilyVersion() string {
return "1.0"

func (self *IntkeyHandler) FamilyVersions() []string {
return []string{"1.0"}
}

func (self *IntkeyHandler) Namespaces() []string {
Expand Down
4 changes: 2 additions & 2 deletions sdk/examples/noop_go/src/sawtooth_noop/handler/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ const FAMILY_NAME = "noop"
func (self *NoopHandler) FamilyName() string {
return FAMILY_NAME
}
func (self *NoopHandler) FamilyVersion() string {
return "1.0"
func (self *NoopHandler) FamilyVersions() []string {
return []string{"1.0"}
}
func (self *NoopHandler) Namespaces() []string {
return []string{self.namespace}
Expand Down
5 changes: 3 additions & 2 deletions sdk/examples/xo_go/src/sawtooth_xo/handler/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,9 @@ type Game struct {
func (self *XoHandler) FamilyName() string {
return "xo"
}
func (self *XoHandler) FamilyVersion() string {
return "1.0"

func (self *XoHandler) FamilyVersions() []string {
return []string{"1.0"}
}

func (self *XoHandler) Namespaces() []string {
Expand Down
8 changes: 4 additions & 4 deletions sdk/go/src/sawtooth_sdk/processor/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,16 @@ import (
// processor.AddHandler(myHandler)
// processor.Start()
//
// The FamilyName(), FamilyVersion(), and Namespaces() methods are
// The FamilyName(), FamilyVersions(), and Namespaces() methods are
// used by the processor to route processing requests to the handler.
type TransactionHandler interface {
// FamilyName should return the name of the transaction family that this
// handler can process, e.g. "intkey"
FamilyName() string

// FamilyVersion should return the version of the transaction family that
// this handler can process, e.g. "1.0"
FamilyVersion() string
// FamilyVersions should return the versions of the transaction
// family that this handler can process. Eg., ["1.0", "1.5"]
FamilyVersions() []string

// Namespaces should return a slice containing all the handler's
// namespaces, e.g. []string{"abcdef"}
Expand Down
24 changes: 13 additions & 11 deletions sdk/go/src/sawtooth_sdk/processor/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,14 +115,16 @@ func (self *TransactionProcessor) Start() error {
poller.Add(workers.Socket(), zmq.POLLIN)

// Register all handlers with the validator
for _, h := range self.handlers {
err := register(validator, h, queue)
if err != nil {
return fmt.Errorf(
"Error registering handler (%v, %v, %v): %v",
h.FamilyName(), h.FamilyVersion,
h.Namespaces(), err,
)
for _, handler := range self.handlers {
for _, version := range handler.FamilyVersions() {
err := register(validator, handler, version, queue)
if err != nil {
return fmt.Errorf(
"Error registering handler (%v, %v, %v): %v",
handler.FamilyName(), version,
handler.Namespaces(), err,
)
}
}
}

Expand Down Expand Up @@ -297,10 +299,10 @@ func receiveWorkers(ids map[string]string, validator, workers messaging.Connecti
}

// Register a handler with the validator
func register(validator messaging.Connection, handler TransactionHandler, queue chan *validator_pb2.Message) error {
func register(validator messaging.Connection, handler TransactionHandler, version string, queue chan *validator_pb2.Message) error {
regRequest := &processor_pb2.TpRegisterRequest{
Family: handler.FamilyName(),
Version: handler.FamilyVersion(),
Version: version,
Namespaces: handler.Namespaces(),
}

Expand Down Expand Up @@ -348,7 +350,7 @@ func register(validator messaging.Connection, handler TransactionHandler, queue
}
logger.Infof(
"Successfully registered handler (%v, %v, %v)",
handler.FamilyName(), handler.FamilyVersion,
handler.FamilyName(), version,
handler.Namespaces(),
)

Expand Down
11 changes: 10 additions & 1 deletion sdk/go/src/sawtooth_sdk/processor/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,16 @@ func findHandler(handlers []TransactionHandler, header *transaction_pb2.Transact
break
}

if header.GetFamilyVersion() != handler.FamilyVersion() {
HeaderVersion := header.GetFamilyVersion()
HasVersion := false
for _, version := range handler.FamilyVersions() {
if version == HeaderVersion {
HasVersion = true
break
}
}

if !HasVersion {
break
}

Expand Down

0 comments on commit 3639d9e

Please sign in to comment.