void transaction_evaluation_state::evaluate( const signed_transaction& trx_arg )
   { try {
      reset();

      auto trx_id = trx_arg.id();
      otransaction_location current_loc = _current_state->get_transaction_location( trx_id );
      if( !!current_loc )
         fail( BTS_DUPLICATE_TRANSACTION, "transaction has already been processed" );

      trx = trx_arg;
      auto digest = trx_arg.digest();
      for( auto sig : trx.signatures )
      {
         auto key = fc::ecc::public_key( sig, digest ).serialize();
         signed_keys.insert( address(key) );
         signed_keys.insert( address(pts_address(key,false,56) ) );
         signed_keys.insert( address(pts_address(key,true,56) )  );
         signed_keys.insert( address(pts_address(key,false,0) )  );
         signed_keys.insert( address(pts_address(key,true,0) )   );
      }
      for( auto op : trx.operations )
      {
         evaluate_operation( op );
      }
      post_evaluate();
      validate_required_fee();
      update_delegate_votes();
   } FC_RETHROW_EXCEPTIONS( warn, "", ("trx",trx_arg) ) }
   void transaction_evaluation_state::evaluate( const signed_transaction& trx_arg, bool skip_signature_check, bool enforce_canonical )
   { try {
      _skip_signature_check = skip_signature_check;
      try {
        if( _current_state->now() >= trx_arg.expiration )
        {
           if( _current_state->now() > trx_arg.expiration || _current_state->get_head_block_num() >= BTS_V0_4_21_FORK_BLOCK_NUM )
           {
               const auto expired_by_sec = (_current_state->now() - trx_arg.expiration).to_seconds();
               FC_CAPTURE_AND_THROW( expired_transaction, (trx_arg)(_current_state->now())(expired_by_sec) );
           }
        }
        if( (_current_state->now() + BTS_BLOCKCHAIN_MAX_TRANSACTION_EXPIRATION_SEC) < trx_arg.expiration )
           FC_CAPTURE_AND_THROW( invalid_transaction_expiration, (trx_arg)(_current_state->now()) );

        auto trx_id = trx_arg.id();

        if( _current_state->is_known_transaction( trx_arg.expiration, trx_arg.digest( _chain_id ) ) )
          if (_current_state->get_head_block_num() >= FORK_25)
            FC_CAPTURE_AND_THROW( duplicate_transaction, (trx_id) );

        trx = trx_arg;
        if( !_skip_signature_check )
        {
           auto digest = trx_arg.digest( _chain_id );
           for( const auto& sig : trx.signatures )
           {
              auto key = fc::ecc::public_key( sig, digest, enforce_canonical ).serialize();
              signed_keys.insert( address(key) );
              signed_keys.insert( address(pts_address(key,false,56) ) );
              signed_keys.insert( address(pts_address(key,true,56) )  );
              signed_keys.insert( address(pts_address(key,false,0) )  );
              signed_keys.insert( address(pts_address(key,true,0) )   );
           }
        }
        current_op_index = 0;
        for( const auto& op : trx.operations )
        {
           evaluate_operation( op );
           ++current_op_index;
        }
        post_evaluate();
        validate_required_fee();
        update_delegate_votes();
      }
      catch ( const fc::exception& e )
      {
         validation_error = e;
         throw;
      }
   } FC_RETHROW_EXCEPTIONS( warn, "", ("trx",trx_arg) ) }
   void transaction_evaluation_state::evaluate( const signed_transaction& trx_arg, bool skip_signature_check )
   { try {
      reset();
      _skip_signature_check = skip_signature_check;
      try {
        if( trx_arg.expiration < _current_state->now() )
        {
           auto expired_by_sec = (trx_arg.expiration - _current_state->now()).to_seconds();
           FC_CAPTURE_AND_THROW( expired_transaction, (trx_arg)(_current_state->now())(expired_by_sec) );
        }
        if( trx_arg.expiration > (_current_state->now() + BTS_BLOCKCHAIN_MAX_TRANSACTION_EXPIRATION_SEC) )
           FC_CAPTURE_AND_THROW( invalid_transaction_expiration, (trx_arg)(_current_state->now()) );

        auto trx_size = fc::raw::pack_size(trx_arg);
        if(  trx_size > BTS_BLOCKCHAIN_MAX_TRANSACTION_SIZE )
           FC_CAPTURE_AND_THROW( oversized_transaction, (trx_size ) );
       
        auto trx_id = trx_arg.id();

        if( _current_state->is_known_transaction( trx_id ) )
           FC_CAPTURE_AND_THROW( duplicate_transaction, (trx_id) );
       
        trx = trx_arg;
        if( !_skip_signature_check )
        {
           auto digest = trx_arg.digest( _chain_id );
           for( auto sig : trx.signatures )
           {
              auto key = fc::ecc::public_key( sig, digest ).serialize();
              signed_keys.insert( address(key) );
              signed_keys.insert( address(pts_address(key,false,56) ) );
              signed_keys.insert( address(pts_address(key,true,56) )  );
              signed_keys.insert( address(pts_address(key,false,0) )  );
              signed_keys.insert( address(pts_address(key,true,0) )   );
           }
        }
        for( auto op : trx.operations )
        {
           evaluate_operation( op );
        }
        post_evaluate();
        validate_required_fee();
        update_delegate_votes();
      } 
      catch ( const fc::exception& e )
      {
         validation_error = e;
         throw;
      }
   } FC_RETHROW_EXCEPTIONS( warn, "", ("trx",trx_arg) ) }
 void transaction_evaluation_state::evaluate( const signed_transaction& trx_arg )
 { try {
    reset();
    try {
      if( trx_arg.expiration && *trx_arg.expiration < _current_state->now() )
         FC_CAPTURE_AND_THROW( expired_transaction, (trx_arg)(_current_state->now()) );
     
      auto trx_id = trx_arg.id();
      ilog( "id: ${id}", ("id",trx_id) );
      otransaction_record known_transaction= _current_state->get_transaction( trx_id );
      if( known_transaction )
         FC_CAPTURE_AND_THROW( duplicate_transaction, (known_transaction) );
     
      trx = trx_arg;
      auto digest = trx_arg.digest( _chain_id );
      for( auto sig : trx.signatures )
      {
         auto key = fc::ecc::public_key( sig, digest ).serialize();
         signed_keys.insert( address(key) );
         signed_keys.insert( address(pts_address(key,false,56) ) );
         signed_keys.insert( address(pts_address(key,true,56) )  );
         signed_keys.insert( address(pts_address(key,false,0) )  );
         signed_keys.insert( address(pts_address(key,true,0) )   );
      }
      for( auto op : trx.operations )
      {
         evaluate_operation( op );
      }
      post_evaluate();
      validate_required_fee();
      update_delegate_votes();
    } 
    catch ( const fc::exception& e )
    {
       validation_error = e;
       throw;
    }
 } FC_RETHROW_EXCEPTIONS( warn, "", ("trx",trx_arg) ) }
Exemple #5
0
int
evaluate_expression(struct obj_data * obj, char *expr)
{
  struct stack_data ops, vals;
  char *ptr, *end, name[200];
  int temp, index;

  if (!expr)
    return TRUE;

  if (!isalpha(*expr))
    return TRUE;

  ops.len = vals.len = 0;
  ptr = expr;
  while (*ptr)
    {
      if (isspace(*ptr))
    ptr++;
      else
    {
      if ((temp = find_oper_num(*ptr)) == NOTHING)
        {
          end = ptr;
          while (*ptr && !isspace(*ptr) && (find_oper_num(*ptr) == NOTHING))
        ptr++;
          strncpy(name, end, ptr - end);
          name[ptr - end] = 0;
          for (index = 0; *extra_bits[index] != '\n'; index++)
        if (!str_cmp(name, extra_bits[index]))
          {
            push(&vals, IS_SET_AR(GET_OBJ_EXTRA(obj), index));
            break;
          }
          if (*extra_bits[index] == '\n')
        push(&vals, isname(name, obj->name));
        }
      else
        {
          if (temp != OPER_OPEN_PAREN)
        while (top(&ops) > temp)
          evaluate_operation(&ops, &vals);

          if (temp == OPER_CLOSE_PAREN)
        {
          if ((temp = pop(&ops)) != OPER_OPEN_PAREN)
            {
              log("Illegal parenthesis in shop keyword expression");
              return (FALSE);
            }
        } else
        push(&ops, temp);
          ptr++;
        }
    }
    }
  while (top(&ops) != NOTHING)
    evaluate_operation(&ops, &vals);
  temp = pop(&vals);
  if (top(&vals) != NOTHING)
    {
      log("Extra operands left on shop keyword expression stack");
      return (FALSE);
    }
  return (temp);
}