Skip to content
This repository has been archived by the owner on Aug 16, 2024. It is now read-only.

Commit

Permalink
Remove deprecated JSON-RPC client integration
Browse files Browse the repository at this point in the history
  • Loading branch information
bisgardo committed Aug 14, 2023
1 parent 5f0da43 commit b302f30
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 96 deletions.
9 changes: 9 additions & 0 deletions packages/wallet-connectors/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- `WalletConnect`: Fix schema object format conversion in `signAndSendTransaction` in request payloads.
- `WalletConnect`: Use standard string identifiers for transaction type in request payload.

### Removed

- `WalletConnection`: The deprecated method `getJsonRpcClient()` and related symbols has been removed
in favor of the new gRPC client (`ConcordiumGRPCClient`) for the Node API v2.
Existing usage is migrated by simply constructing and using this client instead of the one fetched with `connection.getJsonRpcClient`.
The `Network` type has a field `grpcOpts` which may be used to construct the client (see its docstring for details).
The field is optional, but present on the predefined constants `TESTNET` and `MAINNET`.
For users of `@concordium/react-components`, this all wrapped into the hook `useGrpcClient`.

## [0.3.1] - 2023-06-04

### Added
Expand Down
6 changes: 1 addition & 5 deletions packages/wallet-connectors/src/BrowserWallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,6 @@ export class BrowserWalletConnector implements WalletConnector, WalletConnection
return this.client.getMostRecentlySelectedAccount();
}

getJsonRpcClient() {
return this.client.getJsonRpcClient();
}

/**
* Returns a gRPC client that is ready to perform requests against some Concordium Node connected to network/chain
* that the connected account lives on.
Expand All @@ -101,7 +97,7 @@ export class BrowserWalletConnector implements WalletConnector, WalletConnection
* that is independent of any connection.
* See {@link Network.grpcOpts} for more details.
*
* Implementation detail: The method cannot be moved to {@link WalletConnector}
* Implementation detail: The method cannot be moved to {@link BrowserWalletConnector}
* as the Browser Wallet's RPC client doesn't work until a connection has been established.
*
* @return The Browser Wallet's internal gRPC client.
Expand Down
24 changes: 3 additions & 21 deletions packages/wallet-connectors/src/WalletConnect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ import {
AccountTransactionPayload,
AccountTransactionSignature,
AccountTransactionType,
HttpProvider,
InitContractPayload,
JsonRpcClient,
UpdateContractPayload,
getTransactionKindString,
serializeInitContractParameters,
Expand Down Expand Up @@ -206,18 +204,10 @@ export class WalletConnectConnection implements WalletConnection {

session: SessionTypes.Struct;

readonly jsonRpcClient: JsonRpcClient | undefined;

constructor(
connector: WalletConnectConnector,
chainId: string,
session: SessionTypes.Struct,
jsonRpcClient: JsonRpcClient | undefined
) {
constructor(connector: WalletConnectConnector, chainId: string, session: SessionTypes.Struct) {
this.connector = connector;
this.chainId = chainId;
this.session = session;
this.jsonRpcClient = jsonRpcClient;
}

getConnector() {
Expand All @@ -238,13 +228,6 @@ export class WalletConnectConnection implements WalletConnection {
return fullAddress.substring(fullAddress.lastIndexOf(':') + 1);
}

getJsonRpcClient() {
if (!this.jsonRpcClient) {
throw new Error('no JSON RPC URL provided in network configuration');
}
return this.jsonRpcClient;
}

async signAndSendTransaction(
accountAddress: string,
type: AccountTransactionType,
Expand Down Expand Up @@ -393,7 +376,7 @@ export class WalletConnectConnector implements WalletConnector {
}

async connect() {
const { name, jsonRpcUrl } = this.network;
const { name } = this.network;

const chainId = `${WALLET_CONNECT_SESSION_NAMESPACE}:${name}`;
const session = await new Promise<SessionTypes.Struct | undefined>((resolve) => {
Expand All @@ -403,8 +386,7 @@ export class WalletConnectConnector implements WalletConnector {
// Connect was cancelled.
return undefined;
}
const jsonRpcClient = jsonRpcUrl ? new JsonRpcClient(new HttpProvider(jsonRpcUrl)) : undefined;
const connection = new WalletConnectConnection(this, chainId, session, jsonRpcClient);
const connection = new WalletConnectConnection(this, chainId, session);
this.connections.set(session.topic, connection);
this.delegate.onConnected(connection, connection.getConnectedAccount());
return connection;
Expand Down
69 changes: 1 addition & 68 deletions packages/wallet-connectors/src/WalletConnection.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
import { Buffer } from 'buffer/';
import { SendTransactionPayload, SmartContractParameters } from '@concordium/browser-wallet-api-helpers';
import {
AccountTransactionSignature,
AccountTransactionType,
JsonRpcClient,
SchemaVersion,
toBuffer,
} from '@concordium/web-sdk';
import { AccountTransactionSignature, AccountTransactionType, SchemaVersion, toBuffer } from '@concordium/web-sdk';
import { GrpcWebOptions } from '@protobuf-ts/grpcweb-transport';

export type ModuleSchema = {
Expand Down Expand Up @@ -150,32 +144,6 @@ export interface WalletConnection {
*/
ping(): Promise<void>;

/**
* Returns a JSON-RPC client that is ready to perform requests against some Concordium Node connected to network/chain
* that the connected account lives on.
*
* This method is included because it's part of the Browser Wallet API.
* It should be used with care as it's hard to guarantee that it actually connects to the expected network.
* As explained in {@link Network.jsonRpcUrl}, the application may easily instantiate its own client and use that instead.
*
* Implementation detail: The method cannot be moved to {@link WalletConnector}
* as the Browser Wallet's internal client doesn't work until a connection has been established.
*
* The client implements version 1 of the Node's API which is deprecated in favor of
* <code>ConcordiumGRPCClient</code> from {@link https://www.npmjs.com/package/@concordium/web-sdk @concordium/web-sdk}.
*
* The method {@link BrowserWalletConnector.getGrpcClient} exists for exposing the wallet's internal gRPC Web client for API version 2,
* but it's not recommended for use in most cases as there's no need for the client to be associated with a particular connection.
*
* Instead, instantiate the client manually or using a hook (for React) as described in {@link Network.grpcOpts}.
*
* @return A JSON-RPC client for performing requests against a Concordium Node connected to the appropriate network.
* @throws If the connection uses {@link Network.jsonRpcUrl} and that value is undefined.
* @throws If the connection is to the Browser Wallet and the installed version doesn't support the method.
* @deprecated Use <code>ConcordiumGRPCClient<code> instead.
*/
getJsonRpcClient(): JsonRpcClient;

/**
* Assembles a transaction and sends it off to the wallet for approval and submission.
*
Expand Down Expand Up @@ -255,30 +223,6 @@ export interface Network {
*/
grpcOpts: GrpcWebOptions | undefined;

/**
* The URL of a {@link https://github.com/Concordium/concordium-json-rpc Concordium JSON-RPC proxy} instance
* for performing API (v1) queries against a Concordium Node instance connected to this network.
*
* The value is currently used only for {@link WalletConnectConnection WalletConnect connections}
* as {@link BrowserWalletConnector Browser Wallet connections} use the Browser Wallet's internal client.
*
* Setting the URL to the empty string disables the automatic initialization of the client returned by
* {@link WalletConnection.getJsonRpcClient} for WalletConnect connections.
* The concrete implementation {@link WalletConnectConnection.getJsonRpcClient} will then throw an exception
* as there is no client instance to return.
*
* There is no fundamental difference between using a client belonging to a connection compared to one that is initialized directly.
* Keeping it separate from connections gives the dApp more control and allows the client to be used even if no connections have been established.
*
* Initializing a separate client is straightforward:
* <pre>
* import { HttpProvider, JsonRpcClient } from '@concordium/web-sdk';
* ...
* const client = new JsonRpcClient(new HttpProvider(network.jsonRpcUrl));
* </pre>
*/
jsonRpcUrl: string;

/**
* The base URL of a {@link https://github.com/Concordium/concordium-scan CCDScan} instance
* connected to this network.
Expand Down Expand Up @@ -359,14 +303,3 @@ export interface WalletConnector {
*/
disconnect(): Promise<void>;
}

/**
* Convenience function for invoking an async function with the JSON-RPC proxy client of the given {@link WalletConnection}.
*
* @param connection The connected used to resolve the RPC client.
* @param f The async function to invoke.
* @return The promise returned by {@link f}.
*/
export async function withJsonRpcClient<T>(connection: WalletConnection, f: (c: JsonRpcClient) => Promise<T>) {
return f(connection.getJsonRpcClient());
}
2 changes: 0 additions & 2 deletions packages/wallet-connectors/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ export const TESTNET: Network = {
grpcOpts: {
baseUrl: 'https://grpc.testnet.concordium.com:20000',
},
jsonRpcUrl: 'https://json-rpc.testnet.concordium.com',
ccdScanBaseUrl: 'https://testnet.ccdscan.io',
};

Expand All @@ -36,6 +35,5 @@ export const MAINNET: Network = {
grpcOpts: {
baseUrl: 'https://grpc.mainnet.concordium.software:20000',
},
jsonRpcUrl: 'https://json-rpc.mainnet.concordium.software',
ccdScanBaseUrl: 'https://ccdscan.io',
};

0 comments on commit b302f30

Please sign in to comment.