本文整理匯總了Golang中github.com/btcsuite/btcrpcclient.Client.GetBlockHash方法的典型用法代碼示例。如果您正苦於以下問題:Golang Client.GetBlockHash方法的具體用法?Golang Client.GetBlockHash怎麽用?Golang Client.GetBlockHash使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/btcsuite/btcrpcclient.Client
的用法示例。
在下文中一共展示了Client.GetBlockHash方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: 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.")
}
示例2: 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)))
}