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
- Variables
- type ClientMgr
- func (this *ClientMgr) GetBlockByHash(blockHash string) (*types.Block, error)
- func (this *ClientMgr) GetBlockByHeight(height uint32) (*types.Block, error)
- func (this *ClientMgr) GetBlockHash(height uint32) (common.Uint256, error)
- func (this *ClientMgr) GetBlockHeightByTxHash(txHash string) (uint32, error)
- func (this *ClientMgr) GetBlockInfoByHeight(height uint32) ([]byte, error)
- func (this *ClientMgr) GetBlockTxHashesByHeight(height uint32) (*sdkcom.BlockTxHashes, error)
- func (this *ClientMgr) GetCurrentBlockHash() (common.Uint256, error)
- func (this *ClientMgr) GetCurrentBlockHeight() (uint32, error)
- func (this *ClientMgr) GetMemPoolTxCount() (*sdkcom.MemPoolTxCount, error)
- func (this *ClientMgr) GetMemPoolTxState(txHash string) (*sdkcom.MemPoolTxState, error)
- func (this *ClientMgr) GetMerkleProof(txHash string) (*sdkcom.MerkleProof, error)
- func (this *ClientMgr) GetNetworkId() (uint32, error)
- func (this *ClientMgr) GetRestClient() *RestClient
- func (this *ClientMgr) GetRpcClient() *RpcClient
- func (this *ClientMgr) GetSmartContract(contractAddress string) (*sdkcom.SmartContract, error)
- func (this *ClientMgr) GetSmartContractEvent(txHash string) (*sdkcom.SmartContactEvent, error)
- func (this *ClientMgr) GetSmartContractEventByBlock(height uint32) ([]*sdkcom.SmartContactEvent, error)
- func (this *ClientMgr) GetStorage(contractAddress string, key []byte) ([]byte, error)
- func (this *ClientMgr) GetTransaction(txHash string) (*types.Transaction, error)
- func (this *ClientMgr) GetVersion() (string, error)
- func (this *ClientMgr) GetWebSocketClient() *WSClient
- func (this *ClientMgr) NewRestClient() *RestClient
- func (this *ClientMgr) NewRpcClient() *RpcClient
- func (this *ClientMgr) NewWebSocketClient() *WSClient
- func (this *ClientMgr) PreExecTransaction(mutTx *types.MutableTransaction) (*sdkcom.PreExecResult, error)
- func (this *ClientMgr) SendTransaction(mutTx *types.MutableTransaction) (common.Uint256, error)
- func (this *ClientMgr) SetDefaultClient(client DNAClient)
- func (this *ClientMgr) WaitForGenerateBlock(timeout time.Duration, blockCount ...uint32) (bool, error)
- type DNAClient
- type JsonRpcRequest
- type JsonRpcResponse
- type RestClient
- type RestfulReq
- type RestfulResp
- type RpcClient
- type WSAction
- type WSClient
- func (this *WSClient) AddContractFilter(contractAddress string) error
- func (this *WSClient) Close() error
- func (this *WSClient) Connect(address string) error
- func (this *WSClient) DelContractFilter(contractAddress string) error
- func (this *WSClient) GetActionCh() chan *WSAction
- func (this *WSClient) GetDefaultReqTimeout() time.Duration
- func (this *WSClient) GetHeartbeatInterval() int
- func (this *WSClient) GetHeartbeatTimeout() int
- func (this *WSClient) GetOnClose() func(address string)
- func (this *WSClient) GetOnConnect() func(address string)
- func (this *WSClient) GetOnError() func(address string, er error)
- func (this *WSClient) SetDefaultReqTimeout(timeout time.Duration)
- func (this *WSClient) SetHeartbeatInterval(interval int)
- func (this *WSClient) SetHeartbeatTimeout(timeout int)
- func (this *WSClient) SetOnClose(f func(address string))
- func (this *WSClient) SetOnConnect(f func(address string))
- func (this *WSClient) SetOnError(f func(address string, err error))
- func (this *WSClient) SubscribeBlock() error
- func (this *WSClient) SubscribeEvent() error
- func (this *WSClient) SubscribeTxHash() error
- func (this *WSClient) UnsubscribeBlock() error
- func (this *WSClient) UnsubscribeEvent() error
- func (this *WSClient) UnsubscribeTxHash() error
- type WSRequest
- type WSResponse
- type WSSubscribeStatus
Constants ¶
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" )
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" )
const ( WS_VERSION = "1.0.0" WS_ERROR_SUCCESS = 0 )
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" )
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" )
const (
ACTION_SEND_RAW_TRANSACTION = "sendrawtransaction"
)
const JSON_RPC_VERSION = "2.0"
JsonRpc version
const REST_VERSION = "1.0.0"
Variables ¶
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 (*ClientMgr) GetBlockByHeight ¶
func (*ClientMgr) GetBlockHash ¶
func (*ClientMgr) GetBlockHeightByTxHash ¶
func (*ClientMgr) GetBlockInfoByHeight ¶
func (*ClientMgr) GetBlockTxHashesByHeight ¶
func (this *ClientMgr) GetBlockTxHashesByHeight(height uint32) (*sdkcom.BlockTxHashes, error)
func (*ClientMgr) GetCurrentBlockHash ¶
func (*ClientMgr) GetCurrentBlockHeight ¶
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 (*ClientMgr) GetRestClient ¶
func (this *ClientMgr) GetRestClient() *RestClient
func (*ClientMgr) GetRpcClient ¶
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 (*ClientMgr) GetTransaction ¶
func (this *ClientMgr) GetTransaction(txHash string) (*types.Transaction, error)
func (*ClientMgr) GetVersion ¶
func (*ClientMgr) GetWebSocketClient ¶
func (*ClientMgr) NewRestClient ¶
func (this *ClientMgr) NewRestClient() *RestClient
func (*ClientMgr) NewRpcClient ¶
func (*ClientMgr) NewWebSocketClient ¶
func (*ClientMgr) PreExecTransaction ¶
func (this *ClientMgr) PreExecTransaction(mutTx *types.MutableTransaction) (*sdkcom.PreExecResult, error)
func (*ClientMgr) SendTransaction ¶
func (*ClientMgr) SetDefaultClient ¶
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 (*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 RestfulResp ¶
type RpcClient ¶
type RpcClient struct {
// contains filtered or unexported fields
}
RpcClient for dna rpc api
func (*RpcClient) SetAddress ¶
SetAddress set rpc server address. Simple http://localhost:20336
type WSClient ¶
type WSClient struct {
// contains filtered or unexported fields
}
func NewWSClient ¶
func NewWSClient() *WSClient
func (*WSClient) AddContractFilter ¶
func (*WSClient) DelContractFilter ¶
func (*WSClient) GetActionCh ¶
func (*WSClient) GetDefaultReqTimeout ¶
func (*WSClient) GetHeartbeatInterval ¶
func (*WSClient) GetHeartbeatTimeout ¶
func (*WSClient) GetOnClose ¶
func (*WSClient) GetOnConnect ¶
func (*WSClient) GetOnError ¶
func (*WSClient) SetDefaultReqTimeout ¶
func (*WSClient) SetHeartbeatInterval ¶
func (*WSClient) SetHeartbeatTimeout ¶
func (*WSClient) SetOnClose ¶
func (*WSClient) SetOnConnect ¶
func (*WSClient) SetOnError ¶
func (*WSClient) SubscribeBlock ¶
func (*WSClient) SubscribeEvent ¶
func (*WSClient) SubscribeTxHash ¶
func (*WSClient) UnsubscribeBlock ¶
func (*WSClient) UnsubscribeEvent ¶
func (*WSClient) UnsubscribeTxHash ¶
type WSRequest ¶
type WSRequest struct { Id string Params map[string]interface{} ResCh chan *WSResponse }
type WSResponse ¶
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