Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ type App struct {
ScopedTransferKeeper capabilitykeeper.ScopedKeeper
ScopedMonitoringKeeper capabilitykeeper.ScopedKeeper

ScopedVotingKeeper capabilitykeeper.ScopedKeeper
VotingKeeper votingmodulekeeper.Keeper
ScopedOracleKeeper capabilitykeeper.ScopedKeeper
OracleKeeper oraclemodulekeeper.Keeper
Expand Down Expand Up @@ -408,11 +409,16 @@ func New(
scopedOracleKeeper,
)
oracleModule := oraclemodule.NewAppModule(appCodec, app.OracleKeeper, app.AccountKeeper, app.BankKeeper)
scopedVotingKeeper := app.CapabilityKeeper.ScopeToModule(votingmoduletypes.ModuleName)
app.ScopedVotingKeeper = scopedVotingKeeper
app.VotingKeeper = *votingmodulekeeper.NewKeeper(
appCodec,
keys[votingmoduletypes.StoreKey],
keys[votingmoduletypes.MemStoreKey],
app.GetSubspace(votingmoduletypes.ModuleName),
app.IBCKeeper.ChannelKeeper,
&app.IBCKeeper.PortKeeper,
scopedVotingKeeper,

app.AccountKeeper,
app.BankKeeper,
Expand All @@ -428,6 +434,7 @@ func New(
ibcRouter.AddRoute(ibctransfertypes.ModuleName, transferIBCModule)
ibcRouter.AddRoute(monitoringptypes.ModuleName, monitoringModule)
ibcRouter.AddRoute(oraclemoduletypes.ModuleName, oracleModule)
ibcRouter.AddRoute(votingmoduletypes.ModuleName, votingModule)
// this line is used by starport scaffolding # ibc/app/router
app.IBCKeeper.SetRouter(ibcRouter)

Expand Down
9 changes: 5 additions & 4 deletions proto/voting/genesis.proto
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ option go_package = "mande-chain/x/voting/types";
// GenesisState defines the voting module's genesis state.
message GenesisState {
Params params = 1 [(gogoproto.nullable) = false];
repeated VoteBook voteBookList = 2 [(gogoproto.nullable) = false];
repeated AggregateVotesCasted aggregateVotesCastedList = 3 [(gogoproto.nullable) = false];
repeated AggregateVotesReceived aggregateVotesReceivedList = 4 [(gogoproto.nullable) = false];
repeated Credibility credibilityList = 5 [(gogoproto.nullable) = false];
string port_id = 2;
repeated VoteBook voteBookList = 3 [(gogoproto.nullable) = false];
repeated AggregateVotesCasted aggregateVotesCastedList = 4 [(gogoproto.nullable) = false];
repeated AggregateVotesReceived aggregateVotesReceivedList = 5 [(gogoproto.nullable) = false];
repeated Credibility credibilityList = 6 [(gogoproto.nullable) = false];
// this line is used by starport scaffolding # genesis/proto/state
}
18 changes: 18 additions & 0 deletions proto/voting/packet.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
syntax = "proto3";
package mandechain.voting;

// this line is used by starport scaffolding # proto/packet/import

option go_package = "mande-chain/x/voting/types";

message VotingPacketData {
oneof packet {
NoData noData = 1;
// this line is used by starport scaffolding # ibc/packet/proto/field
}
}

message NoData {
}

// this line is used by starport scaffolding # ibc/packet/proto/message
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ import { AggregateVotesCasted } from "./module/types/voting/aggregate_votes_cast
import { AggregateVotesReceived } from "./module/types/voting/aggregate_votes_received"
import { Credibility } from "./module/types/voting/credibility"
import { AppliedX } from "./module/types/voting/credibility"
import { VotingPacketData } from "./module/types/voting/packet"
import { NoData } from "./module/types/voting/packet"
import { Params } from "./module/types/voting/params"
import { VoteBook } from "./module/types/voting/vote_book"


export { AggregateVotesCasted, AggregateVotesReceived, Credibility, AppliedX, Params, VoteBook };
export { AggregateVotesCasted, AggregateVotesReceived, Credibility, AppliedX, VotingPacketData, NoData, Params, VoteBook };

async function initTxClient(vuexGetters) {
return await txClient(vuexGetters['common/wallet/signer'], {
Expand Down Expand Up @@ -60,6 +62,8 @@ const getDefaultState = () => {
AggregateVotesReceived: getStructure(AggregateVotesReceived.fromPartial({})),
Credibility: getStructure(Credibility.fromPartial({})),
AppliedX: getStructure(AppliedX.fromPartial({})),
VotingPacketData: getStructure(VotingPacketData.fromPartial({})),
NoData: getStructure(NoData.fromPartial({})),
Params: getStructure(Params.fromPartial({})),
VoteBook: getStructure(VoteBook.fromPartial({})),

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,31 +11,35 @@ export const protobufPackage = "mandechain.voting";
/** GenesisState defines the voting module's genesis state. */
export interface GenesisState {
params: Params | undefined;
port_id: string;
voteBookList: VoteBook[];
aggregateVotesCastedList: AggregateVotesCasted[];
aggregateVotesReceivedList: AggregateVotesReceived[];
/** this line is used by starport scaffolding # genesis/proto/state */
credibilityList: Credibility[];
}

const baseGenesisState: object = {};
const baseGenesisState: object = { port_id: "" };

export const GenesisState = {
encode(message: GenesisState, writer: Writer = Writer.create()): Writer {
if (message.params !== undefined) {
Params.encode(message.params, writer.uint32(10).fork()).ldelim();
}
if (message.port_id !== "") {
writer.uint32(18).string(message.port_id);
}
for (const v of message.voteBookList) {
VoteBook.encode(v!, writer.uint32(18).fork()).ldelim();
VoteBook.encode(v!, writer.uint32(26).fork()).ldelim();
}
for (const v of message.aggregateVotesCastedList) {
AggregateVotesCasted.encode(v!, writer.uint32(26).fork()).ldelim();
AggregateVotesCasted.encode(v!, writer.uint32(34).fork()).ldelim();
}
for (const v of message.aggregateVotesReceivedList) {
AggregateVotesReceived.encode(v!, writer.uint32(34).fork()).ldelim();
AggregateVotesReceived.encode(v!, writer.uint32(42).fork()).ldelim();
}
for (const v of message.credibilityList) {
Credibility.encode(v!, writer.uint32(42).fork()).ldelim();
Credibility.encode(v!, writer.uint32(50).fork()).ldelim();
}
return writer;
},
Expand All @@ -55,19 +59,22 @@ export const GenesisState = {
message.params = Params.decode(reader, reader.uint32());
break;
case 2:
message.voteBookList.push(VoteBook.decode(reader, reader.uint32()));
message.port_id = reader.string();
break;
case 3:
message.voteBookList.push(VoteBook.decode(reader, reader.uint32()));
break;
case 4:
message.aggregateVotesCastedList.push(
AggregateVotesCasted.decode(reader, reader.uint32())
);
break;
case 4:
case 5:
message.aggregateVotesReceivedList.push(
AggregateVotesReceived.decode(reader, reader.uint32())
);
break;
case 5:
case 6:
message.credibilityList.push(
Credibility.decode(reader, reader.uint32())
);
Expand All @@ -91,6 +98,11 @@ export const GenesisState = {
} else {
message.params = undefined;
}
if (object.port_id !== undefined && object.port_id !== null) {
message.port_id = String(object.port_id);
} else {
message.port_id = "";
}
if (object.voteBookList !== undefined && object.voteBookList !== null) {
for (const e of object.voteBookList) {
message.voteBookList.push(VoteBook.fromJSON(e));
Expand Down Expand Up @@ -129,6 +141,7 @@ export const GenesisState = {
const obj: any = {};
message.params !== undefined &&
(obj.params = message.params ? Params.toJSON(message.params) : undefined);
message.port_id !== undefined && (obj.port_id = message.port_id);
if (message.voteBookList) {
obj.voteBookList = message.voteBookList.map((e) =>
e ? VoteBook.toJSON(e) : undefined
Expand Down Expand Up @@ -171,6 +184,11 @@ export const GenesisState = {
} else {
message.params = undefined;
}
if (object.port_id !== undefined && object.port_id !== null) {
message.port_id = object.port_id;
} else {
message.port_id = "";
}
if (object.voteBookList !== undefined && object.voteBookList !== null) {
for (const e of object.voteBookList) {
message.voteBookList.push(VoteBook.fromPartial(e));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
/* eslint-disable */
import { Writer, Reader } from "protobufjs/minimal";

export const protobufPackage = "mandechain.voting";

export interface VotingPacketData {
/** this line is used by starport scaffolding # ibc/packet/proto/field */
noData: NoData | undefined;
}

export interface NoData {}

const baseVotingPacketData: object = {};

export const VotingPacketData = {
encode(message: VotingPacketData, writer: Writer = Writer.create()): Writer {
if (message.noData !== undefined) {
NoData.encode(message.noData, writer.uint32(10).fork()).ldelim();
}
return writer;
},

decode(input: Reader | Uint8Array, length?: number): VotingPacketData {
const reader = input instanceof Uint8Array ? new Reader(input) : input;
let end = length === undefined ? reader.len : reader.pos + length;
const message = { ...baseVotingPacketData } as VotingPacketData;
while (reader.pos < end) {
const tag = reader.uint32();
switch (tag >>> 3) {
case 1:
message.noData = NoData.decode(reader, reader.uint32());
break;
default:
reader.skipType(tag & 7);
break;
}
}
return message;
},

fromJSON(object: any): VotingPacketData {
const message = { ...baseVotingPacketData } as VotingPacketData;
if (object.noData !== undefined && object.noData !== null) {
message.noData = NoData.fromJSON(object.noData);
} else {
message.noData = undefined;
}
return message;
},

toJSON(message: VotingPacketData): unknown {
const obj: any = {};
message.noData !== undefined &&
(obj.noData = message.noData ? NoData.toJSON(message.noData) : undefined);
return obj;
},

fromPartial(object: DeepPartial<VotingPacketData>): VotingPacketData {
const message = { ...baseVotingPacketData } as VotingPacketData;
if (object.noData !== undefined && object.noData !== null) {
message.noData = NoData.fromPartial(object.noData);
} else {
message.noData = undefined;
}
return message;
},
};

const baseNoData: object = {};

export const NoData = {
encode(_: NoData, writer: Writer = Writer.create()): Writer {
return writer;
},

decode(input: Reader | Uint8Array, length?: number): NoData {
const reader = input instanceof Uint8Array ? new Reader(input) : input;
let end = length === undefined ? reader.len : reader.pos + length;
const message = { ...baseNoData } as NoData;
while (reader.pos < end) {
const tag = reader.uint32();
switch (tag >>> 3) {
default:
reader.skipType(tag & 7);
break;
}
}
return message;
},

fromJSON(_: any): NoData {
const message = { ...baseNoData } as NoData;
return message;
},

toJSON(_: NoData): unknown {
const obj: any = {};
return obj;
},

fromPartial(_: DeepPartial<NoData>): NoData {
const message = { ...baseNoData } as NoData;
return message;
},
};

type Builtin = Date | Function | Uint8Array | string | number | undefined;
export type DeepPartial<T> = T extends Builtin
? T
: T extends Array<infer U>
? Array<DeepPartial<U>>
: T extends ReadonlyArray<infer U>
? ReadonlyArray<DeepPartial<U>>
: T extends {}
? { [K in keyof T]?: DeepPartial<T[K]> }
: Partial<T>;
13 changes: 13 additions & 0 deletions x/voting/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,18 @@ func InitGenesis(ctx sdk.Context, k keeper.Keeper, genState types.GenesisState)
for _, elem := range genState.CredibilityList {
k.SetCredibility(ctx, elem)
}
k.SetPort(ctx, genState.PortId)
// Only try to bind to port if it is not already bound, since we may already own
// port capability from capability InitGenesis
if !k.IsBound(ctx, genState.PortId) {
// module binds to the port on InitChain
// and claims the returned capability
err := k.BindPort(ctx, genState.PortId)
if err != nil {
panic("could not claim port capability: " + err.Error())
}
}

// this line is used by starport scaffolding # genesis/module/init
k.SetParams(ctx, genState.Params)
}
Expand All @@ -33,6 +45,7 @@ func InitGenesis(ctx sdk.Context, k keeper.Keeper, genState types.GenesisState)
func ExportGenesis(ctx sdk.Context, k keeper.Keeper) *types.GenesisState {
genesis := types.DefaultGenesis()
genesis.Params = k.GetParams(ctx)
genesis.PortId = k.GetPort(ctx)

genesis.VoteBookList = k.GetAllVoteBook(ctx)
genesis.AggregateVotesCastedList = k.GetAllAggregateVotesCasted(ctx)
Expand Down
3 changes: 3 additions & 0 deletions x/voting/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
func TestGenesis(t *testing.T) {
genesisState := types.GenesisState{
Params: types.DefaultParams(),
PortId: types.PortID,

VoteBookList: []types.VoteBook{
{
Expand Down Expand Up @@ -57,6 +58,8 @@ func TestGenesis(t *testing.T) {
nullify.Fill(&genesisState)
nullify.Fill(got)

require.Equal(t, genesisState.PortId, got.PortId)

require.ElementsMatch(t, genesisState.VoteBookList, got.VoteBookList)
require.ElementsMatch(t, genesisState.AggregateVotesCastedList, got.AggregateVotesCastedList)
require.ElementsMatch(t, genesisState.AggregateVotesReceivedList, got.AggregateVotesReceivedList)
Expand Down
12 changes: 12 additions & 0 deletions x/voting/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@ import (
paramtypes "github.com/cosmos/cosmos-sdk/x/params/types"
oracletypes "mande-chain/x/oracle/types"
"mande-chain/x/voting/types"
"github.com/ignite/cli/ignite/pkg/cosmosibckeeper"
)

type (
Keeper struct {
*cosmosibckeeper.Keeper
cdc codec.BinaryCodec
storeKey sdk.StoreKey
memKey sdk.StoreKey
Expand All @@ -32,6 +34,9 @@ func NewKeeper(
storeKey,
memKey sdk.StoreKey,
ps paramtypes.Subspace,
channelKeeper cosmosibckeeper.ChannelKeeper,
portKeeper cosmosibckeeper.PortKeeper,
scopedKeeper cosmosibckeeper.ScopedKeeper,

accountKeeper types.AccountKeeper, bankKeeper types.BankKeeper, stakingKeeper types.StakingKeeper, oracleKeeper types.OracleKeeper,
) *Keeper {
Expand All @@ -41,6 +46,13 @@ func NewKeeper(
}

return &Keeper{
Keeper: cosmosibckeeper.NewKeeper(
types.PortKey,
storeKey,
channelKeeper,
portKeeper,
scopedKeeper,
),

cdc: cdc,
storeKey: storeKey,
Expand Down
Loading