Skip to content

Commit

Permalink
Merge pull request #24 from it-chain/feature/renew
Browse files Browse the repository at this point in the history
hotfix
  • Loading branch information
hea9549 authored Aug 4, 2018
2 parents 7e6c341 + 01c61b4 commit 4aac4dd
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 15 deletions.
9 changes: 5 additions & 4 deletions rpc/client_stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"fmt"
"io"

"github.com/it-chain/tesseract"
"github.com/it-chain/tesseract/pb"
"google.golang.org/grpc"
)
Expand Down Expand Up @@ -70,7 +71,7 @@ func (cs *ClientStream) StartHandle() {
}()
}

func (cs *ClientStream) RunICode(request *pb.Request, callBack func(response *pb.Response, err error)) error {
func (cs *ClientStream) RunICode(request *pb.Request, callBack tesseract.CallBack) error {
cs.Handler.AddCallback(request.Uuid, callBack)
return cs.clientStream.Send(request)
}
Expand All @@ -84,12 +85,12 @@ func (c *ClientStream) Close() {
}

type DefaultHandler struct {
callBacks map[string]func(response *pb.Response, err error)
callBacks map[string]tesseract.CallBack
}

func NewDefaultHandler() *DefaultHandler {
return &DefaultHandler{
callBacks: make(map[string]func(response *pb.Response, err error)),
callBacks: make(map[string]tesseract.CallBack),
}
}

Expand All @@ -102,6 +103,6 @@ func (d *DefaultHandler) Handle(response *pb.Response, err error) {
delete(d.callBacks, response.Uuid)
}

func (d *DefaultHandler) AddCallback(uuid string, callback func(response *pb.Response, err error)) {
func (d *DefaultHandler) AddCallback(uuid string, callback tesseract.CallBack) {
d.callBacks[uuid] = callback
}
23 changes: 12 additions & 11 deletions tesseract.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,17 @@ import (
)

type ContainerID = string
type CallBack func(response *pb.Response, err error)

type Tesseract struct {
Clients map[ContainerID]*rpc.ClientStream
}

type Request struct {
uuid string
typeName string
funcName string
args []string
Uuid string
TypeName string
FuncName string
Args []string
}

type ICodeInfo struct {
Expand Down Expand Up @@ -190,20 +191,20 @@ func retryConnectWithTimeOut(timeout time.Duration) (*rpc.ClientStream, error) {
}
}

func (t *Tesseract) Request(containerID string, req Request, callBack func(response *pb.Response, err error)) error {
// args : Transaction
func (t *Tesseract) Request(containerID string, req Request, callback CallBack) error {
// Args : Transaction
// Get Container handler using SmartContract ID
// Send Query or Invoke massage
// Receive result
// Return result

client := t.Clients[containerID]
err := client.RunICode(&pb.Request{
Uuid: req.uuid,
Type: req.typeName,
FunctionName: req.funcName,
Args: req.args,
}, callBack)
Uuid: req.Uuid,
Type: req.TypeName,
FunctionName: req.FuncName,
Args: req.Args,
}, callback)

if err != nil {
return err
Expand Down

0 comments on commit 4aac4dd

Please sign in to comment.