evm-blockchain-tools
Version:
This is a collection of resuseable tools to support development for EVM-powered blockchains
76 lines • 3.11 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());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.TronGateway = void 0;
const tronweb_1 = __importDefault(require("tronweb"));
const constants_1 = require("../common/constants");
const utils_1 = require("../utils");
class TronGateway {
constructor(config) {
this.config = config;
this.network = constants_1.APP_NETWORK.TRON;
this.signerAddress = this._tron.address.fromPrivateKey(config.privateKey);
this.connect();
}
connect() {
this._tron = new tronweb_1.default({
fullHost: this.config.fullHostUrl,
headers: {
"TRON-PRO-API-KEY": this.config.apiKey,
},
privateKey: this.config.privateKey,
});
}
get signer() {
return this._tron.trx.getAccount(this.signerAddress);
}
getCurrentBlock() {
var _a, _b;
return __awaiter(this, void 0, void 0, function* () {
const blockData = yield this._tron.trx.getCurrentBlock();
return (_b = (_a = blockData === null || blockData === void 0 ? void 0 : blockData.block_header) === null || _a === void 0 ? void 0 : _a.raw_data) === null || _b === void 0 ? void 0 : _b.number;
});
}
isValidTxFormat(txHash) {
return (0, utils_1.isValidTronTxFormat)(txHash);
}
getBlock(blockNumber) {
return this._tron.trx.getBlockByNumber(blockNumber);
}
getGasPrice() {
return __awaiter(this, void 0, void 0, function* () {
throw new Error("get gas price not supported for Tron");
});
}
recoverSigner(message, signedMessage) {
return this._tron.trx.verifyMessageV2(message, signedMessage);
}
getSignerAddress() {
return __awaiter(this, void 0, void 0, function* () {
return this.signerAddress;
});
}
getTransactionByID(txID) {
return __awaiter(this, void 0, void 0, function* () {
const txInfo = yield this._tron.trx.getTransactionInfo(txID);
const txData = yield this._tron.trx.getTransaction(txID);
return {
txInfo,
txData,
};
});
}
}
exports.TronGateway = TronGateway;
//# sourceMappingURL=tron-gateway.js.map