"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
class Protocol {
    /**
     * Remember that the current handler should be the first one.
     * @param handlers - protocol version handlers ordered from the newest to the oldest
     */
    constructor(handlers) {
        /**
         * Validated if steem operation it is a valid wise
         * @param op - an steem operation in format: steem.OperationWithDescriptor object (if it is a pending operation block_num should equal Infinity)
         */
        this.validateOperation = (op) => {
            const so = {
                block_num: Infinity,
                transaction_num: 0,
                transaction_id: "",
                timestamp: new Date(),
                ops: [op]
            };
            return this.validateSteemTransaction(so);
        };
        /**
         * Validated if steem operation (object with blockchain data and timestamp) it is a valid wise
         * @param op - an steem operation object that implements SteemTransaction interface
         */ // TODO test
        this.validateSteemTransaction = (so) => {
            const res = this.handleOrReject(so);
            return res != undefined;
        };
        this.registry = handlers;
        if (this.registry.length == 0)
            throw new Error("You must specify at least one protocol version handler");
    }
    handleOrReject(transaction) {
        for (const pv of this.registry) {
            const result = pv.handleOrReject(transaction);
            if (result) {
                return result;
            }
        }
        return undefined;
    }
    serializeToBlockchain(op) {
        return this.registry[0].serializeToBlockchain(op);
    }
    getHandlers() {
        return this.registry;
    }
}
exports.Protocol = Protocol;
//# sourceMappingURL=Protocol.js.map