eosio.cdt icon indicating copy to clipboard operation
eosio.cdt copied to clipboard

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

Open Avm07 opened this issue 4 years ago • 0 comments

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());
	}

Avm07 avatar Dec 25 '20 10:12 Avm07