UNPKG

@sova-labs/sdk

Version:
127 lines 4.59 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || (function () { var ownKeys = function(o) { ownKeys = Object.getOwnPropertyNames || function (o) { var ar = []; for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; return ar; }; return ownKeys(o); }; return function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); __setModuleDefault(result, mod); return result; }; })(); var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.SearcherService = void 0; const node_path_1 = __importDefault(require("node:path")); const grpc = __importStar(require("@grpc/grpc-js")); const protoLoader = __importStar(require("@grpc/proto-loader")); const node_util_1 = require("node:util"); const grpc_js_1 = require("@grpc/grpc-js"); const protoPath = node_path_1.default.join(__dirname, '..', 'sova-grpc-proto', 'proto', 'searcher.proto'); const packageDefinition = protoLoader.loadSync(protoPath, { keepCase: false, longs: String, enums: String, oneofs: true, }); const proto = grpc.loadPackageDefinition(packageDefinition); const pkg = proto.searcher; class SearcherService { constructor(url, secureConnection, accessToken) { this.accessToken = accessToken; const metadata = new grpc.Metadata(); if (this.accessToken) { metadata.add('authorization', `Bearer ${this.accessToken.value}`); } this.client = new pkg.SearcherService(url, secureConnection ? grpc_js_1.ChannelCredentials.createSsl() : grpc.credentials.createInsecure(), { metadata }); } subscribeBundleResults() { return this.client.SubscribeBundleResults({}, {}); } sendBundle(messages, expireAt) { let expirationNs = undefined; if (expireAt) { const milliseconds = expireAt.getTime(); expirationNs = { seconds: Math.floor(milliseconds / 1000), nanos: (milliseconds % 1000) * 1e6 }; } const request = { message: messages, expirationNs, }; return (0, node_util_1.promisify)(this.client.SendBundle.bind(this.client, request))(); } getTipAddresses() { return (0, node_util_1.promisify)(this.client.GetTipAddresses.bind(this.client, {}))(); } subscribeMempool(subscription) { return this.client.subscribeMempool(subscription); } subscribeByAddresses(addresses) { return this.subscribeMempool({ addresses: { address: addresses, } }); } subscribeByWorkchain(workchainId) { return this.subscribeMempool({ workchain: { workchainId, } }); } subscribeByWorkchainShard(workchainId, shard) { return this.subscribeMempool({ workchainShard: { workchainId, shard, } }); } subscribeByExternalOutMessageOpcode(workchainId, shard, opcode) { return this.subscribeMempool({ externalOutMessageBodyOpcode: { workchainId, shard, opcode } }); } subscribeByInternalMessageOpcode(workchainId, shard, opcode) { return this.subscribeMempool({ internalMessageBodyOpcode: { opcode } }); } } exports.SearcherService = SearcherService; //# sourceMappingURL=searcher.service.js.map