Nectarflower-go, nectar without nectar 2
Similar to my nectaflower-js library that I made for this post Use Nectar without using Hive-Nectar. I decided to show that what I'm working on can be incredibly useful to the hive community even those that wouldn't make use of hive-nectar.
So here is my attempt at the nectarflower-go library to make use of the json metadata from @nectarflower, that is updated hourly!
package main
import (
"fmt"
"log"
"github.com/thecrazygm/nectarflower-go/hive"
)
func main() {
// Create a client just to fetch nodes
client := hive.NewClient()
// Get nodes from account
nodeData, err := client.GetNodesFromAccount("nectarflower")
if err != nil {
log.Fatalf("Error fetching nodes: %v", err)
}
// Print the list of passing nodes
fmt.Println("Passing nodes:")
for _, node := range nodeData.Nodes {
fmt.Println(node)
}
}
But in order to make it work, it had to have a working client, so that is included as well, it's fairly crude, but does function. Here is an example of it grabbing the block 10 back from current head.
// Create a client
client := hive.NewClient()
// Get the current block number
var props map[string]any
err := client.Call("database_api.get_dynamic_global_properties", nil, &props)
if err != nil {
log.Fatalf("Error fetching global properties: %v", err)
}
// Convert to int64
currentBlockNum, ok := props["head_block_number"].(float64)
if !ok {
log.Fatalf("Error getting block number")
}
// Fetch a specific block
targetBlockNum := int64(currentBlockNum) - 10
blockParams := map[string]any{
"block_num": targetBlockNum,
}
var block map[string]any
err = client.Call("block_api.get_block", blockParams, &block)
if err != nil {
log.Fatalf("Error fetching block: %v", err)
}
// Access block data
blockData, ok := block["block"].(map[string]any)
if ok {
fmt.Printf("Block ID: %v\n", blockData["block_id"])
}
If you want to see the full example, it's in the github.
I'll continue doing what I love and hope that it maybe helps someone else out there. Plus, it's always great to learn new things, and I've been learning golang slowly over the last year or so. This just gave me a proper foot in the behind to get better at it.
As usual,
Michael Garcia a.k.a. TheCrazyGM
Pretty cool, although GO is not a very popular language.
Do you even VSC bro?
No, I VS enterprise bro.