common

package
v1.1.3-beta Latest Latest
Warning

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

Go to latest
Published: Jan 8, 2020 License: Apache-2.0 Imports: 19 Imported by: 12

Documentation

Index

Constants

View Source
const (
	BIT_JSONRPC   byte = 1
	BIT_WEBSOCKET byte = 2
)

Variables

View Source
var ErrMessage = map[ErrCode]string{
	SUCCESS:                 "SUCCESS",
	SESSION_EXPIRED:         "SESSION EXPIRED",
	SERVICE_CEILING:         "SERVICE CEILING",
	ILLEGAL_DATAFORMAT:      "ILLEGAL DATAFORMAT",
	INVALID_METHOD:          "INVALID METHOD",
	INVALID_PARAMS:          "INVALID PARAMS",
	INVALID_TOKEN:           "VERIFY TOKEN ERROR",
	INVALID_TRANSACTION:     "INVALID TRANSACTION",
	INVALID_ASSET:           "INVALID ASSET",
	INVALID_BLOCK:           "INVALID BLOCK",
	INVALID_HASH:            "INVALID HASH",
	INVALID_VERSION:         "INVALID VERSION",
	UNKNOWN_TRANSACTION:     "UNKNOWN TRANSACTION",
	UNKNOWN_ASSET:           "UNKNOWN ASSET",
	UNKNOWN_BLOCK:           "UNKNOWN BLOCK",
	UNKNOWN_HASH:            "UNKNOWN HASH",
	INTERNAL_ERROR:          "INTERNAL ERROR",
	SMARTCODE_ERROR:         "SMARTCODE EXEC ERROR",
	WRONG_NODE:              "WRONG NODE TO CONNECT",
	ErrDuplicatedTx:         "INTERNAL ERROR, Duplicate transaction",
	ErrDuplicateInput:       "INTERNAL ERROR, ErrDuplicateInput",
	ErrAssetPrecision:       "INTERNAL ERROR, ErrAssetPrecision",
	ErrTransactionBalance:   "INTERNAL ERROR, ErrTransactionBalance",
	ErrAttributeProgram:     "INTERNAL ERROR, ErrAttributeProgram",
	ErrTransactionContracts: "INTERNAL ERROR, ErrTransactionContracts",
	ErrTransactionPayload:   "INTERNAL ERROR, ErrTransactionPayload",
	ErrDoubleSpend:          "INTERNAL ERROR, ErrDoubleSpend",
	ErrTxHashDuplicate:      "INTERNAL ERROR, ErrTxHashDuplicate",
	ErrStateUpdaterVaild:    "INTERNAL ERROR, ErrStateUpdaterVaild",
	ErrSummaryAsset:         "INTERNAL ERROR, ErrSummaryAsset",
	ErrXmitFail:             "INTERNAL ERROR, ErrXmitFail",
	ErrAppendTxnPool:        "INTERNAL ERROR, can not append tx to txpool",
	ErrNullID:               "INTERNAL ERROR, there is no ID in account",
	ErrZeroID:               "INTERNAL ERROR, it's zero ID in account",
	ErrNullDB:               "INTERNAL ERROR, DB service is unavailable",
}
View Source
var InitialAPIHandlers = map[string]APIHandler{
	"getlatestblockhash":   {Handler: getLatestBlockHash, AccessCtrl: BIT_JSONRPC},
	"getblock":             {Handler: getBlock, AccessCtrl: BIT_JSONRPC | BIT_WEBSOCKET},
	"getblockcount":        {Handler: getBlockCount, AccessCtrl: BIT_JSONRPC},
	"getlatestblockheight": {Handler: getLatestBlockHeight, AccessCtrl: BIT_JSONRPC | BIT_WEBSOCKET},
	"getblocktxsbyheight":  {Handler: getBlockTxsByHeight, AccessCtrl: BIT_JSONRPC},
	"getconnectioncount":   {Handler: getConnectionCount, AccessCtrl: BIT_JSONRPC | BIT_WEBSOCKET},
	"getrawmempool":        {Handler: getRawMemPool, AccessCtrl: BIT_JSONRPC},
	"gettransaction":       {Handler: getTransaction, AccessCtrl: BIT_JSONRPC | BIT_WEBSOCKET},
	"sendrawtransaction":   {Handler: sendRawTransaction, AccessCtrl: BIT_JSONRPC | BIT_WEBSOCKET},
	"getwsaddr":            {Handler: getWsAddr, AccessCtrl: BIT_JSONRPC},
	"getwssaddr":           {Handler: getWssAddr, AccessCtrl: BIT_JSONRPC},
	"getversion":           {Handler: getVersion, AccessCtrl: BIT_JSONRPC},
	"getneighbor":          {Handler: getNeighbor, AccessCtrl: BIT_JSONRPC},
	"getnodestate":         {Handler: getNodeState, AccessCtrl: BIT_JSONRPC},
	"getchordringinfo":     {Handler: getChordRingInfo, AccessCtrl: BIT_JSONRPC},
	"setdebuginfo":         {Handler: setDebugInfo},
	"getbalancebyaddr":     {Handler: getBalanceByAddr, AccessCtrl: BIT_JSONRPC},
	"getbalancebyassetid":  {Handler: GetBalanceByAssetID, AccessCtrl: BIT_JSONRPC},
	"getnoncebyaddr":       {Handler: getNonceByAddr, AccessCtrl: BIT_JSONRPC},
	"getid":                {Handler: getId, AccessCtrl: BIT_JSONRPC},
	"getaddressbyname":     {Handler: getAddressByName, AccessCtrl: BIT_JSONRPC},
	"getsubscription":      {Handler: getSubscription, AccessCtrl: BIT_JSONRPC},
	"getsubscribers":       {Handler: getSubscribers, AccessCtrl: BIT_JSONRPC},
	"getsubscriberscount":  {Handler: getSubscribersCount, AccessCtrl: BIT_JSONRPC},
	"getasset":             {Handler: getAsset, AccessCtrl: BIT_JSONRPC},
	"getmyextip":           {Handler: getMyExtIP, AccessCtrl: BIT_JSONRPC},
	"findsuccessoraddr":    {Handler: findSuccessorAddr, AccessCtrl: BIT_JSONRPC},
	"findsuccessoraddrs":   {Handler: findSuccessorAddrs, AccessCtrl: BIT_JSONRPC},
}

Functions

func GetBalanceByAssetID

func GetBalanceByAssetID(s Serverer, params map[string]interface{}) map[string]interface{}

getBalanceByAssetID gets balance by address params: {"address":<address>, "assetid":<assetid>} return: {"resultOrData":<result>|<error data>, "error":<errcode>}

func GetBlockTransactions

func GetBlockTransactions(block *block.Block) interface{}

func MakeDeleteNameTransaction

func MakeDeleteNameTransaction(wallet vault.Wallet, name string, nonce uint64, fee Fixed64) (*transaction.Transaction, error)

func MakeGenerateIDTransaction

func MakeGenerateIDTransaction(ctx context.Context, wallet vault.Wallet, regFee Fixed64, nonce uint64, txnFee Fixed64, maxTxnHash Uint256) (*transaction.Transaction, error)

func MakeIssueAssetTransaction

func MakeIssueAssetTransaction(wallet vault.Wallet, name, symbol string, totalSupply Fixed64, precision uint32, nonce uint64, fee Fixed64) (*transaction.Transaction, error)

func MakeNanoPayTransaction

func MakeNanoPayTransaction(wallet vault.Wallet, recipient Uint160, id uint64, amount Fixed64, txnExpiration, nanoPayExpiration uint32) (*transaction.Transaction, error)

func MakeRegisterNameTransaction

func MakeRegisterNameTransaction(wallet vault.Wallet, name string, nonce uint64, fee Fixed64) (*transaction.Transaction, error)

func MakeSigChainTransaction

func MakeSigChainTransaction(wallet vault.Wallet, sigChain []byte, nonce uint64) (*transaction.Transaction, error)

func MakeSubscribeTransaction

func MakeSubscribeTransaction(wallet vault.Wallet, identifier string, topic string, duration uint32, meta string, nonce uint64, fee Fixed64) (*transaction.Transaction, error)

func MakeTransferTransaction

func MakeTransferTransaction(wallet vault.Wallet, receipt Uint160, nonce uint64, value, fee Fixed64) (*transaction.Transaction, error)

func MakeUnsubscribeTransaction

func MakeUnsubscribeTransaction(wallet vault.Wallet, identifier string, topic string, nonce uint64, fee Fixed64) (*transaction.Transaction, error)

func NodeInfo

func NodeInfo(addr string, pubkey, id []byte) map[string]string

func RespPacking

func RespPacking(result interface{}, errcode ErrCode) map[string]interface{}

func ResponsePack

func ResponsePack(errCode ErrCode) map[string]interface{}

Types

type APIHandler

type APIHandler struct {
	Handler    Handler
	AccessCtrl byte
}

func (*APIHandler) IsAccessableByJsonrpc

func (ah *APIHandler) IsAccessableByJsonrpc() bool

IsAccessableByJsonrpc return true if the handler is able to be invoked by jsonrpc

func (*APIHandler) IsAccessableByWebsocket

func (ah *APIHandler) IsAccessableByWebsocket() bool

IsAccessableByWebsocket return true if the handler is able to be invoked by websocket

type ErrCode

type ErrCode int64
const (
	SUCCESS                  ErrCode = 0
	SESSION_EXPIRED          ErrCode = 41001
	SERVICE_CEILING          ErrCode = 41002
	ILLEGAL_DATAFORMAT       ErrCode = 41003
	INVALID_METHOD           ErrCode = 42001
	INVALID_PARAMS           ErrCode = 42002
	INVALID_TOKEN            ErrCode = 42003
	INVALID_TRANSACTION      ErrCode = 43001
	INVALID_ASSET            ErrCode = 43002
	INVALID_BLOCK            ErrCode = 43003
	INVALID_HASH             ErrCode = 43004
	INVALID_VERSION          ErrCode = 43005
	UNKNOWN_TRANSACTION      ErrCode = 44001
	UNKNOWN_ASSET            ErrCode = 44002
	UNKNOWN_BLOCK            ErrCode = 44003
	UNKNOWN_HASH             ErrCode = 44004
	INTERNAL_ERROR           ErrCode = 45001
	SMARTCODE_ERROR          ErrCode = 47001
	WRONG_NODE               ErrCode = 48001
	ErrNoCode                ErrCode = -2
	ErrNoError               ErrCode = 0
	ErrUnknown               ErrCode = -1
	ErrDuplicatedTx          ErrCode = 1
	ErrInputOutputTooLong    ErrCode = 45002
	ErrDuplicateInput        ErrCode = 45003
	ErrAssetPrecision        ErrCode = 45004
	ErrTransactionBalance    ErrCode = 45005
	ErrAttributeProgram      ErrCode = 45006
	ErrTransactionContracts  ErrCode = 45007
	ErrTransactionPayload    ErrCode = 45008
	ErrDoubleSpend           ErrCode = 45009
	ErrTxHashDuplicate       ErrCode = 45010
	ErrStateUpdaterVaild     ErrCode = 45011
	ErrSummaryAsset          ErrCode = 45012
	ErrXmitFail              ErrCode = 45013
	ErrDuplicateName         ErrCode = 45015
	ErrMineReward            ErrCode = 45016
	ErrDuplicateSubscription ErrCode = 45017
	ErrSubscriptionLimit     ErrCode = 45018
	ErrDoNotPropagate        ErrCode = 45019
	ErrAlreadySubscribed     ErrCode = 45020
	ErrAppendTxnPool         ErrCode = 45021
	ErrNullID                ErrCode = 45022
	ErrZeroID                ErrCode = 45023
	ErrNullDB                ErrCode = 45024
)

func VerifyAndSendTx

func VerifyAndSendTx(localNode *node.LocalNode, txn *transaction.Transaction) (ErrCode, error)

type Error

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

func (*Error) Code

func (e *Error) Code() ErrCode

func (*Error) Error

func (e *Error) Error() string

type ErrorWithCode

type ErrorWithCode interface {
	error
	Code() ErrCode
}

func NewError

func NewError(code ErrCode, msg ...string) ErrorWithCode

type Handler

type Handler func(Serverer, map[string]interface{}) map[string]interface{}

type Serverer

type Serverer interface {
	GetNetNode() *node.LocalNode
}

Jump to

Keyboard shortcuts

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