Giter VIP home page Giter VIP logo

tx-broadcast-monitoring's Introduction

Transaction Broadcasting and Monitoring Client

demo gif

Overview

Transaction Broadcasting and Monitoring Client, This tool is a console application that follows a design called hexagonal architecture. This design helps keep everything organized so it's easier to change things and test them without confusion. Basically, it helps you send out transactions and watch what happens to them, all through a user-friendly console. It's built to be straightforward and reliable, perfect for getting your transactions handled smoothly. Let's dive in and see how it works.

Features

  • Broadcast: send HTTP request with POST method for make a transaction with the server and store the TxHash into sqlite database.
  • Show Transaction: query and show the Transaction History with the transaction status(CONFIRMED,PENDING,FAILED and DNE)
  • Check Transaction: polling the Transaction Status from server and update into database

Installation

  1. Clone "Transaction Broadcast and Monitoring Client" repository project into your machine.
git clone https://github.com/dxckboi/tx-broadcast-monitoring.git
  1. configuration the config file or clone the example.yaml to config.yaml.
binance:
  url: https://testnet.binance.vision/api # binance api url
  api_key: KsjQtk5UH6nXIzaZo5mYORAgLbPXxJgr40pQ¡h×9HdeSN7fnShfYk4yFcqHC1bUo # binance api key
  secret_key: nT04uwYxeRKXCNB3MTQm6AIbS71H0TFEtlAwIpHMWOJM7MMyzT31bGnkTUKmST # binance secret key

broadcast:
  url: https://mock-node-wgqbnxruha-as.a.run.app # broadcast url
  check_status_interval: 10 # seconds
  1. Then run the following command for install Go dependencies.
go mod download
  1. Finally run the following command for start the application.
go run main.go

Usage

Here’s a simple example script that demonstrates how to use the Client Module to handle a transaction:

Handling Transaction Statuses

The methodology for checking/handling the transaction statuses, I used Long-Running Operations in the client site for polling the result from the Broadcast Server every 10 seconds by using github.com/go-co-op/gocron dependency for schedule the running task (you can config the polling range in config field check_status_interval) so you can see the handle method named func (h *handler) CheckTransaction().

type handler struct {
	service   domain.Service
	validator *validator.Validate
}

func NewHandler(service domain.Service) *handler {
	return &handler{
		service:   service,
		validator: validator.New(),
	}
}

func (h *handler) Run() {
	for {
		h.AskMenu()
	}
}

func (h *handler) AskMenu() {
	const (
		BROADCAST         = "Broadcast"
		SHOW_TRANSACTIONS = "Show Transactions"
		QUIT              = "Quit"
	)

	menuItems := []string{
		BROADCAST,
		SHOW_TRANSACTIONS,
		QUIT,
	}

	answer, err := prompt.New().Ask("Menu").Choose(menuItems)
	if err != nil {
		log.Panic().Err(err).Msg("Handler::AskMenu(): failed to retrieve answer")
	}

	switch answer {
	case BROADCAST:
		h.Broadcast()
	case SHOW_TRANSACTIONS:
		h.ShowTransactions()
	case QUIT:
		h.Quit()
	default:
		log.Error().Msg("Handler::AskMenu(): invalid answer")
		h.AskMenu()
	}
}

/* ...other function... */

func (h *handler) CheckTransaction() {
	conf := config.Get().Broadcast
	scheduler := gocron.NewScheduler(time.Local)
	scheduler.Every(conf.CheckStatusInterval).Seconds().Do(h.service.CheckTxPending)
	scheduler.StartAsync()
}

func (h *handler) Quit() {
	log.Info().Msg("Handler::Quit(): quitting")
	os.Exit(0)
}

tx-broadcast-monitoring's People

Contributors

dxckboi avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.