tp

package
v0.1.1-0...-84673a0 Latest Latest
Warning

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

Go to latest
Published: Mar 9, 2020 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Attribute

func Attribute(key, value string) processor.Attribute

Attribute returns a sawtooth event attribute.

func MakeWallet

func MakeWallet(pubkey string) (string, *processor.InvalidTransactionError)

MakeWallet return a wallet address from public key

func Must

func Must(endpoint string, handler *Handler)

Must starts a Sawtooth Transaction Processor. Panic if starting failure.

func NewTPRequestBytes

func NewTPRequestBytes(cmd int32, data proto.Message) ([]byte, error)

NewTPRequestBytes returns bytes encoding from request.

func Run

func Run(endpoint string, handler *Handler) error

Run starts a Sawtooth Transaction Processor.

func TxErrore

TxErrore returns a InvaildTransactionError with an error.

func TxErrorf

func TxErrorf(format string, a ...interface{}) *processor.InvalidTransactionError

TxErrorf returns a InvaildTransactionError with a formatted string.

func TxErrorp

TxErrorp returns a InvalidTransactionError with a protobuf message.

func UnmarshalTPRequest

func UnmarshalTPRequest(data []byte, pb proto.Message) (int32, error)

UnmarshalTPRequest returns data and command in TPReqest.

Types

type Context

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

Context wraps sawtooth processor context.

func (*Context) AddEvent

func (ctx *Context) AddEvent(typ string, data []byte, attributes ...processor.Attribute) *processor.InvalidTransactionError

AddEvent adds event to chain.

func (*Context) AddEventMessage

func (ctx *Context) AddEventMessage(typ string, data proto.Message, attributes ...processor.Attribute) *processor.InvalidTransactionError

AddEventMessage adds event to chain.

func (*Context) AddReceiptData

func (ctx *Context) AddReceiptData(data proto.Message) *processor.InvalidTransactionError

AddReceiptData adds receipt data.

func (*Context) Cmd

func (ctx *Context) Cmd() int32

Cmd returns current transaction command.

func (*Context) Context

func (ctx *Context) Context() *processor.Context

Context returns internal *process.Context.

func (*Context) Del

func (ctx *Context) Del(addrs []string) ([]string, error)

Del remove state from chain.

func (*Context) Get

func (ctx *Context) Get(address string, data proto.Message) (bool, *processor.InvalidTransactionError)

Get returns a state with address.

func (*Context) GetAll

GetAll returns states with multiple addresses.

func (*Context) Set

func (ctx *Context) Set(address string, data proto.Message) *processor.InvalidTransactionError

Set state into chain.

func (*Context) SetAll

SetAll sets all data into chain.

func (*Context) Setting

func (ctx *Context) Setting(address string) (string, *processor.InvalidTransactionError)

Setting returns value in setting-tp.

func (*Context) SignerPublicKey

func (ctx *Context) SignerPublicKey() string

SignerPublicKey returns transaction signer public key.

func (*Context) String

func (ctx *Context) String() string

type ErrCode

type ErrCode uint32

ErrCode ...

const (
	Internal      ErrCode = 999987 // internal error.
	Wallet        ErrCode = 999988 // generating wallet failure.
	BadParameters ErrCode = 999989 // any fields in request is invalid.
	LenNotMatch   ErrCode = 999990 // data length not match.
	Conflict      ErrCode = 999991 // address conflict.
	NotFound      ErrCode = 999992 // state not found.
	GetState      ErrCode = 999993 // getting state error.
	SetState      ErrCode = 999994 // setting state error.
	Events        ErrCode = 999995 // add event error.
	ReceiptData   ErrCode = 999996 // add event error.
	Unmarshal     ErrCode = 999997 // data (protobuf) unmarshal failure.
	Marshal       ErrCode = 999998 // data (protobuf) marshal failure.
	UnknownCmd    ErrCode = 999999 // unknown command.
)

Errors of tp.

func ToErrCode

func ToErrCode(raw []byte) ErrCode

ToErrCode convert bytes to CtzErrCode

func (ErrCode) String

func (c ErrCode) String() string

func (ErrCode) ToBytes

func (c ErrCode) ToBytes() []byte

ToBytes converts ErrCode to bytes.

func (ErrCode) TxErrore

TxErrore returns a InvalidTransactionError.

func (ErrCode) TxErrorf

func (c ErrCode) TxErrorf(format string, a ...interface{}) *processor.InvalidTransactionError

TxErrorf returns a InvalidTransactionError.

type Family

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

Family is for TransactionProcessor.

func NewFamily

func NewFamily(name string, versions, namespaces []string) *Family

NewFamily returns a Sawtooth TP family.

func (*Family) FamilyName

func (f *Family) FamilyName() string

FamilyName returns family name defined in processor.TransactionHandler.

func (*Family) FamilyVersions

func (f *Family) FamilyVersions() []string

FamilyVersions returns family support versions defined in processor.TransactionHandler.

func (*Family) Namespaces

func (f *Family) Namespaces() []string

Namespaces returns namespaces of family defined in processor.TransactionHandler.

func (*Family) String

func (f *Family) String() string

type Handler

type Handler struct {
	*Family
	// contains filtered or unexported fields
}

Handler is a handler for Sawtooth Transaction Processor.

func NewHandler

func NewHandler(family *Family) *Handler

NewHandler returns a SawTK handler.

func (*Handler) Add

func (h *Handler) Add(cmd int32, hf HandlerFunc)

Add an handler function for some command.

func (*Handler) Apply

Apply implements Apply function of processor.TransactionHandler. Decode payload in req (*processor_pb2.TpProcessRequest), and change to user's payload.

type HandlerFunc

type HandlerFunc func(ctx *Context, req *TPRequest) *processor.InvalidTransactionError

HandlerFunc SawTK TP handler function.

func MakeHandlerFunc

func MakeHandlerFunc(f interface{}) HandlerFunc

MakeHandlerFunc returns a HandlerFunc. It will unmarshal payload to specific datatype defined in f automatically.

type RequestValidator

type RequestValidator interface {
	proto.Message
	Validate() *processor.InvalidTransactionError
}

RequestValidator is for MakeHandlerFunc to check req is ok or not.

Jump to

Keyboard shortcuts

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