UNPKG

airgap-coin-lib

Version:

The airgap-coin-lib is a protocol agnostic library to prepare, sign and broadcast cryptocurrency transactions.

39 lines 1.35 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var StateMachine = /** @class */ (function () { function StateMachine(initialState, validTransitions) { this.state = initialState; this.validTransitions = validTransitions; } StateMachine.prototype.transitionTo = function (state) { if (this.canTransitionTo(state)) { this.state = state; } else { throw new Error("Invalid state transition: " + this.state + " -> " + state); } }; StateMachine.prototype.getState = function () { return this.state; }; StateMachine.prototype.addValidStateTransition = function (from, to) { var states = this.validTransitions.get(to); if (states !== undefined && states.indexOf(from) === -1) { states.push(from); this.validTransitions.set(to, states); } else { this.validTransitions.set(to, [from]); } }; StateMachine.prototype.canTransitionTo = function (state) { var states = this.validTransitions.get(state); if (states !== undefined) { return states.indexOf(this.state) !== -1; } return false; }; return StateMachine; }()); exports.StateMachine = StateMachine; //# sourceMappingURL=StateMachine.js.map