"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.LoggingJsonRpcProvider = void 0;
const ethers_1 = require("ethers");
const utils_1 = require("@streamr/utils");
const logger = new utils_1.Logger(module);
class LoggingJsonRpcProvider extends ethers_1.JsonRpcProvider {
    urlConfig;
    constructor(urlConfig, network, options) {
        super(urlConfig, network, options);
        this.urlConfig = urlConfig;
    }
    async send(method, params) {
        const traceId = (0, utils_1.randomString)(5);
        const startTime = Date.now();
        const logContext = {
            traceId,
            method,
            params,
            connection: {
                url: this.urlConfig.url,
                timeout: this.urlConfig.timeout
            }
        };
        logger.debug('Send request', logContext);
        let result;
        try {
            result = await super.send(method, params);
        }
        catch (err) {
            logger.debug('Encountered error while requesting', {
                ...logContext,
                err,
                elapsedTime: Date.now() - startTime
            });
            throw err;
        }
        logger.debug('Received response', {
            ...logContext,
            elapsedTime: Date.now() - startTime
        });
        return result;
    }
}
exports.LoggingJsonRpcProvider = LoggingJsonRpcProvider;
//# sourceMappingURL=LoggingJsonRpcProvider.js.map