本文整理汇总了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)))
}