"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const log_1 = tslib_1.__importDefault(require("../log"));
const network_1 = require("../network");
const proto_1 = require("./proto");
/**
 * BEvm service
 */
class BEvmRPC {
    constructor(srvid) {
        this.timeout = 60 * 1000; // 60 seconds
        this.conn = new network_1.WebSocketConnection(srvid.getWebSocketAddress(), BEvmRPC.serviceName);
    }
    /**
     * Set a new timeout value for future requests.
     *
     * @param value Timeout in [ms]
     */
    setTimeout(value) {
        this.timeout = value;
    }
    /**
     * Execute a view method (read-only)
     *
     * @param byzcoinId         ByzCoin ID
     * @param bevmInstanceId    BEvm instance ID
     * @param accountAddress    Address of the EVM account
     * @param contractAddress   Address of the smart contract
     * @param callData          ABI-packed call arguments
     *
     * @return Result of the view method execution
     */
    viewCall(byzcoinId, bevmInstanceId, accountAddress, contractAddress, callData) {
        return tslib_1.__awaiter(this, void 0, void 0, function* () {
            this.conn.setTimeout(this.timeout);
            log_1.default.lvl3("Sending BEvm call request...");
            const msg = new proto_1.ViewCallRequest({
                accountAddress,
                bevmInstanceId,
                byzcoinId,
                callData,
                contractAddress,
            });
            return this.conn.send(msg, proto_1.ViewCallResponse);
        });
    }
}
exports.BEvmRPC = BEvmRPC;
BEvmRPC.serviceName = "BEvm";
