Skip to content
This repository has been archived by the owner on Aug 2, 2022. It is now read-only.

[feature] Add to_string() method to extended_asset & extended_symbol #1021

Open
Avm07 opened this issue Dec 25, 2020 · 0 comments
Open

[feature] Add to_string() method to extended_asset & extended_symbol #1021

Avm07 opened this issue Dec 25, 2020 · 0 comments
Labels
enhancement New feature or request

Comments

@Avm07
Copy link

Avm07 commented Dec 25, 2020

Since we have standart for printing extended_asset & extended_symbol.

void extended_asset::print()const {
         quantity.print();
         ::eosio::print("@", contract);
      }
      
 void extended_symbol::print( bool show_precision = true )const {
         sym.print( show_precision );
         ::eosio::print("@", contract);
      }     

I think we should have to_string() methods related to this.

Possible realization using eosio.cdt v1.7.0

std::string extended_symbol::to_string() const {
		std::string str = sym.to_string() + "@" + contract.to_string();
		return str;
	}
	
std::string extended_asset::to_string() const {
		std::string str = quantity.to_string() + "@" + contract.to_string();
		return str;
	}	

Case of usage:

  1. Returning assert message with related data
  2. creating checksum256 index for extended_asset & extended_symbol
struct [[eosio::table]] example {
   uint64_t id;
   extended_symbol token;
   
   uint64_t primary_key() const {
   	return id;
   }

   checksum256 token_hash_key() const {
   	std::string str = token.to_string();
   	return sha256(str.data(), str.size());
   }
@sanaraufx sanaraufx added the enhancement New feature or request label Mar 26, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants