當前位置: 首頁>>代碼示例>>Golang>>正文


Golang btcrpcclient.Client類代碼示例

本文整理匯總了Golang中github.com/btcsuite/btcrpcclient.Client的典型用法代碼示例。如果您正苦於以下問題:Golang Client類的具體用法?Golang Client怎麽用?Golang Client使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Client類的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: getInfo

func getInfo(client *btcrpcclient.Client) {
	// getinfo demo
	info, err := client.GetInfo()
	if err != nil {
		logger.Crit(err.Error())
	}
	logger.Info(fmt.Sprintf("Bitcoind Info: %v", spew.Sdump(info)))

}
開發者ID:dyzz,項目名稱:gobtclib,代碼行數:9,代碼來源:main.go

示例2: makeDestinationScriptSource

// makeDestinationScriptSource creates a ChangeSource which is used to receive
// all correlated previous input value.  A non-change address is created by this
// function.
func makeDestinationScriptSource(rpcClient *btcrpcclient.Client, accountName string) txauthor.ChangeSource {
	return func() ([]byte, error) {
		destinationAddress, err := rpcClient.GetNewAddress(accountName)
		if err != nil {
			return nil, err
		}
		return txscript.PayToAddrScript(destinationAddress)
	}
}
開發者ID:justusranvier,項目名稱:btcwallet,代碼行數:12,代碼來源:main.go

示例3: checkBlock

func checkBlock(client *btcrpcclient.Client, blockNum int64) {
	blockHash, err := client.GetBlockHash(653895)
	if err != nil {
		logger.Crit(err.Error())
		return
	}
	block, err := client.GetBlock(blockHash)
	if err != nil {
		logger.Crit(err.Error())
		return
	}

	txs := block.Transactions()

	var processedBlock = &message.ProcessedBlock{make([]*message.ProcessedTx, len(txs))}

	logger.Info("Processing txs...")
	for txIndex, tx := range txs {
		vouts := tx.MsgTx().TxOut
		result := make([]*message.TxResult, len(vouts))
		for i, vout := range vouts {
			addr := NewAddrFromPkScript(vout.PkScript, true)
			if addr != nil {
				result[i] = &message.TxResult{
					&message.TxResult_Transfer{
						&message.ValueTransfer{
							addr.String(),
							int32(vout.Value),
						},
					},
				}
			} else {
				result[i] = &message.TxResult{
					&message.TxResult_Msg{
						&message.OpReturnMsg{string(decodePkScript(vout.PkScript))},
					},
				}
			}
		}
		processedBlock.Txs[txIndex] = &message.ProcessedTx{
			tx.Sha().String(),
			result,
		}
	}
	spew.Dump(processedBlock)
	data, err := proto.Marshal(processedBlock)
	if err != nil {
		logger.Crit(err.Error())
	} else {
		logger.Info("Publish to ZMQ...")
		spew.Dump(sender)
		sender.SendBytes(data, 0)
	}
	logger.Info("Process done.")
}
開發者ID:dyzz,項目名稱:gobtclib,代碼行數:55,代碼來源:main.go

示例4: LookupAddress

// LookupAddress returns the minimum balance of the specified address for the last dur amount of time.
func LookupAddress(c *btcrpcclient.Client, addr btcutil.Address, dur time.Duration) (float64, error) {
	more := true
	offset := 0
	for more {
		more = false
		txs, err := c.SearchRawTransactionsVerbose(addr, offset, 1000, false, false, nil)
		if err != nil {
			return 0, err
		}
		if len(txs) == 1000 {
			more = true
			offset += 1000
		}
		for _, tx := range txs {
			_ = tx
		}
	}
	return 0, nil
}
開發者ID:d4l3k,項目名稱:btcinterned,代碼行數:20,代碼來源:interned.go

示例5: poolUtxos

// poolUtxos receives a new block notification from the node server
// and pools the newly mined utxos to the corresponding actor's a.utxo
func (com *Communication) poolUtxos(client *rpc.Client, actors []*Actor) {
	defer com.wg.Done()
	// Update utxo pool on each block connected
	for {
		select {
		case b, ok := <-com.blockQueue.dequeue:
			if !ok {
				return
			}
			block, err := client.GetBlock(b.hash)
			if err != nil {
				log.Printf("Cannot get block: %v", err)
				return
			}
			// add new outputs to unspent pool
			for i, tx := range block.Transactions() {
			next:
				for n, vout := range tx.MsgTx().TxOut {
					if i == 0 {
						// in case of coinbase tx, add it to coinbase queue
						// if the chan is full, the first tx would be mature
						// so add it to the pool
						select {
						case com.coinbaseQueue <- tx:
							break next
						default:
							// dequeue the first mature tx
							mTx := <-com.coinbaseQueue
							// enqueue the latest tx
							com.coinbaseQueue <- tx
							// we'll process the mature tx next
							// so point tx to mTx
							tx = mTx
							// reset vout as per the new tx
							vout = tx.MsgTx().TxOut[n]
						}
					}
					// fetch actor who owns this output
					var actor *Actor
					if len(actors) == 1 {
						actor = actors[0]
					} else {
						actor, err = com.getActor(actors, vout)
						if err != nil {
							log.Printf("Cannot get actor: %v", err)
							continue next
						}
					}
					txout := com.getUtxo(tx, vout, uint32(n))
					// to be usable, the utxo amount should be
					// split-able after deducting the fee
					if txout.Amount > btcutil.Amount((*maxSplit))*(minFee) {
						// if it's usable, add utxo to actor's pool
						select {
						case actor.utxoQueue.enqueue <- txout:
						case <-com.exit:
						}
					}
				}
			}
			// allow Communicate to sync with the processed block
			if b.height == int32(*startBlock)-1 {
				select {
				case com.blockQueue.processed <- b:
				case <-com.exit:
					return
				}
			}
			if b.height >= int32(*startBlock) {
				var txCount, utxoCount int
				for _, a := range actors {
					utxoCount += len(a.utxoQueue.utxos)
				}
				txCount = len(block.Transactions())
				log.Printf("Block %s (height %d) attached with %d transactions", b.hash, b.height, txCount)
				log.Printf("%d transaction outputs available to spend", utxoCount)
				select {
				case com.blockQueue.processed <- b:
				case <-com.exit:
					return
				}
				select {
				case com.blockTxCount <- txCount:
				case <-com.exit:
					return
				}
			}
		case <-com.exit:
			return
		}
	}
}
開發者ID:stormasm,項目名稱:btcsim1020,代碼行數:94,代碼來源:comm.go

示例6: checkBlock

func checkBlock(client *btcrpcclient.Client, blockNum int64) {
	blockHash, err := client.GetBlockHash(blockNum)
	if err != nil {
		logger.Crit(err.Error())
		return
	}
	block, err := client.GetBlock(blockHash)
	if err != nil {
		logger.Crit(err.Error())
		return
	}

	txs := block.Transactions()

	var processedBlock = &message.ProcessedBlock{
		int32(blockNum),
		make([]*message.ProcessedTx, 0),
	}

	logger.Info("Processing txs...")
	start := time.Now()
	var wg sync.WaitGroup
	for txIndex, tx := range txs {
		wg.Add(1)
		go func(txIndex int, tx *btcutil.Tx) {
			defer wg.Done()
			vouts := tx.MsgTx().TxOut
			result := make([]*message.TxResult, len(vouts))
			hasReturn := false
			for i, vout := range vouts {
				btcAddr := addr.NewAddrFromPkScript(vout.PkScript, isTestnet)
				if btcAddr != nil {
					result[i] = &message.TxResult{
						&message.TxResult_Transfer{
							&message.ValueTransfer{
								btcAddr.String(),
								uint64(vout.Value),
							},
						},
					}
				} else {
					msg := decodePkScript(vout.PkScript)
					if msg != nil {
						result[i] = &message.TxResult{
							&message.TxResult_Msg{
								&message.OpReturnMsg{string(msg)},
							},
						}
						hasReturn = true
					}
				}
			}
			if hasReturn {
				processedBlock.Txs = append(processedBlock.Txs,
					&message.ProcessedTx{
						tx.Sha().String(),
						result,
					})
			}
		}(txIndex, tx)
	}
	wg.Wait()
	spew.Dump(processedBlock)
	data, err := proto.Marshal(processedBlock)
	if err != nil {
		logger.Crit(err.Error())
	} else {
		logger.Info("Publish to ZMQ...")
		spew.Dump(data)
		sender.SendBytes(data, 0)
	}
	elapsed := time.Since(start)
	logger.Info(fmt.Sprintf("Process done in %s", elapsed))
	logger.Info(fmt.Sprintf("Block %d has %d OP_Return Txs", blockNum, len(processedBlock.Txs)))
}
開發者ID:libreoscar,項目名稱:btcwatch,代碼行數:75,代碼來源:main.go


注:本文中的github.com/btcsuite/btcrpcclient.Client類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。