@blockbolt/boltpay-wallet
Version:
BlockBolt package for SUI wallet
56 lines • 2.14 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.TreasuryService = void 0;
const constant_1 = require("../utils/constant");
class TreasuryError extends Error {
constructor(message, coinType) {
super(message);
this.coinType = coinType;
this.name = 'TreasuryError';
}
}
class TreasuryService {
constructor(client) {
this.client = client;
}
async getTreasury(coinType) {
var _a;
try {
if (coinType === constant_1.CONSTANTS.SUI_COIN_TYPE) {
return constant_1.CONSTANTS.SUI_TREASURY;
}
const response = await this.client.getObject({
id: constant_1.CONSTANTS.DATABASE_OBJECT_ID,
options: { showContent: true },
});
const content = (_a = response.data) === null || _a === void 0 ? void 0 : _a.content;
if (!(content === null || content === void 0 ? void 0 : content.fields)) {
throw new TreasuryError('Invalid database object structure', coinType);
}
const entries = content.fields.entries.fields.contents;
if (!entries) {
throw new TreasuryError('No entries found in database object', coinType);
}
const treasuryData = entries.map((entry) => ({
key: entry.fields.key,
value: entry.fields.value,
}));
const result = treasuryData.find((entry) => entry.key === coinType);
if (!result) {
throw new TreasuryError(`TreasuryError not found for ${coinType}`, coinType);
}
return result.value;
}
catch (error) {
if (error instanceof TreasuryError) {
console.error(`TreasuryError not found: ${error.message} (CoinType: ${error.coinType})`);
}
else {
console.error('Unexpected error in getTreasury:', error);
}
throw error;
}
}
}
exports.TreasuryService = TreasuryService;
//# sourceMappingURL=TresuryService.js.map