示例#1
0
void test_big( const std::string& expected ) {
    typename H::encoder enc;
    for (char c : TEST6) { enc.put(c); }
    for (int i = 0; i < 16777215; i++) {
        enc.write( TEST6.c_str(), TEST6.size() );
    }
    H hash = enc.result();
    BOOST_CHECK_EQUAL( expected, (std::string) hash );

    enc.reset();
    enc.write( TEST1.c_str(), TEST1.size() );
    hash = enc.result();
    BOOST_CHECK( hash >= H::hash( TEST1 ) );
    test<H>( TEST1, (std::string) hash );

    hash = hash ^ hash;
    hash.data()[hash.data_size() - 1] = 1;
    for (int i = hash.data_size() * 8 - 1; i > 0; i--) {
        H other = hash << i;
        BOOST_CHECK( other != hash );
        BOOST_CHECK( other > hash );
        BOOST_CHECK( hash < other );
    }

    H hash2( expected );
    fc::variant v;
    to_variant( hash2, v );
    from_variant( v, hash );
    BOOST_CHECK( hash == hash2 );

    H hash3( expected.substr(15) + "000000000000000" );
    BOOST_CHECK( hash3 == hash2 << 60 );
}
示例#2
0
 void operator()( const char* name )const
 {
    auto it = vo.find(name);
    if( it != vo.end() )
    {
       from_variant( it->value(), (value.*member), _max_depth );
       assert( count_left > 0 );    // x.find(k) returns true for n distinct values of k only if x.size() >= n
       --count_left;
    }
 }
      virtual void apply( const protocol::custom_json_operation& outer_o ) override
      {
         try
         {
            fc::variant v = fc::json::from_string( outer_o.json );

            std::vector< CustomOperationType > custom_operations;
            if( v.is_array() && v.size() > 0 && v.get_array()[0].is_array() )
            {
               // it looks like a list
               from_variant( v, custom_operations );
            }
            else
            {
               custom_operations.emplace_back();
               from_variant( v, custom_operations[0] );
            }

            apply_operations( custom_operations, operation( outer_o ) );
         } FC_CAPTURE_AND_RETHROW( (outer_o) )
      }
示例#4
0
void from_variant( const variant& var,  ecc::public_key& vo )
{
    ecc::public_key_data dat;
    from_variant( var, dat );
    vo = ecc::public_key(dat);
}
示例#5
0
void from_variant( const variant& var,  ecc::private_key& vo )
{
    fc::sha256 sec;
    from_variant( var, sec );
    vo = ecc::private_key::regenerate(sec);
}
示例#6
0
 void operator()( const char* name )const
 {
    auto itr = vo.find(name);
    if( itr != vo.end() )
       from_variant( itr->value(), val.*member, _max_depth );
 }
示例#7
0
inline void from_variant( const fc::variant& v, steem::protocol::legacy_steem_asset& leg )
{
   steem::protocol::asset a;
   from_variant( v, a );
   leg = steem::protocol::legacy_steem_asset::from_asset( a );
}
示例#8
0
 result_type operator()( const Member& dummy )
 {
    Member result;
    from_variant( v, result );
    return result;    // converted from StaticVariant to Result automatically due to return type
 }
示例#9
0
void debug_apply_update( database& db, const fc::variant_object& vo )
{
   static const uint8_t
      db_action_nil = 0,
      db_action_create = 1,
      db_action_write = 2,
      db_action_update = 3,
      db_action_delete = 4;

   // "_action" : "create"   object must not exist, unspecified fields take defaults
   // "_action" : "write"    object may exist, is replaced entirely, unspecified fields take defaults
   // "_action" : "update"   object must exist, unspecified fields don't change
   // "_action" : "delete"   object must exist, will be deleted

   // if _action is unspecified:
   // - delete if object contains only ID field
   // - otherwise, write

   object_id_type oid;
   uint8_t action = db_action_nil;
   auto it_id = vo.find("id");
   FC_ASSERT( it_id != vo.end() );

   from_variant( it_id->value(), oid );
   action = ( vo.size() == 1 ) ? db_action_delete : db_action_write;

   from_variant( vo["id"], oid );
   if( vo.size() == 1 )
      action = db_action_delete;
   auto it_action = vo.find("_action" );
   if( it_action != vo.end() )
   {
      const std::string& str_action = it_action->value().get_string();
      if( str_action == "create" )
         action = db_action_create;
      else if( str_action == "write" )
         action = db_action_write;
      else if( str_action == "update" )
         action = db_action_update;
      else if( str_action == "delete" )
         action = db_action_delete;
   }

   auto& idx = db.get_index( oid );

   switch( action )
   {
      case db_action_create:
         FC_ASSERT( false );
         break;
      case db_action_write:
         db.modify( db.get_object( oid ), [&]( object& obj )
         {
            idx.object_default( obj );
            idx.object_from_variant( vo, obj, GRAPHENE_MAX_NESTED_OBJECTS );
         } );
         break;
      case db_action_update:
         db.modify( db.get_object( oid ), [&]( object& obj )
         {
            idx.object_from_variant( vo, obj, GRAPHENE_MAX_NESTED_OBJECTS );
         } );
         break;
      case db_action_delete:
         db.remove( db.get_object( oid ) );
         break;
      default:
         FC_ASSERT( false );
   }
}
void dns_cli::process_command(const std::string& cmd, const std::string& args)
{
    std::vector<std::string> argv;
    boost::split(argv, args, boost::is_any_of(" "), boost::token_compress_on);
    //std::stringstream ss(args); TODO: Unnecessary?

    const dns_db_ptr db = std::dynamic_pointer_cast<dns_db>(client()->get_chain());
    const dns_wallet_ptr wallet = std::dynamic_pointer_cast<dns_wallet>(client()->get_wallet());

    if (cmd == "bid_on_domain")
    {
        if (check_unlock())
        {
            FC_ASSERT(argv.size() == 3); // cmd name amount
            std::string name = argv[1];
            asset bid = asset(uint64_t(atoi(argv[2].c_str())));
            signed_transactions tx_pool;

            auto tx = wallet->bid_on_domain(name, bid, tx_pool, *db);

            client()->broadcast_transaction(tx);
        }
    }
    else if (cmd == "auction_domain")
    {
        if (check_unlock())
        {
            FC_ASSERT(argv.size() == 3); // cmd name price
            std::string name = argv[1];
            asset price = asset(uint64_t(atoi(argv[2].c_str())));
            signed_transactions tx_pool;

            auto tx = wallet->auction_domain(name, price, tx_pool, *db);

            client()->broadcast_transaction(tx);
        }
    }
    else if (cmd == "transfer_domain")
    {
        if (check_unlock())
        {
            FC_ASSERT(argv.size() == 3); // cmd name to
            std::string name = argv[1];
            auto to_owner = bts::blockchain::address(argv[2]);
            signed_transactions tx_pool;

            auto tx = wallet->transfer_domain(name, to_owner, tx_pool, *db);

            client()->broadcast_transaction(tx);
        }
    }
    else if (cmd == "update_domain_record")
    {
        if (check_unlock())
        {
            FC_ASSERT(argv.size() == 3); // cmd name path
            std::string name = argv[1];
            asset bid = asset(uint64_t(atoi(argv[2].c_str())));
            signed_transactions tx_pool;

            auto tx = wallet->bid_on_domain(name, bid, tx_pool, *db);

            client()->broadcast_transaction(tx);
        }

        // convert arbitrary json value to string..., this validates that it parses
        // properly.
        //fc::variant val = fc::json::from_string(json_value);
    }
    else if (cmd == "list_active_auctions")
    {
        FC_ASSERT(argv.size() == 1);

        auto active_auctions = get_active_auctions(*db);

        for (auto output : active_auctions)
        {
            auto dns_output = to_domain_output(output);

            std::cout << "[" << output.amount.get_rounded_amount() << "] " << dns_output.name << "\n";
        }
    }
    else if (cmd == "lookup_domain_record")
    {
        FC_ASSERT(argv.size() == 2);
        std::string name = argv[1];

        auto value = lookup_value(name, *db);
        std::string record;
        from_variant(value, record);

        std::cout << record << "\n";
    }
    else
    {
        cli::process_command(cmd, args);
    }
}
示例#11
0
void debug_apply_update( chain::database& db, const fc::variant_object& vo )
{
   static const uint8_t
      db_action_nil = 0,
      db_action_create = 1,
      db_action_write = 2,
      db_action_update = 3,
      db_action_delete = 4,
      db_action_set_hardfork = 5;

   wlog( "debug_apply_update:  ${o}", ("o", vo) );

   // "_action" : "create"   object must not exist, unspecified fields take defaults
   // "_action" : "write"    object may exist, is replaced entirely, unspecified fields take defaults
   // "_action" : "update"   object must exist, unspecified fields don't change
   // "_action" : "delete"   object must exist, will be deleted

   // if _action is unspecified:
   // - delete if object contains only ID field
   // - otherwise, write

   graphene::db::object_id_type oid;
   uint8_t action = db_action_nil;
   auto it_id = vo.find("id");
   FC_ASSERT( it_id != vo.end() );

   from_variant( it_id->value(), oid );
   action = ( vo.size() == 1 ) ? db_action_delete : db_action_write;

   from_variant( vo["id"], oid );
   if( vo.size() == 1 )
      action = db_action_delete;
   auto it_action = vo.find("_action" );
   if( it_action != vo.end() )
   {
      const std::string& str_action = it_action->value().get_string();
      if( str_action == "create" )
         action = db_action_create;
      else if( str_action == "write" )
         action = db_action_write;
      else if( str_action == "update" )
         action = db_action_update;
      else if( str_action == "delete" )
         action = db_action_delete;
      else if( str_action == "set_hardfork" )
         action = db_action_set_hardfork;
   }

   auto& idx = db.get_index( oid );

   switch( action )
   {
      case db_action_create:
         /*
         idx.create( [&]( object& obj )
         {
            idx.object_from_variant( vo, obj );
         } );
         */
         FC_ASSERT( false );
         break;
      case db_action_write:
         db.modify( db.get_object( oid ), [&]( graphene::db::object& obj )
         {
            idx.object_default( obj );
            idx.object_from_variant( vo, obj );
         } );
         break;
      case db_action_update:
         db.modify( db.get_object( oid ), [&]( graphene::db::object& obj )
         {
            idx.object_from_variant( vo, obj );
         } );
         break;
      case db_action_delete:
         db.remove( db.get_object( oid ) );
         break;
      case db_action_set_hardfork:
         {
            uint32_t hardfork_id;
            from_variant( vo[ "hardfork_id" ], hardfork_id );
            db.set_hardfork( hardfork_id, false );
         }
         break;
      default:
         FC_ASSERT( false );
   }
}