client

package module
v0.0.0-...-f1492f4 Latest Latest
Warning

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

Go to latest
Published: Mar 18, 2021 License: MIT Imports: 11 Imported by: 0

README

hiverpc-go

Experimental HIVE RPC Interface in GO

asuleymanov/hive-go

GoDoc Go Report Card

Golang RPC client library for Hive.

Usage

import "github.com/KLYE-Dev/hiverpc-go"

Example

This is just a code snippet. Please check the examples directory for more complete and ready to use examples.

	cls,_ := client.NewClient([]string{"ws://localhost:8090"},"hive")
	defer cls.Close()

	// Get config.
	log.Println("---> GetConfig()")
	config, err := cls.Database.GetConfig()
	if err != nil {
		return err
	}

	// Use the last irreversible block number as the initial last block number.
	props, err := cls.Database.GetDynamicGlobalProperties()
	if err != nil {
		return err
	}
	lastBlock := props.LastIrreversibleBlockNum

	// Keep processing incoming blocks forever.
	log.Printf("---> Entering the block processing loop (last block = %v)\n", lastBlock)
	for {
		// Get current properties.
		props, err := cls.Database.GetDynamicGlobalProperties()
		if err != nil {
			return err
		}

		// Process new blocks.
		for props.LastIrreversibleBlockNum-lastBlock > 0 {
			block, err := cls.Database.GetBlock(lastBlock)
			if err != nil {
				return err
			}

			// Process the transactions.
			for _, tx := range block.Transactions {
				for _, operation := range tx.Operations {
					switch op := operation.Data().(type) {
					case *types.VoteOperation:
						log.Printf("@%v voted for @%v/%v\n", op.Voter, op.Author, op.Permlink)

						// You can add more cases here, it depends on
						// what operations you actually need to process.
					}
				}
			}

			lastBlock++
		}

		// Sleep for HIVEIT_BLOCK_INTERVAL seconds before the next iteration.
		time.Sleep(time.Duration(config.BlockInterval) * time.Second)
	}

Package Organisation

You need to create a Client object to be able to do anything. Then you just need to call NewClient().

Once you create a Client object, you can start calling the methods exported via hived's RPC endpoint by invoking associated methods on the client object. There are multiple APIs that can be exported, e.g. database_api and login_api, so the methods on the Client object are also namespaced accoding to these APIs. For example, to call get_block from database_api, you need to use Client.Database.GetBlock method.

When looking for a method to call, all you need is to turn the method name into CamelCase, e.g. get_config becomes Client.Database.GetConfig.

Status

This package is still under rapid development and it is by no means complete. For now there is no promise considering API stability. Some response objects maybe be typed incorrectly. The package is already usable, though. See the examples directory.

To check the API coverate, please check the README files in the relevat API package in the apis subdirectory.

License

MIT, see the LICENSE file.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInitializeTransport = errors.New("Failed to initialize transport.")
)
View Source
var (
	//OpTypeKey include a description of the operation and the key needed to sign it
	OpTypeKey = make(map[types.OpType][]string)
)

Functions

func JSONOpString

func JSONOpString(v []types.Operation) (string, error)

JSONOpString generate Operations to String

func JSONTrxString

func JSONTrxString(v *transactions.SignedTransaction) (string, error)

JSONTrxString generate Trx to String

func SetAsset

func SetAsset(amount float64, symbol string) *types.Asset

SetAsset returns data of type Asset

Types

type BResp

type BResp struct {
	ID       string
	BlockNum int32
	TrxNum   int32
	Expired  bool
	JSONTrx  string
}

BResp of response when sending a transaction.

type Client

type Client struct {
	AsyncProtocol bool

	// Database represents database_api.
	API *api.API

	// Current keys for operations
	CurrentKeys *Keys
	// contains filtered or unexported fields
}

Client can be used to access HIVE remote APIs. There is a public field for every HIVE API available, e.g. Client.Database corresponds to database_api.

func NewClient

func NewClient(s string) (*Client, error)

NewClient creates a new RPC client that use the given CallCloser internally. Initialize only server present API. Absent API initialized as nil value.

func (*Client) Close

func (client *Client) Close() error

Close should be used to close the client when no longer needed. It simply calls Close() on the underlying CallCloser.

func (*Client) GetTrx

func (client *Client) GetTrx(strx []types.Operation) (*types.Transaction, error)

func (*Client) PerMvest

func (client *Client) PerMvest() (float64, error)

PerMvest returns the ratio of TotalVersingFund to TotalVestingShares.

func (*Client) SendTrx

func (client *Client) SendTrx(username string, strx []types.Operation) (*BResp, error)

SendTrx generates and sends an array of transactions to HIVE.

func (*Client) SetKeys

func (client *Client) SetKeys(keys *Keys)

SetKeys you can specify keys for signing transactions.

func (*Client) SigningKeys

func (client *Client) SigningKeys(trx types.Operation) ([][]byte, error)

SigningKeys returns the key from the CurrentKeys

type Keys

type Keys struct {
	PKey []string
	AKey []string
	OKey []string
	MKey []string
}

Keys is used as a keystroke for a specific user. Only a few keys can be set.

Directories

Path Synopsis
encoding
wif
rfc6979
Package rfc6979 is an implementation of RFC 6979's deterministic DSA.
Package rfc6979 is an implementation of RFC 6979's deterministic DSA.

Jump to

Keyboard shortcuts

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