-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathwrappedConnection.ts
72 lines (68 loc) · 1.84 KB
/
wrappedConnection.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import { AnchorProvider } from "@project-serum/anchor";
import NodeWallet from "@project-serum/anchor/dist/cjs/nodewallet";
import { Connection, Keypair } from "@solana/web3.js";
import axios from "axios";
export class WrappedConnection extends Connection {
provider: AnchorProvider;
payer: Keypair;
rpcUrl: string;
constructor(payer: Keypair, connectionString: string, rpcUrl?: string) {
super(connectionString, "confirmed");
this.rpcUrl = rpcUrl ?? connectionString;
this.provider = new AnchorProvider(
new Connection(connectionString),
new NodeWallet(payer),
{
commitment: super.commitment,
skipPreflight: true,
}
);
this.payer = payer;
}
async getAsset(assetId: any): Promise<any> {
try {
const response = await axios.post(this.rpcUrl, {
jsonrpc: "2.0",
method: "get_asset",
id: "compression-example",
params: [assetId],
});
return response.data.result;
} catch (error) {
console.error(error);
}
}
async getAssetProof(assetId: any): Promise<any> {
try {
const response = await axios.post(this.rpcUrl, {
jsonrpc: "2.0",
method: "get_asset_proof",
id: "compression-example",
params: [assetId],
});
return response.data.result;
} catch (error) {
console.error(error);
}
}
async getAssetsByOwner(
assetId: string,
sortBy: any,
limit: number,
page: number,
before: string,
after: string
): Promise<any> {
try {
const response = await axios.post(this.rpcUrl, {
jsonrpc: "2.0",
method: "get_assets_by_owner",
id: "compression-example",
params: [assetId, sortBy, limit, page, before, after],
});
return response.data.result;
} catch (error) {
console.error(error);
}
}
}