Ejemplo n.º 1
0
      signed_transaction load_genesis( const fc::path& csv, uint64_t& total_coins )
      {
          total_coins = 0;
          signed_transaction coinbase;
          coinbase.version = 0;
        //  coinbase.valid_after = 0;
        //  coinbase.valid_blocks = 0;

          std::ifstream in(csv.generic_string().c_str(), std::ios::binary);
          std::string line;
          std::getline( in, line );
          while( in.good() )
          {
            std::stringstream ss(line);
            std::string addr;
            uint64_t amnt;
            ss >> addr >> amnt;
            total_coins += amnt;
            coinbase.outputs.push_back( 
              trx_output( claim_by_pts_output( bts::pts_address(addr) ), amnt, asset::bts) );
            std::getline( in, line );
          }

          return coinbase;
      }
Ejemplo n.º 2
0
void cafs::export_link( const cafs::link& l, const fc::path& d ) {
 try {
    if( !fc::exists( d.parent_path() ) ) { 
      slog( "create '%s'", d.generic_string().c_str() );
      fc::create_directories(d.parent_path()); 
    }
    fc::vector<char> ch = get_chunk( l.id );
    derandomize( l.seed, ch  );
    //  slog( "derandomized... '%s'", fc::to_hex( ch.data(), 16 ).c_str() );
    if( ch.size() == 0 ) {
      FC_THROW_MSG( "Empty Chunk!" );
    }
    switch( ch[0] ) {
      case file_data_type: {
        slog( "file data..." );
    //    slog( "post randomized... '%s'", fc::to_hex( ch.data(), ch.size() ).c_str() );
        fc::ofstream ofile( d, fc::ofstream::binary );
        ofile.write( ch.data()+1, ch.size()-1 );
        break;
      }
      case directory_type: {
        slog( "directory data..." );
        fc::datastream<const char*> ds(ch.data()+1, ch.size()-1);
        directory d;
        fc::raw::unpack( ds, d );
        slog( "%s", fc::json::to_string( d ).c_str() );
        for( auto itr = d.entries.begin(); itr != d.entries.end(); ++itr ) {
          slog( "entry: %s", itr->name.c_str() );
          /*
          fc::vector<char> fdat = get_file( itr->ref );
          switch( itr->ref.type ) {
            case file_data_type: {
              break;
            }
            case directory_type: {
              slog( "%s", fc::json::to_string( fc::raw::unpack<directory>(fdat) ).c_str() );
              break;
            }
            case file_header_type: {
              slog( "%s", fc::json::to_string( fc::raw::unpack<file_header>(fdat) ).c_str() );
              break;
            }
            default:
              wlog( "Unknown Type %d", int(itr->ref.type) );
          }
          */
        }
  
        break;
      }
      case file_header_type: {
        slog( "file header..." );
        fc::datastream<const char*> ds(ch.data()+1, ch.size()-1);
        slog( "data %s", fc::to_hex( ch.data(), 16 ).c_str() );
        file_header fh;
        fc::raw::unpack( ds, fh);
        slog( "%s", fc::json::to_string( fh ).c_str() );
  
        fc::ofstream ofile( d, fc::ofstream::binary );
        for( auto i = fh.chunks.begin(); i != fh.chunks.end(); ++i ) {
          fc::vector<char> c = get_chunk( i->hash );
          derandomize( i->seed, c );
          ofile.write( c.data(), c.size() );
        }
        break;
      }
      default:
        FC_THROW_MSG( "Unknown File Type %s", int(ch[0]) );
    }
 } catch ( fc::error_report& e ) {
   throw FC_REPORT_PUSH( e, "Unable to export link ${link} to ${path}", fc::value().set("link", fc::string(l)).set("path", d.generic_string() ) );
 }
}
Ejemplo n.º 3
0
 inline void pack( Stream& s, const fc::path& tp )
 {
    fc::raw::pack( s, tp.generic_string() );
 }