@bioneisme/greenfield-cli
Version:
CLI For BNB Greenfield SDK
76 lines (75 loc) • 3.67 kB
JavaScript
;
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.updateBucketVisibility = void 0;
const common_1 = require("@bnb-chain/greenfield-cosmos-types/greenfield/storage/common");
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 updateBucketVisibility(visibility, bucketName) {
return __awaiter(this, void 0, void 0, function* () {
try {
let visibilityType;
switch (visibility) {
case "public-read":
visibilityType = common_1.VisibilityType.VISIBILITY_TYPE_PUBLIC_READ;
break;
case "unspecified":
visibilityType = common_1.VisibilityType.VISIBILITY_TYPE_UNSPECIFIED;
break;
case "private":
visibilityType = common_1.VisibilityType.VISIBILITY_TYPE_PRIVATE;
break;
default:
// eslint-disable-next-line @typescript-eslint/no-unused-vars
visibilityType = common_1.VisibilityType.UNRECOGNIZED;
break;
}
const publicKey = String(config_1.config.get("publicKey"));
if (!publicKey || publicKey === "undefined") {
console.error("public key is required. Please set it in the system config");
return;
}
const spAddress = String(config_1.config.get("spAddress"));
if (!spAddress || spAddress === "undefined") {
console.error("spAddress is required. Please set it in the system config");
return;
}
const msg = {
paymentAddress: publicKey,
operator: spAddress,
bucketName: bucketName,
visibility: visibilityType,
};
const bucket = yield sdk_1.GreenfieldClient.client.bucket.updateBucketInfo(msg);
const simulateInfo = yield bucket
.simulate({
denom: "BNB",
})
.catch(() => { });
const privateKey = yield (0, password_1.getPrivateKey)();
const broadcast = yield bucket.broadcast({
denom: "BNB",
gasLimit: Number((simulateInfo === null || simulateInfo === void 0 ? void 0 : simulateInfo.gasLimit) || 1200),
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(`bucket creation failed: ${e}`);
}
});
}
exports.updateBucketVisibility = updateBucketVisibility;