From 392cbe2dcf9c11985481cbd6fc005de924f419ff Mon Sep 17 00:00:00 2001 From: Ondra Chaloupka Date: Wed, 26 Oct 2022 10:44:30 +0200 Subject: [PATCH] Governance: Fix MultiChoice VoteType serialization --- packages/governance-sdk/src/governance/accounts.ts | 6 ++++-- .../governance-sdk/src/governance/serialisation.ts | 10 +++++++--- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/packages/governance-sdk/src/governance/accounts.ts b/packages/governance-sdk/src/governance/accounts.ts index 0587abbb..721fa49e 100644 --- a/packages/governance-sdk/src/governance/accounts.ts +++ b/packages/governance-sdk/src/governance/accounts.ts @@ -201,11 +201,13 @@ export enum VoteTypeKind { export class VoteType { type: VoteTypeKind; - choiceCount: number | undefined; + max_voter_options: number | undefined; + max_winning_options: number | undefined; constructor(args: { type: VoteTypeKind; choiceCount: number | undefined }) { this.type = args.type; - this.choiceCount = args.choiceCount; + this.max_voter_options = args.choiceCount; + this.max_winning_options = args.choiceCount; } static SINGLE_CHOICE = new VoteType({ diff --git a/packages/governance-sdk/src/governance/serialisation.ts b/packages/governance-sdk/src/governance/serialisation.ts index 48f01f9a..caee69f1 100644 --- a/packages/governance-sdk/src/governance/serialisation.ts +++ b/packages/governance-sdk/src/governance/serialisation.ts @@ -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); }; @@ -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; + // max_voter_options and max_winning_options are not implemented at backend + writer.buf.writeUInt8(value.max_voter_options || 0, writer.length); + writer.length += 1; + writer.buf.writeUInt8(value.max_winning_options || 0, writer.length); + writer.length += 1; } };