Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * New script file
- */
- /**
- * Track the trade of a stock from one trader to another
- * @param {org.acme.trading.Trade} trade - the trade to be processed
- * @transaction
- */
- function tradeStock(trade) {
- // set the new owner of the stock
- trade.stock.owner = trade.newOwner;
- return getAssetRegistry('org.acme.trading.Stock')
- .then(function (assetRegistry) {
- // persist the state of the stock
- return assetRegistry.update(trade.stock);
- });
- }
- /**
- * Initialize some test assets and participants useful for running a demo.
- * @param {org.acme.trading.SetupDemo} setupDemo - the SetupDemo transaction
- * @transaction
- */
- function setupDemo(setupDemo) {
- var factory = getFactory();
- var NS = 'org.acme.trading';
- // create trader 1
- var trader1 = factory.newResource(NS, 'Trader', 'bob@email.com');
- trader1.name = 'Bob Smith';
- // create trader 2
- var trader2 = factory.newResource(NS, 'Trader', 'alice@email.com');
- trader2.name = 'Alice Jones';
- // Create regulator
- var regulator = factory.newResource(NS, 'Regulator', 'sec@email.com');
- regulator.orgName = 'Securities and Exchange Commission';
- // Create a stock owned by Bob
- var stock = factory.newResource(NS, 'Stock', 'AAPL');
- stock.mainExchange = "NYSE";
- stock.quantity = 300;
- stock.owner = factory.newRelationship(NS, 'Trader', 'bob@email.com');
- return getParticipantRegistry(NS + '.Trader')
- .then(function (traderRegistry) {
- // add the growers
- return traderRegistry.addAll([trader1, trader2]);
- })
- .then(function() {
- return getParticipantRegistry(NS + '.Regulator');
- })
- .then(function(regulatorRegistry) {
- // add the importers
- return regulatorRegistry.addAll([regulator]);
- })
- .then(function() {
- return getAssetRegistry(NS + '.Stock');
- })
- .then(function(stockRegistry) {
- // add the shippers
- return stockRegistry.addAll([stock]);
- });
- }
Add Comment
Please, Sign In to add comment