当前位置: 首页>>代码示例>>Golang>>正文


Golang Cmd.Method方法代码示例

本文整理汇总了Golang中github.com/conformal/btcjson.Cmd.Method方法的典型用法代码示例。如果您正苦于以下问题:Golang Cmd.Method方法的具体用法?Golang Cmd.Method怎么用?Golang Cmd.Method使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/conformal/btcjson.Cmd的用法示例。


在下文中一共展示了Cmd.Method方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: marshalAndSendPost

// marshalAndSendPost marshals the passed command to JSON-RPC and sends it to
// the server by issuing an HTTP POST request and returns a response channel
// on which the reply will be delivered.  Typically a new connection is opened
// and closed for each command when using this method, however, the underlying
// HTTP client might coalesce multiple commands depending on several factors
// including the remote server configuration.
func (c *Client) marshalAndSendPost(cmd btcjson.Cmd, responseChan chan *futureResult) {
	marshalledJSON, err := json.Marshal(cmd)
	if err != nil {
		responseChan <- &futureResult{reply: nil, err: err}
		return
	}

	// Generate a request to the configured RPC server.
	protocol := "http"
	if !c.config.DisableTLS {
		protocol = "https"
	}
	url := protocol + "://" + c.config.Host
	req, err := http.NewRequest("POST", url, bytes.NewReader(marshalledJSON))
	if err != nil {
		responseChan <- &futureResult{reply: nil, err: err}
		return
	}
	req.Close = true
	req.Header.Set("Content-Type", "application/json")

	// Configure basic access authorization.
	req.SetBasicAuth(c.config.User, c.config.Pass)

	log.Tracef("Sending command [%s] with id %d", cmd.Method(), cmd.Id())
	c.sendPostRequest(req, cmd, responseChan)
}
开发者ID:GeertJohan,项目名称:btcrpcclient,代码行数:33,代码来源:infrastructure.go

示例2: standardCmdReply

// standardCmdReply checks that a parsed command is a standard
// Bitcoin JSON-RPC command and runs the proper handler to reply to the
// command.
func standardCmdReply(cmd btcjson.Cmd, s *rpcServer) (reply btcjson.Reply) {
	id := cmd.Id()
	reply.Id = &id

	handler, ok := rpcHandlers[cmd.Method()]
	if !ok {
		reply.Error = &btcjson.ErrMethodNotFound
		return reply
	}

	result, err := handler(s, cmd)
	if err != nil {
		jsonErr, ok := err.(btcjson.Error)
		if !ok {
			// In the case where we did not have a btcjson
			// error to begin with, make a new one to send,
			// but this really should not happen.
			jsonErr = btcjson.Error{
				Code:    btcjson.ErrInternal.Code,
				Message: err.Error(),
			}
		}
		reply.Error = &jsonErr
	} else {
		reply.Result = result
	}
	return reply
}
开发者ID:Nevtep,项目名称:mastercoind,代码行数:31,代码来源:rpcserver.go

示例3: respondToAnyCmd

// respondToAnyCmd checks that a parsed command is a standard or
// extension JSON-RPC command and runs the proper handler to reply to
// the command.  Any and all responses are sent to the wallet from
// this function.
func respondToAnyCmd(cmd btcjson.Cmd, s *rpcServer, wallet walletChan) {
	// Lookup the websocket extension for the command and if it doesn't
	// exist fallback to handling the command as a standard command.
	wsHandler, ok := wsHandlers[cmd.Method()]
	if !ok {
		reply := standardCmdReply(cmd, s)
		mreply, _ := json.Marshal(reply)
		wallet <- mreply
		return
	}

	// Call the appropriate handler which responds unless there was an
	// error in which case the error is marshalled and sent here.
	if err := wsHandler(s, cmd, wallet); err != nil {
		var reply btcjson.Reply
		jsonErr, ok := err.(btcjson.Error)
		if ok {
			reply.Error = &jsonErr
			mreply, _ := json.Marshal(reply)
			wallet <- mreply
			return
		}

		// In the case where we did not have a btcjson
		// error to begin with, make a new one to send,
		// but this really should not happen.
		jsonErr = btcjson.Error{
			Code:    btcjson.ErrInternal.Code,
			Message: err.Error(),
		}
		reply.Error = &jsonErr
		mreply, _ := json.Marshal(reply)
		wallet <- mreply
	}
}
开发者ID:Nevtep,项目名称:mastercoind,代码行数:39,代码来源:rpcwebsocket.go

示例4: handleBtcdConnectedNtfn

// handleBtcdConnectedNtfn handles btcwallet btcdconnected notifications,
// updating the GUI with info about whether btcd is connected to btcwallet
// or not.
func handleBtcdConnectedNtfn(n btcjson.Cmd) {
	bcn, ok := n.(*btcws.BtcdConnectedNtfn)
	if !ok {
		log.Printf("[ERR] %v handler: unexpected type", n.Method())
		return
	}

	updateChans.btcdConnected <- bcn.Connected
}
开发者ID:hsk81,项目名称:btcgui,代码行数:12,代码来源:updates.go

示例5: marshalAndSend

// marshalAndSend marshals the passed command to JSON-RPC and sends it to the
// server.  It returns a response channel on which the reply will be delivered.
func (c *Client) marshalAndSend(cmd btcjson.Cmd, responseChan chan *futureResult) {
	marshalledJSON, err := json.Marshal(cmd)
	if err != nil {
		responseChan <- &futureResult{reply: nil, err: err}
		return
	}

	log.Tracef("Sending command [%s] with id %d", cmd.Method(), cmd.Id())
	c.sendMessage(marshalledJSON)
}
开发者ID:GeertJohan,项目名称:btcrpcclient,代码行数:12,代码来源:infrastructure.go

示例6: handleBlockDisconnectedNtfn

// handleBlockDisconnectedNtfn handles btcd/btcwallet blockdisconnected
// notifications resulting from blocks disconnected from the main chain.
//
// TODO(jrick): handle this by rolling back tx history and balances.
func handleBlockDisconnectedNtfn(n btcjson.Cmd) {
	bdn, ok := n.(*btcws.BlockDisconnectedNtfn)
	if !ok {
		log.Printf("[ERR] %v handler: unexpected type", n.Method())
		return
	}

	// TODO
	_ = bdn
}
开发者ID:hsk81,项目名称:btcgui,代码行数:14,代码来源:updates.go

示例7: NtfnRescanProgress

// NtfnRescanProgress handles btcd rescanprogress notifications resulting
// from a partially completed rescan.
func NtfnRescanProgress(n btcjson.Cmd) error {
	cn, ok := n.(*btcws.RescanProgressNtfn)
	if !ok {
		return fmt.Errorf("%v handler: unexpected type", n.Method())
	}

	// Notify the rescan manager of the completed partial progress for
	// the current rescan.
	AcctMgr.rm.MarkProgress(cn.LastProcessed)

	return nil
}
开发者ID:GeertJohan,项目名称:btcwallet,代码行数:14,代码来源:ntfns.go

示例8: handleWalletLockStateNtfn

// handleWalletLockStateNtfn handles btcwallet walletlockstate notifications
// by updating the GUI with whether the wallet is locked or not, setting
// the sensitivity of various widgets for locking or unlocking the wallet.
func handleWalletLockStateNtfn(n btcjson.Cmd) {
	wlsn, ok := n.(*btcws.WalletLockStateNtfn)
	if !ok {
		log.Printf("[ERR] %v handler: unexpected type", n.Method())
		return
	}

	// TODO(jrick): do proper filtering and display all
	// account balances somewhere
	if wlsn.Account == "" {
		updateChans.lockState <- wlsn.Locked
	}
}
开发者ID:hsk81,项目名称:btcgui,代码行数:16,代码来源:updates.go

示例9: NtfnTxMined

// NtfnTxMined handles btcd notifications resulting from newly
// mined transactions that originated from this wallet.
func NtfnTxMined(n btcjson.Cmd, marshaled []byte) {
	tmn, ok := n.(*btcws.TxMinedNtfn)
	if !ok {
		log.Errorf("%v handler: unexpected type", n.Method())
		return
	}

	txid, err := btcwire.NewShaHashFromStr(tmn.TxID)
	if err != nil {
		log.Errorf("%v handler: invalid hash string", n.Method())
		return
	}
	blockhash, err := btcwire.NewShaHashFromStr(tmn.BlockHash)
	if err != nil {
		log.Errorf("%v handler: invalid block hash string", n.Method())
		return
	}

	err = accountstore.RecordMinedTx(txid, blockhash,
		tmn.BlockHeight, tmn.Index, tmn.BlockTime)
	if err != nil {
		log.Errorf("%v handler: %v", n.Method(), err)
		return
	}

	// Remove mined transaction from pool.
	UnminedTxs.Lock()
	delete(UnminedTxs.m, TXID(*txid))
	UnminedTxs.Unlock()
}
开发者ID:hsk81,项目名称:btcwallet,代码行数:32,代码来源:btcdrpc.go

示例10: handleAccountBalanceNtfn

// handleAccountBalanceNtfn handles btcwallet accountbalance notifications by
// updating the GUI with either a new confirmed or unconfirmed balance.
func handleAccountBalanceNtfn(n btcjson.Cmd) {
	abn, ok := n.(*btcws.AccountBalanceNtfn)
	if !ok {
		log.Printf("[ERR] %v handler: unexpected type", n.Method())
		return
	}

	// TODO(jrick): do proper filtering and display all
	// account balances somewhere
	if abn.Account == "" {
		if abn.Confirmed {
			updateChans.balance <- abn.Balance
		} else {
			updateChans.unconfirmed <- abn.Balance
		}
	}

}
开发者ID:hsk81,项目名称:btcgui,代码行数:20,代码来源:updates.go

示例11: NtfnBlockDisconnected

// NtfnBlockDisconnected handles btcd notifications resulting from
// blocks disconnected from the main chain in the event of a chain
// switch and notifies frontends of the new blockchain height.
func NtfnBlockDisconnected(n btcjson.Cmd, marshaled []byte) {
	bdn, ok := n.(*btcws.BlockDisconnectedNtfn)
	if !ok {
		log.Errorf("%v handler: unexpected type", n.Method())
		return
	}
	hash, err := btcwire.NewShaHashFromStr(bdn.Hash)
	if err != nil {
		log.Errorf("%v handler: invalid hash string", n.Method())
		return
	}

	// Rollback Utxo and Tx data stores.
	accountstore.Rollback(bdn.Height, hash)

	// Pass notification to frontends too.
	frontendNotificationMaster <- marshaled
}
开发者ID:hsk81,项目名称:btcwallet,代码行数:21,代码来源:btcdrpc.go

示例12: NtfnBlockDisconnected

// NtfnBlockDisconnected handles btcd notifications resulting from
// blocks disconnected from the main chain in the event of a chain
// switch and notifies frontends of the new blockchain height.
func NtfnBlockDisconnected(n btcjson.Cmd) error {
	bdn, ok := n.(*btcws.BlockDisconnectedNtfn)
	if !ok {
		return fmt.Errorf("%v handler: unexpected type", n.Method())
	}
	hash, err := btcwire.NewShaHashFromStr(bdn.Hash)
	if err != nil {
		return fmt.Errorf("%v handler: invalid hash string", n.Method())
	}

	// Rollback Utxo and Tx data stores.
	AcctMgr.Rollback(bdn.Height, hash)

	// Pass notification to frontends too.
	marshaled, _ := n.MarshalJSON()
	allClients <- marshaled

	return nil
}
开发者ID:GeertJohan,项目名称:btcwallet,代码行数:22,代码来源:ntfns.go

示例13: respondToAnyCmd

// respondToAnyCmd checks that a parsed command is a standard or
// extension JSON-RPC command and runs the proper handler to reply to
// the command.  Any and all responses are sent to the wallet from
// this function.
func respondToAnyCmd(cmd btcjson.Cmd, s *rpcServer, c handlerChans) *btcjson.Reply {
	// Lookup the websocket extension for the command and if it doesn't
	// exist fallback to handling the command as a standard command.
	wsHandler, ok := wsHandlers[cmd.Method()]
	if !ok {
		// No websocket-specific handler so handle like a legacy
		// RPC connection.
		response := standardCmdReply(cmd, s)
		return &response
	}
	result, jsonErr := wsHandler(s, cmd, c)
	id := cmd.Id()
	response := btcjson.Reply{
		Id:     &id,
		Result: result,
		Error:  jsonErr,
	}
	return &response
}
开发者ID:kawalgrover,项目名称:btcd,代码行数:23,代码来源:rpcwebsocket.go

示例14: handleTxNtfn

// handleTxNtfn handles btcwallet newtx notifications by updating the GUI
// with details about a new tx to or from wallet addresses.
func handleTxNtfn(n btcjson.Cmd) {
	tn, ok := n.(*btcws.TxNtfn)
	if !ok {
		log.Printf("[ERR] %v handler: unexpected type", n.Method())
		return
	}

	// TODO(jrick): do proper filtering and display
	// tx details for all accounts.
	if tn.Account == "" {
		attr, err := parseTxDetails(tn.Details)
		if err != nil {
			log.Printf("[ERR] %v handler: bad details: %v",
				n.Method(), err)
			return
		}
		updateChans.prependOverviewTx <- attr
		updateChans.prependTx <- attr
	}
}
开发者ID:hsk81,项目名称:btcgui,代码行数:22,代码来源:updates.go

示例15: NtfnBlockConnected

// NtfnBlockConnected handles btcd notifications resulting from newly
// connected blocks to the main blockchain.
//
// TODO(jrick): Send block time with notification.  This will be used
// to mark wallet files with a possibly-better earliest block height,
// and will greatly reduce rescan times for wallets created with an
// out of sync btcd.
func NtfnBlockConnected(n btcjson.Cmd) error {
	bcn, ok := n.(*btcws.BlockConnectedNtfn)
	if !ok {
		return fmt.Errorf("%v handler: unexpected type", n.Method())
	}
	hash, err := btcwire.NewShaHashFromStr(bcn.Hash)
	if err != nil {
		return fmt.Errorf("%v handler: invalid hash string", n.Method())
	}

	// Update the blockstamp for the newly-connected block.
	bs := &wallet.BlockStamp{
		Height: bcn.Height,
		Hash:   *hash,
	}
	curBlock.Lock()
	curBlock.BlockStamp = *bs
	curBlock.Unlock()

	// btcd notifies btcwallet about transactions first, and then sends
	// the new block notification.  New balance notifications for txs
	// in blocks are therefore sent here after all tx notifications
	// have arrived and finished being processed by the handlers.
	workers := NotifyBalanceRequest{
		block: *hash,
		wg:    make(chan *sync.WaitGroup),
	}
	NotifyBalanceSyncerChans.access <- workers
	if wg := <-workers.wg; wg != nil {
		wg.Wait()
		NotifyBalanceSyncerChans.remove <- *hash
	}
	AcctMgr.BlockNotify(bs)

	// Pass notification to frontends too.
	marshaled, _ := n.MarshalJSON()
	allClients <- marshaled

	return nil
}
开发者ID:GeertJohan,项目名称:btcwallet,代码行数:47,代码来源:ntfns.go


注:本文中的github.com/conformal/btcjson.Cmd.Method方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。