utils

Last updated: 2024-11-07 21:04:56.691540 File source: link on GitLab

utils

Table of Contents

Specification

Description

This package contains utility tools and functionalities used by other packages

Structure and Organisation

Here is quick overview of the contents of this directory:

  • README: Current file which is aimed towards developers who wish to use and modify the package functionality.

  • blockchain: This file contains methods and data types related to interaction with blockchain.

  • file_system: This file contains a method to retrieve the size of the volume.

  • init: This file initializes an Open Telemetry logger for this package. It also defines constants to reflect the status of transaction.

  • network: This file contains helper methods for DMS API calls and responses.

  • progress_io: This file defines wrapper functions for readers and writers with progress tracking capabilities.

  • syncmap: This file defines a SyncMap type which is a thread-safe version of the standard Go map with strongly-typed methods and functions for managing key-value pairs concurrently.

  • utils: This file contains various utility functions for the DMS functionality.

  • validate: This contains helper functions that perform different kinds of validation checks and numeric conversions.

  • specs: This folder contains the class diagram for the package.

Files with *_test.go naming contains unit tests of the specified functionality.

Class Diagram

Source File

utils Class Diagram

Rendered from source file

!$rootUrlGitlab = "https://gitlab.com/nunet/device-management-service/-/raw/main"
!$packageRelativePath = "/utils"
!$packageUrlGitlab = $rootUrlGitlab + $packageRelativePath
 
!include $packageUrlGitlab/specs/class_diagram.puml

Functionality

utils package defines various helper methods for functionality defined in the different packages of DMS. Refer to utils.go for details.

Data Types

Blockchain data models

  • utils.UTXOs: TBD

type UTXOs struct {
	TxHash  string `json:"tx_hash"`
	IsSpent bool   `json:"is_spent"`
}
  • utils.TxHashResp: TBD

type TxHashResp struct {
	TxHash          string `json:"tx_hash"`
	TransactionType string `json:"transaction_type"`
	DateTime        string `json:"date_time"`
}
  • utils.ClaimCardanoTokenBody: TBD

type ClaimCardanoTokenBody struct {
	ComputeProviderAddress string `json:"compute_provider_address"`
	TxHash                 string `json:"tx_hash"`
}
  • utils.rewardRespToCPD: TBD

type rewardRespToCPD struct {
	ServiceProviderAddr string `json:"service_provider_addr"`
	ComputeProviderAddr string `json:"compute_provider_addr"`
	RewardType          string `json:"reward_type,omitempty"`
	SignatureDatum      string `json:"signature_datum,omitempty"`
	MessageHashDatum    string `json:"message_hash_datum,omitempty"`
	Datum               string `json:"datum,omitempty"`
	SignatureAction     string `json:"signature_action,omitempty"`
	MessageHashAction   string `json:"message_hash_action,omitempty"`
	Action              string `json:"action,omitempty"`
}
  • utils.UpdateTxStatusBody: TBD

type UpdateTxStatusBody struct {
	Address string `json:"address,omitempty"`
}

progress_io data models

  • utils.IOProgress: TBD

type IOProgress struct {
	n         float64
	size      float64
	started   time.Time
	estimated time.Time
	err       error
}
  • utils.Reader: TBD

type Reader struct {
	reader   io.Reader
	lock     sync.RWMutex
	Progress IOProgress
}
  • utils.Writer: TBD

type Writer struct {
	writer   io.Writer
	lock     sync.RWMutex
	Progress IOProgress
}

syncmap data models

  • utils.SyncMap: a concurrency-safe sync.Map that uses strongly-typed method signatures to ensure the types of its stored data are known.

type SyncMap[K comparable, V any] struct {
	sync.Map
}

Testing

The unit tests for the functionality are defined in network_test.go and utils_test.go files.

Proposed Functionality / Requirements

List of issues related to the implementation of the utils package can be found below. These include proposals for modifications to the package or new functionality needed to cover the requirements of other packages.

References

Last updated