@steeveproject/ngx-steem-keychain
Version:
Your Angular interface to Steem Keychain
68 lines • 1.85 kB
JavaScript
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,uselessCode} checked by tsc
*/
import { InvalidArgumentsError } from './errors/invalid-arguments-error';
/*
* Operation represents a blockchain operation,
* which has a name and some parameters.
*/
export class Operation {
/**
* @param {?} name
* @param {?} params
*/
constructor(name, params) {
this.name = name;
this.params = params;
}
/*
* fromArray can be used to convert [operationName, operationParams] into an Operation.
*/
/**
* @param {?} operation
* @return {?}
*/
static fromArray(operation) {
if (!operation) {
throw new InvalidArgumentsError('operation array is unset');
}
if (operation.length !== 2) {
throw new InvalidArgumentsError('operation array length invalid (must be 2)');
}
const [name, params] = operation;
if (typeof name !== 'string') {
throw new InvalidArgumentsError('operation[0] (operation name) must be a string');
}
if (typeof params !== 'object') {
throw new InvalidArgumentsError('operation[1] (operation params) must be an object');
}
return new Operation(name, params);
}
/*
* toArray turns [operationName, operationParams].
*/
/**
* @return {?}
*/
toArray() {
return [this.name, this.params];
}
/*
* toJSON implements custom JSON serialization.
* It simply calls toArray() and returns the result.
*/
/**
* @return {?}
*/
toJSON() {
return this.toArray();
}
}
if (false) {
/** @type {?} */
Operation.prototype.name;
/** @type {?} */
Operation.prototype.params;
}
//# sourceMappingURL=operation.js.map