UNPKG

@bioneisme/greenfield-cli

Version:
64 lines (63 loc) 2.71 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.createGroup = void 0; const sdk_1 = require("../../utils/sdk"); const config_1 = require("../../utils/config"); const password_1 = require("../../helpers/password"); // Create an object with the required properties function getGroupNameByUrl(urlInfo) { const bucketName = parseBucket(urlInfo); if (bucketName === "") { throw new Error("fail to parse group name"); } return bucketName; } function parseBucket(urlPath) { if (urlPath.includes("gnfd://")) { urlPath = urlPath.replace("gnfd://", ""); } const splits = urlPath.split("/", 1); return splits[0]; } function createGroup(urlPath) { return __awaiter(this, void 0, void 0, function* () { try { const publicKey = String(config_1.config.get("publicKey")); const privateKey = yield (0, password_1.getPrivateKey)(); const parsedUrl = getGroupNameByUrl(urlPath); const msg = { creator: publicKey, groupName: parsedUrl, members: [], }; const group = yield sdk_1.GreenfieldClient.client.group.createGroup(msg); const simulateInfo = yield group .simulate({ denom: "BNB", }) .catch(() => { }); const broadcast = yield group.broadcast({ denom: "BNB", gasLimit: Number((simulateInfo === null || simulateInfo === void 0 ? void 0 : simulateInfo.gasLimit) || 2400), gasPrice: (simulateInfo === null || simulateInfo === void 0 ? void 0 : simulateInfo.gasPrice) || "5000000000000", payer: publicKey, granter: "", privateKey: String("0x" + privateKey), }); console.log(broadcast); } catch (e) { console.error(`group creation failed: ${e}`); } }); } exports.createGroup = createGroup;