Skip to content

Commit

Permalink
Enable RPC call with unresolved parameters (#70)
Browse files Browse the repository at this point in the history
The Web3.js RPC implementation was always adding an object parameter containing the connection's commitment even when no explicit commitment or extra option was provided.
  • Loading branch information
lorisleiva authored Jun 23, 2023
1 parent 1e2ab1a commit 8ab5ee3
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 16 deletions.
5 changes: 5 additions & 0 deletions .changeset/sour-poems-flash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@metaplex-foundation/umi-rpc-web3js': patch
---

Enable RPC call with unresolved parameters
1 change: 1 addition & 0 deletions packages/umi-rpc-web3js/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import pkg from './package.json';

export default createConfigs({
pkg,
additionalExternals: ['@metaplex-foundation/umi/serializers'],
builds: [
{
dir: 'dist/esm',
Expand Down
23 changes: 7 additions & 16 deletions packages/umi-rpc-web3js/src/createWeb3JsRpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ import {
TransactionSignature,
TransactionStatus,
TransactionWithMeta,
base58,
createAmount,
dateTime,
isZeroAmount,
Expand All @@ -48,6 +47,7 @@ import {
fromWeb3JsPublicKey,
toWeb3JsPublicKey,
} from '@metaplex-foundation/umi-web3js-adapters';
import { base58 } from '@metaplex-foundation/umi/serializers';
import {
AccountInfo as Web3JsAccountInfo,
Connection as Web3JsConnection,
Expand Down Expand Up @@ -290,7 +290,6 @@ export function createWeb3JsRpc(
): Promise<Result> => {
const client = (getConnection() as any)._rpcClient as RpcClient;
const resolvedParams = resolveCallParams(
getConnection(),
(params ? [...params] : []) as [...Params],
options.commitment,
options.extra
Expand Down Expand Up @@ -412,22 +411,14 @@ function parseConfirmStrategy(
}

function resolveCallParams<Params extends any[]>(
connection: Web3JsConnection,
args: Params,
override?: Commitment,
commitment?: Commitment,
extra?: object
): Params {
const commitment =
override || (connection.commitment as Commitment | undefined);
if (commitment || extra) {
let options: any = {};
if (commitment) {
options.commitment = commitment;
}
if (extra) {
options = { ...options, ...extra };
}
args.push(options);
}
if (!commitment && !extra) return args;
let options: any = {};
if (commitment) options.commitment = commitment;
if (extra) options = { ...options, ...extra };
args.push(options);
return args;
}

0 comments on commit 8ab5ee3

Please sign in to comment.