avail-js-sdk
Version:
Avail library of functions to interact with blockchain and manipulate transactions
40 lines (39 loc) • 1.86 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());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.WaitFor = void 0;
exports.signAndSendTransaction = signAndSendTransaction;
const _1 = require(".");
const transaction_options_1 = require("./transaction_options");
var WaitFor;
(function (WaitFor) {
WaitFor[WaitFor["BlockInclusion"] = 0] = "BlockInclusion";
WaitFor[WaitFor["BlockFinalization"] = 1] = "BlockFinalization";
})(WaitFor || (exports.WaitFor = WaitFor = {}));
function signAndSendTransaction(client, tx, account, waitFor, options) {
return __awaiter(this, void 0, void 0, function* () {
let retryCount = 3;
for (;;) {
yield (0, transaction_options_1.populateMortality)(client, options);
const txHash = yield tx.signAndSend(account, options);
const watcher = new _1.Watcher(client, txHash, waitFor);
const details = yield watcher.run();
if (details != null) {
return details;
}
if (retryCount == 0) {
break;
}
retryCount -= 1;
}
throw new Error("Failed to submit and/or find transactions");
});
}