UNPKG

blockchain-api

Version:

API utilities for interacting with the Exatechl2 blockchain

55 lines (54 loc) 1.43 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.isTransactionObject = isTransactionObject; exports.isSystemContract = isSystemContract; exports.checkIsContract = checkIsContract; exports.getContractBytecode = getContractBytecode; const rpc_1 = require("../../core/rpc"); const registry_1 = require("../../utils/registry"); /** * * @param value * @returns */ function isTransactionObject(value) { return typeof value !== 'string' && value !== null && typeof value === 'object' && 'hash' in value; } /** * * @param address * @returns */ function isSystemContract(address) { return (0, registry_1.isSystemContract)(address.toLowerCase()); } /** * * @param {string} address * @returns {Promise<boolean>} */ async function checkIsContract(address) { try { const code = await (0, rpc_1.callRpc)('eth_getCode', [address, 'latest']); return code !== '0x' && code !== '0x0'; } catch (error) { console.error(`Error checking if ${address} is a contract:`, error); return false; } } /** * * @param {string} address * @returns {Promise<string>} */ async function getContractBytecode(address) { try { const code = await (0, rpc_1.callRpc)('eth_getCode', [address, 'latest']); return code; } catch (error) { console.error(`Error getting bytecode for ${address}:`, error); throw error; } }