// CheckProposalsUpdates updates the proposal changes if they exist and updates
// them to the proposal db.
979055
func (db *ProposalDB) CheckProposalsUpdates() error {
	if db == nil || db.dbP == nil {
		return errDef
	}

	db.mtx.Lock()
	defer func() {
		// Update the lastSync before the function exits.

		db.lastSync = time.Now().UTC().Unix()
		db.mtx.Unlock()
	}()

	// Retrieve and update all current proposals whose vote statuses is either
	// NotAuthorized, Authorized and Started
	numRecords, err := db.updateInProgressProposals()
	if err != nil {
		return err
	}

	// Retrieve and update any new proposals created since the previous
	// proposals were stored in the db.
	lastProposal, err := db.lastSavedProposal()
	if err != nil {
		return fmt.Errorf("lastSavedProposal failed: %v", err)
	}

	var queryParam string
	if len(lastProposal) > 0 && lastProposal[0].TokenVal != "" {
		queryParam = fmt.Sprintf("?after=%s", lastProposal[0].TokenVal)
	}

	n, err := db.saveProposals(queryParam)
	if err != nil {
		return err
	}

	// Add the sum of the newly added proposals.
	numRecords += n

	log.Infof("%d proposal records (politeia proposals-storm) were updated", numRecords)

	return nil
}
720112
func (m *GormRoleMappingRepository) CheckExists(ctx context.Context, id uuid.UUID) error {
	defer goa.MeasureSince([]string{"goa", "db", "role_mapping", "exists"}, time.Now())
	return base.CheckExistsWithCustomIDColumn(ctx, m.db, m.TableName(), "role_mapping_id", id.String())
}
1337132
func (gov *Governmint) validateProposal(store base.KVStore, p types.Proposal, proposer *types.Entity) (res tmsp.Result) {
	// Ensure that the proposal is unique
	if _, exists := gov.GetActiveProposal(store, p.ID); exists {
		return tmsp.NewError(tmsp.CodeType_GovDuplicateProposal,
			Fmt("Proposal with id %v already exists", p.ID))
	}
	// Ensure that the voting group exists
	voteGroup, ok := gov.GetGroup(store, p.VoteGroupID)
	if !ok {
		return tmsp.NewError(tmsp.CodeType_GovUnknownGroup,
			Fmt("Vote group with id %v doesn't exist", p.VoteGroupID))
	}
	// Ensure that the proposer belongs to the voting group
	if !isMemberOf(voteGroup, proposer.Addr) {
		return tmsp.NewError(tmsp.CodeType_Unauthorized,
			Fmt("Proposer %X is not member of %v", proposer.Addr, voteGroup.ID))
	}
	// Type dependent checks
	switch pInfo := p.Info.(type) {
	case *types.GroupCreateProposalInfo:
		// Ensure that the group ID is not taken
		if _, exists := gov.GetGroup(store, pInfo.NewGroupID); exists {
			return tmsp.NewError(tmsp.CodeType_GovDuplicateGroup,
				Fmt("Group with id %v already exists", pInfo.NewGroupID))
		}
		// Ensure that the member entities are unique
		if ok, dupe := validateUniqueMembers(pInfo.Members); !ok {
			return tmsp.NewError(tmsp.CodeType_GovDuplicateMember,
				Fmt("Duplicate member %v", dupe))
		}
		// Ensure that the member voting powers are reasonable
		for _, member := range pInfo.Members {
			if member.VotingPower == 0 {
				return tmsp.NewError(tmsp.CodeType_GovInvalidVotingPower,
					Fmt("Member cannot have 0 voting power"))
			}
			if member.VotingPower > MaxVotingPower {
				return tmsp.NewError(tmsp.CodeType_GovInvalidVotingPower,
					Fmt("Member voting power too large"))
			}
		}
		// Ensure that all the entities exist
		entityAddrs := entityAddrsFromMembers(pInfo.Members)
		_, unknownEntityAddr := gov.loadEntities(store, entityAddrs)
		if unknownEntityAddr != nil {
			return tmsp.NewError(tmsp.CodeType_GovUnknownEntity,
				Fmt("Group creation with unknown entity %X", unknownEntityAddr))
		}
	case *types.GroupUpdateProposalInfo:
		// Ensure that the update group exists
		updateGroup, ok := gov.GetGroup(store, pInfo.UpdateGroupID)
		if !ok {
			return tmsp.NewError(tmsp.CodeType_GovUnknownGroup,
				Fmt("Group with id %v doesn't exist", pInfo.UpdateGroupID))
		}
		// Ensure that the update group's parent is the voting group
		// XXX Admin check?
		if updateGroup.ParentID != voteGroup.ID {
			return tmsp.NewError(tmsp.CodeType_Unauthorized,
				Fmt("Group %v cannot update %v", voteGroup.ID, updateGroup.ID))
		}
		// Ensure that the member entities are unique
		if ok, dupe := validateUniqueMembers(pInfo.ChangedMembers); !ok {
			return tmsp.NewError(tmsp.CodeType_GovDuplicateMember,
				Fmt("Duplicate member %v", dupe))
		}
		// Ensure that the member voting powers are reasonable
		for _, member := range pInfo.ChangedMembers {
			if member.VotingPower == 0 {
				// This is fine, we're removing members.
			}
			if member.VotingPower > MaxVotingPower {
				return tmsp.NewError(tmsp.CodeType_GovInvalidVotingPower,
					Fmt("Member voting power too large"))
			}
		}
		// Ensure that all the entities exist
		entityAddrs := entityAddrsFromMembers(pInfo.ChangedMembers)
		_, unknownEntityAddr := gov.loadEntities(store, entityAddrs)
		if unknownEntityAddr != nil {
			return tmsp.NewError(tmsp.CodeType_GovUnknownEntity,
				Fmt("Group creation with unknown entity %X", unknownEntityAddr))
		}
	case *types.TextProposalInfo:
		// TODO text string validation, e.g. max length
	case *types.UpgradeProposalInfo:
		// Ensure that the group is admin.
		if voteGroup.ID != types.AdminGroupID {
			return tmsp.NewError(tmsp.CodeType_Unauthorized,
				Fmt("Upgrade proposals must be voted on by admin group"))
		}
		// Ensure that the number of modules is > 0.
		if len(pInfo.Modules) == 0 {
			return tmsp.NewError(tmsp.CodeType_EncodingError,
				Fmt("Software upgrade requires > 0 modules"))
		}
	}
	return tmsp.NewResultOK(nil, "")
}
611601
func (cm *Validator) ProposeConfigUpdate(update *cb.Envelope) (*cb.ConfigEnvelope, error) {
	return cm.ProposeConfigUpdateVal, cm.ProposeConfigUpdateError
}
813295
func (s *GatewayAssociationProposal) SetProposalId(v string) *GatewayAssociationProposal {
	s.ProposalId = &v
	return s
}
1364325
func (lsi *LastSignedInfo) SignProposal(sign tmCryptoSigner, chainID string, proposal *types.Proposal) error {
	lsi.Lock()
	defer lsi.Unlock()
	if err := lsi.signProposal(sign, chainID, proposal); err != nil {
		return fmt.Errorf("error signing proposal: %v", err)
	}
	return nil
}
1010464
func (vi *ValidatorImpl) ProposeConfigUpdate(configtx *cb.Envelope) (*cb.ConfigEnvelope, error) {
	return vi.proposeConfigUpdate(configtx)
}
462479
func (rb *route) procureValues(bldr builder, jt *jointab, val sqlparser.Expr) (sqltypes.PlanValue, error) {
	switch val := val.(type) {
	case sqlparser.ValTuple:
		pv := sqltypes.PlanValue{}
		for _, val := range val {
			v, err := rb.procureValues(bldr, jt, val)
			if err != nil {
				return pv, err
			}
			pv.Values = append(pv.Values, v)
		}
		return pv, nil
	case *sqlparser.ColName:
		joinVar := jt.Procure(bldr, val, rb.Order())
		return sqltypes.PlanValue{Key: joinVar}, nil
	default:
		return sqlparser.NewPlanValue(val)
	}
}
892336
func ValidateConditionalEndpoints(endpoints, oldEndpoints *api.Endpoints) field.ErrorList {
	var errs field.ErrorList
	// If the SCTPSupport feature is disabled, and the old object isn't using the SCTP feature, prevent the new object from using it
	if !utilfeature.DefaultFeatureGate.Enabled(features.SCTPSupport) && len(endpointsSCTPFields(oldEndpoints)) == 0 {
		for _, f := range endpointsSCTPFields(endpoints) {
			errs = append(errs, field.NotSupported(f, api.ProtocolSCTP, []string{string(api.ProtocolTCP), string(api.ProtocolUDP)}))
		}
	}
	return errs
}
1109681
func (o *ObjectConstraint) GetPropDependencies(from string) []string {
	o.deplock.Lock()
	defer o.deplock.Unlock()

	l, ok := o.propdeps[from]
	if !ok {
		return nil
	}

	return l
}
1314037
func (s *ProposalSummary) SetProposalId(v string) *ProposalSummary {
	s.ProposalId = &v
	return s
}
1095583
func (g *GenOpts) CheckOpts() error {
	if !filepath.IsAbs(g.Target) {
		if _, err := filepath.Abs(g.Target); err != nil {
			return fmt.Errorf("could not locate target %s: %v", g.Target, err)
		}
	}
	if filepath.IsAbs(g.ServerPackage) {
		return fmt.Errorf("you shouldn't specify an absolute path in --server-package: %s", g.ServerPackage)
	}
	if !filepath.IsAbs(g.Spec) && !strings.HasPrefix(g.Spec, "http://") && !strings.HasPrefix(g.Spec, "https://") {
		if _, err := filepath.Abs(g.Spec); err != nil {
			return fmt.Errorf("could not locate spec: %s", g.Spec)
		}
	}
	return nil
}
43781
func (m *Miniredis) checkPubsub(c *server.Peer) bool {
	m.Lock()
	defer m.Unlock()

	ctx := getCtx(c)
	if ctx.subscriber == nil {
		return false
	}

	c.WriteError("ERR only (P)SUBSCRIBE / (P)UNSUBSCRIBE / PING / QUIT allowed in this context")
	return true
}
337973
func (f *expirationCheckFilter) ProcessProposal(ctx context.Context, signedProp *peer.SignedProposal) (*peer.ProposalResponse, error) {
	if err := validateProposal(signedProp); err != nil {
		return nil, err
	}
	return f.next.ProcessProposal(ctx, signedProp)
}
880050
func checkPropsExist(loginDoc map[string]interface{}) error {
	// Make sure the user provides a username
	id, ok := loginDoc["username"].(string)
	if ok != true {
		return errors.New("Need username to login")
	} else if len(id) < variables.ShortestUsername {
		// FIXME: Make concatination constant
		return errors.New("Username must be at least " + strconv.Itoa(variables.ShortestUsername))
	}
	// Make sure the user provides a password
	password, ok := loginDoc["password"].(string)
	if ok != true {
		return errors.New("Need password to login")
	} else if len(password) < variables.ShortestPassword {
		// FIXME: Make concatination constant
		return errors.New("Password must be at least " + strconv.Itoa(variables.ShortestPassword))
	}
	return nil
}
414165
func (pgb *ChainDB) proposalsUpdateHandler() {
	// Do not initiate the async update if invalid piparser instance was found.
	if pgb.piparser == nil {
		log.Debug("invalid piparser instance was found: async update stopped")
		return
	}

	go func() {
		for range pgb.piparser.UpdateSignal() {
			count, err := pgb.PiProposalsHistory()
			if err != nil {
				log.Error("pgb.PiProposalsHistory failed : %v", err)
			} else {
				log.Infof("%d politeia's proposal commits were processed", count)
			}
		}
	}()
}
315578
func (r *GormTrackerRepository) CheckExists(ctx context.Context, id uuid.UUID) error {
	return repository.CheckExists(ctx, r.db, trackersTableName, id)
}