Пример #1
0
   private_keys wallet_db::get_account_private_keys( const fc::sha512& password )const
   { try {
       private_keys keys;
       keys.reserve( accounts.size() * 2 );

       auto insert_key = [&keys,&password]( const owallet_key_record& key_rec )
       {
          if( key_rec.valid() && key_rec->has_private_key() )
          {
             try {
                keys.push_back( key_rec->decrypt_private_key( password ) );
             } catch ( const fc::exception& e )
             {
                elog( "error decrypting private key: ${e}", ("e", e.to_detail_string() ) );
             }
          }
       };

       for( const auto& item : accounts )
       {
          insert_key(lookup_key(item.second.account_address));
          for( const auto& active_key : item.second.active_key_history )
            insert_key(lookup_key(active_key.second));
       }

       keys.shrink_to_fit();
       return keys;
   } FC_RETHROW_EXCEPTIONS( warn, "" ) }
Пример #2
0
/** lookup all needed special keys not defined by ncurses */
void lookup_keys() {
    int not_ok = 0;

    key_kNXT3 = lookup_key("kNXT3");
    key_kPRV3 = lookup_key("kPRV3");
    key_kNXT5 = lookup_key("kNXT5");
    key_kPRV5 = lookup_key("kPRV5");

    if ((key_kNXT3 || key_kPRV3) == 0) {
	showmsg("Terminal does not support Alt-PgUp/PgDn keys");
	not_ok = 1;
    }

    if ((key_kNXT5 || key_kPRV5) == 0) {
	showmsg("Terminal does not support Ctrl-PgUp/PgDn keys");
	not_ok = 1;
    }

    if (not_ok == 1) {
	showmsg("See ':CQD' in man page for setting Auto_CQ delay");
	showmsg("");
	beep();
	sleep(2);
    }
}
Пример #3
0
   public_key_type wallet_db::generate_new_account( const fc::sha512& password, const string& account_name,
                                                    const private_key_type& owner_private_key )
   { try {
       FC_ASSERT( is_open() );

       owallet_account_record account_record = lookup_account( account_name );
       FC_ASSERT( !account_record.valid(), "Wallet already contains an account with that name!" );

       const public_key_type owner_public_key = owner_private_key.get_public_key();
       const address owner_address = address( owner_public_key );

       const private_key_type active_private_key = get_account_child_key( owner_private_key, 0 );
       const public_key_type active_public_key = active_private_key.get_public_key();
       const address active_address = address( active_public_key );

       account_record = lookup_account( owner_address );
       FC_ASSERT( !account_record.valid(), "Wallet already contains an account with that key!" );

       account_record = lookup_account( active_address );
       FC_ASSERT( !account_record.valid(), "Wallet already contains an account with the new derived active key!" );

       owallet_key_record key_record = lookup_key( owner_address );
       FC_ASSERT( !key_record.valid() || !key_record->has_private_key(), "Wallet already contains that key!" );

       key_record = lookup_key( active_address );
       FC_ASSERT( !key_record.valid() || !key_record->has_private_key(), "Wallet already contains the new derived active key!" );

       key_data active_key;
       active_key.account_address = owner_address;
       active_key.public_key = active_public_key;
       active_key.encrypt_private_key( password, active_private_key );

       key_data owner_key;
       owner_key.account_address = owner_address;
       owner_key.public_key = owner_public_key;
       owner_key.encrypt_private_key( password, owner_private_key );

       account_data account;
       account.name = account_name;
       account.owner_key = owner_public_key;
       account.set_active_key( blockchain::now(), active_public_key );
       account.last_update = blockchain::now();

       store_key( active_key );
       store_key( owner_key );
       store_account( account );

       return owner_public_key;
   } FC_CAPTURE_AND_RETHROW( (account_name) ) }
Пример #4
0
   void wallet_db::add_account( const account_record& blockchain_account,
                                const variant& private_data  )
   { try {
      wallet_account_record war;
      account_record& tmp  = war;
      tmp = blockchain_account;
      war.private_data = private_data;
      war.account_address = address(blockchain_account.owner_key);

      war.wallet_record_index = new_wallet_record_index();
      if (has_private_key(war.account_address))
          war.is_my_account = true;
      store_record( war );

      auto current_key = lookup_key( blockchain_account.owner_key );
      if( current_key.valid() )
      {  
         current_key->account_address = address(blockchain_account.owner_key);
         store_record( *current_key );
      }
      else
      {
         wallet_key_record new_key;
         new_key.wallet_record_index = new_wallet_record_index();
         new_key.account_address = address(blockchain_account.owner_key);
         new_key.public_key = blockchain_account.active_key();
         my->load_key_record( new_key, false );
         store_key( new_key );
      }
   } FC_CAPTURE_AND_RETHROW( (blockchain_account) ) }
Пример #5
0
static void set_key(int fd, const char* scancode_str, const char* keyname)
{
	unsigned scancode;
	char *endptr;
	char t[105] = "KEY_UNKNOWN";
	const struct key *k;

	scancode = (unsigned) strtol(scancode_str, &endptr, 0);
	if (*endptr != '\0') {
		fprintf(stderr, "ERROR: Invalid scancode\n");
		exit(1);
	}

	snprintf(t, sizeof(t), "KEY_%s", keyname);

	if (!(k = lookup_key(t, strlen(t)))) {
		fprintf(stderr, "ERROR: Unknown key name '%s'\n", keyname);
		exit(1);
	}

	if (evdev_set_keycode(fd, scancode, k->id) < 0)
		fprintf(stderr, "setting scancode 0x%2X to key code %i failed\n", 
			scancode, k->id);
	else
		printf("setting scancode 0x%2X to key code %i\n", 
			scancode, k->id);
}
Пример #6
0
   void wallet_db::store_account( const account_data& account )
   { try {
       FC_ASSERT( is_open() );
       FC_ASSERT( account.name != string() );
       FC_ASSERT( account.owner_key != public_key_type() );

       owallet_account_record account_record = lookup_account( account.owner_address() );
       if( !account_record.valid() )
           account_record = wallet_account_record();

       account_data& temp = *account_record;
       temp = account;

       store_and_reload_record( *account_record );

       set<public_key_type> account_public_keys;
       account_public_keys.insert( account_record->owner_key );
       for( const auto& active_key_item : account_record->active_key_history )
       {
           const public_key_type& active_key = active_key_item.second;
           if( active_key == public_key_type() ) continue;
           account_public_keys.insert( active_key );
       }
       if( account.is_delegate() )
       {
           for( const auto& item : account.delegate_info->signing_key_history )
           {
               const public_key_type& signing_key = item.second;
               if( signing_key == public_key_type() ) continue;
               account_public_keys.insert( signing_key );
           }
       }

       for( const public_key_type& account_public_key : account_public_keys )
       {
           const address account_address = address( account_public_key );
           owallet_key_record key_record = lookup_key( account_address );
           if( !key_record.valid() )
           {
               key_data key;
               key.account_address = account_address;
               key.public_key = account_public_key;
               store_key( key );
           }
           else if( key_record->has_private_key() )
           {
               if( !account_record->is_my_account )
               {
                   account_record->is_my_account = true;
                   store_and_reload_record( *account_record );
               }

               if( key_record->account_address != account_record->owner_address() )
               {
                   key_record->account_address = account_record->owner_address();
                   store_key( *key_record );
               }
           }
       }
   } FC_CAPTURE_AND_RETHROW( (account) ) }
Пример #7
0
void* avahi_cache_walk(AvahiCache *c, AvahiKey *pattern, AvahiCacheWalkCallback cb, void* userdata) {
    void* ret;

    assert(c);
    assert(pattern);
    assert(cb);

    if (avahi_key_is_pattern(pattern)) {
        AvahiCacheEntry *e, *n;

        for (e = c->entries; e; e = n) {
            n = e->entry_next;

            if (avahi_key_pattern_match(pattern, e->record->key))
                if ((ret = cb(c, pattern, e, userdata)))
                    return ret;
        }

    } else {
        AvahiCacheEntry *e, *n;

        for (e = lookup_key(c, pattern); e; e = n) {
            n = e->by_key_next;

            if ((ret = cb(c, pattern, e, userdata)))
                return ret;
        }
    }

    return NULL;
}
Пример #8
0
   void WalletDb::store_account( const AccountData& account )
   { try {
       FC_ASSERT( is_open() ,"Wallet not open!");
       FC_ASSERT( account.name != string() );
       FC_ASSERT( account.owner_key != PublicKeyType() );

       oWalletAccountEntry account_entry = lookup_account( account.owner_address() );
       if( !account_entry.valid() )
           account_entry = WalletAccountEntry();

       AccountData& temp = *account_entry;
       temp = account;

       store_and_reload_entry( *account_entry );

       set<PublicKeyType> account_public_keys;
       account_public_keys.insert( account_entry->owner_key );
       for( const auto& active_key_item : account_entry->active_key_history )
       {
           const PublicKeyType& active_key = active_key_item.second;
           if( active_key == PublicKeyType() ) continue;
           account_public_keys.insert( active_key );
       }
       if( account.is_delegate() )
       {
           for( const auto& item : account.delegate_info->signing_key_history )
           {
               const PublicKeyType& signing_key = item.second;
               if( signing_key == PublicKeyType() ) continue;
               account_public_keys.insert( signing_key );
           }
       }

       for( const PublicKeyType& account_public_key : account_public_keys )
       {
           const Address account_address = Address( account_public_key );
           oWalletKeyEntry key_entry = lookup_key( account_address );
           if( !key_entry.valid() )
           {
               KeyData key;
               key.account_address = account_address;
               key.public_key = account_public_key;
               store_key( key );
           }
           else if( key_entry->has_private_key() )
           {
               if( !account_entry->is_my_account )
               {
                   account_entry->is_my_account = true;
                   store_and_reload_entry( *account_entry );
               }

               if( key_entry->account_address != account_entry->owner_address() )
               {
                   key_entry->account_address = account_entry->owner_address();
                   store_key( *key_entry );
               }
           }
       }
   } FC_CAPTURE_AND_RETHROW( (account) ) }
Пример #9
0
unsigned char
handle_key_press(event_t *ev)
{
    XWMHints *wm_hints;
#ifdef COUNT_X_EVENTS
    static unsigned long keypress_cnt = 0;
#endif

    PROF_INIT(handle_key_press);
    D_EVENTS(("handle_key_press(ev [%8p] on window 0x%08x)\n", ev, ev->xany.window));
#if UNUSED_BLOCK
    REQUIRE_RVAL(XEVENT_IS_MYWIN(ev, &primary_data), 0);
#endif

    COUNT_EVENT(keypress_cnt);
    if (!(BITFIELD_IS_SET(eterm_options, ETERM_OPTIONS_NO_INPUT))) {
        lookup_key(ev);
    }
    if (BITFIELD_IS_SET(vt_options, VT_OPTIONS_URG_ALERT)) {
        wm_hints = XGetWMHints(Xdisplay, TermWin.parent);
        wm_hints->flags &= ~XUrgencyHint;
        XSetWMHints(Xdisplay, TermWin.parent, wm_hints);
        XFree(wm_hints);
    }
    PROF_DONE(handle_key_press);
    PROF_TIME(handle_key_press);
    return 1;
}
/***********************************************************//**
    Evaluate a function using the function monitor to recall/store evaluations

    \param[in] x    - location at which to evaluate
    \param[in] args - void pointer to function monitor

    \return evaluation of a function
***************************************************************/
double function_monitor_eval(const double * x, void * args)
{
    //printf("In eval function monitor \n");   
    struct FunctionMonitor * fm = args;
    
    //printf("serial;ize it \n");
    //printf("x = ");
    //printf("fm->dim=%zu\n",fm->dim);
    //dprint(fm->dim,x);
    //printf("ok!\n");
    char * ser = serialize_darray_to_text(fm->dim,(double *)x);

    char * sval = lookup_key(fm->evals,ser);
    //printf("sval = %s\n",sval);
    double val;
    if (sval != NULL){
        val = deserialize_double_from_text(sval);
        //memmove(&val, sval, sizeof(double));
        //printf("here! val=%3.5f\n",val);
    }
    else{
        val = fm->f.fnd((double *)x,fm->args);
        //printf("val=%G\n",val);
        sval = serialize_double_to_text(val);
        //printf("sval = %s\n",sval);
        struct Cpair * cp = cpair_create(ser,sval);
        add_cpair(fm->evals, cp);
        cpair_free(cp);
    }
    //printf("done with eval function monitor \n");
    free(ser); ser = NULL;
    free(sval); sval = NULL;
    return val;
}       
Пример #11
0
void load_keys_from_section (char *terminal, char *profile_name)
{
    char *section_name;
    void *profile_keys;
    char *key, *value, *valcopy;
    int  key_code;

    if (!terminal)
	return;

    section_name = copy_strings ("terminal:", terminal, 0);
    profile_keys = profile_init_iterator (section_name, profile_name);
    if (!profile_keys){
	free (section_name);
	return;
    }
    
    while (profile_keys){
	profile_keys = profile_iterator_next (profile_keys, &key, &value);
	key_code = lookup_key (key);
	valcopy = convert_controls (value);
	if (key_code)
	    define_sequence (key_code, valcopy, MCKEY_NOACTION);
	free (valcopy);
    }
    free (section_name);
    return;
}
Пример #12
0
   void wallet_db::store_key( const key_data& key )
   { try {
       FC_ASSERT( is_open() );
       FC_ASSERT( key.public_key != public_key_type() );

       owallet_key_record key_record = lookup_key( key.get_address() );
       if( !key_record.valid() )
           key_record = wallet_key_record();

       key_data& temp = *key_record;
       temp = key;

       store_and_reload_record( *key_record, true );

       if( key_record->has_private_key() )
       {
           owallet_account_record account_record = lookup_account( key.public_key );
           if( !account_record.valid() )
               account_record = lookup_account( key.account_address );

           if( account_record.valid() )
           {
               if( key_record->account_address != account_record->owner_address() )
               {
                   key_record->account_address = account_record->owner_address();
                   store_and_reload_record( *key_record, true );
               }
           }
       }
   } FC_CAPTURE_AND_RETHROW( (key) ) }
Пример #13
0
   PrivateKeyType WalletDb::generate_new_account_child_key( const fc::sha512& password, const string& account_name )
   { try {
       FC_ASSERT( is_open() ,"Wallet not open!");

       oWalletAccountEntry account_entry = lookup_account( account_name );
       FC_ASSERT( account_entry.valid(), "Account not found!" );
       FC_ASSERT( !account_entry->is_retracted(), "Account has been retracted!" );
       FC_ASSERT( account_entry->is_my_account, "Not my account!" );

       const oWalletKeyEntry key_entry = lookup_key( Address( account_entry->active_key() ) );
       FC_ASSERT( key_entry.valid(), "Active key not found!" );
       FC_ASSERT( key_entry->has_private_key(), "Active private key not found!" );

       const PrivateKeyType active_private_key = key_entry->decrypt_private_key( password );
       uint32_t seq_num = account_entry->last_used_gen_sequence;
       PrivateKeyType account_child_private_key;
       PublicKeyType account_child_public_key;
       Address account_child_address;
       while( true )
       {
           ++seq_num;
           FC_ASSERT( seq_num != 0, "Overflow!" );

           account_child_private_key = get_account_child_key( active_private_key, seq_num );
           account_child_public_key = account_child_private_key.get_public_key();
           account_child_address = Address( account_child_public_key );

           oWalletKeyEntry key_entry = lookup_key( account_child_address );
           if( key_entry.valid() && key_entry->has_private_key() ) continue;

           break;
       }

       account_entry->last_used_gen_sequence = seq_num;

       KeyData key;
       key.account_address = account_entry->owner_address();
       key.public_key = account_child_public_key;
       key.encrypt_private_key( password, account_child_private_key );
       key.gen_seq_number = seq_num;

       store_account( *account_entry );
       store_key( key );

       return account_child_private_key;
   } FC_CAPTURE_AND_RETHROW( (account_name) ) }
Пример #14
0
struct lambda_expression *
abbreviation_lookup(const char *id)
{
	struct lambda_expression *r = NULL;
	void *p = lookup_key(abbr_table, id);
	if (p) r = copy_expression(p);
	return r;
}
Пример #15
0
static void
load_keys_from_section (const char *terminal, mc_config_t * cfg)
{
    char *section_name;
    gchar **profile_keys, **keys;
    char *valcopy, *value;
    long key_code;

    if (terminal == NULL)
        return;

    section_name = g_strconcat ("terminal:", terminal, (char *) NULL);
    keys = mc_config_get_keys (cfg, section_name, NULL);

    for (profile_keys = keys; *profile_keys != NULL; profile_keys++)
    {
        /* copy=other causes all keys from [terminal:other] to be loaded. */
        if (g_ascii_strcasecmp (*profile_keys, "copy") == 0)
        {
            valcopy = mc_config_get_string (cfg, section_name, *profile_keys, "");
            load_keys_from_section (valcopy, cfg);
            g_free (valcopy);
            continue;
        }

        key_code = lookup_key (*profile_keys, NULL);
        if (key_code != 0)
        {
            gchar **values;

            values = mc_config_get_string_list (cfg, section_name, *profile_keys, NULL);
            if (values != NULL)
            {
                gchar **curr_values;

                for (curr_values = values; *curr_values != NULL; curr_values++)
                {
                    valcopy = convert_controls (*curr_values);
                    define_sequence (key_code, valcopy, MCKEY_NOACTION);
                    g_free (valcopy);
                }

                g_strfreev (values);
            }
            else
            {
                value = mc_config_get_string (cfg, section_name, *profile_keys, "");
                valcopy = convert_controls (value);
                define_sequence (key_code, valcopy, MCKEY_NOACTION);
                g_free (valcopy);
                g_free (value);
            }
        }
    }
    g_strfreev (keys);
    g_free (section_name);
}
Пример #16
0
void
keybind_cmd_bind (GArray * keymap, const char *keybind, long action)
{
    char *caption = NULL;
    long key;

    key = lookup_key (keybind, &caption);
    keymap_add (keymap, key, action, caption);
    g_free (caption);
}
Пример #17
0
static int merge_table(int fd, FILE *f) {
        int r = 0;
        int line = 0;

        while (!feof(f)) {
                char s[256], *p;
                unsigned scancode;
                int new_keycode, old_keycode;

                if (!fgets(s, sizeof(s), f))
                        break;

                line++;
                p = s+strspn(s, "\t ");
                if (*p == '#' || *p == '\n')
                        continue;

                if (sscanf(p, "%i %i", &scancode, &new_keycode) != 2) {
                        char t[105] = "KEY_UNKNOWN";
                        const struct key *k;

                        if (sscanf(p, "%i %100s", &scancode, t+4) != 2) {
                                fprintf(stderr, "WARNING: Parse failure at line %i, ignoring.\n", line);
                                r = -1;
                                continue;
                        }

                        if (!(k = lookup_key(t, strlen(t)))) {
                                fprintf(stderr, "WARNING: Unknown key '%s' at line %i, ignoring.\n", t, line);
                                r = -1;
                                continue;
                        }

                        new_keycode = k->id;
                }


                if ((old_keycode = evdev_get_keycode(fd, scancode, 0)) < 0) {
                        r = -1;
                        continue;
                }

                if (evdev_set_keycode(fd, scancode, new_keycode) < 0) {
                        r = -1;
                        continue;
                }

                if (new_keycode != old_keycode)
                        fprintf(stderr, "Remapped scancode 0x%02x to 0x%02x (prior: 0x%02x)\n",
                                scancode, new_keycode, old_keycode);
        }

        fclose(f);
        return r;
}
Пример #18
0
command_t lookup_command (int character)
{
	void *cmd = lookup_key (character);
	if (! cmd)
		cmd = cmd_unbound;

	last_command = this_command;
	this_command = character;

	return (command_t) cmd;
}
Пример #19
0
int parse_key(Tty *tty, KeyStatus *key_status)
{
  static u8 keymap_col=0;

  int scan_code = get_data_from_tty_buf(tty);
  switch (scan_code)
  {
    case -1:
      break;
    case 0xe1:
      break;
    case 0xe0:
      scan_code = get_data_from_tty_buf(tty);
      key_status->key = lookup_key(scan_code & 0x7f, keymap_col);
      key_status->press = ((scan_code & 0x80) ? RELEASE: PRESS);
      break;
    default:
      key_status->key = lookup_key(scan_code & 0x7f, keymap_col);
      key_status->press = ((scan_code & 0x80) ? RELEASE: PRESS);
      break;
  }
}
Пример #20
0
   public_key_type wallet_db::generate_new_account( const fc::sha512& password, const string& account_name, const variant& private_data )
   { try {
       FC_ASSERT( is_open() );

       owallet_account_record account_record = lookup_account( account_name );
       FC_ASSERT( !account_record.valid(), "Wallet already contains an account with that name!" );

       uint32_t key_index = get_last_wallet_child_key_index();
       private_key_type account_private_key;
       public_key_type account_public_key;
       address account_address;
       while( true )
       {
           ++key_index;
           FC_ASSERT( key_index != 0, "Overflow!" );

           account_private_key = get_wallet_child_key( password, key_index );
           account_public_key = account_private_key.get_public_key();
           account_address = address( account_public_key );

           account_record = lookup_account( account_address );
           if( account_record.valid() ) continue;

           owallet_key_record key_record = lookup_key( account_address );
           if( key_record.valid() && key_record->has_private_key() ) continue;

           break;
       }

       key_data key;
       key.account_address = account_address;
       key.public_key = account_public_key;
       key.encrypt_private_key( password, account_private_key );
       key.gen_seq_number = key_index;

       account_data account;
       account.name = account_name;
       account.owner_key = account_public_key;
       account.set_active_key( blockchain::now(), account_public_key );
       account.private_data = private_data;
       account.is_my_account = true;

       set_last_wallet_child_key_index( key_index );
       store_key( key );
       store_account( account );

       return account_public_key;
   } FC_CAPTURE_AND_RETHROW( (account_name) ) }
Пример #21
0
   private_key_type wallet_db::generate_new_one_time_key( const fc::sha512& password )
   { try {
       FC_ASSERT( is_open() );
       const private_key_type one_time_private_key = private_key_type::generate();

       const address one_time_address = address( one_time_private_key.get_public_key() );
       const owallet_key_record key_record = lookup_key( one_time_address );
       FC_ASSERT( !key_record.valid() );

       key_data key;
       key.public_key = one_time_private_key.get_public_key();
       key.encrypt_private_key( password, one_time_private_key );
       store_key( key );

       return one_time_private_key;
   } FC_CAPTURE_AND_RETHROW() }
Пример #22
0
   PrivateKeyType WalletDb::generate_new_one_time_key( const fc::sha512& password )
   { try {
       FC_ASSERT( is_open() ,"Wallet not open!");
       const PrivateKeyType one_time_private_key = PrivateKeyType::generate();

       const Address one_time_address = Address( one_time_private_key.get_public_key() );
       const oWalletKeyEntry key_entry = lookup_key( one_time_address );
       FC_ASSERT( !key_entry.valid() );

       KeyData key;
       key.public_key = one_time_private_key.get_public_key();
       key.encrypt_private_key( password, one_time_private_key );
       store_key( key );

       return one_time_private_key;
   } FC_CAPTURE_AND_RETHROW() }
/***********************************************************//**
    Add a Cpair to the table

    \param[in] ht - hashtable
    \param[in] cp - cpair to insert
    
    \return
        0 if good, 1 if some err, 2 if exists
***************************************************************/
int add_cpair(struct HashtableCpair * ht, struct Cpair * cp){

    char * curr_pl = NULL;

    size_t val = hashsimple(ht->size,cp->a);
    
    curr_pl = lookup_key(ht,cp->a);
    if (curr_pl != NULL) {
        free(curr_pl); curr_pl = NULL;
        return 2;
    }
    
    pair_push(&(ht->table[val]), cp);
    free(curr_pl);

    return 0;
}
Пример #24
0
   void WalletDb::add_contact_account( const AccountEntry& blockchain_account_entry, const variant& private_data )
   { try {
       FC_ASSERT( is_open() ,"Wallet not open!");

       oWalletAccountEntry entry = lookup_account( blockchain_account_entry.name );
       FC_ASSERT( !entry.valid(), "Wallet already contains an account with that name!" );

       const PublicKeyType account_address = blockchain_account_entry.owner_key;
       oWalletKeyEntry key_entry = lookup_key( account_address );
       FC_ASSERT( !key_entry.valid(), "Wallet already contains that key" );

       entry = WalletAccountEntry();
       AccountEntry& temp_entry = *entry;
       temp_entry = blockchain_account_entry;
       entry->private_data = private_data;

       store_account( *entry );
   } FC_CAPTURE_AND_RETHROW( (blockchain_account_entry) ) }
Пример #25
0
   void wallet_db::add_contact_account( const account_record& blockchain_account_record, const variant& private_data )
   { try {
       FC_ASSERT( is_open() );

       owallet_account_record record = lookup_account( blockchain_account_record.name );
       FC_ASSERT( !record.valid(), "Wallet already contains an account with that name!" );

       const public_key_type account_address = blockchain_account_record.owner_key;
       owallet_key_record key_record = lookup_key( account_address );
       FC_ASSERT( !key_record.valid(), "Wallet already contains that key" );

       record = wallet_account_record();
       account_record& temp_record = *record;
       temp_record = blockchain_account_record;
       record->private_data = private_data;

       store_account( *record );
   } FC_CAPTURE_AND_RETHROW( (blockchain_account_record) ) }
Пример #26
0
 vector<wallet_balance_record> wallet_db::get_all_balances( const string& account_name, uint32_t limit )
 {
     auto ret = vector<wallet_balance_record>();
     auto count = 0;
     for( auto item : balances )
     {
         if (count == limit && limit != -1)
             break;
         auto okey = lookup_key(item.second.owner());
         FC_ASSERT(okey.valid(), "expect a key record to exist at this point");
         auto oacct = lookup_account( okey->account_address );
         if ( oacct.valid() && oacct->name == account_name )
         {
             ret.push_back(item.second);
             count++;
         }
     }
     return ret;
 }
Пример #27
0
   void wallet_db::add_account( const string& new_account_name,
                                const public_key_type& new_account_key,
                                const variant& private_data )
   {
      auto current_account_itr = name_to_account_wallet_record_index.find( new_account_name );
      FC_ASSERT( current_account_itr == name_to_account_wallet_record_index.end(),
                 "Account with name ${name} already exists",
                 ("name",new_account_name) );
      auto current_address_itr = address_to_account_wallet_record_index.find( new_account_key );
      FC_ASSERT( current_address_itr == address_to_account_wallet_record_index.end(),
                 "Account with address ${address} already exists",
                 ("name",new_account_key) );

      wallet_account_record war;
      war.name = new_account_name;
      war.id = 0;
      war.account_address = address( new_account_key );
      war.owner_key = new_account_key;
      war.set_active_key( blockchain::now(), new_account_key );
      war.private_data = private_data;

      war.wallet_record_index = new_wallet_record_index();
      if (has_private_key(war.account_address))
          war.is_my_account = true;
      store_record( war );

      auto current_key = lookup_key( new_account_key );
      if( current_key )
      {
         current_key->account_address = address(new_account_key);
         store_record( *current_key, true );
      }
      else
      {
         wallet_key_record new_key;
         new_key.wallet_record_index = new_wallet_record_index();
         new_key.account_address = address(new_account_key);
         new_key.public_key = new_account_key;
         my->load_key_record( new_key, false );
         store_key( new_key );
      }
   }
Пример #28
0
 private_keys wallet_db::get_account_private_keys( const fc::sha512& password )
 { try {
     private_keys keys;
     keys.reserve( accounts.size() );
     for( const auto& item : accounts )
     {
        auto key_rec = lookup_key(item.second.account_address);
        if( key_rec.valid() && key_rec->has_private_key() )
        {
           try {
              keys.push_back( key_rec->decrypt_private_key( password ) );
           } catch ( const fc::exception& e )
           {
              wlog( "error decrypting private key: ${e}", ("e", e.to_detail_string() ) );
              throw; // TODO... don't thtrow here, just log
           }
        }
     }
     return keys;
 } FC_RETHROW_EXCEPTIONS( warn, "" ) }
Пример #29
0
/*
 * Examine value and assign proper key number to *key based on the result.
 * Return 0 on succes and 1 on error
 */
int parse_key(char *value, int *key) {
    int temp;

    /* Is it a printable char inside ''s? */
    if (value[0] == '\'' && value[2] == '\'' && strlen(value) == 3)  {
        *key = (int)value[1];
        return 0;
    }
    /* Is it a key specifier? */
    if ( (temp = lookup_key(value)) != -1 ) {
        *key = temp;
        return 0;
    }
    /* Is it a raw number? */
    if (sscanf(value, "%d", &temp) == 1) {
        *key = temp;
        return 0;
    }
    /* Nothing found, return error code */
    return 1;
}
Пример #30
0
   void WalletDb::import_key( const fc::sha512& password, const string& account_name, const PrivateKeyType& private_key,
                               bool move_existing )
   { try {
       FC_ASSERT( is_open() ,"Wallet not open!");

       oWalletAccountEntry account_entry = lookup_account( account_name );
       FC_ASSERT( account_entry.valid(), "Account name not found!" );

       const PublicKeyType public_key = private_key.get_public_key();

       oWalletKeyEntry key_entry = lookup_key( Address( public_key ) );
       if( !key_entry.valid() )
           key_entry = WalletKeyEntry();
       else if( !move_existing )
           FC_ASSERT( key_entry->account_address == account_entry->owner_address() );

       key_entry->account_address = account_entry->owner_address();
       key_entry->public_key = public_key;
       key_entry->encrypt_private_key( password, private_key );

       store_key( *key_entry );
   } FC_CAPTURE_AND_RETHROW( (account_name)(move_existing) ) }