UNPKG

@taquito/taquito

Version:

High level functionality that builds upon the other packages in the Tezos Typescript Library Suite.

55 lines 3.02 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.RpcTzProvider = void 0; const operations_1 = require("../operations/operations"); const utils_1 = require("@taquito/utils"); const core_1 = require("@taquito/core"); const provider_1 = require("../provider"); const prepare_1 = require("../prepare"); class RpcTzProvider extends provider_1.Provider { constructor(context) { super(context); this.prepare = new prepare_1.PrepareProvider(this.context); } getBalance(address) { return __awaiter(this, void 0, void 0, function* () { const addressValidation = utils_1.validateAddress(address); if (addressValidation !== utils_1.ValidationResult.VALID) { throw new core_1.InvalidAddressError(address, utils_1.invalidErrorDetail(addressValidation)); } return this.context.readProvider.getBalance(address, 'head'); }); } getDelegate(address) { return __awaiter(this, void 0, void 0, function* () { const addressValidation = utils_1.validateAddress(address); if (addressValidation !== utils_1.ValidationResult.VALID) { throw new core_1.InvalidAddressError(address, utils_1.invalidErrorDetail(addressValidation)); } return this.context.readProvider.getDelegate(address, 'head'); }); } activate(pkh, secret) { return __awaiter(this, void 0, void 0, function* () { const pkhValidation = utils_1.validateKeyHash(pkh); if (pkhValidation !== utils_1.ValidationResult.VALID) { throw new utils_1.InvalidKeyHashError(pkh, utils_1.invalidErrorDetail(pkhValidation)); } const prepared = yield this.prepare.activate({ pkh, secret }); const forgedBytes = yield this.forge(prepared); const bytes = `${forgedBytes.opbytes}00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000`; return new operations_1.Operation(yield this.rpc.injectOperation(bytes), Object.assign(Object.assign({}, forgedBytes), { opbytes: bytes }), [], this.context.clone()); }); } } exports.RpcTzProvider = RpcTzProvider; //# sourceMappingURL=rpc-tz-provider.js.map