Add complete account dump to file
This commit introduces the ability to dump the complete content of an
account to a JSON file (compact or not depending on the provided format
option).
Example:
```sh
solana account -u m \
  --output json-compact \
  --output-file SRM_token.json \
  SRMuApVNdxXokk5GT7XD5cUUgXMBCoAz2LHeuAoKWRt
```
Note: Behavior remains untouched if format option `--output` is not
provided (only account data gets written to file).
(cherry picked from commit 0e9e67b65d)
			
			
This commit is contained in:
		@@ -462,18 +462,27 @@ pub fn process_show_account(
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    let mut account_string = config.output_format.formatted_string(&cli_account);
 | 
					    let mut account_string = config.output_format.formatted_string(&cli_account);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if config.output_format == OutputFormat::Display
 | 
					    match config.output_format {
 | 
				
			||||||
        || config.output_format == OutputFormat::DisplayVerbose
 | 
					        OutputFormat::Json | OutputFormat::JsonCompact => {
 | 
				
			||||||
    {
 | 
					            if let Some(output_file) = output_file {
 | 
				
			||||||
        if let Some(output_file) = output_file {
 | 
					                let mut f = File::create(output_file)?;
 | 
				
			||||||
            let mut f = File::create(output_file)?;
 | 
					                f.write_all(account_string.as_bytes())?;
 | 
				
			||||||
            f.write_all(&data)?;
 | 
					                writeln!(&mut account_string)?;
 | 
				
			||||||
            writeln!(&mut account_string)?;
 | 
					                writeln!(&mut account_string, "Wrote account to {}", output_file)?;
 | 
				
			||||||
            writeln!(&mut account_string, "Wrote account data to {}", output_file)?;
 | 
					            }
 | 
				
			||||||
        } else if !data.is_empty() {
 | 
					 | 
				
			||||||
            use pretty_hex::*;
 | 
					 | 
				
			||||||
            writeln!(&mut account_string, "{:?}", data.hex_dump())?;
 | 
					 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					        OutputFormat::Display | OutputFormat::DisplayVerbose => {
 | 
				
			||||||
 | 
					            if let Some(output_file) = output_file {
 | 
				
			||||||
 | 
					                let mut f = File::create(output_file)?;
 | 
				
			||||||
 | 
					                f.write_all(&data)?;
 | 
				
			||||||
 | 
					                writeln!(&mut account_string)?;
 | 
				
			||||||
 | 
					                writeln!(&mut account_string, "Wrote account data to {}", output_file)?;
 | 
				
			||||||
 | 
					            } else if !data.is_empty() {
 | 
				
			||||||
 | 
					                use pretty_hex::*;
 | 
				
			||||||
 | 
					                writeln!(&mut account_string, "{:?}", data.hex_dump())?;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        OutputFormat::DisplayQuiet => (),
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    Ok(account_string)
 | 
					    Ok(account_string)
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user