hivego

package module
v0.0.0-...-22b3995 Latest Latest
Warning

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

Go to latest
Published: Dec 7, 2024 License: MIT Imports: 17 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

HiveGo - A client for the Hive blockchain

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

Example usage:

create a client:

hrpc := hivego.NewHiveRpc("https://api.myHiveBlockchainNode.com")

submit a custom json tx:

txid, err := hrpc.BroadcastJson([]string{submittingAccount}, []string{}, id, string(jsonPayload), &activeWif)

vote a post:

txid, err := hrpc.VotePost(voter, author, permlink, weight, &wif)

get n blocks starting from block x as the raw response from the rpc (in bytes):

responseBytes, err := hrpc.GetBlockRangeFast(startBlock int, count int)

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

View Source
var OperationType = operationTypes{
	Vote:                        "vote_operation",
	Comment:                     "comment_operation",
	Transfer:                    "transfer_operation",
	TransferToVesting:           "transfer_to_vesting_operation",
	WithdrawVesting:             "withdraw_vesting_operation",
	LimitOrderCreate:            "limit_order_create_operation",
	LimitOrderCancel:            "limit_order_cancel_operation",
	FeedPublish:                 "feed_publish_operation",
	Convert:                     "convert_operation",
	AccountCreate:               "account_create_operation",
	AccountUpdate:               "account_update_operation",
	WitnessUpdate:               "witness_update_operation",
	AccountWitnessVote:          "account_witness_vote_operation",
	AccountWitnessProxy:         "account_witness_proxy_operation",
	Pow:                         "pow_operation",
	Custom:                      "custom_operation",
	ReportOverProduction:        "report_over_production_operation",
	DeleteComment:               "delete_comment_operation",
	CustomJson:                  "custom_json_operation",
	CommentOptions:              "comment_options_operation",
	SetWithdrawVestingRoute:     "set_withdraw_vesting_route_operation",
	LimitOrderCreate2:           "limit_order_create2_operation",
	ClaimAccount:                "claim_account_operation",
	CreateClaimedAccount:        "create_claimed_account_operation",
	RequestAccountRecovery:      "request_account_recovery_operation",
	RecoverAccount:              "recover_account_operation",
	ChangeRecoveryAccount:       "change_recovery_account_operation",
	EscrowTransfer:              "escrow_transfer_operation",
	EscrowDispute:               "escrow_dispute_operation",
	EscrowRelease:               "escrow_release_operation",
	Pow2:                        "pow2_operation",
	EscrowApprove:               "escrow_approve_operation",
	TransferToSavings:           "transfer_to_savings_operation",
	TransferFromSavings:         "transfer_from_savings_operation",
	CancelTransferFromSavings:   "cancel_transfer_from_savings_operation",
	CustomBinary:                "custom_binary_operation",
	DeclineVotingRights:         "decline_voting_rights_operation",
	ResetAccount:                "reset_account_operation",
	SetResetAccount:             "set_reset_account_operation",
	ClaimRewardBalance:          "claim_reward_balance_operation",
	DelegateVestingShares:       "delegate_vesting_shares_operation",
	AccountCreateWithDelegation: "account_create_with_delegation_operation",
	WitnessSetProperties:        "witness_set_properties_operation",
	AccountUpdate2:              "account_update2_operation",
	CreateProposal:              "create_proposal_operation",
	UpdateProposalVotes:         "update_proposal_votes_operation",
	RemoveProposal:              "remove_proposal_operation",
	UpdateProposal:              "update_proposal_operation",
	CollateralizedConvert:       "collateralized_convert_operation",
	RecurrentTransfer:           "recurrent_transfer_operation",
}
View Source
var PublicKeyPrefix = "STM"

Functions

func DecodePublicKey

func DecodePublicKey(pubKey string) (*secp256k1.PublicKey, error)

Decodes a base58 Hive public key to secp256k1 public key

func GetPublicKeyString

func GetPublicKeyString(pubKey *secp256k1.PublicKey) *string

func GphBase58CheckDecode

func GphBase58CheckDecode(input string) ([]byte, [1]byte, error)

func SignDigest

func SignDigest(digest []byte, wif *string) ([]byte, error)

func WriteUvarint

func WriteUvarint(w io.Writer, x uint64) error

todo: UNTESTED encodes a uint64 into a variable-length byte slice and writes it to w

func WriteVarint

func WriteVarint(w io.Writer, x int64) error

todo: UNTESTED encodes an int64 into a variable-length byte slice and writes it to w

Types

type AccountData

type AccountData struct {
	ID                            int64         `json:"id"`
	Name                          string        `json:"name"`
	Owner                         Authority     `json:"owner"`
	Active                        Authority     `json:"active"`
	Posting                       Authority     `json:"posting"`
	MemoKey                       string        `json:"memo_key"`
	JSONMetadata                  string        `json:"json_metadata"`
	Proxy                         string        `json:"proxy"`
	LastOwnerUpdate               CustomTime    `json:"last_owner_update"`
	LastAccountUpdate             CustomTime    `json:"last_account_update"`
	Created                       CustomTime    `json:"created"`
	Mined                         bool          `json:"mined"`
	RecoveryAccount               string        `json:"recovery_account"`
	LastAccountRecovery           CustomTime    `json:"last_account_recovery"`
	CommentCount                  int32         `json:"comment_count"`
	LifetimeVoteCount             int32         `json:"lifetime_vote_count"`
	PostCount                     int32         `json:"post_count"`
	CanVote                       bool          `json:"can_vote"`
	VotingPower                   int16         `json:"voting_power"`
	LastVoteTime                  CustomTime    `json:"last_vote_time"`
	Balance                       string        `json:"balance"`
	SavingsBalance                string        `json:"savings_balance"`
	HbdBalance                    string        `json:"hbd_balance"`
	HbdSeconds                    string        `json:"hbd_seconds"`
	HbdSecondsLastUpdate          CustomTime    `json:"hbd_seconds_last_update"`
	HbdLastInterestPayment        CustomTime    `json:"hbd_last_interest_payment"`
	SavingsHbdBalance             string        `json:"savings_hbd_balance"`
	SavingsHbdSeconds             string        `json:"savings_hbd_seconds"`
	SavingsHbdLastUpdate          CustomTime    `json:"savings_hbd_last_update"`
	SavingsHbdLastInterestPayment CustomTime    `json:"savings_hbd_last_interest_payment"`
	SavingsWithdrawRequests       int32         `json:"savings_withdraw_requests"`
	RewardHbdBalance              string        `json:"reward_hbd_balance"`
	RewardHiveBalance             string        `json:"reward_hive_balance"`
	RewardVestingBalance          string        `json:"reward_vesting_balance"`
	RewardVestingHive             string        `json:"reward_vesting_hive"`
	VestingShares                 string        `json:"vesting_shares"`
	DelegatedVestingShares        string        `json:"delegated_vesting_shares"`
	ReceivedVestingShares         string        `json:"received_vesting_shares"`
	VestingWithdrawRate           string        `json:"vesting_withdraw_rate"`
	NextVestingWithdrawal         CustomTime    `json:"next_vesting_withdrawal"`
	Withdrawn                     int64         `json:"withdrawn"`
	ToWithdraw                    int64         `json:"to_withdraw"`
	WithdrawRoutes                int32         `json:"withdraw_routes"`
	CurationRewards               int64         `json:"curation_rewards"`
	PostingRewards                int64         `json:"posting_rewards"`
	ProxiedVsfVotes               []int64       `json:"proxied_vsf_votes"`
	WitnessesVotedFor             int32         `json:"witnesses_voted_for"`
	LastPost                      CustomTime    `json:"last_post"`
	LastRootPost                  CustomTime    `json:"last_root_post"`
	AverageBandwidth              string        `json:"average_bandwidth"`
	LifetimeBandwidth             string        `json:"lifetime_bandwidth"`
	LastBandwidthUpdate           CustomTime    `json:"last_bandwidth_update"`
	PostVotingPower               string        `json:"post_voting_power"`
	Reputation                    int64         `json:"reputation"`
	PostBandwidth                 int64         `json:"post_bandwidth"`
	PendingClaimedAccounts        int32         `json:"pending_claimed_accounts"`
	PendingTransfers              int32         `json:"pending_transfers"`
	PreviousOwnerUpdate           CustomTime    `json:"previous_owner_update"`
	TransferHistory               []interface{} `json:"transfer_history"`
	MarketHistory                 []interface{} `json:"market_history"`
	PostHistory                   []interface{} `json:"post_history"`
	VoteHistory                   []interface{} `json:"vote_history"`
	OtherHistory                  []interface{} `json:"other_history"`
	WitnessVotes                  []string      `json:"witness_votes"`
	TagsUsage                     []interface{} `json:"tags_usage"`
	GuestBloggers                 []interface{} `json:"guest_bloggers"`
	DelayedVotes                  []interface{} `json:"delayed_votes"`
	VotingManabar                 RC            `json:"voting_manabar"`
	DownvoteManabar               RC            `json:"downvote_manabar"`
	GovernanceVoteExpirationTs    CustomTime    `json:"governance_vote_expiration_ts"`
	PostingJSONMetadata           string        `json:"posting_json_metadata"`
}

type Authority

type Authority struct {
	AccountAuths    [][]interface{} `json:"account_auths"`
	KeyAuths        [][]interface{} `json:"key_auths"`
	WeightThreshold int             `json:"weight_threshold"`
}

type Auths

type Auths struct {
	WeightThreshold int              `json:"weight_threshold"`
	AccountAuths    [][2]interface{} `json:"account_auths"` // tuple (string, int)
	KeyAuths        [][2]interface{} `json:"key_auths"`     // tuple (string, int)
}

type Block

type Block struct {
	BlockNumber           int
	BlockID               string        `json:"block_id"`
	Previous              string        `json:"previous"`
	Timestamp             string        `json:"timestamp"`
	Witness               string        `json:"witness"`
	TransactionMerkleRoot string        `json:"transaction_merkle_root"`
	Transactions          []Transaction `json:"transactions"`
	Extensions            []interface{} `json:"extensions"`
	SigningKey            string        `json:"signing_key"`
	TransactionIds        []string      `json:"transaction_ids"`
	WitnessSignature      string        `json:"witness_signature"`
}

type CustomTime

type CustomTime time.Time

func (CustomTime) ToTime

func (ct CustomTime) ToTime() time.Time

func (*CustomTime) UnmarshalJSON

func (ct *CustomTime) UnmarshalJSON(b []byte) error

type HiveOperation

type HiveOperation interface {
	SerializeOp() ([]byte, error)
	OpName() string
}

type HiveRpcNode

type HiveRpcNode struct {
	MaxConn     int
	MaxBatch    int
	NoBroadcast bool
	// contains filtered or unexported fields
}

func NewHiveRpc

func NewHiveRpc(addr string) *HiveRpcNode

func NewHiveRpcWithOpts

func NewHiveRpcWithOpts(addr string, maxConn int, maxBatch int) *HiveRpcNode

func (*HiveRpcNode) Broadcast

func (h *HiveRpcNode) Broadcast(ops []HiveOperation, wif *string) (string, error)

func (*HiveRpcNode) BroadcastJson

func (h *HiveRpcNode) BroadcastJson(reqAuth []string, reqPostAuth []string, id string, cj string, wif *string) (string, error)

func (*HiveRpcNode) ClaimRewards

func (h *HiveRpcNode) ClaimRewards(Account string, wif *string) (string, error)

func (*HiveRpcNode) GetAccount

func (h *HiveRpcNode) GetAccount(accountNames []string) ([]AccountData, error)

func (*HiveRpcNode) GetBlock

func (h *HiveRpcNode) GetBlock(blockNum int) (Block, error)

func (*HiveRpcNode) GetBlockRange

func (h *HiveRpcNode) GetBlockRange(startBlock int, count int) (<-chan Block, error)

func (*HiveRpcNode) GetDynamicGlobalProps

func (h *HiveRpcNode) GetDynamicGlobalProps() ([]byte, error)

func (*HiveRpcNode) GetTransaction

func (h *HiveRpcNode) GetTransaction(txId string, includeReversible bool) ([]byte, error)

func (*HiveRpcNode) StreamBlocks

func (h *HiveRpcNode) StreamBlocks() (<-chan Block, error)

func (*HiveRpcNode) Transfer

func (h *HiveRpcNode) Transfer(from string, to string, amount string, memo string, wif *string) (string, error)

func (*HiveRpcNode) UpdateAccount

func (h *HiveRpcNode) UpdateAccount(
	account string,
	owner *Auths,
	active *Auths,
	posting *Auths,
	jsonMetadata string,
	memoKey string,
	wif *string,
) (string, error)

func (*HiveRpcNode) VotePost

func (h *HiveRpcNode) VotePost(voter string, author string, permlink string, weight int, wif *string) (string, error)

type KeyPair

type KeyPair struct {
	PrivateKey *secp256k1.PrivateKey
	PublicKey  *secp256k1.PublicKey
}

func KeyPairFromWif

func KeyPairFromWif(wif string) (*KeyPair, error)

Gets a KeyPair from a given WIF String

func (*KeyPair) GetPublicKeyString

func (kp *KeyPair) GetPublicKeyString() *string

type Operation

type Operation struct {
	Type  string                 `json:"type"`
	Value map[string]interface{} `json:"value"`
}

type RC

type RC struct {
	CurrentMana    int64 `json:"current_mana"`
	LastUpdateTime int64 `json:"last_update_time"`
}

type Transaction

type Transaction struct {
	Expiration           string        `json:"expiration"`
	Extensions           []interface{} `json:"extensions"`
	Operations           []Operation   `json:"operations"`
	RefBlockNum          uint16        `json:"ref_block_num"`
	RefBlockPrefix       uint32        `json:"ref_block_prefix"`
	Signatures           []string      `json:"signatures"`
	RequiredAuths        []string      `json:"required_auths,omitempty"`
	RequiredPostingAuths []string      `json:"required_posting_auths,omitempty"`
}

type TransactionQueryParams

type TransactionQueryParams struct {
	TransactionId     string `json:"id"`
	IncludeReversible bool   `json:"include_reversible"`
}

Jump to

Keyboard shortcuts

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