client

package
v0.0.0-...-8aa4d74 Latest Latest
Warning

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

Go to latest
Published: Feb 13, 2019 License: GPL-3.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	UrlPrefixForAPIV1 = "/api/v1"

	UrlAccountTransactions   = "/accounts/{id}/transactions"
	UrlAccount               = "/accounts/{id}"
	UrlAccountOperations     = "/accounts/{id}/operations"
	UrlAccountFrozenAccounts = "/accounts/{id}/frozen-accounts"
	UrlFrozenAccounts        = "/frozen-accounts"
	UrlTransactions          = "/transactions"
	UrlTransactionByHash     = "/transactions/{id}"
	UrlTransactionStatus     = "/transactions/{id}/status"
	UrlTransactionOperations = "/transactions/{id}/operations"
	UrlSubscribe             = "/subscribe"
)

Variables

This section is empty.

Functions

func NewDefaultListOptionsFromQuery

func NewDefaultListOptionsFromQuery(v neturl.Values) (options *storage.DefaultListOptions, err error)

NewDefaultListOptionsFromQuery makes ListOptions from url.Query.

Types

type Account

type Account struct {
	Links struct {
		Self         Link `json:"self"`
		Transactions Link `json:"transactions"`
		Operations   Link `json:"operations"`
	} `json:"_links"`

	Address    string `json:"address"`
	SequenceID uint64 `json:"sequence_id"`
	Balance    string `json:"balance"`
	Linked     string `json:"linked"`
}

type Client

type Client struct {
	URL string

	HTTP *common.HTTP2Client
}

func MustNewClient

func MustNewClient(url string) *Client

Calls `NewClient` and panic if an `error` is returned

func NewClient

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

Create a new Client object

Params:

url = The url of the node, e.g. "https://127.0.0.1:1234"

Returns:

error   = An error object, if the client could not be created.
          `nil` otherwise.
Client* = If `error == nil`, the constructed `Client`

func (*Client) Get

func (c *Client) Get(path string, headers http.Header) (response *http.Response, err error)

func (*Client) LoadAFrozenAccounts

func (c *Client) LoadAFrozenAccounts(id string, queries ...Q) (fPage FrozenAccountsPage, err error)

func (*Client) LoadAccount

func (c *Client) LoadAccount(id string, queries ...Q) (account Account, err error)

func (*Client) LoadFrozenAccountsByLinked

func (c *Client) LoadFrozenAccountsByLinked(id string, queries ...Q) (fPage FrozenAccountsPage, err error)

func (*Client) LoadOperationsByAccount

func (c *Client) LoadOperationsByAccount(id string, queries ...Q) (oPage OperationsPage, err error)

func (*Client) LoadOperationsByTransaction

func (c *Client) LoadOperationsByTransaction(id string, queries ...Q) (oPage OperationsPage, err error)

func (*Client) LoadTransaction

func (c *Client) LoadTransaction(id string, queries ...Q) (transaction Transaction, err error)

func (*Client) LoadTransactionStatus

func (c *Client) LoadTransactionStatus(id string, queries ...Q) (transactionHistory TransactionStatus, err error)

func (*Client) LoadTransactions

func (c *Client) LoadTransactions(queries ...Q) (tPage TransactionsPage, err error)

func (*Client) LoadTransactionsByAccount

func (c *Client) LoadTransactionsByAccount(id string, queries ...Q) (tPage TransactionsPage, err error)

func (*Client) Post

func (c *Client) Post(path string, body []byte, headers http.Header) (response *http.Response, err error)

func (*Client) StreamAccount

func (c *Client) StreamAccount(ctx context.Context, handler func(Account), ids ...string) error

Stream account updates from the node

Params:

ctx = Context to use. The streaming starts a goroutine and doesn't stop.
      A common pattern is to pass `context.WithCancel(context.Background())`.
      See go's `context` package for more details.
handler = The handler function that will be called every time an account is updated.

Returns: An `error` object, or `nil`

func (*Client) StreamTransactionStatus

func (c *Client) StreamTransactionStatus(ctx context.Context, id string, handler func(TransactionStatus)) (err error)

func (*Client) StreamTransactions

func (c *Client) StreamTransactions(ctx context.Context, handler func(Transaction), ids ...string) error

Stream transactions from the node

Params:

ctx = Context to use. The streaming starts a goroutine and doesn't stop.
      A common pattern is to pass `context.WithCancel(context.Background())`.
      See go's `context` package for more details.
handler = The handler function that will be called every time a transaction is received.
ids     = An (optional) list of transaction hashes to listen to.
          If `nil`, all transactions will be streamed to the handler.

Returns: An `error` object, or `nil`

func (*Client) StreamTransactionsByAccount

func (c *Client) StreamTransactionsByAccount(ctx context.Context, id string, handler func(Transaction)) (err error)

func (*Client) SubmitTransaction

func (c *Client) SubmitTransaction(tx []byte) (TransactionPostError, error)

Submit a transaction to the node (via POST `UrlTransactions`)

Params:

tx = JSON serialized Transaction that will be sent as body

Returns:

TransactionPostError = An object describing the node's answer if there's an error
error = An error object, or `nil`

func (*Client) SubmitTransactionAndWait

func (c *Client) SubmitTransactionAndWait(hash string, tx []byte) (pTransaction TransactionPostError, err error)

Submit a transaction to the node (via POST `UrlTransactions`)

Params:

hash = the hash of the transaction
tx = JSON serialized Transaction that will be sent as body

Returns:

TransactionPostError = An object describing the node's answer if there's an error
error = An error object, or `nil`

func (*Client) ToResponse

func (c *Client) ToResponse(resp *http.Response, response interface{}) (err error)

type CollectTxFee

type CollectTxFee struct {
	Target    string `json:"target"`
	Amount    []byte `json:"amount"`
	Txs       uint64 `json:"txs"`
	Height    uint64 `json:"block-height"`
	BlockHash string `json:"block-hash"`
	TotalTxs  uint64 `json:"total-txs"`
	TotalOps  uint64 `json:"total-ops"`
}

type CongressVoting

type CongressVoting struct {
	Contract string `json:"contract"`
	Voting   struct {
		Start uint64 `json:"start"`
		End   uint64 `json:"end"`
	} `json:"voting"`
	FundingAddress string        `json:"funding_address"`
	Amount         common.Amount `json:"amount"`
}

type CongressVotingResult

type CongressVotingResult struct {
	BallotStamps struct {
		Hash string   `json:"hash"`
		Urls []string `json:"urls"`
	} `json:"ballot_stamps"`
	Voters struct {
		Hash string   `json:"hash"`
		Urls []string `json:"urls"`
	} `json:"voters"`
	Membership struct {
		Hash string   `json:"hash"`
		Urls []string `json:"urls"`
	} `json:"membership"`
	Result struct {
		Count uint64 `json:"count"`
		Yes   uint64 `json:"yes"`
		No    uint64 `json:"no"`
		ABS   uint64 `json:"abs"`
	} `json:"result"`
	CongressVotingHash string `json:"congress_voting_hash"`
}

type CreateAccount

type CreateAccount struct {
	Target string `json:"target"`
	Amount []byte `json:"amount"`
	Linked string `json:"linked,omitempty"`
}

type Error

type Error struct {
	Problem Problem
}

func (Error) Error

func (e Error) Error() string

type FrozenAccount

type FrozenAccount struct {
	Links struct {
		Self Link `json:"self"`
	} `json:"_links"`

	Address                    string                      `json:"address"`
	Linked                     string                      `json:"linked"`
	CreateBlockHeight          uint64                      `json:"create_block_height"`
	CreateOpHash               string                      `json:"create_op_hash"`
	SequenceID                 uint64                      `json:"sequence_id"`
	Amount                     common.Amount               `json:"amount"`
	State                      resource.FrozenAccountState `json:"state"`
	UnfreezingBlockHeight      uint64                      `json:"unfreezing_block_height"`
	UnfreezingOpHash           string                      `json:"unfreezing_op_hash"`
	UnfreezingRemainingBlockes uint64                      `json:"unfreezing_remaining_blockheight"`
	PaymentOpHash              string                      `json:"payment_op_hash"`
}

type FrozenAccountsPage

type FrozenAccountsPage struct {
	Links struct {
		Self Link `json:"self"`
	} `json:"_links"`
	Embedded struct {
		Records []FrozenAccount `json:"records"`
	} `json:"_embedded"`
}

type Inflation

type Inflation struct {
	Target         string `json:"target"`
	Amount         []byte `json:"amount"`
	InitialBalance []byte `json:"initial-balance"`
	Ratio          string `json:"ratio"`
	Height         uint64 `json:"block-height"`
	BlockHash      string `json:"block-hash"`
	TotalTxs       uint64 `json:"total-txs"`
	TotalOps       uint64 `json:"total-ops"`
}
type Link struct {
	Href      string `json:"href"`
	Templated bool   `json:"templated,omitempty"`
}

type Operation

type Operation struct {
	Links struct {
		Self        Link `json:"self"`
		Transaction Link `json:"transaction"`
	} `json:"_links"`
	Hash        string      `json:"hash"`
	Source      string      `json:"source"`
	Target      string      `json:"target"`
	Type        string      `json:"type"`
	TxHash      string      `json:"tx_hash"`
	BlockHeight uint64      `json:"block_height"`
	Index       uint64      `json:"index"`
	Body        interface{} `json:"body"`
}

type OperationsPage

type OperationsPage struct {
	Links struct {
		Self Link `json:"self"`
		Next Link `json:"next"`
		Prev Link `json:"prev"`
	} `json:"_links"`
	Embedded struct {
		Records []Operation `json:"records"`
	} `json:"_embedded"`
}

type Payment

type Payment struct {
	Target string `json:"target"`
	Amount []byte `json:"amount"`
}

type Problem

type Problem struct {
	Type     string                     `json:"type"`
	Title    string                     `json:"title"`
	Status   int                        `json:"status"`
	Detail   string                     `json:"detail,omitempty"`
	Instance string                     `json:"instance,omitempty"`
	Extras   map[string]json.RawMessage `json:"extras,omitempty"`
}

type Q

type Q struct {
	Key   QueryKey
	Value string
}

type Queries

type Queries []Q

type QueryKey

type QueryKey string
const (
	QueryLimit  QueryKey = "limit"
	QueryOrder  QueryKey = "reverse"
	QueryCursor QueryKey = "cursor"
	QueryType   QueryKey = "type"
)

func (QueryKey) String

func (qk QueryKey) String() string

type Transaction

type Transaction struct {
	Links struct {
		Self       Link `json:"self"`
		Account    Link `json:"account"`
		Operations Link `json:"operations"`
	} `json:"_links"`
	Hash           string `json:"hash"`
	Source         string `json:"source"`
	Fee            string `json:"fee"`
	SequenceID     uint64 `json:"sequence_id"`
	Created        string `json:"created"`
	OperationCount uint64 `json:"operation_count"`
}

type TransactionPostError

type TransactionPostError struct {
	Links struct {
		Self   Link `json:"self"`
		Status Link `json:"status"`
	} `json:"_links"`
	Hash    string      `json:"hash"`
	Status  string      `json:"status"`
	Message interface{} `json:"message"`
}

type TransactionStatus

type TransactionStatus struct {
	Links struct {
		Self        Link `json:"self"`
		Transaction Link `json:"transaction"`
	} `json:"_links"`
	Hash   string `json:"hash"`
	Status string `json:"status"`
}

type TransactionsPage

type TransactionsPage struct {
	Links struct {
		Self Link `json:"self"`
		Next Link `json:"next"`
		Prev Link `json:"prev"`
	} `json:"_links"`
	Embedded struct {
		Records []Transaction `json:"records"`
	} `json:"_embedded"`
}

Jump to

Keyboard shortcuts

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