hiveenginego

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 16, 2024 License: MIT Imports: 7 Imported by: 1

README

HiveEngineGo - A client for the Hive Engine side chain on the Hive blockchain

This fork will be adding more functionality as it seems like the upstream repo might be abandoned. New functions will be added to the bottom, but above the warning.

At this time, there are only a few functions from the client. More will be added.

Example usage:

create a client:

herpc := hiveenginego.NewHiveEngineRpc("http://MyHiveEngineApi")

Query latest block info:

latestBlockInfo, err := herpc.GetLatestBlockInfo()
//Returns a struct
latestBlockNum := latestBlockInfo.BlockNumber

Get All NFT of a given symbol (return rpc resonse as raw bytes):

rawNftBytes, err := herpc.GetSymbolAllNftFast("STAR")

Get block range as the raw response from the rpc (in bytes):

rpcResponsesBytes, err := herpc.GetBlockRangeFast(start, end)

Get an account's balances for a token:

balances, err :=  herpc.GetBalances("BEE", "alice", 10, 0)
// Numbers above are limit and offset, string arguments are case insensitive
// Returns a struct
stake := balances.Stake
balance := balances.Balance
etc.

Get buy/sell books for a token:

book, err :=  herpc.GetBook("buy", "BEE", 10, 0)
// Numbers above are limit and offset, string arguments are case insensitive.
// Returns a struct: book is still an array/slice
buyBook := book.Book
firstPrice := buyBook[0].Price

Get account's open orders for a token for a token:

orders, err :=  herpc.GetAccountOrders("BEE", "Alice", 10, 0)
// Numbers above are limit and offset, string arguments are case insensitive.
// Returns a struct of each book struct (still returned as a slice)
buyOrders := orders.Buy
firstPrice := buyOrders.Book[0].Price

Get trade history for a token:

history, err :=  herpc.GetHistory("BEE", 10, 0)
// Numbers above are limit and offset, string arguments are case insensitive.
// Returns a struct of an array of records
log := history.Log
firstRecord := log[0]
firstRecordTimestamp := log[0].Timestamp

Get metrics for a token:

metrics, err :=  herpc.GetMetrics("BEE", 10, 0)
// Numbers above are limit and offset, string arguments are case insensitive.
// Returns an array of a struct - Metrics returns as an array because of the query method it uses.
highest := (*response)[0].HighestBid

WARNING: It is not recommended to stream blocks from public APIs. They are provided as a service to users and saturating them with block requests may (rightfully) result in your IP getting banned

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Balances

type Balances struct {
	Account              string `json:"account"`
	Symbol               string `json:"symbol"`
	Balance              string `json:"balance"`
	Stake                string `json:"stake"`
	PendingUnstake       string `json:"pendingUnstake"`
	DelegationsIn        string `json:"delegationsIn"`
	DelegationsOut       string `json:"delegationsOut"`
	PendingUndelegations string `json:"pendingUndelegations"`
	// contains filtered or unexported fields
}

type BroadcastTx

type BroadcastTx struct {
}

type ContractQueryParams

type ContractQueryParams struct {
	Contract string                     `json:"contract"`
	Table    string                     `json:"table"`
	Query    interface{}                `json:"query"`
	Limit    int                        `json:"limit"`
	Offset   int                        `json:"offset"`
	Index    []ContractQueryParamsIndex `json:"indexes"`
}

type ContractQueryParamsIndex

type ContractQueryParamsIndex struct {
	Index      string `json:"index,omitempty"`
	Descending bool   `json:"descending"`
}

type ContractQueryParamsQuery

type ContractQueryParamsQuery struct {
	Account string `json:"account,omitempty"`
	NftId   string `json:"_id,omitempty"`
}

type ContractTx

type ContractTx struct {
	ContractName    string      `json:"contractName"`
	ContractAction  string      `json:"contractAction"`
	ContractPayload interface{} `json:"contractPayload"`
}

func CreateFungibleTokenTransfer

func CreateFungibleTokenTransfer(symbol string, to string, quantity string, memo string) ContractTx

func CreateNftTransfer

func CreateNftTransfer(symbol string, nftIds []int, to string, memo string) []ContractTx

type EngineBlock

type EngineBlock struct {
	BlockNumber         int             `json:"blockNumber"`
	RefHiveBlockNumber  int             `json:"refHiveBlockNumber"`
	Timestamp           string          `json:"timestamp"`
	Transactions        json.RawMessage `json:"transactions"`
	VirtualTransactions json.RawMessage `json:"virtualTransactions,omitempty"`
	Hash                string          `json:"hash"`
	DatabaseHash        string          `json:"databasehash"`
	MerkleRoot          string          `json:"merkleRoot"`
	Round               int             `json:"round"`
	RoundHash           string          `json:"roundHash"`
	Witness             string          `json:"witness"`
	SigningKey          string          `json:"signingKey"`
	RoundSignature      string          `json:"roundSignature"`
}

type EngineNft

type EngineNft struct {
	Id              int             `json:"_id"`
	Account         string          `json:"account"`
	OwnedBy         string          `json:"ownedBy"`
	LockedTokens    json.RawMessage `json:"lockedTokens"`
	Properties      json.RawMessage `json:"properties"`
	PreviousAccount string          `json:"previousAccount"`
	PreviousOwnedBy string          `json:"previousOwnedBy"`
}

type EngineStatus

type EngineStatus struct {
	LastBlockNumber             int    `json:"lastBlockNumber"`
	LastBlockRefHiveBlockNumber int    `json:"lastBlockRefHiveBlockNumber"`
	LastParsedHiveBlockNumber   int    `json:"lastParsedHiveBlockNumber"`
	LastVerifiedBlockNumber     int    `json:"lastVerifiedBlockNumber"`
	SSCnodeVersion              string `json:"SSCnodeVersion"`
	ChainId                     string `json:"chainId"`
	Domain                      string `json:"domain"`
	Lightnode                   bool   `json:"lightnode"`
	LastHash                    string `json:"lastHash"`
}

type FungibleBalance

type FungibleBalance struct {
	Id                   int    `json:"_id"`
	Account              string `json:"account"`
	Symbol               string `json:"symbol"`
	Balance              string `json:"balance"`
	Stake                string `json:"stake"`
	PendingUnstake       string `json:"pendingUnstake"`
	DelegationsIn        string `json:"delegationsIn"`
	DelegationsOut       string `json:"delegationsOut"`
	PendingUndelegations string `json:"pendingUndelegations"`
}

type FungibleTokenTransfer

type FungibleTokenTransfer struct {
	Symbol   string `json:"symbol"`
	To       string `json:"to"`
	Quantity string `json:"quantity"`
	Memo     string `json:"memo"`
}

type History

type History struct {
	Log []Record
}

type HiveEngineFungibleToken

type HiveEngineFungibleToken struct {
	FungibleId           int             `json:"_id"`
	Issuer               string          `json:"issuer"`
	Symbol               string          `json:"symbol"`
	Name                 string          `json:"name"`
	MetaData             json.RawMessage `json:"metadata"`
	DelegationEnabled    bool            `json:"delegationEnabled"`
	Precision            int             `json:"precision"`
	StakingEnabled       bool            `json:"stakingEnabled"`
	UndelegationCooldown int             `json:"undelegationCooldown"`
	UnstakingCooldown    int             `json:"unstakingCooldown"`
}

type HiveEngineRpcNode

type HiveEngineRpcNode struct {
	Endpoints engineApiEndpoints
	RpcNode   rpcServer
}

func NewHiveEngineRpc

func NewHiveEngineRpc(addr string) *HiveEngineRpcNode

func NewHiveEngineRpcWithOpts

func NewHiveEngineRpcWithOpts(addr string, blockchain string, contracts string, maxConn int, maxBatch int) *HiveEngineRpcNode

func (HiveEngineRpcNode) GetAccountOrders

func (h HiveEngineRpcNode) GetAccountOrders(token, account string, limit, offset int) (*PersonalOrders, error)

func (HiveEngineRpcNode) GetAllFungibleTokens

func (h HiveEngineRpcNode) GetAllFungibleTokens() ([]HiveEngineFungibleToken, error)

func (HiveEngineRpcNode) GetAllWitnesses

func (h HiveEngineRpcNode) GetAllWitnesses() ([]Witness, error)

func (HiveEngineRpcNode) GetBalances

func (h HiveEngineRpcNode) GetBalances(token, account string, limit, offset int) (*Balances, error)

func (HiveEngineRpcNode) GetBlockRange

func (h HiveEngineRpcNode) GetBlockRange(startBlock int, endBlock int) ([][]byte, error)

func (HiveEngineRpcNode) GetBlockRangeFast

func (h HiveEngineRpcNode) GetBlockRangeFast(startBlock int, endBlock int) ([][]byte, error)

func (HiveEngineRpcNode) GetBook

func (h HiveEngineRpcNode) GetBook(bookType, token string, limit, offset int) (*OrderBook, error)

func (HiveEngineRpcNode) GetHistory

func (h HiveEngineRpcNode) GetHistory(token string, limit, offset int) (*History, error)

func (HiveEngineRpcNode) GetLatestBlockInfo

func (h HiveEngineRpcNode) GetLatestBlockInfo() (*EngineBlock, error)

func (HiveEngineRpcNode) GetMetrics

func (h HiveEngineRpcNode) GetMetrics(token string, limit, offset int) (*Metrics, error)

func (HiveEngineRpcNode) GetStatus

func (h HiveEngineRpcNode) GetStatus() (*EngineStatus, error)

func (HiveEngineRpcNode) GetSymbolAllNft

func (h HiveEngineRpcNode) GetSymbolAllNft(nftSymbol string) ([]EngineNft, error)

func (HiveEngineRpcNode) GetSymbolAllNftFast

func (h HiveEngineRpcNode) GetSymbolAllNftFast(nftSymbol string) ([][]byte, error)

func (HiveEngineRpcNode) GetSymbolAllNftMarket

func (h HiveEngineRpcNode) GetSymbolAllNftMarket(nftSymbol string, chunkSize int) ([]NftMarketOffer, error)

func (HiveEngineRpcNode) QueryContract

func (h HiveEngineRpcNode) QueryContract(qParams ContractQueryParams) ([]byte, error)

func (HiveEngineRpcNode) QueryContractBatch

func (h HiveEngineRpcNode) QueryContractBatch(qParams []ContractQueryParams) ([][]byte, error)

func (HiveEngineRpcNode) QueryContractByAcc

func (h HiveEngineRpcNode) QueryContractByAcc(qParams ContractQueryParams) ([]byte, error)

func (HiveEngineRpcNode) QueryContractByAccBatch

func (h HiveEngineRpcNode) QueryContractByAccBatch(qParams []ContractQueryParams) ([][]byte, error)

type Metrics

type Metrics struct {
	Symbol                 string  `json:"symbol"`
	Volume                 float64 `json:",string"`
	VolumeExpiration       int     `json:"volumeExpiration"`
	LastPrice              float64 `json:",string"`
	LowestAsk              float64 `json:",string"`
	HighestBid             float64 `json:",string"`
	LastDayPrice           float64 `json:",string"`
	LastDayPriceExpiration int     `json:"lastDayPruceExpiration"`
	PriceChangeHive        float64 `json:",string"`
	PriceChangePercent     string  `json:"priceChangePercent"`
	// contains filtered or unexported fields
}

type NftMarketOffer

type NftMarketOffer struct {
	Id          int             `json:"_id"`
	Account     string          `json:"account"`
	OwnedBy     string          `json:"ownedBy"`
	NftId       string          `json:"nftId"`
	Grouping    json.RawMessage `json:"grouping"`
	Timestamp   int             `json:"timestamp"`
	Price       string          `json:"price"`
	PriceDec    json.RawMessage `json:"priceDec"`
	PriceSymbol string          `json:"priceSymbol"`
	Fee         int             `json:"fee"`
}

type NftTransferPayload

type NftTransferPayload struct {
	Nfts []NftsForNftTransfer `json:"nfts"`
	To   string               `json:"to"`
	Memo string               `json:"memo,omitempty"`
}

type NftsForNftTransfer

type NftsForNftTransfer struct {
	Symbol string   `json:"symbol"`
	Ids    []string `json:"ids"`
}

type Order

type Order struct {
	TxId         string      `json:"txId"`
	Timestamp    int         `json:"timestamp"`
	Account      string      `json:"account"`
	Symbol       string      `json:"symbol"`
	Quantity     float64     `json:",string"`
	Price        float64     `json:",string"`
	PriceDec     interface{} `json:"priceDec"`
	TokensLocked float64     `json:",string, omitempty"`
	Expiration   int         `json:"expiration"`
	// contains filtered or unexported fields
}

type OrderBook

type OrderBook struct {
	Book []Order `json:""`
}

type PersonalOrders

type PersonalOrders struct {
	Buy  OrderBook
	Sell OrderBook
}

type QueryIDRange

type QueryIDRange struct {
	Id QueryIntRange `json:"_id"`
}

type QueryIntRange

type QueryIntRange struct {
	GreaterThanEqual int `json:"$gte,omitempty"`
	LessThanEqual    int `json:"$lte,omitempty"`
}

type Record

type Record struct {
	Type      string  `json:"type"`
	Buyer     string  `json:"buyer"`
	Seller    string  `json:"seller"`
	Symbol    string  `json:"symbol"`
	Quantity  float64 `json:",string"`
	Price     float64 `json:",string"`
	Timestamp int     `json:"timestamp"`
	Volume    float64 `json:",string"`
	BuyTxId   string  `json:"buyTxId"`
	SellTxId  string  `json:"sellTxId"`
	// contains filtered or unexported fields
}

type Witness

type Witness struct {
	Id                 int             `json:"_id"`
	Account            string          `json:"account"`
	ApprovalWeight     json.RawMessage `json:"approvalWeight"`
	SigningKey         string          `json:"signingKey"`
	Ip                 string          `json:"ip"`
	IpVersion          int             `json:"ipVersion"`
	RPCPort            int             `json:"RPCPort"`
	P2PPort            int             `json:"P2PPort"`
	Enabled            bool            `json:"enabled"`
	MissedRounds       int             `json:"missedRounds"`
	MissedRoundsInARow int             `json:"missedRoundsInARow"`
	VerifiedRounds     int             `json:"verifiedRounds"`
	LastRoundVerified  int             `json:"lastRoundVerified"`
	LastBlockVerified  int             `json:"lastBlockVerified"`
}

Jump to

Keyboard shortcuts

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