-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
index.ts
54 lines (45 loc) · 1.27 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import { IdlEvent, IdlTypeDef } from "../idl.js";
import { Event } from "../program/event.js";
export * from "./borsh/index.js";
export * from "./spl-token/index.js";
/**
* Coder provides a facade for encoding and decoding all IDL related objects.
*/
export interface Coder {
/**
* Instruction coder.
*/
readonly instruction: InstructionCoder;
/**
* Account coder.
*/
readonly accounts: AccountsCoder;
/**
* Coder for state structs.
*/
readonly state: StateCoder;
/**
* Coder for events.
*/
readonly events: EventCoder;
}
export interface StateCoder {
encode<T = any>(name: string, account: T): Promise<Buffer>;
decode<T = any>(ix: Buffer): T;
}
export interface AccountsCoder<A extends string = string> {
encode<T = any>(accountName: A, account: T): Promise<Buffer>;
decode<T = any>(accountName: A, ix: Buffer): T;
decodeUnchecked<T = any>(accountName: A, ix: Buffer): T;
memcmp(accountName: A, appendData?: Buffer): any;
size(idlAccount: IdlTypeDef): number;
}
export interface InstructionCoder {
encode(ixName: string, ix: any): Buffer;
encodeState(ixName: string, ix: any): Buffer;
}
export interface EventCoder {
decode<E extends IdlEvent = IdlEvent, T = Record<string, string>>(
log: string
): Event<E, T> | null;
}