sdk

package module
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 7, 2019 License: Apache-2.0 Imports: 9 Imported by: 0

README

Go-SDK

Go-SDK is an SDK for creating it-chain SmartContract.

How to create smart contract using Go-SDK

1. Installation Go-SDK
go get -u github.com/DE-labtory/sdk
2. Create your own Icode project

create new go project for your icode.

your icode need to implement or invoke folloing:

  • Implementation go-sdk handler for handle invoke or query
  • Parse -p flag for port in main ( The port is used to create the ibox. )
  • Create Ibox using sdk NewIBox
  • Set handler in IBox
  • Call ibox.On function at the end of main
  • Contain all library using in your icode to vendor folder

sample icode : https://github.com/junbeomlee/learn-icode

3. Implement requires
  • Implementation go-sdk handler for handle invoke or query

sdk-go handler is like below

type RequestHandler interface {
	Name() string
	Versions() []string
	Handle(request *pb.Request, cell *Cell) *pb.Response
}

your icode need to implement this interface.

Name() function need to be return icode name.

Versions() function need to be return versions that your icode can process.

Handle(request *pb.Request, cell *Cell) *pb.Response function need to handle request that your icode want to handle.

  • Parse -p flag for port in main ( The port is used to create the ibox. )

ICode need port for interact with it-chain engine. tesseract will give port using -p flag.

So your icode need to parse -p flag for port.

sample code is :

import (
	"github.com/jessevdk/go-flags"
)

var opts struct {
	Port int `short:"p" long:"port" description:"set port"`
}

func main() {
	logger.EnableFileLogger(true, "./icode.log")
    port := opts.Port
    ...
    ...
    ...
}
  • Create Ibox using sdk NewIBox

IBox handle transaction excute request and interact with engine through tesseract.

You can create IBox just call sdk.NewIBox([port]). Port args must put parsed data

  • Set handler in IBox

After you implement handler , you must set handler to ibox.

You can set handler using [ibox instance].SetHandler([handler instance])

  • Call ibox.On function at the end of main

In the end of main your icode, You must call ibox On function.

IBox on function will create rpc server and start interact with engine.

You can write code like [ibox instance].On([timeout sec])

  • Contain all library using in your icode to vendor folder

if you use any library in your icode, you must make vendor folder.

Sample Icode

You can refer sample icode in https://github.com/DE-labtory/sdk/blob/master/example

Author

@hea9549

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cell

type Cell struct {
	DBHandler *leveldbwrapper.DBHandle
}

func NewCell

func NewCell(name string) *Cell

func (Cell) GetData

func (c Cell) GetData(key string) ([]byte, error)

func (Cell) PutData

func (c Cell) PutData(key string, value []byte) error

type IBox

type IBox struct {
	// contains filtered or unexported fields
}

func NewIBox

func NewIBox(port int) *IBox

func (*IBox) On

func (i *IBox) On(timeout int) error

func (*IBox) SetHandler

func (i *IBox) SetHandler(handler RequestHandler)

type RequestHandler added in v1.0.0

type RequestHandler interface {
	Name() string
	Versions() []string
	Handle(request *pb.Request, cell *Cell) *pb.Response
}

type Server

type Server struct {
	// contains filtered or unexported fields
}

func NewServer

func NewServer(port int) *Server

func (*Server) Close

func (s *Server) Close()

func (*Server) Listen

func (s *Server) Listen(waitTimeOutSec int) error

func (*Server) Ping

func (s *Server) Ping(ctx context.Context, empty *pb.Empty) (*pb.Empty, error)

func (*Server) RunICode

func (s *Server) RunICode(streamServer pb.BistreamService_RunICodeServer) error

func (*Server) SetHandler

func (s *Server) SetHandler(handler func(request *pb.Request) *pb.Response)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL