Skip to content

Commit

Permalink
save
Browse files Browse the repository at this point in the history
  • Loading branch information
NYBACHOK committed Jun 5, 2024
1 parent 67ae30a commit 171902b
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 6 deletions.
42 changes: 38 additions & 4 deletions x/gov/src/keeper.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
use gears::{
application::keepers::params::ParamsKeeper,
context::init::InitContext,
params::ParamsSubspaceKey,
store::{database::Database, StoreKey},
};

use crate::{genesis::GovGenesisState, params::GovParamsKeeper};
use crate::{
errors::SERDE_JSON_CONVERSION, genesis::GovGenesisState, params::GovParamsKeeper,
types::deposit::Deposit,
};

// const PROPOSAL_ID_KEY: [u8; 1] = [0x03];
const PROPOSAL_ID_KEY: [u8; 1] = [0x03];
const KEY_DEPOSIT_PREFIX : [u8;1] = [0x10];

#[allow(dead_code)]
pub struct GovKeeper<SK: StoreKey, PSK: ParamsSubspaceKey> {
Expand All @@ -26,8 +31,37 @@ impl<SK: StoreKey, PSK: ParamsSubspaceKey> GovKeeper<SK, PSK> {

pub fn init_genesis<DB: Database>(
&self,
_ctx: &mut InitContext<'_, DB, SK>,
_genesis: GovGenesisState,
ctx: &mut InitContext<'_, DB, SK>,
GovGenesisState {
starting_proposal_id,
deposits,
votes,
proposals,
params,
}: GovGenesisState,
) {
{
let mut store = ctx.kv_store_mut(&self.store_key);
store.set(PROPOSAL_ID_KEY, starting_proposal_id.to_be_bytes())
}
self.gov_params_keeper.set(ctx, params);

// // check if the deposits pool account exists
// moduleAcc := k.GetGovernanceAccount(ctx)
// if moduleAcc == nil {
// panic(fmt.Sprintf("%s module account has not been set", types.ModuleName))
// }

{
// let mut total_deposits = Vec::with_capacity(deposits.len());
}
}

fn deposit_set<DB: Database>(&self, ctx: &mut InitContext<'_, DB, SK>, deposit: Deposit) {
let deposit_bytes = serde_json::to_vec(&deposit).expect(SERDE_JSON_CONVERSION); // TODO:NOW CORRECT SERIALIZATION

let key =

let mut store = ctx.kv_store_mut(&self.store_key);
}
}
6 changes: 4 additions & 2 deletions x/gov/src/types/deposit.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use gears::types::base::coin::Coin;
use gears::types::{address::AccAddress, base::coin::Coin};
use serde::{Deserialize, Serialize};

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct Deposit {
pub proposal_id: u64,
pub depositor: String,
pub depositor: AccAddress,
pub amount: Vec<Coin>,
}
3 changes: 3 additions & 0 deletions x/gov/src/types/proposal.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use gears::types::base::coin::Coin;
use serde::{Deserialize, Serialize};

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct Proposal {
pub proposal_id: u64,
pub content: Vec<u8>, // TODO
Expand All @@ -12,6 +14,7 @@ pub struct Proposal {
pub voting_end_time: (),
}

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub enum ProposalStatus {
Nil,
DepositPeriod,
Expand Down
3 changes: 3 additions & 0 deletions x/gov/src/types/vote.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
use serde::{Deserialize, Serialize};

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct Vote {
pub proposal_id: u64,
pub voter: String,
Expand Down

0 comments on commit 171902b

Please sign in to comment.