Guest User

Untitled

a guest
Mar 24th, 2018
277
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.03 KB | None | 0 0
  1. /**
  2. * New script file
  3. */
  4.  
  5. /**
  6. * Track the trade of a stock from one trader to another
  7. * @param {org.acme.trading.Trade} trade - the trade to be processed
  8. * @transaction
  9. */
  10. function tradeStock(trade) {
  11.  
  12. // set the new owner of the stock
  13. trade.stock.owner = trade.newOwner;
  14.  
  15. return getAssetRegistry('org.acme.trading.Stock')
  16. .then(function (assetRegistry) {
  17. // persist the state of the stock
  18. return assetRegistry.update(trade.stock);
  19. });
  20. }
  21.  
  22. /**
  23. * Initialize some test assets and participants useful for running a demo.
  24. * @param {org.acme.trading.SetupDemo} setupDemo - the SetupDemo transaction
  25. * @transaction
  26. */
  27. function setupDemo(setupDemo) {
  28.  
  29. var factory = getFactory();
  30. var NS = 'org.acme.trading';
  31.  
  32. // create trader 1
  33. var trader1 = factory.newResource(NS, 'Trader', 'bob@email.com');
  34. trader1.name = 'Bob Smith';
  35.  
  36. // create trader 2
  37. var trader2 = factory.newResource(NS, 'Trader', 'alice@email.com');
  38. trader2.name = 'Alice Jones';
  39.  
  40. // Create regulator
  41. var regulator = factory.newResource(NS, 'Regulator', 'sec@email.com');
  42. regulator.orgName = 'Securities and Exchange Commission';
  43.  
  44. // Create a stock owned by Bob
  45. var stock = factory.newResource(NS, 'Stock', 'AAPL');
  46. stock.mainExchange = "NYSE";
  47. stock.quantity = 300;
  48. stock.owner = factory.newRelationship(NS, 'Trader', 'bob@email.com');
  49.  
  50. return getParticipantRegistry(NS + '.Trader')
  51. .then(function (traderRegistry) {
  52. // add the growers
  53. return traderRegistry.addAll([trader1, trader2]);
  54. })
  55. .then(function() {
  56. return getParticipantRegistry(NS + '.Regulator');
  57. })
  58. .then(function(regulatorRegistry) {
  59. // add the importers
  60. return regulatorRegistry.addAll([regulator]);
  61. })
  62. .then(function() {
  63. return getAssetRegistry(NS + '.Stock');
  64. })
  65. .then(function(stockRegistry) {
  66. // add the shippers
  67. return stockRegistry.addAll([stock]);
  68. });
  69. }
Add Comment
Please, Sign In to add comment