Skip to content

Commit

Permalink
Gosec
Browse files Browse the repository at this point in the history
  • Loading branch information
0Tech committed Jan 24, 2024
1 parent 06cf838 commit ba6bd49
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 16 deletions.
16 changes: 12 additions & 4 deletions x/foundation/keeper/internal/censorship.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,16 @@ func (k Keeper) SetCensorship(ctx sdk.Context, censorship foundation.Censorship)
key := censorshipKey(censorship.MsgTypeUrl)

if censorship.Authority == foundation.CensorshipAuthorityUnspecified {
store.Delete(key)
if err := store.Delete(key); err != nil {
panic(err)
}
return
}

bz := k.cdc.MustMarshal(&censorship)
store.Set(key, bz)
if err := store.Set(key, bz); err != nil {
panic(err)
}
}

func (k Keeper) iterateCensorships(ctx sdk.Context, fn func(censorship foundation.Censorship) (stop bool)) {
Expand Down Expand Up @@ -186,13 +190,17 @@ func (k Keeper) setAuthorization(ctx sdk.Context, grantee sdk.AccAddress, author
if err != nil {
panic(err)
}
store.Set(key, bz)
if err := store.Set(key, bz); err != nil {
panic(err)
}
}

func (k Keeper) deleteAuthorization(ctx sdk.Context, grantee sdk.AccAddress, msgTypeURL string) {
store := k.storeService.OpenKVStore(ctx)
key := grantKey(grantee, msgTypeURL)
store.Delete(key)
if err := store.Delete(key); err != nil {
panic(err)
}
}

func (k Keeper) Accept(ctx sdk.Context, grantee sdk.AccAddress, msg sdk.Msg) error {
Expand Down
12 changes: 9 additions & 3 deletions x/foundation/keeper/internal/member.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ func (k Keeper) GetFoundationInfo(ctx sdk.Context) foundation.FoundationInfo {
func (k Keeper) SetFoundationInfo(ctx sdk.Context, info foundation.FoundationInfo) {
store := k.storeService.OpenKVStore(ctx)
bz := k.cdc.MustMarshal(&info)
store.Set(foundationInfoKey, bz)
if err := store.Set(foundationInfoKey, bz); err != nil {
panic(err)
}
}

func (k Keeper) UpdateMembers(ctx sdk.Context, members []foundation.MemberRequest) error {
Expand Down Expand Up @@ -137,13 +139,17 @@ func (k Keeper) SetMember(ctx sdk.Context, member foundation.Member) {
key := memberKey(addr)

bz := k.cdc.MustMarshal(&member)
store.Set(key, bz)
if err := store.Set(key, bz); err != nil {
panic(err)
}
}

func (k Keeper) deleteMember(ctx sdk.Context, address sdk.AccAddress) {
store := k.storeService.OpenKVStore(ctx)
key := memberKey(address)
store.Delete(key)
if err := store.Delete(key); err != nil {
panic(err)
}
}

func (k Keeper) iterateMembers(ctx sdk.Context, fn func(member foundation.Member) (stop bool)) {
Expand Down
4 changes: 3 additions & 1 deletion x/foundation/keeper/internal/migrations/v2/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ func migrateParams(ctx sdk.Context, store store.KVStore, cdc codec.BinaryCodec,
if bz == nil {
return fmt.Errorf("params not found")
}
store.Delete(ParamsKey)
if err := store.Delete(ParamsKey); err != nil {
return err
}

var params foundation.Params
if err := cdc.Unmarshal(bz, &params); err != nil {
Expand Down
20 changes: 15 additions & 5 deletions x/foundation/keeper/internal/proposal.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ func (k Keeper) getPreviousProposalID(ctx sdk.Context) uint64 {

func (k Keeper) setPreviousProposalID(ctx sdk.Context, id uint64) {
store := k.storeService.OpenKVStore(ctx)
store.Set(previousProposalIDKey, Uint64ToBytes(id))
if err := store.Set(previousProposalIDKey, Uint64ToBytes(id)); err != nil {
panic(err)
}
}

func (k Keeper) SubmitProposal(ctx sdk.Context, proposers []string, metadata string, msgs []sdk.Msg) (*uint64, error) {
Expand Down Expand Up @@ -230,25 +232,33 @@ func (k Keeper) setProposal(ctx sdk.Context, proposal foundation.Proposal) {
key := proposalKey(proposal.Id)

bz := k.cdc.MustMarshal(&proposal)
store.Set(key, bz)
if err := store.Set(key, bz); err != nil {
panic(err)
}
}

func (k Keeper) deleteProposal(ctx sdk.Context, proposalID uint64) {
store := k.storeService.OpenKVStore(ctx)
key := proposalKey(proposalID)
store.Delete(key)
if err := store.Delete(key); err != nil {
panic(err)
}
}

func (k Keeper) addProposalToVPEndQueue(ctx sdk.Context, proposal foundation.Proposal) {
store := k.storeService.OpenKVStore(ctx)
key := proposalByVPEndKey(proposal.VotingPeriodEnd, proposal.Id)
store.Set(key, []byte{})
if err := store.Set(key, []byte{}); err != nil {
panic(err)
}
}

func (k Keeper) removeProposalFromVPEndQueue(ctx sdk.Context, proposal foundation.Proposal) {
store := k.storeService.OpenKVStore(ctx)
key := proposalByVPEndKey(proposal.VotingPeriodEnd, proposal.Id)
store.Delete(key)
if err := store.Delete(key); err != nil {
panic(err)
}
}

func validateActorForProposal(address string, proposal foundation.Proposal) error {
Expand Down
4 changes: 3 additions & 1 deletion x/foundation/keeper/internal/treasury.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,5 +75,7 @@ func (k Keeper) SetPool(ctx sdk.Context, pool foundation.Pool) {

store := k.storeService.OpenKVStore(ctx)
key := poolKey
store.Set(key, bz)
if err := store.Set(key, bz); err != nil {
panic(err)
}
}
8 changes: 6 additions & 2 deletions x/foundation/keeper/internal/vote.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,9 @@ func (k Keeper) setVote(ctx sdk.Context, vote foundation.Vote) {

key := voteKey(vote.ProposalId, voter)
bz := k.cdc.MustMarshal(&vote)
store.Set(key, bz)
if err := store.Set(key, bz); err != nil {
panic(err)
}
}

func (k Keeper) iterateVotes(ctx sdk.Context, proposalID uint64, fn func(vote foundation.Vote) (stop bool)) {
Expand Down Expand Up @@ -127,6 +129,8 @@ func (k Keeper) pruneVotes(ctx sdk.Context, proposalID uint64) {

store := k.storeService.OpenKVStore(ctx)
for _, key := range keys {
store.Delete(key)
if err := store.Delete(key); err != nil {
panic(err)
}
}
}

0 comments on commit ba6bd49

Please sign in to comment.