UNPKG

@crustio/crust-pin

Version:

Decentralized pin on Crust Network

43 lines (42 loc) 1.94 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 }); const type_definitions_1 = require("@crustio/type-definitions"); const api_1 = require("@polkadot/api"); const util_1 = require("./util"); class CrustPinner { constructor(s, chainAddr = 'wss://rpc.crust.network') { this.seeds = s; this.crustApi = new api_1.ApiPromise({ provider: new api_1.WsProvider(chainAddr), typesBundle: type_definitions_1.typesBundleForPolkadot, }); } pin(cid) { return __awaiter(this, void 0, void 0, function* () { try { // 1. Check Api is ready yield this.crustApi.isReadyOrError; // 2. Place storage order const tx = this.crustApi.tx.market.placeStorageOrder(cid, 200 * 1024 * 1024 /* 200MB */, 0, ''); const res = yield util_1.sendTx(tx, this.seeds); // 3. Disconnect chain this.crustApi.disconnect(); return res; } catch (e) { console.error(`Error happens on calling Crust Chain, details: ${e.message}`); return false; } }); } } exports.default = CrustPinner;