Skip to content

Commit 65a54ad

Browse files
author
Egor Komarov
committed
feat: support everscale-inpage-provider@0.6.0; bump version;
1 parent 446a5d6 commit 65a54ad

2 files changed

Lines changed: 72 additions & 10 deletions

File tree

package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "everscale-standalone-client",
3-
"version": "2.1.27",
3+
"version": "2.2.0",
44
"repository": "https://github.com/broxus/everscale-standalone-client",
55
"scripts": {
66
"build": "tsc",
@@ -21,12 +21,12 @@
2121
},
2222
"dependencies": {
2323
"@broxus/await-semaphore": "^0.1.5",
24-
"bignumber.js": "^9.1.0",
24+
"bignumber.js": "^9.3.0",
2525
"events": "^3.3.0",
26-
"everscale-inpage-provider": "^0.3.64",
26+
"everscale-inpage-provider": "^0.6.0",
2727
"fast-safe-stringify": "^2.1.1",
28-
"nekoton-wasm": "^1.3.2",
29-
"node-fetch": "^2.6.7"
28+
"nekoton-wasm": "^1.5.0",
29+
"node-fetch": "^3.3.2"
3030
},
3131
"types": "index.d.ts",
3232
"main": "index_main.js",

src/client/index.ts

Lines changed: 67 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,13 @@ export const SUPPORTED_PERMISSIONS: ever.Permission[] = ['basic', 'accountIntera
106106
*/
107107
export class EverscaleStandaloneClient extends SafeEventEmitter implements ever.Provider {
108108
private readonly _context: Context;
109-
private _handlers: { [K in ever.ProviderMethod]?: ProviderHandler<K> } = {
109+
private _handlers: { [K in ever.ProviderMethod]: ProviderHandler<K> } = {
110+
addAsset: () => { throw new UnsupportedMethodError('addAsset'); },
111+
encryptData: () => { throw new UnsupportedMethodError('encryptData'); },
112+
decryptData: () => { throw new UnsupportedMethodError('decryptData'); },
113+
estimateFees: () => { throw new UnsupportedMethodError('estimateFees'); },
114+
addNetwork: () => { throw new UnsupportedMethodError('addNetwork'); },
115+
changeNetwork: () => { throw new UnsupportedMethodError('changeNetwork'); },
110116
requestPermissions,
111117
changeAccount,
112118
disconnect,
@@ -142,16 +148,13 @@ export class EverscaleStandaloneClient extends SafeEventEmitter implements ever.
142148
decodeTransactionEvents,
143149
verifySignature,
144150
sendUnsignedExternalMessage,
145-
// addAsset, // not supported
146151
signData,
147152
signDataRaw,
148-
// encryptData, // not supported
149-
// decryptData, // not supported
150-
// estimateFees, // not supported
151153
sendMessage,
152154
sendMessageDelayed,
153155
sendExternalMessage,
154156
sendExternalMessageDelayed,
157+
runGetter,
155158
};
156159

157160
public static async create(params: ClientProperties = {}): Promise<EverscaleStandaloneClient> {
@@ -1494,6 +1497,47 @@ const sendExternalMessageDelayed: ProviderHandler<'sendExternalMessageDelayed'>
14941497
};
14951498
};
14961499

1500+
const runGetter: ProviderHandler<'runGetter'> = async (ctx, req) => {
1501+
requireParams(req);
1502+
1503+
const { address, cachedState, getterCall, withSignatureId } = req.params;
1504+
requireString(req, req.params, 'address');
1505+
requireOptional(req, req.params, 'cachedState', requireContractState);
1506+
requireGetterCall(req, req.params, 'getterCall');
1507+
requireOptionalSignatureId(req, req.params, 'withSignatureId');
1508+
1509+
let contractState = cachedState;
1510+
if (contractState == null) {
1511+
requireConnection(req, ctx);
1512+
contractState = await ctx.connectionController.use(async ({ data: { transport } }) =>
1513+
transport.getFullContractState(address),
1514+
);
1515+
}
1516+
1517+
if (contractState == null) {
1518+
throw invalidRequest(req, 'Account not found');
1519+
}
1520+
if (!contractState.isDeployed || contractState.lastTransactionId == null) {
1521+
throw invalidRequest(req, 'Account is not deployed');
1522+
}
1523+
1524+
const signatureId = await computeSignatureId(req, ctx, withSignatureId);
1525+
1526+
try {
1527+
const { output, code } = core.nekoton.runGetter(
1528+
ctx.clock,
1529+
contractState.boc,
1530+
getterCall.abi,
1531+
getterCall.getter,
1532+
getterCall.params,
1533+
signatureId,
1534+
);
1535+
return { output, code };
1536+
} catch (e: any) {
1537+
throw invalidRequest(req, e.toString());
1538+
}
1539+
};
1540+
14971541
function requireKeystore(req: any, context: Context): asserts context is Context & { keystore: Keystore } {
14981542
if (context.keystore == null) {
14991543
throw invalidRequest(req, 'Keystore not found');
@@ -1701,6 +1745,18 @@ function requireFunctionCall<O, P extends keyof O>(
17011745
requireObject(req, property, 'params');
17021746
}
17031747

1748+
function requireGetterCall<O, P extends keyof O>(
1749+
req: ever.RawProviderRequest<ever.ProviderMethod>,
1750+
object: O,
1751+
key: P,
1752+
) {
1753+
requireObject(req, object, key);
1754+
const property = object[key] as unknown as ever.GetterCall<string>;
1755+
requireString(req, property, 'abi');
1756+
requireString(req, property, 'getter');
1757+
requireObject(req, property, 'params');
1758+
}
1759+
17041760
function requireOptionalRawFunctionCall<O, P extends keyof O>(
17051761
req: ever.RawProviderRequest<ever.ProviderMethod>,
17061762
object: O,
@@ -1811,3 +1867,9 @@ const stringifyReplacer = (_: unknown, value: unknown): unknown => {
18111867
}
18121868
return value;
18131869
};
1870+
1871+
class UnsupportedMethodError extends Error {
1872+
constructor(method: string) {
1873+
super(`Method "${method}" is not supported`);
1874+
}
1875+
}

0 commit comments

Comments
 (0)