Created
May 6, 2017 22:21
-
-
Save dmdeklerk/6ebb05d28ee28a70f99406c93711324d to your computer and use it in GitHub Desktop.
Sample index.js for README
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var Console = (function () { | |
function Console() { | |
} | |
Console.prototype.log = function (message) { | |
heat.logger.info(message); | |
}; | |
return Console; | |
}()); | |
var console = new Console(); | |
var Long = Packages.java.lang.Long; | |
var ByteOrder = Packages.java.nio.ByteOrder; | |
var ByteBuffer = Packages.java.nio.ByteBuffer; | |
var Convert = Packages.com.heatledger.util.Convert; | |
var Crypto2 = Packages.com.heatledger.crypto.Crypto; | |
var Account = Packages.com.heatledger.Account; | |
var microservice; | |
(function (microservice) { | |
function MicroService(name) { | |
return function (target) { | |
microservice.manager().addService(name, function () { | |
function F(args) { | |
return target.apply(this, args); | |
} | |
F.prototype = target.prototype; | |
return new F(arguments); | |
}); | |
}; | |
} | |
microservice.MicroService = MicroService; | |
var AbstractMicroService = (function () { | |
function AbstractMicroService() { | |
} | |
AbstractMicroService.prototype.destroy = function () { }; | |
return AbstractMicroService; | |
}()); | |
microservice.AbstractMicroService = AbstractMicroService; | |
function manager() { | |
return this['_manager'] || (this['_manager'] = new ServiceManager()); | |
} | |
microservice.manager = manager; | |
var Service = (function () { | |
function Service(name, factory) { | |
this.name = name; | |
this.factory = factory; | |
} | |
return Service; | |
}()); | |
var ServiceManager = (function () { | |
function ServiceManager() { | |
this.services = {}; | |
this.running = []; | |
} | |
ServiceManager.prototype.addService = function (name, factory) { | |
this.services[name] = new Service(name, factory); | |
}; | |
ServiceManager.prototype.hasService = function (name) { | |
return !!this.services[name]; | |
}; | |
ServiceManager.prototype.runService = function (name, config) { | |
var service = this.services[name]; | |
if (!service) { | |
return 1; | |
} | |
this.running.push(service.factory.call(null, config)); | |
return 0; | |
}; | |
return ServiceManager; | |
}()); | |
})(microservice || (microservice = {})); | |
var __extends = (this && this.__extends) || (function () { | |
var extendStatics = Object.setPrototypeOf || | |
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || | |
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; | |
return function (d, b) { | |
extendStatics(d, b); | |
function __() { this.constructor = d; } | |
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); | |
}; | |
})(); | |
var subscriber; | |
(function (subscriber) { | |
subscriber.COMPLETE = "COMPLETE"; | |
subscriber.TRUE = "TRUE"; | |
subscriber.FALSE = "FALSE"; | |
function create(serviceId) { | |
return new Subscriber(serviceId); | |
} | |
subscriber.create = create; | |
var Subscriber = (function () { | |
function Subscriber(serviceId) { | |
this.serviceId = serviceId; | |
} | |
Subscriber.prototype.payment = function () { | |
return new PaymentSubscriberBuilder(this.serviceId); | |
}; | |
Subscriber.prototype.assetTransfer = function () { | |
return new AssetTransferSubscriberBuilder(this.serviceId); | |
}; | |
return Subscriber; | |
}()); | |
var TransactionSubscriberBuilder = (function () { | |
function TransactionSubscriberBuilder(serviceId) { | |
this._account = 0; | |
this._sender = 0; | |
this._recipient = 0; | |
this._onAdd = null; | |
this._onRemove = null; | |
this._onConfirmed = null; | |
this._unconfirmed = false; | |
this._confirmations = 0; | |
this.serviceId = serviceId; | |
} | |
TransactionSubscriberBuilder.prototype.account = function (account) { | |
this._account = account; | |
return this; | |
}; | |
TransactionSubscriberBuilder.prototype.sender = function (sender) { | |
this._sender = sender; | |
return this; | |
}; | |
TransactionSubscriberBuilder.prototype.recipient = function (recipient) { | |
this._recipient = recipient; | |
return this; | |
}; | |
TransactionSubscriberBuilder.prototype.onAdd = function (onAdd) { | |
this._onAdd = onAdd; | |
return this; | |
}; | |
TransactionSubscriberBuilder.prototype.onRemove = function (onRemove) { | |
this._onRemove = onRemove; | |
return this; | |
}; | |
TransactionSubscriberBuilder.prototype.onConfirmed = function (onConfirmed) { | |
this._onConfirmed = onConfirmed; | |
return this; | |
}; | |
TransactionSubscriberBuilder.prototype.unconfirmed = function (unconfirmed) { | |
this._unconfirmed = unconfirmed; | |
return this; | |
}; | |
TransactionSubscriberBuilder.prototype.confirmations = function (confirmations) { | |
this._confirmations = confirmations; | |
return this; | |
}; | |
TransactionSubscriberBuilder.prototype.type = function (type) { | |
this._type = type; | |
return this; | |
}; | |
TransactionSubscriberBuilder.prototype.subtype = function (subtype) { | |
this._subtype = subtype; | |
return this; | |
}; | |
TransactionSubscriberBuilder.prototype.subscribe = function () { | |
var unsubscribe = []; | |
if (util.isDefined(this._onConfirmed)) { | |
unsubscribe.push(this.subscribeConfirmed()); | |
} | |
if (util.isDefined(this._onAdd) || util.isDefined(this._onRemove)) { | |
unsubscribe.push(heat.events.subscribeTransaction(this._type, this._subtype, this._account, this._sender, this._recipient, this._unconfirmed, this._onAdd, this._onRemove)); | |
} | |
return function () { return unsubscribe.forEach(function (fn) { fn(); }); }; | |
}; | |
TransactionSubscriberBuilder.prototype.subscribeConfirmed = function () { | |
var _this = this; | |
var unsubscribe = []; | |
var add = function (event) { | |
heat.transactionStore.addTransaction(_this.serviceId, event.transaction); | |
if (_this.get(event.transaction.id, subscriber.COMPLETE) == subscriber.TRUE) { | |
return; | |
} | |
var onConfirmed = function (event) { | |
if (_this.get(event.transaction.id, subscriber.COMPLETE) == subscriber.TRUE) { | |
return; | |
} | |
_this._onConfirmed(event); | |
}; | |
heat.transactionStore.registerConfirmedListener(event.transaction.id, _this._confirmations, onConfirmed); | |
unsubscribe.push(function () { | |
heat.transactionStore.unRegisterConfirmedListener(event.transaction.id, _this._confirmations, onConfirmed); | |
}); | |
}; | |
unsubscribe.push(heat.events.subscribeTransaction(this._type, this._subtype, this._account, this._sender, this._recipient, this._unconfirmed, add, null)); | |
return function () { return unsubscribe.forEach(function (fn) { fn(); }); }; | |
}; | |
TransactionSubscriberBuilder.prototype.get = function (transactionId, key) { | |
return heat.transactionStore.getEntryValue(this.serviceId, transactionId, key); | |
}; | |
TransactionSubscriberBuilder.prototype.put = function (transactionId, key, value) { | |
return heat.transactionStore.setEntryValue(this.serviceId, transactionId, key, value); | |
}; | |
return TransactionSubscriberBuilder; | |
}()); | |
var PaymentSubscriberBuilder = (function (_super) { | |
__extends(PaymentSubscriberBuilder, _super); | |
function PaymentSubscriberBuilder(id) { | |
return _super.call(this, id) || this; | |
} | |
PaymentSubscriberBuilder.prototype.subscribe = function () { | |
this.type(0); | |
this.subtype(0); | |
return _super.prototype.subscribe.call(this); | |
}; | |
return PaymentSubscriberBuilder; | |
}(TransactionSubscriberBuilder)); | |
var AssetTransferSubscriberBuilder = (function (_super) { | |
__extends(AssetTransferSubscriberBuilder, _super); | |
function AssetTransferSubscriberBuilder(id) { | |
return _super.call(this, id) || this; | |
} | |
AssetTransferSubscriberBuilder.prototype.subscribe = function () { | |
this.type(2); | |
this.subtype(2); | |
return _super.prototype.subscribe.call(this); | |
}; | |
return AssetTransferSubscriberBuilder; | |
}(TransactionSubscriberBuilder)); | |
})(subscriber || (subscriber = {})); | |
var util; | |
(function (util) { | |
function isDefined(value) { return typeof value !== 'undefined'; } | |
util.isDefined = isDefined; | |
function decryptEncryptedMessage(transaction, secretPhrase) { | |
var encryptedData = transaction.encryptedMessage.encryptedData; | |
var privateKey = Crypto2.getPrivateKey(secretPhrase); | |
var bytes = encryptedData.decrypt(privateKey, transaction.senderPublicKey); | |
return Convert.toString(bytes); | |
} | |
util.decryptEncryptedMessage = decryptEncryptedMessage; | |
})(util || (util = {})); | |
var __extends = (this && this.__extends) || (function () { | |
var extendStatics = Object.setPrototypeOf || | |
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || | |
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; | |
return function (d, b) { | |
extendStatics(d, b); | |
function __() { this.constructor = d; } | |
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); | |
}; | |
})(); | |
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { | |
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; | |
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); | |
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; | |
return c > 3 && r && Object.defineProperty(target, key, r), r; | |
}; | |
var microservice; | |
(function (microservice) { | |
var sample; | |
(function (sample) { | |
var SampleService = (function (_super) { | |
__extends(SampleService, _super); | |
function SampleService(config) { | |
var _this = _super.call(this) || this; | |
_this.config = config; | |
console.log("Sample microservice says: Hello!"); | |
return _this; | |
} | |
return SampleService; | |
}(microservice.AbstractMicroService)); | |
SampleService = __decorate([ | |
microservice.MicroService('sample.service') | |
], SampleService); | |
})(sample = microservice.sample || (microservice.sample = {})); | |
})(microservice || (microservice = {})); | |
var microservice; | |
(function (microservice) { | |
var sample; | |
(function (sample) { | |
function test() { | |
microservice.manager().runService('sample.service', {}); | |
heat.exit(); | |
} | |
sample.test = test; | |
})(sample = microservice.sample || (microservice.sample = {})); | |
})(microservice || (microservice = {})); | |
//# sourceMappingURL=../dist/index.js.map |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment