如何通过blockNumber获取transactionHash?
我输入了 block.transactions.0.transactionHash 但没有捕捉到它(空字符串)。我怎样才能得到交易哈希?
func GetBlockTransactions(number int) string {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
var hashHeaders []models.Block
defer cancel()
options := options.Find().SetProjection(bson.M{"block.transactions.0.transactionHash": 1})
options.SetLimit(1)
results, err := blocksCollections.Find(ctx, bson.M{"block.header.blockNumber": strconv.Itoa(number)}, options)
if err != nil {
fmt.Println(err)
}
//reading from the db in an optimal way
defer results.Close(ctx)
for results.Next(ctx) {
var singleHashHeader models.Block
if err = results.Decode(&singleHashHeader); err != nil {
fmt.Println(err)
}
hashHeaders = append(hashHeaders, singleHashHeader)
}
fmt.Println("%v", hashHeaders[0].Transactions.TransactionHash)
return string(hashHeaders[0].Transactions.TransactionHash)
}
慕田峪9158850
相关分类