本文整理汇总了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;未经允许,请勿转载。 |
请发表评论