rubixchain / rubixgoplatform

GNU General Public License v3.0
8 stars 17 forks source link

Improve Readability of Token Chain Dump Output #190

Closed gklps closed 2 weeks ago

gklps commented 1 month ago

Improve Readability of Token Chain Dump Output

This PR addresses the issue of handling dump.json in JSON data transformation functions and ensures human readability of Token Chain Dump output

Summary

The primary objective of this PR is to fix the panic caused by type assertions when dealing with map[interface{}]interface{} and to enhance the existing flattenKeys and applyKeyMapping functions to handle these cases correctly.

Changes Made

  1. Conversion Function: Introduced convertMap to convert map[interface{}]interface{} to map[string]interface{}.
  2. Updated Functions: Modified flattenKeys and applyKeyMapping functions to handle both map[string]interface{} and map[interface{}]interface{} types.
  3. Main Function: Ensured the main function correctly processes and transforms the JSON data.

Detailed Description

convertMap Function

A new utility function, convertMap, was introduced to convert map[interface{}]interface{} to map[string]interface{}. This ensures that the map keys are always strings, avoiding type assertion issues.

flattenKeys Function

The flattenKeys function was updated to handle both map[string]interface{} and map[interface{}]interface{} types. It uses the convertMap function to ensure all keys are strings.

applyKeyMapping Function

The applyKeyMapping function was also updated to ensure that it processes maps correctly, regardless of the map type.

Usage

Generate the tokenchain dump using ./rubixgoplatform tokenchaindump -token <tokenID> which will create a dump.json file in the current path, once the tokenchaindump is completed run ./rubixgoplatform decodetokenchain which will decode the dump and save the decoded details into a new file called output.json where you can get the decoded details