client

package
v0.0.0-...-b94ffa6 Latest Latest
Warning

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

Go to latest
Published: Jan 13, 2020 License: LGPL-3.0 Imports: 18 Imported by: 1

Documentation

Overview

SPDX-License-Identifier: LGPL-3.0-or-later Copyright 2019 the DNA Dev team Copyright 2018 the Ontology Dev team

SPDX-License-Identifier: LGPL-3.0-or-later Copyright 2019 the DNA Dev team Copyright 2018 the Ontology Dev team

SPDX-License-Identifier: LGPL-3.0-or-later Copyright 2019 DNA Dev team

  • Copyright (C) 2018 The ontology Authors
  • This file is part of The ontology library. *
  • The ontology is free software: you can redistribute it and/or modify
  • it under the terms of the GNU Lesser General Public License as published by
  • the Free Software Foundation, either version 3 of the License, or
  • (at your option) any later version. *
  • The ontology is distributed in the hope that it will be useful,
  • but WITHOUT ANY WARRANTY; without even the implied warranty of
  • MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  • GNU Lesser General Public License for more details. *
  • You should have received a copy of the GNU Lesser General Public License
  • along with The ontology. If not, see <http://www.gnu.org/licenses/>.

RPC client for dna

SPDX-License-Identifier: LGPL-3.0-or-later Copyright 2019 DNA Dev team

  • Copyright (C) 2018 The ontology Authors
  • This file is part of The ontology library. *
  • The ontology is free software: you can redistribute it and/or modify
  • it under the terms of the GNU Lesser General Public License as published by
  • the Free Software Foundation, either version 3 of the License, or
  • (at your option) any later version. *
  • The ontology is distributed in the hope that it will be useful,
  • but WITHOUT ANY WARRANTY; without even the implied warranty of
  • MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  • GNU Lesser General Public License for more details. *
  • You should have received a copy of the GNU Lesser General Public License
  • along with The ontology. If not, see <http://www.gnu.org/licenses/>.

Index

Constants

View Source
const (
	RPC_GET_VERSION                 = "getversion"
	RPC_GET_TRANSACTION             = "getrawtransaction"
	RPC_SEND_TRANSACTION            = "sendrawtransaction"
	RPC_GET_BLOCK                   = "getblock"
	RPC_GET_BLOCK_COUNT             = "getblockcount"
	RPC_GET_BLOCK_HASH              = "getblockhash"
	RPC_GET_CURRENT_BLOCK_HASH      = "getbestblockhash"
	RPC_GET_ONT_BALANCE             = "getbalance"
	RPC_GET_SMART_CONTRACT_EVENT    = "getsmartcodeevent"
	RPC_GET_STORAGE                 = "getstorage"
	RPC_GET_SMART_CONTRACT          = "getcontractstate"
	RPC_GET_GENERATE_BLOCK_TIME     = "getgenerateblocktime"
	RPC_GET_MERKLE_PROOF            = "getmerkleproof"
	RPC_GET_NETWORK_ID              = "getnetworkid"
	RPC_GET_MEM_POOL_TX_COUNT       = "getmempooltxcount"
	RPC_GET_MEM_POOL_TX_STATE       = "getmempooltxstate"
	RPC_GET_BLOCK_TX_HASH_BY_HEIGHT = "getblocktxsbyheight"
	RPC_GET_BLOCK_HEIGHT_BY_TX_HASH = "getblockheightbytxhash"
	SEND_EMERGENCY_GOV_REQ          = "sendemergencygovreq"
	GET_BLOCK_ROOT_WITH_NEW_TX_ROOT = "getblockrootwithnewtxroot"
)
View Source
const (
	GET_GEN_BLK_TIME      = "/api/v1/node/generateblocktime"
	GET_CONN_COUNT        = "/api/v1/node/connectioncount"
	GET_BLK_TXS_BY_HEIGHT = "/api/v1/block/transactions/height/"
	GET_BLK_BY_HEIGHT     = "/api/v1/block/details/height/"
	GET_BLK_BY_HASH       = "/api/v1/block/details/hash/"
	GET_BLK_HEIGHT        = "/api/v1/block/height"
	GET_BLK_HASH          = "/api/v1/block/hash/"
	GET_TX                = "/api/v1/transaction/"
	GET_STORAGE           = "/api/v1/storage/"
	GET_BALANCE           = "/api/v1/balance/"
	GET_CONTRACT_STATE    = "/api/v1/contract/"
	GET_SMTCOCE_EVT_TXS   = "/api/v1/smartcode/event/transactions/"
	GET_SMTCOCE_EVTS      = "/api/v1/smartcode/event/txhash/"
	GET_BLK_HGT_BY_TXHASH = "/api/v1/block/height/txhash/"
	GET_MERKLE_PROOF      = "/api/v1/merkleproof/"
	GET_GAS_PRICE         = "/api/v1/gasprice"
	GET_ALLOWANCE         = "/api/v1/allowance/"
	GET_MEMPOOL_TXCOUNT   = "/api/v1/mempool/txcount"
	GET_MEMPOOL_TXSTATE   = "/api/v1/mempool/txstate/"
	GET_VERSION           = "/api/v1/version"
	GET_NETWORK_ID        = "/api/v1/networkid"
	POST_RAW_TX           = "/api/v1/transaction"
)
View Source
const (
	WS_VERSION       = "1.0.0"
	WS_ERROR_SUCCESS = 0
)
View Source
const (
	WS_ACTION_HEARBEAT                    = "heartbeat"
	WS_ACTION_SUBSCRIBE                   = "subscribe"
	WS_ACTION_GET_BLOCK_TX_HASH_BY_HEIGHT = "getblocktxsbyheight"
	WS_ACTION_GET_BLOCK_BY_HEIGHT         = "getblockbyheight"
	WS_ACTION_GET_BLOCK_BY_HASH           = "getblockbyhash"
	WS_ACTION_GET_BLOCK_HEIGHT            = "getblockheight"
	WS_ACTION_GET_BLOCK_HASH              = "getblockhash"
	WS_ACTION_GET_TRANSACTION             = "gettransaction"
	WS_ACTION_SEND_TRANSACTION            = "sendrawtransaction"
	WS_ACTION_GET_STORAGE                 = "getstorage"
	WS_ACTION_GET_CONTRACT                = "getcontract"
	WS_ACTION_GET_SMARTCONTRACT_BY_HEIGHT = "getsmartcodeeventbyheight"
	WS_ACTION_GET_SMARTCONTRACT_BY_HASH   = "getsmartcodeeventbyhash"
	WS_ACTION_GET_BLOCK_HEIGHT_BY_TX_HASH = "getblockheightbytxhash"
	WS_ACTION_GET_MERKLE_PROOF            = "getmerkleproof"
	WS_ACTION_GET_GENERATE_BLOCK_TIME     = "getgenerateblocktime"
	WS_ACTION_GET_GAS_PRICE               = "getgasprice"
	WS_ACTION_GET_MEM_POOL_TX_STATE       = "getmempooltxstate"
	WS_ACTION_GET_MEM_POOL_TX_COUNT       = "getmempooltxcount"
	WS_ACTION_GET_VERSION                 = "getversion"
	WS_ACTION_GET_NETWORK_ID              = "getnetworkid"

	WS_SUB_ACTION_RAW_BLOCK     = "sendrawblock"
	WS_SUB_ACTION_JSON_BLOCK    = "sendjsonblock"
	WS_SUB_ACTION_BLOCK_TX_HASH = "sendblocktxhashs"
	WS_SUB_ACTION_NOTIFY        = "Notify"
	WS_SUB_ACTION_LOG           = "Log"
)
View Source
const (
	WS_SUB_CONTRACT_FILTER = "ContractsFilter"
	WS_SUB_EVENT           = "SubscribeEvent"
	WS_SUB_JSON_BLOCK      = "SubscribeJsonBlock"
	WS_SUB_RAW_BLOCK       = "SubscribeRawBlock"
	WS_SUB_BLOCK_TX_HASH   = "SubscribeBlockTxHashs"
)
View Source
const (
	ACTION_SEND_RAW_TRANSACTION = "sendrawtransaction"
)
View Source
const JSON_RPC_VERSION = "2.0"

JsonRpc version

View Source
const REST_VERSION = "1.0.0"

Variables

View Source
var (
	WS_RECV_CHAN_SIZE             = 1024
	DEFAULT_REQ_TIMEOUT           = 10 * time.Second
	DEFAULT_WS_HEARTBEAT_INTERVAL = 60 //s
	DEFAULT_WS_HEARTBEAT_TIMEOUT  = DEFAULT_WS_HEARTBEAT_INTERVAL * 5
)

Functions

This section is empty.

Types

type ClientMgr

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

func (*ClientMgr) GetBlockByHash

func (this *ClientMgr) GetBlockByHash(blockHash string) (*types.Block, error)

func (*ClientMgr) GetBlockByHeight

func (this *ClientMgr) GetBlockByHeight(height uint32) (*types.Block, error)

func (*ClientMgr) GetBlockHash

func (this *ClientMgr) GetBlockHash(height uint32) (common.Uint256, error)

func (*ClientMgr) GetBlockHeightByTxHash

func (this *ClientMgr) GetBlockHeightByTxHash(txHash string) (uint32, error)

func (*ClientMgr) GetBlockInfoByHeight

func (this *ClientMgr) GetBlockInfoByHeight(height uint32) ([]byte, error)

func (*ClientMgr) GetBlockTxHashesByHeight

func (this *ClientMgr) GetBlockTxHashesByHeight(height uint32) (*sdkcom.BlockTxHashes, error)

func (*ClientMgr) GetCurrentBlockHash

func (this *ClientMgr) GetCurrentBlockHash() (common.Uint256, error)

func (*ClientMgr) GetCurrentBlockHeight

func (this *ClientMgr) GetCurrentBlockHeight() (uint32, error)

func (*ClientMgr) GetMemPoolTxCount

func (this *ClientMgr) GetMemPoolTxCount() (*sdkcom.MemPoolTxCount, error)

func (*ClientMgr) GetMemPoolTxState

func (this *ClientMgr) GetMemPoolTxState(txHash string) (*sdkcom.MemPoolTxState, error)

func (*ClientMgr) GetMerkleProof

func (this *ClientMgr) GetMerkleProof(txHash string) (*sdkcom.MerkleProof, error)

func (*ClientMgr) GetNetworkId

func (this *ClientMgr) GetNetworkId() (uint32, error)

func (*ClientMgr) GetRestClient

func (this *ClientMgr) GetRestClient() *RestClient

func (*ClientMgr) GetRpcClient

func (this *ClientMgr) GetRpcClient() *RpcClient

func (*ClientMgr) GetSmartContract

func (this *ClientMgr) GetSmartContract(contractAddress string) (*sdkcom.SmartContract, error)

func (*ClientMgr) GetSmartContractEvent

func (this *ClientMgr) GetSmartContractEvent(txHash string) (*sdkcom.SmartContactEvent, error)

func (*ClientMgr) GetSmartContractEventByBlock

func (this *ClientMgr) GetSmartContractEventByBlock(height uint32) ([]*sdkcom.SmartContactEvent, error)

func (*ClientMgr) GetStorage

func (this *ClientMgr) GetStorage(contractAddress string, key []byte) ([]byte, error)

func (*ClientMgr) GetTransaction

func (this *ClientMgr) GetTransaction(txHash string) (*types.Transaction, error)

func (*ClientMgr) GetVersion

func (this *ClientMgr) GetVersion() (string, error)

func (*ClientMgr) GetWebSocketClient

func (this *ClientMgr) GetWebSocketClient() *WSClient

func (*ClientMgr) NewRestClient

func (this *ClientMgr) NewRestClient() *RestClient

func (*ClientMgr) NewRpcClient

func (this *ClientMgr) NewRpcClient() *RpcClient

func (*ClientMgr) NewWebSocketClient

func (this *ClientMgr) NewWebSocketClient() *WSClient

func (*ClientMgr) PreExecTransaction

func (this *ClientMgr) PreExecTransaction(mutTx *types.MutableTransaction) (*sdkcom.PreExecResult, error)

func (*ClientMgr) SendTransaction

func (this *ClientMgr) SendTransaction(mutTx *types.MutableTransaction) (common.Uint256, error)

func (*ClientMgr) SetDefaultClient

func (this *ClientMgr) SetDefaultClient(client DNAClient)

func (*ClientMgr) WaitForGenerateBlock

func (this *ClientMgr) WaitForGenerateBlock(timeout time.Duration, blockCount ...uint32) (bool, error)

WaitForGenerateBlock Wait dna generate block. Default wait 2 blocks. return timeout error when there is no block generate in some time.

type DNAClient

type DNAClient interface {
	// contains filtered or unexported methods
}

type JsonRpcRequest

type JsonRpcRequest struct {
	Version string        `json:"jsonrpc"`
	Id      string        `json:"id"`
	Method  string        `json:"method"`
	Params  []interface{} `json:"params"`
}

JsonRpcRequest object in rpc

type JsonRpcResponse

type JsonRpcResponse struct {
	Id     string          `json:"id"`
	Error  int64           `json:"error"`
	Desc   string          `json:"desc"`
	Result json.RawMessage `json:"result"`
}

JsonRpcResponse object response for JsonRpcRequest

type RestClient

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

RpcClient for dna rpc api

func NewRestClient

func NewRestClient() *RestClient

NewRpcClient return RpcClient instance

func (*RestClient) SetAddress

func (this *RestClient) SetAddress(addr string) *RestClient

SetAddress set rest server address. Simple http://localhost:20334

func (*RestClient) SetHttpClient

func (this *RestClient) SetHttpClient(httpClient *http.Client) *RestClient

SetHttpClient set rest client to RestClient. In most cases SetHttpClient is not necessary

type RestfulReq

type RestfulReq struct {
	Action  string
	Version string
	Type    int
	Data    string
}

type RestfulResp

type RestfulResp struct {
	Action  string          `json:"action"`
	Result  json.RawMessage `json:"result"`
	Error   int64           `json:"error"`
	Desc    string          `json:"desc"`
	Version string          `json:"version"`
}

type RpcClient

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

RpcClient for dna rpc api

func NewRpcClient

func NewRpcClient() *RpcClient

NewRpcClient return RpcClient instance

func (*RpcClient) SetAddress

func (this *RpcClient) SetAddress(addr string) *RpcClient

SetAddress set rpc server address. Simple http://localhost:20336

func (*RpcClient) SetHttpClient

func (this *RpcClient) SetHttpClient(httpClient *http.Client) *RpcClient

SetHttpClient set http client to RpcClient. In most cases SetHttpClient is not necessary

type WSAction

type WSAction struct {
	Action string
	Result interface{}
}

type WSClient

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

func NewWSClient

func NewWSClient() *WSClient

func (*WSClient) AddContractFilter

func (this *WSClient) AddContractFilter(contractAddress string) error

func (*WSClient) Close

func (this *WSClient) Close() error

func (*WSClient) Connect

func (this *WSClient) Connect(address string) error

func (*WSClient) DelContractFilter

func (this *WSClient) DelContractFilter(contractAddress string) error

func (*WSClient) GetActionCh

func (this *WSClient) GetActionCh() chan *WSAction

func (*WSClient) GetDefaultReqTimeout

func (this *WSClient) GetDefaultReqTimeout() time.Duration

func (*WSClient) GetHeartbeatInterval

func (this *WSClient) GetHeartbeatInterval() int

func (*WSClient) GetHeartbeatTimeout

func (this *WSClient) GetHeartbeatTimeout() int

func (*WSClient) GetOnClose

func (this *WSClient) GetOnClose() func(address string)

func (*WSClient) GetOnConnect

func (this *WSClient) GetOnConnect() func(address string)

func (*WSClient) GetOnError

func (this *WSClient) GetOnError() func(address string, er error)

func (*WSClient) SetDefaultReqTimeout

func (this *WSClient) SetDefaultReqTimeout(timeout time.Duration)

func (*WSClient) SetHeartbeatInterval

func (this *WSClient) SetHeartbeatInterval(interval int)

func (*WSClient) SetHeartbeatTimeout

func (this *WSClient) SetHeartbeatTimeout(timeout int)

func (*WSClient) SetOnClose

func (this *WSClient) SetOnClose(f func(address string))

func (*WSClient) SetOnConnect

func (this *WSClient) SetOnConnect(f func(address string))

func (*WSClient) SetOnError

func (this *WSClient) SetOnError(f func(address string, err error))

func (*WSClient) SubscribeBlock

func (this *WSClient) SubscribeBlock() error

func (*WSClient) SubscribeEvent

func (this *WSClient) SubscribeEvent() error

func (*WSClient) SubscribeTxHash

func (this *WSClient) SubscribeTxHash() error

func (*WSClient) UnsubscribeBlock

func (this *WSClient) UnsubscribeBlock() error

func (*WSClient) UnsubscribeEvent

func (this *WSClient) UnsubscribeEvent() error

func (*WSClient) UnsubscribeTxHash

func (this *WSClient) UnsubscribeTxHash() error

type WSRequest

type WSRequest struct {
	Id     string
	Params map[string]interface{}
	ResCh  chan *WSResponse
}

type WSResponse

type WSResponse struct {
	Id      string
	Action  string
	Result  json.RawMessage
	Error   int
	Desc    string
	Version string
}

type WSSubscribeStatus

type WSSubscribeStatus struct {
	ContractsFilter        []string
	SubscribeEvent         bool
	SubscribeJsonBlock     bool
	SubscribeRawBlock      bool
	SubscribeBlockTxHashes bool
}

func (*WSSubscribeStatus) AddContractFilter

func (this *WSSubscribeStatus) AddContractFilter(contractAddress string)

func (*WSSubscribeStatus) DelContractFilter

func (this *WSSubscribeStatus) DelContractFilter(contractAddress string)

func (*WSSubscribeStatus) GetContractFilter

func (this *WSSubscribeStatus) GetContractFilter() []string

func (*WSSubscribeStatus) HasContractFilter

func (this *WSSubscribeStatus) HasContractFilter(contractAddress string) bool

Jump to

Keyboard shortcuts

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