@tatumio/erc20-connector
Version:
ERC20 Connector for Tatum API
156 lines (155 loc) • 7.31 kB
JavaScript
;
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
var __param = (this && this.__param) || function (paramIndex, decorator) {
return function (target, key) { decorator(target, key, paramIndex); }
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.Erc20Controller = void 0;
const common_1 = require("@nestjs/common");
const Erc20Error_1 = require("./Erc20Error");
const PathAddressContractAddressChain_1 = require("./dto/PathAddressContractAddressChain");
class Erc20Controller {
constructor(service) {
this.service = service;
}
async getBalanceErc20(path) {
var _a, _b;
try {
return await this.service.getErc20Balance(path.chain, path.address, path.contractAddress);
}
catch (e) {
throw new Erc20Error_1.Erc20Error(`Unexpected error occurred. Reason: ${((_a = e.message) === null || _a === void 0 ? void 0 : _a.message) || ((_b = e.response) === null || _b === void 0 ? void 0 : _b.data) || e.message || e}`, 'erc20.error');
}
}
async transactionErc20(body) {
var _a, _b;
try {
return await this.service.transferErc20(body);
}
catch (e) {
if (['Array', 'ValidationError'].includes(e.constructor.name)) {
throw new common_1.BadRequestException(e);
}
if (e.constructor.name === 'TatumError' || e.constructor.name === Erc20Error_1.Erc20Error.name) {
throw e;
}
throw new Erc20Error_1.Erc20Error(`Unexpected error occurred. Reason: ${((_a = e.message) === null || _a === void 0 ? void 0 : _a.message) || ((_b = e.response) === null || _b === void 0 ? void 0 : _b.data) || e.message || e}`, 'erc20.error');
}
}
async burnErc20(body) {
var _a, _b;
try {
return await this.service.burnErc20(body);
}
catch (e) {
if (['Array', 'ValidationError'].includes(e.constructor.name)) {
throw new common_1.BadRequestException(e);
}
if (e.constructor.name === 'TatumError' || e.constructor.name === Erc20Error_1.Erc20Error.name) {
throw e;
}
throw new Erc20Error_1.Erc20Error(`Unexpected error occurred. Reason: ${((_a = e.message) === null || _a === void 0 ? void 0 : _a.message) || ((_b = e.response) === null || _b === void 0 ? void 0 : _b.data) || e.message || e}`, 'erc20.error');
}
}
async mintErc20(body) {
var _a, _b;
try {
return await this.service.mintErc20(body);
}
catch (e) {
if (['Array', 'ValidationError'].includes(e.constructor.name)) {
throw new common_1.BadRequestException(e);
}
if (e.constructor.name === 'TatumError' || e.constructor.name === Erc20Error_1.Erc20Error.name) {
throw e;
}
throw new Erc20Error_1.Erc20Error(`Unexpected error occurred. Reason: ${((_a = e.message) === null || _a === void 0 ? void 0 : _a.message) || ((_b = e.response) === null || _b === void 0 ? void 0 : _b.data) || e.message || e}`, 'erc20.error');
}
}
async approveErc20(body) {
var _a, _b;
try {
return await this.service.approveErc20(body);
}
catch (e) {
if (['Array', 'ValidationError'].includes(e.constructor.name)) {
throw new common_1.BadRequestException(e);
}
if (e.constructor.name === 'TatumError' || e.constructor.name === Erc20Error_1.Erc20Error.name) {
throw e;
}
throw new Erc20Error_1.Erc20Error(`Unexpected error occurred. Reason: ${((_a = e.message) === null || _a === void 0 ? void 0 : _a.message) || ((_b = e.response) === null || _b === void 0 ? void 0 : _b.data) || e.message || e}`, 'erc20.error');
}
}
async deployErc20(body) {
var _a, _b;
try {
return await this.service.deployErc20(body);
}
catch (e) {
if (['Array', 'ValidationError'].includes(e.constructor.name)) {
throw new common_1.BadRequestException(e);
}
if (e.constructor.name === 'TatumError' || e.constructor.name === Erc20Error_1.Erc20Error.name) {
throw e;
}
throw new Erc20Error_1.Erc20Error(`Unexpected error occurred. Reason: ${((_a = e.message) === null || _a === void 0 ? void 0 : _a.message) || ((_b = e.response) === null || _b === void 0 ? void 0 : _b.data) || e.message || e}`, 'erc20.error');
}
}
}
__decorate([
common_1.Get('/balance/:chain/:contractAddress/:address'),
__param(0, common_1.Param()),
__metadata("design:type", Function),
__metadata("design:paramtypes", [PathAddressContractAddressChain_1.PathAddressContractAddressChain]),
__metadata("design:returntype", Promise)
], Erc20Controller.prototype, "getBalanceErc20", null);
__decorate([
common_1.Post('/transaction'),
common_1.HttpCode(common_1.HttpStatus.OK),
__param(0, common_1.Body()),
__metadata("design:type", Function),
__metadata("design:paramtypes", [Object]),
__metadata("design:returntype", Promise)
], Erc20Controller.prototype, "transactionErc20", null);
__decorate([
common_1.Post('/burn'),
common_1.HttpCode(common_1.HttpStatus.OK),
__param(0, common_1.Body()),
__metadata("design:type", Function),
__metadata("design:paramtypes", [Object]),
__metadata("design:returntype", Promise)
], Erc20Controller.prototype, "burnErc20", null);
__decorate([
common_1.Post('/mint'),
common_1.HttpCode(common_1.HttpStatus.OK),
__param(0, common_1.Body()),
__metadata("design:type", Function),
__metadata("design:paramtypes", [Object]),
__metadata("design:returntype", Promise)
], Erc20Controller.prototype, "mintErc20", null);
__decorate([
common_1.Post('/approve'),
common_1.HttpCode(common_1.HttpStatus.OK),
__param(0, common_1.Body()),
__metadata("design:type", Function),
__metadata("design:paramtypes", [Object]),
__metadata("design:returntype", Promise)
], Erc20Controller.prototype, "approveErc20", null);
__decorate([
common_1.Post('/deploy'),
common_1.HttpCode(common_1.HttpStatus.OK),
__param(0, common_1.Body()),
__metadata("design:type", Function),
__metadata("design:paramtypes", [Object]),
__metadata("design:returntype", Promise)
], Erc20Controller.prototype, "deployErc20", null);
exports.Erc20Controller = Erc20Controller;