message: cleos changes: fix potential bug in `to_asset`; minor changes to `create_open`
diff: @@ -560,12 +560,11 @@ fc::variant regproducer_variant(const account_name& producer, const public_key_t
  ;
  }
  -chain::action create_open(const string& contract, const name& owner, asset amount, const name& ram_payer) {
  +chain::action create_open(const string& contract, const name& owner, symbol sym, const name& ram_payer) {
  auto open_ = fc::mutable_variant_object
  ("owner", owner)
  - ("symbol", amount.get_symbol())
  + ("symbol", sym)
  ("ram_payer", ram_payer);
  -
  return action {
  tx_permission.empty() ? vector<chain::permission_level>{{ram_payer,config::active_name}} : get_account_permissions(tx_permission),
  contract, "open", variant_to_bin( contract, N(open), open_ )
  @@ -646,11 +645,11 @@ authority parse_json_authority_or_key(const std::string& authorityJsonOrFile) {
  }
  }
  -asset to_asset( const string& code, const string& s ) {
  - static map<eosio::chain::symbol_code, eosio::chain::symbol> cache;
  +asset to_asset( account_name code, const string& s ) {
  + static map< pair<account_name, eosio::chain::symbol_code>, eosio::chain::symbol> cache;
  auto a = asset::from_string( s );
  eosio::chain::symbol_code sym = a.get_symbol().to_symbol_code();
  - auto it = cache.find( sym );
  + auto it = cache.find( make_pair(code, sym) );
  auto sym_str = a.symbol_name();
  if ( it == cache.end() ) {
  auto json = call(get_currency_stats_func, fc::mutable_variant_object("json", false)
  @@ -661,7 +660,7 @@ asset to_asset( const string& code, const string& s ) {
  auto obj_it = obj.find( sym_str );
  if (obj_it != obj.end()) {
  auto result = obj_it->value().as<eosio::chain_apis::read_only::get_currency_stats_result>();
  - auto p = cache.insert(make_pair( sym, result.max_supply.get_symbol() ));
  + auto p = cache.emplace( make_pair( code, sym ), result.max_supply.get_symbol() );
  it = p.first;
  } else {
  EOS_THROW(symbol_type_exception, "Symbol ${s} is not supported by token contract ${c}", ("s", sym_str)("c", code));
  @@ -679,7 +678,7 @@ asset to_asset( const string& code, const string& s ) {
  }
  inline asset to_asset( const string& s ) {
  - return to_asset( "eosio.token", s );
  + return to_asset( N(eosio.token), s );
  }
  struct set_account_permission_subcommand {
  @@ -2436,11 +2435,12 @@ int main( int argc, char** argv ) {
  tx_force_unique = false;
  }
  - auto transfer = create_transfer(con, sender, recipient, to_asset(con, amount), memo);
  + auto transfer_amount = to_asset(con, amount);
  + auto transfer = create_transfer(con, sender, recipient, transfer_amount, memo);
  if (!pay_ram) {
  send_actions( { transfer });
  } else {
  - auto open_ = create_open(con, recipient, to_asset(con, amount), sender);
  + auto open_ = create_open(con, recipient, transfer_amount.get_symbol(), sender);
  send_actions( { open_, transfer } );
  }
  });
  