rpc

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2016 License: MIT Imports: 7 Imported by: 0

README

go-steem/rpc

GoDoc

Golang RPC client library for Steem.

Compatibility

steemd 0.8.0

Usage

  1. import "github.com/go-steem/rpc"
  2. Use rpc.Dial to get the RPC client.
  3. PROFIT!

Example

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

// Instantiate a new client.
client, _ := rpc.Dial("ws://localhost:8090")
defer client.Close()

// Call "get_config".
config, _ := client.GetConfig()

// Start processing blocks.
lastBlock := 1800000
for {
	// Call "get_dynamic_global_properties".
	props, _ := client.GetDynamicGlobalProperties()

	for props.LastIrreversibleBlockNum-lastBlock > 0 {
		// Call "get_block".
		block, _ := client.GetBlock(lastBlock)

		// Process the transactions.
		for _, tx := range block.Transactions {
			for _, op := range tx.Operations {
				switch body := op.Body.(type) {
					// Comment operation.
					case *rpc.CommentOperation:
						content, _ := client.GetContent(body.Author, body.Permlink)
						fmt.Printf("COMMENT @%v %v\n", content.Author, content.URL)

					// Vote operation.
					case *rpc.VoteOperation:
						fmt.Printf("VOTE @%v @%v/%v\n", body.Voter, body.Author, body.Permlink)

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

		lastBlock++
	}

	time.Sleep(time.Duration(config.SteemitBlockInterval) * time.Second)
}

Package Organisation

Once you create a Client object, you can start calling the methods exported via steemd's RPC endpoint by invoking associated methods on the client object. It is enough to just turn the method names into CamelCase, e.g. get_config becomes Client.GetConfig.

There are two methods implemented for the Client object for every method exported via the RPC endpoint. The regular version and the raw version. Let's see an example for get_config:

func (client *Client) GetConfig() (*Config, error) {
	...
}

func (client *Client) GetConfigRaw() (*json.RawMessage, error) {
	...
}

As we can see, the difference is that the raw version returns *json.RawMessage, so it is not trying to unmarshall the response into a properly typed response.

There are two reasons for this:

  1. To be able to see raw data.
  2. To be able to call most of the remote methods even though the response object is not yet known or specified.

It is already benefitial to just have the raw version because at least the method parameters are statically typed.

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.

The following subsections document the API completion. The method names are taken from database_api.hpp in steemit/steem.

TODO: Verify that these are actually the methods available over RPC :D

Subscriptions

TODO: Is this actually callable over the RPC endpoint? It is a bit confusing to see set_ prefix. Needs research.

   (set_subscribe_callback)
   (set_pending_transaction_callback)
   (set_block_applied_callback)
   (cancel_all_subscriptions)
Tags
Method Name Raw Version Full Version
get_trending_tags DONE
get_discussions_by_trending DONE
get_discussions_by_created DONE
get_discussions_by_active DONE
get_discussions_by_cashout DONE
get_discussions_by_payout DONE
get_discussions_by_votes DONE
get_discussions_by_children DONE
get_discussions_by_hot DONE
get_recommended_for DONE
Blocks and Transactions
Method Name Raw Version Full Version
get_block_header DONE
get_block DONE PARTIALLY DONE
get_state DONE
get_trending_categories DONE
get_best_categories DONE
get_active_categories DONE
get_recent_categories DONE
Globals
Method Name Raw Version Full Version
get_config DONE PARTIALLY DONE
get_dynamic_global_properties DONE DONE
get_chain_properties DONE
get_feed_history DONE
get_current_median_history_price DONE
get_witness_schedule DONE
get_hardfork_version DONE DONE
get_next_scheduled_hardfork DONE
Keys
Method Name Raw Version Full Version
get_key_reference
Accounts
Method Name Raw Version Full Version
get_accounts DONE
get_account_references
lookup_account_names DONE
lookup_accounts DONE
get_account_count DONE
get_conversation_requests DONE
get_account_history DONE
Market
Method Name Raw Version Full Version
get_order_book
get_open_orders
Authority / Validation
Method Name Raw Version Full Version
get_transaction_hex
get_transaction
get_required_signatures
get_potential_signatures
verify_authority
verity_account_authority
Votes
Method Name Raw Version Full Version
get_active_votes DONE
get_account_votes DONE
Cotent
Method Name Raw Version Full Version
get_content DONE PARTIALLY DONE
get_content_replies DONE PARTIALLY DONE
get_discussions_by_author_before_date
get_replies_by_last_update DONE
Witnesses
Method Name Raw Version Full Version
get_witnesses
get_witness_by_account
get_witnesses_by_vote
lookup_witness_accounts
get_witness_count
get_active_witnesses
get_miner_queue

License

MIT, see the LICENSE file.

Documentation

Index

Constants

View Source
const (
	OpTypeVote                 = "vote"
	OpTypeComment              = "comment"
	OpTypeTransfer             = "transfer"
	OpTypeTransferToVesting    = "transfer_to_vesting"
	OpTypeWithdrawVesting      = "withdraw_vesting"
	OpTypeLimitOrderCreate     = "limit_order_create"
	OpTypeLimitOrderCancel     = "limit_order_cancel"
	OpTypeFeedPublish          = "feed_publish"
	OpTypeConvert              = "convert"
	OpTypeAccountCreate        = "account_create"
	OpTypeAccountUpdate        = "account_update"
	OpTypeWitnessUpdate        = "witness_update"
	OpTypeAccountWitnessVote   = "account_witness_vote"
	OpTypeAccountWitnessProxy  = "account_witness_proxy"
	OpTypePow                  = "pow"
	OpTypeCustom               = "custom"
	OpTypeReportOverProduction = "report_over_production"
	OpTypeFullConvertRequest   = "fill_convert_request"
	OpTypeCommentReward        = "comment_reward"
	OpTypeCurateReward         = "curate_reward"
	OpTypeLiquidityReward      = "liquidity_reward"
	OpTypeInterest             = "interest"
	OpTypeFillVestingWithdraw  = "fill_vesting_withdraw"
	OpTypeFillOrder            = "fill_order"
)

Variables

This section is empty.

Functions

func AvailableTransports

func AvailableTransports() []string

func RegisterTransport

func RegisterTransport(scheme string, constructor TransportConstructor)

Types

type Block

type Block struct {
	Number                uint32          `json:"-"`
	Timestamp             *types.Time     `json:"timestamp"`
	Witness               string          `json:"witness"`
	WitnessSignature      string          `json:"witness_signature"`
	TransactionMerkleRoot string          `json:"transaction_merkle_root"`
	Previous              string          `json:"previous"`
	Extensions            [][]interface{} `json:"extensions"`
	Transactions          []*Transaction  `json:"transactions"`
}

type Client

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

func Dial

func Dial(address string) (*Client, error)

func (*Client) Close

func (client *Client) Close() error

func (*Client) GetAccountCountRaw

func (client *Client) GetAccountCountRaw() (*json.RawMessage, error)

func (*Client) GetAccountHistoryRaw

func (client *Client) GetAccountHistoryRaw(account string, from uint64, limit uint32) (*json.RawMessage, error)

func (*Client) GetAccountVotesRaw

func (client *Client) GetAccountVotesRaw(voter string) (*json.RawMessage, error)

func (*Client) GetAccountsRaw

func (client *Client) GetAccountsRaw(accountNames []string) (*json.RawMessage, error)

func (*Client) GetActiveCategoriesRaw

func (client *Client) GetActiveCategoriesRaw(after string, limit uint32) (*json.RawMessage, error)

func (*Client) GetActiveVotesRaw

func (client *Client) GetActiveVotesRaw(author, permlink string) (*json.RawMessage, error)

func (*Client) GetBestCategoriesRaw

func (client *Client) GetBestCategoriesRaw(after string, limit uint32) (*json.RawMessage, error)

func (*Client) GetBlock

func (client *Client) GetBlock(blockNum uint32) (*Block, error)

func (*Client) GetBlockHeaderRaw

func (client *Client) GetBlockHeaderRaw(blockNum uint32) (*json.RawMessage, error)

func (*Client) GetBlockRaw

func (client *Client) GetBlockRaw(blockNum uint32) (*json.RawMessage, error)

func (*Client) GetChainPropertiesRaw

func (client *Client) GetChainPropertiesRaw() (*json.RawMessage, error)

func (*Client) GetConfig

func (client *Client) GetConfig() (*Config, error)

func (*Client) GetConfigRaw

func (client *Client) GetConfigRaw() (*json.RawMessage, error)

func (*Client) GetContent

func (client *Client) GetContent(author, permlink string) (*Content, error)

func (*Client) GetContentRaw

func (client *Client) GetContentRaw(author, permlink string) (*json.RawMessage, error)

func (*Client) GetContentReplies

func (client *Client) GetContentReplies(parentAuthor, parentPermlink string) ([]*Content, error)

func (*Client) GetContentRepliesRaw

func (client *Client) GetContentRepliesRaw(parentAuthor, parentPermlink string) (*json.RawMessage, error)

func (*Client) GetConversionRequestsRaw

func (client *Client) GetConversionRequestsRaw(accountName string) (*json.RawMessage, error)

func (*Client) GetCurrentMedianHistoryPriceRaw

func (client *Client) GetCurrentMedianHistoryPriceRaw() (*json.RawMessage, error)

func (*Client) GetDiscussionsByActiveRaw

func (client *Client) GetDiscussionsByActiveRaw(query *DiscussionQuery) (*json.RawMessage, error)

func (*Client) GetDiscussionsByCashoutRaw

func (client *Client) GetDiscussionsByCashoutRaw(query *DiscussionQuery) (*json.RawMessage, error)

func (*Client) GetDiscussionsByChildrenRaw

func (client *Client) GetDiscussionsByChildrenRaw(query *DiscussionQuery) (*json.RawMessage, error)

func (*Client) GetDiscussionsByCreatedRaw

func (client *Client) GetDiscussionsByCreatedRaw(query *DiscussionQuery) (*json.RawMessage, error)

func (*Client) GetDiscussionsByHotRaw

func (client *Client) GetDiscussionsByHotRaw(query *DiscussionQuery) (*json.RawMessage, error)

func (*Client) GetDiscussionsByPayoutRaw

func (client *Client) GetDiscussionsByPayoutRaw(query *DiscussionQuery) (*json.RawMessage, error)

func (*Client) GetDiscussionsByTrendingRaw

func (client *Client) GetDiscussionsByTrendingRaw(query *DiscussionQuery) (*json.RawMessage, error)

func (*Client) GetDiscussionsByVotesRaw

func (client *Client) GetDiscussionsByVotesRaw(query *DiscussionQuery) (*json.RawMessage, error)

func (*Client) GetDynamicGlobalProperties

func (client *Client) GetDynamicGlobalProperties() (*DynamicGlobalProperties, error)

func (*Client) GetDynamicGlobalPropertiesRaw

func (client *Client) GetDynamicGlobalPropertiesRaw() (*json.RawMessage, error)

func (*Client) GetFeedHistoryRaw

func (client *Client) GetFeedHistoryRaw() (*json.RawMessage, error)

func (*Client) GetHardforkVersion

func (client *Client) GetHardforkVersion() (string, error)

func (*Client) GetHardforkVersionRaw

func (client *Client) GetHardforkVersionRaw() (*json.RawMessage, error)

func (*Client) GetNextScheduledHardforkRaw

func (client *Client) GetNextScheduledHardforkRaw() (*json.RawMessage, error)

func (*Client) GetOrderBookRaw

func (client *Client) GetOrderBookRaw(limit uint32) (*json.RawMessage, error)

func (*Client) GetRecentCategoriesRaw

func (client *Client) GetRecentCategoriesRaw(after string, limit uint32) (*json.RawMessage, error)

func (*Client) GetRecommendedForRaw

func (client *Client) GetRecommendedForRaw(user string, limit uint32) (*json.RawMessage, error)

func (*Client) GetRepliesByLastUpdateRaw

func (client *Client) GetRepliesByLastUpdateRaw(
	startAuthor string,
	startPermlink string,
	limit uint32,
) (*json.RawMessage, error)

func (*Client) GetStateRaw

func (client *Client) GetStateRaw(path string) (*json.RawMessage, error)

func (*Client) GetTrendingCategoriesRaw

func (client *Client) GetTrendingCategoriesRaw(after string, limit uint32) (*json.RawMessage, error)

func (*Client) GetTrendingTagsRaw

func (client *Client) GetTrendingTagsRaw(afterTag string, limit uint32) (*json.RawMessage, error)

func (*Client) GetWitnessScheduleRaw

func (client *Client) GetWitnessScheduleRaw() (*json.RawMessage, error)

func (*Client) LookupAccountNamesRaw

func (client *Client) LookupAccountNamesRaw(accountNames []string) (*json.RawMessage, error)

func (*Client) LookupAccountsRaw

func (client *Client) LookupAccountsRaw(lowerBoundName string, limit uint32) (*json.RawMessage, error)

type CommentOperation

type CommentOperation struct {
	Author         string `json:"author"`
	Title          string `json:"title"`
	Permlink       string `json:"permlink"`
	ParentAuthor   string `json:"parent_author"`
	ParentPermlink string `json:"parent_permlink"`
	Body           string `json:"body"`
}

CommentOperation represents either a new post or a comment.

In case Title is filled in and ParentAuthor is empty, it is a new post. The post category can be read from ParentPermlink.

In case the author is just updating an existing post, Body contains only the diff against the original content.

func (*CommentOperation) IsStoryOperation

func (op *CommentOperation) IsStoryOperation() bool

type Config

type Config struct {
	SteemitBlockchainHardforkVersion string `json:"STEEMIT_BLOCKCHAIN_HARDFORK_VERSION"`
	SteemitBlockchainVersion         string `json:"STEEMIT_BLOCKCHAIN_VERSION"`
	SteemitBlockInterval             uint   `json:"STEEMIT_BLOCK_INTERVAL"`
}

type Content

type Content struct {
	Id                      *types.ID        `json:"id"`
	RootTitle               string           `json:"root_title"`
	Active                  *types.Time      `json:"active"`
	AbsRshares              *types.Int       `json:"abs_rshares"`
	PendingPayoutValue      string           `json:"pending_payout_value"`
	TotalPendingPayoutValue string           `json:"total_pending_payout_value"`
	Category                string           `json:"category"`
	Title                   string           `json:"title"`
	LastUpdate              *types.Time      `json:"last_update"`
	Stats                   string           `json:"stats"`
	Body                    string           `json:"body"`
	Created                 *types.Time      `json:"created"`
	Replies                 []*Content       `json:"replies"`
	Permlink                string           `json:"permlink"`
	JsonMetadata            *ContentMetadata `json:"json_metadata"`
	Children                *types.Int       `json:"children"`
	NetRshares              *types.Int       `json:"net_rshares"`
	URL                     string           `json:"url"`
	ActiveVotes             []*Vote          `json:"active_votes"`
	ParentPermlink          string           `json:"parent_permlink"`
	CashoutTime             *types.Time      `json:"cashout_time"`
	TotalPayoutValue        string           `json:"total_payout_value"`
	ParentAuthor            string           `json:"parent_author"`
	ChildrenRshares2        *types.Int       `json:"children_rshares2"`
	Author                  string           `json:"author"`
	Depth                   *types.Int       `json:"depth"`
	TotalVoteWeight         *types.Int       `json:"total_vote_weight"`
}

func (*Content) IsStory

func (content *Content) IsStory() bool

type ContentMetadata

type ContentMetadata struct {
	Users []string
	Tags  []string
	Image []string
}

func (*ContentMetadata) UnmarshalJSON

func (metadata *ContentMetadata) UnmarshalJSON(data []byte) error

type ContentMetadataRaw

type ContentMetadataRaw struct {
	Users []string `json:"users"`
	Tags  []string `json:"tags"`
	Image []string `json:"image"`
}

type DiscussionQuery

type DiscussionQuery struct {
	Tag   string `json:"tag"`
	Limit uint32 `json:"limit"`
	// XXX: Not sure about the type here.
	FilterTags     []string `json:"filter_tags"`
	StartAuthor    string   `json:"start_author,omitempty"`
	StartPermlink  string   `json:"start_permlink,omitempty"`
	ParentAuthor   string   `json:"parent_author,omitempty"`
	ParentPermlink string   `json:"parent_permlink"`
}

type DynamicGlobalProperties

type DynamicGlobalProperties struct {
	Time                     *types.Time `json:"time"`
	TotalPow                 *types.Int  `json:"total_pow"`
	NumPowWitnesses          *types.Int  `json:"num_pow_witnesses"`
	ConfidentialSupply       string      `json:"confidential_supply"`
	TotalVestingShares       string      `json:"total_vesting_shares"`
	CurrentReserveRatio      *types.Int  `json:"current_reserve_ratio"`
	Id                       *types.ID   `json:"id"`
	CurrentSupply            string      `json:"current_supply"`
	MaximumBlockSize         *types.Int  `json:"maximum_block_size"`
	RecentSlotsFilled        string      `json:"recent_slots_filled"`
	CurrentWitness           string      `json:"current_witness"`
	TotalRewardShares2       string      `json:"total_reward_shares2"`
	AverageBlockSize         *types.Int  `json:"average_block_size"`
	CurrentAslot             *types.Int  `json:"current_aslot"`
	LastIrreversibleBlockNum uint32      `json:"last_irreversible_block_num"`
	TotalVersingFundSteem    string      `json:"total_vesting_fund_steem"`
	HeadBlockId              string      `json:"head_block_id"`
	VirtualSupply            string      `json:"virtual_supply"`
	CurrentSBDSupply         string      `json:"current_sbd_supply"`
	ConfidentialSBDSupply    string      `json:"confidential_sbd_supply"`
	TotalRewardFundSteem     string      `json:"total_reward_fund_steem"`
	SBDInterestRate          *types.Int  `json:"sbd_interest_rate"`
	MaxVirtualBandwidth      string      `json:"max_virtual_bandwidth"`
	HeadBlockNumber          *types.Int  `json:"head_block_number"`
}

type Operation

type Operation struct {
	Type string
	Body interface{}
}

func (*Operation) UnmarshalJSON

func (op *Operation) UnmarshalJSON(data []byte) error

type Transaction

type Transaction struct {
	RefBlockNum    *types.Int   `json:"ref_block_num"`
	RefBlockPrefix *types.Int   `json:"ref_block_prefix"`
	Expiration     string       `json:"expiration"`
	Operations     []*Operation `json:"operations"`
}

type Transport

type Transport interface {
	Call(method string, params, response interface{}) error
	Close() error
}

type TransportConstructor

type TransportConstructor func(address string) (Transport, error)

type Vote

type Vote struct {
	Voter  string     `json:"voter"`
	Weight *types.Int `json:"weight"`
}

type VoteOperation

type VoteOperation struct {
	Voter    string     `json:"voter"`
	Author   string     `json:"author"`
	Permlink string     `json:"permlink"`
	Weight   *types.Int `json:"weight"`
}

Directories

Path Synopsis
examples
transports

Jump to

Keyboard shortcuts

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