Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(governance-sdk): DRYer Borsh classes, remove repeated properties & constructors #496

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
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
33 changes: 9 additions & 24 deletions packages/governance-sdk/src/chat/accounts.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { PublicKey } from '@solana/web3.js';
import BN from 'bn.js';
import { BorshClass } from '../tools/borsh';

export const GOVERNANCE_CHAT_PROGRAM_ID = new PublicKey(
'gCHAtYKrUUktTVzE4hEnZdLV4LXrdBf6Hh9qMaJALET',
Expand All @@ -21,36 +22,20 @@ export enum ChatMessageBodyType {
Reaction = 1,
}

export class ChatMessageBody {
export interface ChatMessageBody {
type: ChatMessageBodyType;
value: string;

constructor(args: { type: ChatMessageBodyType; value: string }) {
this.type = args.type;
this.value = args.value;
}
}
export class ChatMessageBody extends BorshClass<ChatMessageBody> {}

export class ChatMessage {
accountType = GovernanceChatAccountType.ChatMessage;

interface ChatMessageProps {
proposal: PublicKey;
author: PublicKey;
postedAt: BN;
replyTo: PublicKey | undefined;
replyTo?: PublicKey;
body: ChatMessageBody;

constructor(args: {
proposal: PublicKey;
author: PublicKey;
postedAt: BN;
replyTo: PublicKey | undefined;
body: ChatMessageBody;
}) {
this.proposal = args.proposal;
this.author = args.author;
this.postedAt = args.postedAt;
this.replyTo = args.replyTo;
this.body = args.body;
}
}
export interface ChatMessage extends ChatMessageProps {}
export class ChatMessage extends BorshClass<ChatMessageProps> {
accountType = GovernanceChatAccountType.ChatMessage;
}
28 changes: 6 additions & 22 deletions packages/governance-sdk/src/core/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,13 @@ import { WalletNotConnectedError, WalletSigner } from '../tools/walletAdapter';

// Context to make RPC calls for given clone programId, current connection, endpoint and wallet
export class RpcContext {
programId: PublicKey;
programVersion: number;
wallet: WalletSigner;
connection: Connection;
endpoint: string;

constructor(
programId: PublicKey,
programVersion: number,
wallet: WalletSigner,
connection: Connection,
endpoint: string,
public programId: PublicKey,
public programVersion: number,
public wallet: WalletSigner,
public connection: Connection,
public endpoint: string,
) {
this.programId = programId;
this.wallet = wallet;
this.connection = connection;
this.endpoint = endpoint;
this.programVersion = programVersion;
}

get walletPubkey() {
Expand All @@ -44,12 +33,7 @@ export class RpcContext {
}

export class MemcmpFilter {
offset: number;
bytes: Buffer;

constructor(offset: number, bytes: Buffer) {
this.offset = offset;
this.bytes = bytes;
constructor(public offset: number, public bytes: Buffer) {
}

isMatch(buffer: Buffer) {
Expand Down
Loading