UNPKG

@mavrykdynamics/taquito

Version:

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

55 lines (54 loc) 3.14 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.RpcMvProvider = void 0; const operations_1 = require("../operations/operations"); const taquito_utils_1 = require("@mavrykdynamics/taquito-utils"); const taquito_core_1 = require("@mavrykdynamics/taquito-core"); const provider_1 = require("../provider"); const prepare_1 = require("../prepare"); class RpcMvProvider 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 = (0, taquito_utils_1.validateAddress)(address); if (addressValidation !== taquito_utils_1.ValidationResult.VALID) { throw new taquito_core_1.InvalidAddressError(address, (0, taquito_utils_1.invalidDetail)(addressValidation)); } return this.context.readProvider.getBalance(address, 'head'); }); } getDelegate(address) { return __awaiter(this, void 0, void 0, function* () { const addressValidation = (0, taquito_utils_1.validateAddress)(address); if (addressValidation !== taquito_utils_1.ValidationResult.VALID) { throw new taquito_core_1.InvalidAddressError(address, (0, taquito_utils_1.invalidDetail)(addressValidation)); } return this.context.readProvider.getDelegate(address, 'head'); }); } activate(pkh, secret) { return __awaiter(this, void 0, void 0, function* () { const pkhValidation = (0, taquito_utils_1.validateKeyHash)(pkh); if (pkhValidation !== taquito_utils_1.ValidationResult.VALID) { throw new taquito_utils_1.InvalidKeyHashError(pkh, (0, taquito_utils_1.invalidDetail)(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.RpcMvProvider = RpcMvProvider;