common

package
v0.3.14-alpha Latest Latest
Warning

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

Go to latest
Published: Oct 2, 2018 License: Apache-2.0 Imports: 20 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",
	ErrCode(errors.ErrDuplicateInput):       "INTERNAL ERROR, ErrDuplicateInput",
	ErrCode(errors.ErrAssetPrecision):       "INTERNAL ERROR, ErrAssetPrecision",
	ErrCode(errors.ErrTransactionBalance):   "INTERNAL ERROR, ErrTransactionBalance",
	ErrCode(errors.ErrAttributeProgram):     "INTERNAL ERROR, ErrAttributeProgram",
	ErrCode(errors.ErrTransactionContracts): "INTERNAL ERROR, ErrTransactionContracts",
	ErrCode(errors.ErrTransactionPayload):   "INTERNAL ERROR, ErrTransactionPayload",
	ErrCode(errors.ErrDoubleSpend):          "INTERNAL ERROR, ErrDoubleSpend",
	ErrCode(errors.ErrTxHashDuplicate):      "INTERNAL ERROR, ErrTxHashDuplicate",
	ErrCode(errors.ErrStateUpdaterVaild):    "INTERNAL ERROR, ErrStateUpdaterVaild",
	ErrCode(errors.ErrSummaryAsset):         "INTERNAL ERROR, ErrSummaryAsset",
	ErrCode(errors.ErrXmitFail):             "INTERNAL ERROR, ErrXmitFail",
}
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},
	"getversion":           {Handler: getVersion, AccessCtrl: BIT_JSONRPC},
	"getneighbor":          {Handler: getNeighbor, AccessCtrl: BIT_JSONRPC},
	"getnodestate":         {Handler: getNodeState, AccessCtrl: BIT_JSONRPC},
	"getchordringinfo":     {Handler: getChordRingInfo, AccessCtrl: BIT_JSONRPC},
	"getunspendoutput":     {Handler: getUnspendOutput, AccessCtrl: BIT_JSONRPC},
	"getbalance":           {Handler: getBalance, AccessCtrl: BIT_JSONRPC},
	"setdebuginfo":         {Handler: setDebugInfo},
	"registasset":          {Handler: registAsset},
	"issueasset":           {Handler: issueAsset},
	"sendtoaddress":        {Handler: sendToAddress},
	"prepaidasset":         {Handler: prepaidAsset},
	"registername":         {Handler: registerName, AccessCtrl: BIT_JSONRPC},
	"deletename":           {Handler: deleteName, AccessCtrl: BIT_JSONRPC},
	"withdrawasset":        {Handler: withdrawAsset},
	"commitpor":            {Handler: commitPor},
	"sigchaintest":         {Handler: sigchaintest},
	"gettotalissued":       {Handler: getTotalIssued},
	"getassetbyhash":       {Handler: getAssetByHash},
	"getbalancebyaddr":     {Handler: getBalanceByAddr},
	"getbalancebyasset":    {Handler: getBalanceByAsset},
	"getunspends":          {Handler: getUnspends},
}

Functions

func GetBlockTransactions

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

func MakeCommitTransaction

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

func MakeDeleteNameTransaction

func MakeDeleteNameTransaction(wallet vault.Wallet) (*transaction.Transaction, error)

func MakeIssueTransaction

func MakeIssueTransaction(wallet vault.Wallet, assetID Uint256, address string, value string) (*transaction.Transaction, error)

func MakePrepaidTransaction

func MakePrepaidTransaction(wallet vault.Wallet, assetID Uint256, value, rates string) (*transaction.Transaction, error)

func MakeRegTransaction

func MakeRegTransaction(wallet vault.Wallet, name string, value string) (*transaction.Transaction, error)

func MakeRegisterNameTransaction

func MakeRegisterNameTransaction(wallet vault.Wallet, name string) (*transaction.Transaction, error)

func MakeTransferTransaction

func MakeTransferTransaction(wallet vault.Wallet, assetID Uint256, batchOut ...BatchOut) (*transaction.Transaction, error)

func MakeWithdrawTransaction

func MakeWithdrawTransaction(wallet vault.Wallet, assetID Uint256, value string) (*transaction.Transaction, error)

func RespPacking

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

func ResponsePack

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

func VerifyAndSendTx

func VerifyAndSendTx(n protocol.Noder, txn *transaction.Transaction) errors.ErrCode

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 BatchOut

type BatchOut struct {
	Address string
	Value   string
}

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
)

type Handler

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

type Serverer

type Serverer interface {
	GetNetNode() (protocol.Noder, error)
	GetWallet() (vault.Wallet, error)
}

Jump to

Keyboard shortcuts

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