sawtooth_client_sdk_go

package module
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Dec 24, 2019 License: Apache-2.0 Imports: 14 Imported by: 0

README

Sawtooth Client SDK for Go

This repo contains the Sawtooth Client SDK for Go (developed by Taekion).

What is it for?

Client libraries that interface with Sawtooth transaction processors tend to repeat a lot of boilerplate code for transaction/batch construction and handling, as well as for performing queries against the data already committed to the blockchain. This library attempts to generalize much of that code in such a way that lets application-specific client libraries avoid handling many of these implementation details.

What does it do?

  • Handles transaction/batch/batchlist construction and signing.
  • Provides a complete abstraction to the Sawtooth REST API.
  • Implements the REST API abstraction via a generalized "transport" abstraction, which can be adapted to other transports (e.g. ZMQ).

How to use it?

A application-specific client library needs to implement the following interface:

type SawtoothClientImpl interface {
    GetFamilyName() string
    GetFamilyVersion() string

    EncodePayload(interface{}) ([]byte, error)
    DecodePayload([]byte, interface{}) error

    EncodeData(interface{}) ([]byte, error)
    DecodeData([]byte, interface{}) error

    GetPayloadInputAddresses(payload interface{}) []string
    GetPayloadOutputAddresses(payload interface{}) []string
}

Once this is done, the library code can then construct an instance of the general library like so:

import (
    "gitee.com/pantazheng/sawtooth-client-sdk-go"
    "gitee.com/pantazheng/sawtooth-client-sdk-go/transport"
)
        
type AppSpecificClient struct {
    *sawtooth-client-sdk-go.SawtoothClient
}

// Assume that this type implements the SawtoothClientImpl interface
type AppSpecificClientImpl struct {}

func NewClient(url string, keyFile string) (*AppSpecificClient, error) {
    args := &sawtooth_client_sdk_go.SawtoothClientArgs{
        URL: url,
        KeyFile: keyFile,
        TransportType: transport.TRANSPORT_REST,
        Impl: &AppSpecificClientImpl{},
    }

    sawtoothClient, err := sawtooth_client_sdk_go.NewClient(args)
    if err != nil {
        return nil, err
    }

    appSpecificClient := &AppSpecificClientImpl{
        SawtoothClient: sawtoothClient,
    }

    return appSpecificClient, nil
}

At this point, the basic structure of the client is in place. Application-specific logic and functionality can be implemented using the functions that the general library provides for executing transactions and queries.

Documentation

Overview

Package sawtooth_client_sdk_go provides an easy-to-use SDK for building Sawtooth client libraries.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Hexdigest

func Hexdigest(str string) string

Hexdigest computes the SHA256 hash of a byte array and returns it as a string.

func HexdigestByte

func HexdigestByte(data []byte) string

HexdigestByte computes the SHA256 hash of a byte array and returns it as a byte array.

Types

type SawtoothClient

type SawtoothClient struct {
	Signer     *signing.Signer
	Transport  transport.SawtoothClientTransport
	ClientImpl SawtoothClientImpl
}

SawtoothClient represents the core functionality of a Sawtooth application client.

func NewClient

func NewClient(args *SawtoothClientArgs) (*SawtoothClient, error)

NewClient constructs a new instance of the SawtoothClient.

func (*SawtoothClient) CreateBatch

func (self *SawtoothClient) CreateBatch(transactions []*transaction_pb2.Transaction) (*batch_pb2.Batch, error)

CreateBatch constructs a batch from a list of payloads.

func (*SawtoothClient) CreateBatchList

func (self *SawtoothClient) CreateBatchList(batches []*batch_pb2.Batch) (*batch_pb2.BatchList, error)

CreateBatchList constructs a batch list from one or more batches.

func (*SawtoothClient) CreateTransaction

func (self *SawtoothClient) CreateTransaction(payload interface{}) (*transaction_pb2.Transaction, error)

CreateTransaction constructs a single transaction from the provided payload.

func (*SawtoothClient) ExecutePayload

func (self *SawtoothClient) ExecutePayload(payload interface{}) (string, error)

ExecutePayload submits a single transaction to the blockchain and returns the batch id.

func (*SawtoothClient) ExecutePayloadBatch

func (self *SawtoothClient) ExecutePayloadBatch(payloads []interface{}) (string, error)

ExecutePayload submits a list of transactions to the blockchain (as a single batch) and returns the batch id.

func (*SawtoothClient) ExecutePayloadBatchSync

func (self *SawtoothClient) ExecutePayloadBatchSync(payloads []interface{}, timeout int, pollInterval int) error

ExecutePayload submits a list of transactions to the blockchain (as a single batch) and waits for commit.

func (*SawtoothClient) ExecutePayloadSync

func (self *SawtoothClient) ExecutePayloadSync(payload interface{}, timeout int, pollInterval int) error

ExecutePayloadSync submits a single transaction to the blockchain and waits for commit.

func (*SawtoothClient) WaitBatch

func (self *SawtoothClient) WaitBatch(batchId string, timeout int, pollInterval int) (bool, error)

WaitBatch performs a polling wait for a particular batch.

type SawtoothClientArgs

type SawtoothClientArgs struct {
	URL           string
	KeyFile       string
	Impl          SawtoothClientImpl
	TransportType transport.SawtoothClientTransportType
}

SawtoothClientArgs holds arguments required to initialize SawtoothClient.

type SawtoothClientImpl

type SawtoothClientImpl interface {
	GetFamilyName() string
	GetFamilyVersion() string

	EncodePayload(interface{}) ([]byte, error)
	DecodePayload([]byte, interface{}) error

	EncodeData(interface{}) ([]byte, error)
	DecodeData([]byte, interface{}) error

	GetPayloadInputAddresses(payload interface{}) []string
	GetPayloadOutputAddresses(payload interface{}) []string
}

SawtoothClientImpl is the interface that must be implemented by each user of the library.

Directories

Path Synopsis
Package examples provides examples of clients implemented with sawtooth-client-sdk-go.
Package examples provides examples of clients implemented with sawtooth-client-sdk-go.
intkey
Package intkey provides an alternative intkey client implementation using sawtooth-client-sdk-go.
Package intkey provides an alternative intkey client implementation using sawtooth-client-sdk-go.
intkey/cli
intkey_cli is an alternative cli implementation for intkey that uses the example client implemented with sawtooth-client-sdk-go.
intkey_cli is an alternative cli implementation for intkey that uses the example client implemented with sawtooth-client-sdk-go.
Package transport provides a generalized interface called SawtoothClientTransport.
Package transport provides a generalized interface called SawtoothClientTransport.
errors
Package error provides a generalized error interface for transport implementations.
Package error provides a generalized error interface for transport implementations.
rest
Package rest provides a SawtoothClientTransport implementation for the Sawtooth REST API.
Package rest provides a SawtoothClientTransport implementation for the Sawtooth REST API.
types
Package types provides generalized types that are used across the transport interface.
Package types provides generalized types that are used across the transport interface.
zmq
Package zmq provides a SawtoothClientTransport implementation for the Sawtooth validator ZMQ interface.
Package zmq provides a SawtoothClientTransport implementation for the Sawtooth validator ZMQ interface.

Jump to

Keyboard shortcuts

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