Newer
Older
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
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 });
const axios_1 = require("axios");
class AeternityService {
constructor(nodeUrl, compilerUrl, contractBytecode) {
this._nodeUrl = "";
this._compilerUrl = "";
this._contractBytecode = "";
this._nodeUrl = nodeUrl;
this._compilerUrl = compilerUrl;
this._contractBytecode = contractBytecode;
if (!nodeUrl) {
throw new Error("Aeternity node URL not defined");
}
if (!compilerUrl) {
throw new Error("Aeternity compiler URL not defined");
}
if (!contractBytecode) {
throw new Error("Aeternity contract bytecode not defined");
}
getTxDataByHash(hash) {
return __awaiter(this, void 0, void 0, function* () {
const { data } = yield axios_1.default(`${this._nodeUrl}/v2/transactions/${hash}`);
return {
hash: data.hash,
blockHeight: data.block_height,
tx: {
callData: data.tx.call_data,
},
};
});
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
decodeContractCallData(callData) {
var _a, _b, _c, _d, _e, _f;
return __awaiter(this, void 0, void 0, function* () {
const { data } = yield axios_1.default({
url: `${this._compilerUrl}/decode-calldata/bytecode/`,
method: "POST",
headers: {
"Content-Type": "application/json",
},
data: {
calldata: callData,
bytecode: this._contractBytecode,
},
});
return {
merkleeTreeFileName: (_c = (_b = (_a = data.arguments[0]) === null || _a === void 0 ? void 0 : _a.value[0]) === null || _b === void 0 ? void 0 : _b.key) === null || _c === void 0 ? void 0 : _c.value,
rootNodeHash: (_f = (_e = (_d = data.arguments[0]) === null || _d === void 0 ? void 0 : _d.value[0]) === null || _e === void 0 ? void 0 : _e.val) === null || _f === void 0 ? void 0 : _f.value,
};
});
}
getBlockData(height) {
return __awaiter(this, void 0, void 0, function* () {
const [blockInfo, blockchainHeight] = yield Promise.all([
axios_1.default(`${this._nodeUrl}/v2/key-blocks/height/${height}`).then(({ data }) => data),
this.getBlockhainHeight(),
]);
return {
blockHeight: blockInfo.height,
timestamp: blockInfo.time,
confirmationsAmount: blockchainHeight - blockInfo.height,
};
});
}
getBlockhainHeight() {
return __awaiter(this, void 0, void 0, function* () {
const { data } = yield axios_1.default(`${this._nodeUrl}/v2/key-blocks/current/height`);
return data.height;
});