// Subscribe to pending transactions from a standard fullnode.
Subscribe to pending transactions from a standard fullnode.
// Subscribe to pending transactions from a standard fullnode .
func main() {
	fullNodeUrl := flag.String("fullnode", os.Getenv("FULLNODE_URL"), "The fullnode URL")
	outputFile := flag.String("output", "fullnode-block.json", "The output file")
	flag.Parse()
	if *fullNodeUrl == "" || *outputFile == "" {
		flag.Usage()
		return
	}
	signals := make(chan os.Signal, 1)
	signal.Notify(signals, syscall.SIGINT, syscall.SIGTERM)
	stopCh := make(chan struct{})
	blockHashCh, err := clients.SubscribeBlockHash(*fullNodeUrl, stopCh)
	if err != nil {
		log.Fatal(err)
	}
	jsonCh := make(chan map[string]common.Hash)
	go func() {
		for blockHash := range blockHashCh {
			jsonMap := make(map[string]common.Hash)
			jsonMap["hash"] = blockHash
			jsonCh <- jsonMap
		}
		close(jsonCh)
	}()
	go utils.Run(jsonCh, stopCh, *outputFile)
	<-signals
	log.Println("Ctrl+C detected, exiting...")
	close(stopCh)
	time.Sleep(1 * time.Second) 
}
func main ( ) { fullNodeUrl := flag . String ( " " , os . Getenv ( " " ) , " " ) outputFile := flag . String ( " " , " " , " " ) flag . Parse ( ) if * fullNodeUrl == " " || * outputFile == " " { flag . Usage ( ) return } signals := make ( chan os . Signal , 1 ) signal . Notify ( signals , syscall . SIGINT , syscall . SIGTERM ) stopCh := make ( chan struct { } ) blockHashCh , err := clients . SubscribeBlockHash ( * fullNodeUrl , stopCh ) if err != nil { log . Fatal ( err ) } jsonCh := make ( chan map [ string ] common . Hash ) go func ( ) { for blockHash := range blockHashCh { jsonMap := make ( map [ string ] common . Hash ) jsonMap [ " " ] = blockHash jsonCh <- jsonMap } close ( jsonCh ) } ( ) go utils . Run ( jsonCh , stopCh , * outputFile ) <- signals log . Println ( " " ) close ( stopCh ) time . Sleep ( 1 * time . Second ) }
Subscribe to pending transactions from a standard fullnode.
Subscribe to pending transactions from a standard fullnode .
// catch Ctrl+C // put into a map // give some time for other goroutines to stop