Skip to content

Commit

Permalink
Implementes decoding findInterfaces function
Browse files Browse the repository at this point in the history
Signed-off-by: emmdim <[email protected]>
  • Loading branch information
emmdim committed Sep 27, 2023
1 parent e302afe commit 7845700
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 2 deletions.
2 changes: 2 additions & 0 deletions packages/js-client/src/internal/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
GasFeeEstimation,
PrepareInstallationStepValue,
DaoAction,
InterfaceParams,
} from '@aragon/sdk-client-common';

export interface IOffchainVotingClient {
Expand Down Expand Up @@ -92,6 +93,7 @@ export interface IOffchainVotingClientEncoding {
export interface IOffchainVotingClientDecoding {
// Fill with methods that encode actions that can be passed to a proposal
// encodeAction(data: Uint8Array): params;
findInterface(data: Uint8Array): InterfaceParams | null;
}

export interface ITokenVotingClientEncoding {
Expand Down
22 changes: 22 additions & 0 deletions packages/js-client/src/internal/modules/decoding.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,29 @@
import { InterfaceParams, getFunctionFragment } from "@aragon/sdk-client-common";
import { OffchainVotingClientCore } from "../core";
import { IOffchainVotingClientDecoding } from "../interfaces";
import { AVAILABLE_FUNCTION_SIGNATURES } from "../constants";
import { bytesToHex } from "@aragon/sdk-common";

export class OffchainVotingClientDecoding extends OffchainVotingClientCore
implements IOffchainVotingClientDecoding {
// add your action decoders here
/**
* Returns the decoded function info given the encoded data of an action
*
* @param {Uint8Array} data
* @return {*} {(InterfaceParams | null)}
* @memberof OffchainVotingClientDecoding
*/
public findInterface(data: Uint8Array): InterfaceParams | null {
try {
const func = getFunctionFragment(data, AVAILABLE_FUNCTION_SIGNATURES);
return {
id: func.format("minimal"),
functionName: func.name,
hash: bytesToHex(data).substring(0, 10),
};
} catch {
return null;
}
}
}
2 changes: 1 addition & 1 deletion packages/js-client/src/internal/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ export function toNewProposal(
allowFailureMap: SCProposal.allowFailureMap, //number;
tally: SCProposal.tally, //number[][];
settings,
vochainMetadata: vochainProposal.meta,
vochainMetadata: vochainProposal,
tallyVochain: vochainProposal.results.map((x) => x.map((y) => Number(y))),
tallyVochainFinal: vochainProposal.finalResults,
} as GaslessVotingProposal;
Expand Down
3 changes: 2 additions & 1 deletion packages/js-client/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
} from '@aragon/sdk-client-common';
import { BigNumber } from '@ethersproject/bignumber';
import { VocdoniVoting } from '@vocdoni/offchain-voting-ethers';
import { PublishedElection } from '@vocdoni/sdk';

// extend the ContextParams interface with the params that you need
export type OffchainVotingContextParams = ContextParams & {
Expand Down Expand Up @@ -169,7 +170,7 @@ export type GaslessVotingProposal = ProposalBase & {
allowFailureMap: number;
tally: number[][];
settings: GaslessPluginVotingSettings;
vochainMetadata: any;
vochainMetadata: PublishedElection;
tallyVochain: number[][];
tallyVochainFinal: boolean;
};
Expand Down

0 comments on commit 7845700

Please sign in to comment.