@mavrykdynamics/taquito
Version:
High level functionality that builds upon the other packages in the Mavryk Typescript Library Suite.
77 lines (76 loc) • 3.45 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.BatchWalletOperation = void 0;
const taquito_rpc_1 = require("@mavrykdynamics/taquito-rpc");
const rpc_batch_provider_1 = require("../batch/rpc-batch-provider");
const types_1 = require("../operations/types");
const operation_1 = require("./operation");
const errors_1 = require("./errors");
class BatchWalletOperation extends operation_1.WalletOperation {
constructor(opHash, context, newHead$) {
super(opHash, context, newHead$);
this.opHash = opHash;
this.context = context;
this.getOriginatedContractAddresses = () => __awaiter(this, void 0, void 0, function* () {
const opResult = yield this.operationResults();
if (!opResult) {
throw new errors_1.ObservableError('Unable to fetch operation results');
}
else {
const originationOpResults = opResult.filter((x) => x.kind === 'origination');
let addresses = [];
for (const res of originationOpResults) {
if (res.metadata.operation_result.originated_contracts) {
addresses = [...addresses, ...res.metadata.operation_result.originated_contracts];
}
}
return addresses;
}
});
}
revealOperation() {
return __awaiter(this, void 0, void 0, function* () {
const operationResult = yield this.operationResults();
if (!operationResult) {
throw new errors_1.ObservableError('Unable to fetch operation results');
}
else {
return operationResult.find((x) => x.kind === taquito_rpc_1.OpKind.REVEAL);
}
});
}
status() {
return __awaiter(this, void 0, void 0, function* () {
if (!this._included) {
return 'pending';
}
const op = yield this.operationResults();
if (op) {
return (op
.filter((result) => rpc_batch_provider_1.BATCH_KINDS.indexOf(result.kind) !== -1)
.map((result) => {
if ((0, types_1.hasMetadataWithResult)(result)) {
const opResult = result.metadata.operation_result;
return opResult.status;
}
else {
return 'unknown';
}
})[0] || 'unknown');
}
else {
throw new errors_1.ObservableError('Unable to fetch operation results');
}
});
}
}
exports.BatchWalletOperation = BatchWalletOperation;