Skip to content

Commit

Permalink
Governance: Fix MultiChoice VoteType serialization
Browse files Browse the repository at this point in the history
  • Loading branch information
ochaloup committed Oct 26, 2022
1 parent 3bbb3cc commit a2eb60d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
6 changes: 4 additions & 2 deletions packages/governance-sdk/src/governance/accounts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,11 +201,13 @@ export enum VoteTypeKind {

export class VoteType {
type: VoteTypeKind;
choiceCount: number | undefined;
maxVoterOptions: number | undefined;
maxWinningOptions: number | undefined;

constructor(args: { type: VoteTypeKind; choiceCount: number | undefined }) {
this.type = args.type;
this.choiceCount = args.choiceCount;
this.maxVoterOptions = args.choiceCount;
this.maxWinningOptions = args.choiceCount;
}

static SINGLE_CHOICE = new VoteType({
Expand Down
10 changes: 7 additions & 3 deletions packages/governance-sdk/src/governance/serialisation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ import { deserializeBorsh } from '../tools/borsh';
return VoteType.SINGLE_CHOICE;
}

const choiceCount = reader.buf.readUInt16LE(reader.offset);
const choiceCount = reader.buf.readUInt8(reader.offset);
reader.offset += 2; // skip two bytes
return VoteType.MULTI_CHOICE(choiceCount);
};

Expand All @@ -111,8 +112,11 @@ import { deserializeBorsh } from '../tools/borsh';
writer.length += 1;

if (value.type === VoteTypeKind.MultiChoice) {
writer.buf.writeUInt16LE(value.choiceCount!, writer.length);
writer.length += 2;
// maxVoterOptions and maxWinningOtions are not implemented at backend
writer.buf.writeUInt8(value.maxVoterOptions || 0, writer.length);
writer.length += 1;
writer.buf.writeUInt8(value.maxWinningOptions || 0, writer.length);
writer.length += 1;
}
};

Expand Down

0 comments on commit a2eb60d

Please sign in to comment.