web3-core
Advanced tools
Comparing version 4.3.3-dev.53e2466.0 to 4.3.3-dev.553f270.0
@@ -1,2 +0,2 @@ | ||
import { HexString, JsonRpcResponse, Transaction, Web3APIMethod, Web3APIRequest, Web3APIReturnType } from 'web3-types'; | ||
import { HexString, JsonRpcPayload, JsonRpcResponse, Transaction, Web3APIMethod, Web3APIReturnType } from 'web3-types'; | ||
export declare type TransactionTypeParser = (transaction: Transaction) => HexString | undefined; | ||
@@ -12,5 +12,5 @@ export interface Method { | ||
export interface RequestManagerMiddleware<API> { | ||
processRequest<AnotherMethod extends Web3APIMethod<API>>(request: Web3APIRequest<API, AnotherMethod>, options?: { | ||
processRequest<ParamType = unknown[]>(request: JsonRpcPayload<ParamType>, options?: { | ||
[key: string]: unknown; | ||
}): Promise<Web3APIRequest<API, AnotherMethod>>; | ||
}): Promise<JsonRpcPayload<ParamType>>; | ||
processResponse<AnotherMethod extends Web3APIMethod<API>, ResponseType = Web3APIReturnType<API, AnotherMethod>>(response: JsonRpcResponse<ResponseType>, options?: { | ||
@@ -17,0 +17,0 @@ [key: string]: unknown; |
@@ -125,5 +125,3 @@ "use strict"; | ||
return __awaiter(this, void 0, void 0, function* () { | ||
let requestObj = Object.assign({}, request); | ||
if (!(0, web3_utils_1.isNullish)(this.middleware)) | ||
requestObj = yield this.middleware.processRequest(requestObj); | ||
const requestObj = Object.assign({}, request); | ||
let response = yield this._sendRequest(requestObj); | ||
@@ -155,5 +153,8 @@ if (!(0, web3_utils_1.isNullish)(this.middleware)) | ||
} | ||
const payload = web3_utils_1.jsonRpc.isBatchRequest(request) | ||
let payload = (web3_utils_1.jsonRpc.isBatchRequest(request) | ||
? web3_utils_1.jsonRpc.toBatchPayload(request) | ||
: web3_utils_1.jsonRpc.toPayload(request); | ||
: web3_utils_1.jsonRpc.toPayload(request)); | ||
if (!(0, web3_utils_1.isNullish)(this.middleware)) { | ||
payload = yield this.middleware.processRequest(payload); | ||
} | ||
if ((0, utils_js_1.isWeb3Provider)(provider)) { | ||
@@ -182,6 +183,8 @@ let response; | ||
return new Promise((resolve, reject) => { | ||
const rejectWithError = (err) => reject(this._processJsonRpcResponse(payload, err, { | ||
legacy: true, | ||
error: true, | ||
})); | ||
const rejectWithError = (err) => { | ||
reject(this._processJsonRpcResponse(payload, err, { | ||
legacy: true, | ||
error: true, | ||
})); | ||
}; | ||
const resolveWithResponse = (response) => resolve(this._processJsonRpcResponse(payload, response, { | ||
@@ -208,3 +211,13 @@ legacy: true, | ||
const responsePromise = result; | ||
responsePromise.then(resolveWithResponse).catch(rejectWithError); | ||
responsePromise.then(resolveWithResponse).catch(error => { | ||
try { | ||
// Attempt to process the error response | ||
const processedError = this._processJsonRpcResponse(payload, error, { legacy: true, error: true }); | ||
reject(processedError); | ||
} | ||
catch (processingError) { | ||
// Catch any errors that occur during the error processing | ||
reject(processingError); | ||
} | ||
}); | ||
} | ||
@@ -323,3 +336,3 @@ }); | ||
// However, more processing will happen at a higher level to decode the error data, | ||
// according to the Error ABI, if it was available as of EIP-838. | ||
// according to the Error ABI, if it was available as of EIP-838. | ||
if (error === null || error === void 0 ? void 0 : error.message.includes('revert')) | ||
@@ -326,0 +339,0 @@ throw new web3_errors_1.ContractExecutionError(error); |
@@ -119,5 +119,3 @@ /* | ||
return __awaiter(this, void 0, void 0, function* () { | ||
let requestObj = Object.assign({}, request); | ||
if (!isNullish(this.middleware)) | ||
requestObj = yield this.middleware.processRequest(requestObj); | ||
const requestObj = Object.assign({}, request); | ||
let response = yield this._sendRequest(requestObj); | ||
@@ -149,5 +147,8 @@ if (!isNullish(this.middleware)) | ||
} | ||
const payload = jsonRpc.isBatchRequest(request) | ||
let payload = (jsonRpc.isBatchRequest(request) | ||
? jsonRpc.toBatchPayload(request) | ||
: jsonRpc.toPayload(request); | ||
: jsonRpc.toPayload(request)); | ||
if (!isNullish(this.middleware)) { | ||
payload = yield this.middleware.processRequest(payload); | ||
} | ||
if (isWeb3Provider(provider)) { | ||
@@ -176,6 +177,8 @@ let response; | ||
return new Promise((resolve, reject) => { | ||
const rejectWithError = (err) => reject(this._processJsonRpcResponse(payload, err, { | ||
legacy: true, | ||
error: true, | ||
})); | ||
const rejectWithError = (err) => { | ||
reject(this._processJsonRpcResponse(payload, err, { | ||
legacy: true, | ||
error: true, | ||
})); | ||
}; | ||
const resolveWithResponse = (response) => resolve(this._processJsonRpcResponse(payload, response, { | ||
@@ -202,3 +205,13 @@ legacy: true, | ||
const responsePromise = result; | ||
responsePromise.then(resolveWithResponse).catch(rejectWithError); | ||
responsePromise.then(resolveWithResponse).catch(error => { | ||
try { | ||
// Attempt to process the error response | ||
const processedError = this._processJsonRpcResponse(payload, error, { legacy: true, error: true }); | ||
reject(processedError); | ||
} | ||
catch (processingError) { | ||
// Catch any errors that occur during the error processing | ||
reject(processingError); | ||
} | ||
}); | ||
} | ||
@@ -317,3 +330,3 @@ }); | ||
// However, more processing will happen at a higher level to decode the error data, | ||
// according to the Error ABI, if it was available as of EIP-838. | ||
// according to the Error ABI, if it was available as of EIP-838. | ||
if (error === null || error === void 0 ? void 0 : error.message.includes('revert')) | ||
@@ -320,0 +333,0 @@ throw new ContractExecutionError(error); |
@@ -1,2 +0,2 @@ | ||
import { HexString, JsonRpcResponse, Transaction, Web3APIMethod, Web3APIRequest, Web3APIReturnType } from 'web3-types'; | ||
import { HexString, JsonRpcPayload, JsonRpcResponse, Transaction, Web3APIMethod, Web3APIReturnType } from 'web3-types'; | ||
export declare type TransactionTypeParser = (transaction: Transaction) => HexString | undefined; | ||
@@ -12,5 +12,5 @@ export interface Method { | ||
export interface RequestManagerMiddleware<API> { | ||
processRequest<AnotherMethod extends Web3APIMethod<API>>(request: Web3APIRequest<API, AnotherMethod>, options?: { | ||
processRequest<ParamType = unknown[]>(request: JsonRpcPayload<ParamType>, options?: { | ||
[key: string]: unknown; | ||
}): Promise<Web3APIRequest<API, AnotherMethod>>; | ||
}): Promise<JsonRpcPayload<ParamType>>; | ||
processResponse<AnotherMethod extends Web3APIMethod<API>, ResponseType = Web3APIReturnType<API, AnotherMethod>>(response: JsonRpcResponse<ResponseType>, options?: { | ||
@@ -17,0 +17,0 @@ [key: string]: unknown; |
{ | ||
"name": "web3-core", | ||
"version": "4.3.3-dev.53e2466.0+53e2466", | ||
"version": "4.3.3-dev.553f270.0+553f270", | ||
"description": "Web3 core tools for sub-packages. This is an internal package.", | ||
@@ -33,3 +33,3 @@ "main": "./lib/commonjs/index.js", | ||
"build:check": "node -e \"require('./lib')\"", | ||
"lint": "eslint --ext .js,.ts .", | ||
"lint": "eslint --cache --cache-strategy content --ext .ts .", | ||
"lint:fix": "eslint --fix --ext .js,.ts .", | ||
@@ -46,13 +46,13 @@ "format": "prettier --write '**/*'", | ||
"dependencies": { | ||
"web3-errors": "1.1.5-dev.53e2466.0+53e2466", | ||
"web3-eth-accounts": "4.1.3-dev.53e2466.0+53e2466", | ||
"web3-eth-iban": "4.0.8-dev.53e2466.0+53e2466", | ||
"web3-providers-http": "4.1.1-dev.53e2466.0+53e2466", | ||
"web3-providers-ws": "4.0.8-dev.53e2466.0+53e2466", | ||
"web3-types": "1.6.1-dev.53e2466.0+53e2466", | ||
"web3-utils": "4.2.4-dev.53e2466.0+53e2466", | ||
"web3-validator": "2.0.6-dev.53e2466.0+53e2466" | ||
"web3-errors": "1.1.5-dev.553f270.0+553f270", | ||
"web3-eth-accounts": "4.1.3-dev.553f270.0+553f270", | ||
"web3-eth-iban": "4.0.8-dev.553f270.0+553f270", | ||
"web3-providers-http": "4.1.1-dev.553f270.0+553f270", | ||
"web3-providers-ws": "4.0.8-dev.553f270.0+553f270", | ||
"web3-types": "1.6.1-dev.553f270.0+553f270", | ||
"web3-utils": "4.2.4-dev.553f270.0+553f270", | ||
"web3-validator": "2.0.6-dev.553f270.0+553f270" | ||
}, | ||
"optionalDependencies": { | ||
"web3-providers-ipc": "4.0.8-dev.53e2466.0+53e2466" | ||
"web3-providers-ipc": "4.0.8-dev.553f270.0+553f270" | ||
}, | ||
@@ -75,3 +75,3 @@ "devDependencies": { | ||
}, | ||
"gitHead": "53e24664e4c660826eb10207b480848e677a73e6" | ||
"gitHead": "553f270e49c35b68adec64454db8d32a03646de7" | ||
} |
@@ -18,7 +18,12 @@ /* | ||
import { HexString, JsonRpcResponse, Transaction, Web3APIMethod, Web3APIRequest, Web3APIReturnType } from 'web3-types'; | ||
import { | ||
HexString, | ||
JsonRpcPayload, | ||
JsonRpcResponse, | ||
Transaction, | ||
Web3APIMethod, | ||
Web3APIReturnType, | ||
} from 'web3-types'; | ||
export type TransactionTypeParser = ( | ||
transaction: Transaction, | ||
) => HexString | undefined; | ||
export type TransactionTypeParser = (transaction: Transaction) => HexString | undefined; | ||
@@ -36,14 +41,14 @@ export interface Method { | ||
export interface RequestManagerMiddleware<API> { | ||
processRequest< | ||
AnotherMethod extends Web3APIMethod<API> | ||
>( | ||
request: Web3APIRequest<API, AnotherMethod>, | ||
options?: { [key: string]: unknown }): Promise<Web3APIRequest<API, AnotherMethod>>; | ||
processRequest<ParamType = unknown[]>( | ||
request: JsonRpcPayload<ParamType>, | ||
options?: { [key: string]: unknown }, | ||
): Promise<JsonRpcPayload<ParamType>>; | ||
processResponse< | ||
AnotherMethod extends Web3APIMethod<API>, | ||
ResponseType = Web3APIReturnType<API, AnotherMethod>> | ||
( | ||
response: JsonRpcResponse<ResponseType>, | ||
options?: { [key: string]: unknown }): Promise<JsonRpcResponse<ResponseType>>; | ||
} | ||
ResponseType = Web3APIReturnType<API, AnotherMethod>, | ||
>( | ||
response: JsonRpcResponse<ResponseType>, | ||
options?: { [key: string]: unknown }, | ||
): Promise<JsonRpcResponse<ResponseType>>; | ||
} |
@@ -82,3 +82,3 @@ /* | ||
useRpcCallSpecification?: boolean, | ||
requestManagerMiddleware?: RequestManagerMiddleware<API> | ||
requestManagerMiddleware?: RequestManagerMiddleware<API>, | ||
) { | ||
@@ -92,7 +92,5 @@ super(); | ||
if (!isNullish(requestManagerMiddleware)) | ||
this.middleware = requestManagerMiddleware; | ||
if (!isNullish(requestManagerMiddleware)) this.middleware = requestManagerMiddleware; | ||
} | ||
} | ||
/** | ||
@@ -155,3 +153,3 @@ * Will return all available providers | ||
public setMiddleware(requestManagerMiddleware: RequestManagerMiddleware<API>){ | ||
public setMiddleware(requestManagerMiddleware: RequestManagerMiddleware<API>) { | ||
this.middleware = requestManagerMiddleware; | ||
@@ -173,12 +171,7 @@ } | ||
>(request: Web3APIRequest<API, Method>): Promise<ResponseType> { | ||
const requestObj = { ...request }; | ||
let requestObj = {...request}; | ||
if (!isNullish(this.middleware)) | ||
requestObj = await this.middleware.processRequest(requestObj); | ||
let response = await this._sendRequest<Method, ResponseType>(requestObj); | ||
if (!isNullish(this.middleware)) | ||
response = await this.middleware.processResponse(response); | ||
if (!isNullish(this.middleware)) response = await this.middleware.processResponse(response); | ||
@@ -217,6 +210,11 @@ if (jsonRpc.isResponseWithResult(response)) { | ||
const payload = jsonRpc.isBatchRequest(request) | ||
? jsonRpc.toBatchPayload(request) | ||
: jsonRpc.toPayload(request); | ||
let payload = ( | ||
jsonRpc.isBatchRequest(request) | ||
? jsonRpc.toBatchPayload(request) | ||
: jsonRpc.toPayload(request) | ||
) as JsonRpcPayload; | ||
if (!isNullish(this.middleware)) { | ||
payload = await this.middleware.processRequest(payload); | ||
} | ||
if (isWeb3Provider(provider)) { | ||
@@ -258,3 +256,3 @@ let response; | ||
return new Promise<JsonRpcResponse<ResponseType>>((resolve, reject) => { | ||
const rejectWithError = (err: unknown) => | ||
const rejectWithError = (err: unknown) => { | ||
reject( | ||
@@ -270,2 +268,4 @@ this._processJsonRpcResponse( | ||
); | ||
}; | ||
const resolveWithResponse = (response: JsonRpcResponse<ResponseType>) => | ||
@@ -300,3 +300,16 @@ resolve( | ||
>; | ||
responsePromise.then(resolveWithResponse).catch(rejectWithError); | ||
responsePromise.then(resolveWithResponse).catch(error => { | ||
try { | ||
// Attempt to process the error response | ||
const processedError = this._processJsonRpcResponse( | ||
payload, | ||
error as JsonRpcResponse<ResponseType, unknown>, | ||
{ legacy: true, error: true }, | ||
); | ||
reject(processedError); | ||
} catch (processingError) { | ||
// Catch any errors that occur during the error processing | ||
reject(processingError); | ||
} | ||
}); | ||
} | ||
@@ -458,6 +471,6 @@ }); | ||
} | ||
// This message means that there was an error while executing the code of the smart contract | ||
// However, more processing will happen at a higher level to decode the error data, | ||
// according to the Error ABI, if it was available as of EIP-838. | ||
// according to the Error ABI, if it was available as of EIP-838. | ||
if (error?.message.includes('revert')) throw new ContractExecutionError(error); | ||
@@ -464,0 +477,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
482042
8489