Esempio n. 1
0
   std::vector<fc::ecc::private_key> import_bitcoin_wallet( const fc::path& wallet_dat, const std::string& passphrase )
   { try {

      wallet_db db( wallet_dat.to_native_ansi_path().c_str() );
      return collect_keys( db, passphrase );

   } FC_RETHROW_EXCEPTIONS( warn, "" ) }
Esempio n. 2
0
std::vector<fc::ecc::private_key> import_electrum_wallet( const fc::path& wallet_dat, const std::string& passphrase )
{ try {
  std::vector<fc::ecc::private_key> keys;
  electrumwallet wallet( wallet_dat.to_native_ansi_path());
  if( !wallet.ok() ) FC_THROW_EXCEPTION( fc::invalid_arg_exception, "invalid electrum wallet");
  wallet.derivekeys( passphrase );
  return wallet.keys();
} FC_RETHROW_EXCEPTIONS( warn, "" ) }
Esempio n. 3
0
        void open( const fc::path& dir, bool create = true, size_t cache_size = 0 )
        { try {
           FC_ASSERT( !is_open(), "Database is already open!" );

           ldb::Options opts;
           opts.comparator = &_comparer;
           opts.create_if_missing = create;
           opts.max_open_files = 64;
           opts.compression = leveldb::kNoCompression;

           if( cache_size > 0 )
           {
               opts.write_buffer_size = cache_size / 4; // up to two write buffers may be held in memory simultaneously
               _cache.reset( leveldb::NewLRUCache( cache_size / 2 ) );
               opts.block_cache = _cache.get();
           }

           if( ldb::kMajorVersion > 1 || ( leveldb::kMajorVersion == 1 && leveldb::kMinorVersion >= 16 ) )
           {
               // LevelDB versions before 1.16 consider short writes to be corruption. Only trigger error
               // on corruption in later versions.
               opts.paranoid_checks = true;
           }

           _read_options.verify_checksums = true;
           _iter_options.verify_checksums = true;
           _iter_options.fill_cache = false;
           _sync_options.sync = true;

           // Given path must exist to succeed toNativeAnsiPath
           fc::create_directories( dir );
           std::string ldbPath = dir.to_native_ansi_path();

           ldb::DB* ndb = nullptr;
           const auto ntrxstat = ldb::DB::Open( opts, ldbPath.c_str(), &ndb );
           if( !ntrxstat.ok() )
           {
               elog( "Failure opening database: ${db}\nStatus: ${msg}", ("db",dir)("msg",ntrxstat.ToString()) );
               FC_THROW_EXCEPTION( level_pod_map_open_failure, "Failure opening database: ${db}\nStatus: ${msg}",
                                   ("db",dir)("msg",ntrxstat.ToString()) );
           }
           _db.reset( ndb );

           try_upgrade_db( dir, ndb, fc::get_typename<Value>::name(), sizeof( Value ) );
        } FC_CAPTURE_AND_RETHROW( (dir)(create)(cache_size) ) }
Esempio n. 4
0
        void open( const fc::path& dir, bool create = true, size_t cache_size = 0 )
        { try {
           ldb::Options opts;
           opts.comparator = &_comparer;
           opts.create_if_missing = create;

           if (cache_size) {
               _cache.reset(leveldb::NewLRUCache(cache_size));
               opts.block_cache = _cache.get();
           }
           /*
           if( ldb::kMajorVersion > 1 || ( leveldb::kMajorVersion == 1 && leveldb::kMinorVersion >= 16 ) )
           {
               // LevelDB versions before 1.16 consider short writes to be corruption. Only trigger error
               // on corruption in later versions.
               opts.paranoid_checks = true;
           }
           opts.max_open_files = 64;

           _read_options.verify_checksums = true;
           _iter_options.verify_checksums = true;
           _iter_options.fill_cache = false;
           _sync_options.sync = true;
           */

           /// \warning Given path must exist to succeed toNativeAnsiPath
           fc::create_directories(dir);

           std::string ldbPath = dir.to_native_ansi_path();

           ldb::DB* ndb = nullptr;
           auto ntrxstat = ldb::DB::Open( opts, ldbPath.c_str(), &ndb );
           if( !ntrxstat.ok() )
           {
               FC_THROW_EXCEPTION( db_in_use_exception, "Unable to open database ${db}\n\t${msg}",
                    ("db",dir)
                    ("msg",ntrxstat.ToString())
                    );
           }
           _db.reset(ndb);
           try_upgrade_db( dir,ndb, fc::get_typename<Value>::name(),sizeof(Value) );
        } FC_RETHROW_EXCEPTIONS( warn, "" ) }
Esempio n. 5
0
      void mmap_struct_base::open( const fc::path& file, size_t s, bool create )
      {
         if( !fc::exists( file ) || fc::file_size(file) != s )
         {
            fc::ofstream out( file );
            char buffer[1024];
            memset( buffer, 0, sizeof(buffer) );

            size_t bytes_left = s;
            while( bytes_left > 0 )
            {
               size_t to_write = std::min<size_t>(bytes_left, sizeof(buffer) );
               out.write( buffer, to_write );
               bytes_left -= to_write;
            }
         }

         std::string filePath = file.to_native_ansi_path(); 

         _file_mapping.reset( new fc::file_mapping( filePath.c_str(), fc::read_write ) );
         _mapped_region.reset( new fc::mapped_region( *_file_mapping, fc::read_write, 0, s ) );
      }
Esempio n. 6
0
        void open( const fc::path& dir, bool create = true )
        {
           ldb::Options opts;
           opts.create_if_missing = create;
           opts.comparator = & _comparer;

           /// \waring Given path must exist to succeed toNativeAnsiPath
           fc::create_directories(dir);

           std::string ldbPath = dir.to_native_ansi_path();

           ldb::DB* ndb = nullptr;
           auto ntrxstat = ldb::DB::Open( opts, ldbPath.c_str(), &ndb );
           if( !ntrxstat.ok() )
           {
               FC_THROW_EXCEPTION( db_in_use_exception, "Unable to open database ${db}\n\t${msg}", 
                    ("db",dir)
                    ("msg",ntrxstat.ToString()) 
                    );
           }
           _db.reset(ndb);
           UpgradeDbIfNecessary(dir,ndb, fc::get_typename<Value>::name(),sizeof(Value));
        }