@kyve/core-beta
Version:
🚀 The base KYVE node implementation.
47 lines (46 loc) • 1.6 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.Bundlr = void 0;
const client_1 = __importDefault(require("@bundlr-network/client"));
const axios_1 = __importDefault(require("axios"));
class Bundlr {
constructor() {
this.name = "Bundlr";
this.decimals = 12;
}
async init(storagePriv) {
this.jwk = JSON.parse(storagePriv);
this.client = new client_1.default("http://node1.bundlr.network", "arweave", this.jwk);
return this;
}
async getBalance() {
const atomicUnits = await this.client.getLoadedBalance();
return atomicUnits.toString();
}
async saveBundle(bundle, tags) {
const transactionOptions = {
tags: [
{
name: "Content-Type",
value: "text/plain",
},
...tags,
],
};
const transaction = this.client.createTransaction(bundle, transactionOptions);
await transaction.sign();
await transaction.upload();
return {
storageId: transaction.id,
storageData: transaction.rawData,
};
}
async retrieveBundle(storageId, timeout) {
const { data: storageData } = await axios_1.default.get(`https://arweave.net/${storageId}`, { responseType: "arraybuffer", timeout });
return { storageId, storageData };
}
}
exports.Bundlr = Bundlr;