http_client

package
v2.0.3 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2020 License: MIT Imports: 11 Imported by: 7

Documentation

Overview

Package http_client is the interface for uses API v2 methods.

Example
package main

import (
	"context"
	"fmt"
	"github.com/MinterTeam/minter-go-sdk/v2/api/http_client"
	"github.com/MinterTeam/minter-go-sdk/v2/transaction"
	"github.com/MinterTeam/minter-go-sdk/v2/wallet"
	"io"
	"log"
	"math/big"
	"strings"
)

func main() {
	client, _ := http_client.NewConcise("http://localhost:8843/v2")
	w, _ := wallet.Create("1 2 3 4 5 6 7 8 9 10 11 12", "")
	data := transaction.NewSendData().SetCoin(0).SetValue(big.NewInt(1)).MustSetTo(w.Address)
	transactionsBuilder := transaction.NewBuilder(transaction.TestNetChainID)
	tx, _ := transactionsBuilder.NewTransaction(data)
	sign, _ := tx.SetNonce(1).SetGasPrice(1).Sign(w.PrivateKey)
	encode, _ := sign.Encode()
	hash, _ := sign.Hash()
	subscribeClient, _ := client.Subscribe(context.Background(), fmt.Sprintf("tx.hash = '%s'", strings.ToUpper(hash[2:])))
	defer subscribeClient.CloseSend()

	res, _ := client.SendTransaction(encode)
	if res.Code != 0 {
		panic(res.Log)
	}

	recv, err := subscribeClient.Recv()
	if err == io.EOF {
		return
	}
	if err == context.Canceled || err == context.DeadlineExceeded {
		return
	}
	if err != nil {
		panic(err)
	}
	log.Println("OK", recv.Result)
}
Output:

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func ErrorBody

func ErrorBody(err error) (int, *models.ErrorBody, error)

ErrorBody returns error as API model

Types

type Client

type Client struct {
	api_service.ClientService
}

Client is go-swagger HTTP client

func New

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

New returns HTTP client from go-swagger generator

func (*Client) CoinID

func (c *Client) CoinID(symbol string, optionalHeight ...uint64) (uint64, error)

CoinID returns ID of coin symbol.

func (*Client) Nonce added in v2.0.1

func (c *Client) Nonce(address string, optionalHeight ...uint64) (uint64, error)

Nonce returns next transaction number (nonce) of an address.

type Concise added in v2.0.1

type Concise struct {
	api_service.ClientService
	// contains filtered or unexported fields
}

Concise http concise HTTP client, with wrapper over go-swagger Client methods

func NewConcise added in v2.0.1

func NewConcise(address string) (*Concise, error)

NewConcise returns concise HTTP client, with wrapper over go-swagger methods

func (*Concise) Address added in v2.0.1

func (c *Concise) Address(address string, optionalHeight ...uint64) (*models.AddressResponse, error)

Address returns coins list, balance and transaction count of an address.

func (*Concise) Addresses added in v2.0.1

func (c *Concise) Addresses(addresses []string, optionalHeight ...uint64) (*models.AddressesResponse, error)

Addresses returns list of addresses.

func (*Concise) Block added in v2.0.1

func (c *Concise) Block(height uint64) (*models.BlockResponse, error)

Block returns block data at given height.

func (*Concise) Candidate added in v2.0.1

func (c *Concise) Candidate(publicKey string, optionalHeight ...uint64) (*models.CandidateResponse, error)

Candidate returns candidate’s res by provided public_key.

func (*Concise) Candidates added in v2.0.1

func (c *Concise) Candidates(includeStakes bool, status string, optionalHeight ...uint64) (*models.CandidatesResponse, error)

Candidates returns list of candidates.

func (*Concise) CoinID added in v2.0.1

func (c *Concise) CoinID(symbol string, optionalHeight ...uint64) (uint64, error)

CoinID returns ID of coin symbol.

func (*Concise) CoinInfo added in v2.0.1

func (c *Concise) CoinInfo(symbol string, optionalHeight ...uint64) (*models.CoinInfoResponse, error)

CoinInfo returns information about coin symbol.

func (*Concise) CoinInfoByID added in v2.0.1

func (c *Concise) CoinInfoByID(id uint64, optionalHeight ...uint64) (*models.CoinInfoResponse, error)

CoinInfoByID returns information about coin ID.

func (*Concise) EstimateCoinIDBuy added in v2.0.1

func (c *Concise) EstimateCoinIDBuy(coinToSell, coinToBuy uint64, valueToBuy string, optionalHeight ...uint64) (*models.EstimateCoinBuyResponse, error)

EstimateCoinIDBuy return estimate of buy coin transaction.

func (*Concise) EstimateCoinIDSell added in v2.0.1

func (c *Concise) EstimateCoinIDSell(coinToBuy, coinToSell uint64, valueToSell string, optionalHeight ...uint64) (*models.EstimateCoinSellResponse, error)

EstimateCoinIDSell return estimate of sell coin transaction.

func (*Concise) EstimateCoinIDSellAll added in v2.0.1

func (c *Concise) EstimateCoinIDSellAll(coinToBuy, coinToSell, gasPrice uint64, valueToSell string, optionalHeight ...uint64) (*models.EstimateCoinSellAllResponse, error)

EstimateCoinIDSellAll return estimate of sell all coin transaction.

func (*Concise) EstimateCoinSymbolBuy added in v2.0.1

func (c *Concise) EstimateCoinSymbolBuy(coinToSell, coinToBuy, valueToBuy string, optionalHeight ...uint64) (*models.EstimateCoinBuyResponse, error)

EstimateCoinSymbolBuy return estimate of buy coin transaction.

func (*Concise) EstimateCoinSymbolSell added in v2.0.1

func (c *Concise) EstimateCoinSymbolSell(coinToBuy, coinToSell, valueToSell string, optionalHeight ...uint64) (*models.EstimateCoinSellResponse, error)

EstimateCoinSymbolSell return estimate of sell coin transaction.

func (*Concise) EstimateCoinSymbolSellAll added in v2.0.1

func (c *Concise) EstimateCoinSymbolSellAll(coinToBuy, coinToSell string, gasPrice uint64, valueToSell string, optionalHeight ...uint64) (*models.EstimateCoinSellAllResponse, error)

EstimateCoinSymbolSellAll return estimate of sell all coin transaction.

func (*Concise) EstimateTxCommission added in v2.0.1

func (c *Concise) EstimateTxCommission(tx string, optionalHeight ...uint64) (*models.EstimateTxCommissionResponse, error)

EstimateTxCommission return estimate of encoding transaction.

func (*Concise) Events added in v2.0.1

func (c *Concise) Events(height uint64, search ...string) (*models.EventsResponse, error)

Events returns events at given height.

func (*Concise) Frozen added in v2.0.1

func (c *Concise) Frozen(address string, optionalCoinID ...uint64) (*models.FrozenResponse, error)

Frozen returns frozen balance.

func (*Concise) Genesis added in v2.0.1

func (c *Concise) Genesis() (*models.GenesisResponse, error)

Genesis returns genesis file.

func (*Concise) Halts added in v2.0.1

func (c *Concise) Halts(height uint64) (*models.HaltsResponse, error)

Halts returns the candidate votes for stopping the network at block.

func (*Concise) MaxGasPrice added in v2.0.1

func (c *Concise) MaxGasPrice(optionalHeight ...uint64) (*models.MaxGasPriceResponse, error)

MaxGasPrice returns current max gas.

func (*Concise) MinGasPrice added in v2.0.1

func (c *Concise) MinGasPrice() (*models.MinGasPriceResponse, error)

MinGasPrice returns current min gas price.

func (*Concise) MissedBlocks added in v2.0.1

func (c *Concise) MissedBlocks(publicKey string, optionalHeight ...uint64) (*models.MissedBlocksResponse, error)

MissedBlocks returns missed blocks by validator public key.

func (*Concise) NetInfo added in v2.0.1

func (c *Concise) NetInfo() (*models.NetInfoResponse, error)

NetInfo returns network res

func (*Concise) Nonce added in v2.0.1

func (c *Concise) Nonce(address string, optionalHeight ...uint64) (uint64, error)

Nonce returns next transaction number (nonce) of an address.

func (*Concise) SendTransaction added in v2.0.1

func (c *Concise) SendTransaction(tx string) (*models.SendTransactionResponse, error)

SendTransaction returns the result of sending signed tx. To ensure that transaction was successfully committed to the blockchain, you need to find the transaction by the hash and ensure that the status code equals to 0.

func (*Concise) Status added in v2.0.1

func (c *Concise) Status() (*models.StatusResponse, error)

Status returns node status including pubkey, latest block.

func (*Concise) Subscribe added in v2.0.1

func (c *Concise) Subscribe(ctx context.Context, query string) (*SubscriberClient, error)

Subscribe returns a subscription for events by query.

func (*Concise) Transaction added in v2.0.1

func (c *Concise) Transaction(hash string) (*models.TransactionResponse, error)

Transaction returns transaction res.

func (*Concise) Transactions added in v2.0.1

func (c *Concise) Transactions(query string, page, perPage int32) (*models.TransactionsResponse, error)

Transactions returns transactions by query.

func (*Concise) UnconfirmedTxs added in v2.0.1

func (c *Concise) UnconfirmedTxs(limit int32) (*models.UnconfirmedTxsResponse, error)

UnconfirmedTxs returns unconfirmed transactions.

func (*Concise) Validators added in v2.0.1

func (c *Concise) Validators(optionalHeight ...uint64) (*models.ValidatorsResponse, error)

Validators returns list of active validators.

func (*Concise) WaitList added in v2.0.1

func (c *Concise) WaitList(publicKey, address string, optionalHeight ...uint64) (*models.WaitListResponse, error)

WaitList returns the list of address stakes in waitlist.

func (*Concise) WithContextFunc added in v2.0.2

func (c *Concise) WithContextFunc(contextFunc func(context.Context) func() context.Context) *Concise

WithContextFunc returns new Concise client with new context Example:

timeout := func(c context.Context) func() context.Context {
	return func() context.Context {
		ctx, _ := context.WithTimeout(c, 10*time.Second)
		return ctx
	}
}

func (*Concise) WithTimeout added in v2.0.1

func (c *Concise) WithTimeout(timeout time.Duration) *Concise

WithTimeout returns copy of Concise with timeout.

type SubscriberClient

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

SubscriberClient is subscriber

func (*SubscriberClient) CloseSend

func (s *SubscriberClient) CloseSend() error

CloseSend closes the send direction of the stream.

func (*SubscriberClient) Recv

Recv returns message SubscribeOKBody.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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