{"version":3,"sources":["https://lively-kernel.org/lively4/lively4-stable/src/blockchain/view/transactionNetworkView.js"],"names":["TransactionNetworkView","constructor","blockchainNodeView","_nodeView","nodeClickHandler","_onNodeClick","bind","_displayedTransactions","_newTransactions","_nodeIndices","Map","reset","draw","addTransaction","transaction","push","addTransactions","transactions","concat","_constructNodes","_constructLinks","forEach","set","hash","size","addNode","displayName","allTransactions","receiver","inputs","input","sender","outputs","hasOutput","addLink","get","amount","node","tx","Error","lively","openComponentInWindow","then","comp"],"mappings":";;;;;;;;AACe,YAAMA,sBAAN,CAA6B;AAC1CC,oBAAYC,kBAAZ,EAAgC;AAC9B,eAAKC,SAAL,GAAiBD,kBAAjB;AACA,eAAKC,SAAL,CAAeC,gBAAf,GAAkC,KAAKC,YAAL,CAAkBC,IAAlB,CAAuB,IAAvB,CAAlC;;AAEA,eAAKC,sBAAL,GAA8B,EAA9B;AACA,eAAKC,gBAAL,GAAwB,EAAxB;AACA,eAAKC,YAAL,GAAoB,IAAIC,GAAJ,EAApB;AACD;;AAEDC,gBAAQ;AACN,eAAKJ,sBAAL,GAA8B,EAA9B;AACA,eAAKC,gBAAL,GAAwB,EAAxB;AACA,eAAKC,YAAL,GAAoB,IAAIC,GAAJ,EAApB;AACA,eAAKP,SAAL,CAAeQ,KAAf;AACA,eAAKC,IAAL;AACD;;AAEDC,uBAAeC,WAAf,EAA4B;AAC1B,eAAKN,gBAAL,CAAsBO,IAAtB,CAA2BD,WAA3B;AACA,iBAAO,IAAP;AACD;;AAEDE,wBAAgBC,YAAhB,EAA8B;AAC5B,eAAKT,gBAAL,GAAwB,KAAKA,gBAAL,CAAsBU,MAAtB,CAA6BD,YAA7B,CAAxB;AACA,iBAAO,IAAP;AACD;;AAEDL,eAAO;AACL,eAAKO,eAAL;AACA,eAAKC,eAAL;AACA,eAAKjB,SAAL,CAAeS,IAAf;;AAEA,eAAKL,sBAAL,GAA8B,KAAKA,sBAAL,CAA4BW,MAA5B,CAAmC,KAAKV,gBAAxC,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AAGf,IAAH,IAAWc,KAAKd,IAAnC,EAAyC;AACvC;AACD;;AAEDT,0BAAcwB,EAAd;AACD,WAND;;AAQA,cAAI,CAACxB,WAAL,EAAkB;AAChB,kBAAM,IAAIyB,KAAJ,CAAU,qCAAV,CAAN;AACD;;AAEDC,iBAAOC,qBAAP,CAA6B,wBAA7B,EAAuDC,IAAvD,CAA6DC,IAAD,IAAU;AACpE,gBAAI,CAACA,IAAL,EAAW;AACT;AACD;;AAEDA,iBAAK7B,WAAL,GAAmBA,WAAnB;AACA,mBAAO6B,IAAP;AACD,WAPD;AAQD;AAvGyC;;yBAAvB3C,sB","file":"transactionNetworkView.js","sourcesContent":["\nexport default class TransactionNetworkView {\n  constructor(blockchainNodeView) {\n    this._nodeView = blockchainNodeView;\n    this._nodeView.nodeClickHandler = this._onNodeClick.bind(this);\n    \n    this._displayedTransactions = [];\n    this._newTransactions = [];\n    this._nodeIndices = new Map();\n  }\n  \n  reset() {\n    this._displayedTransactions = [];\n    this._newTransactions = [];\n    this._nodeIndices = new Map();\n    this._nodeView.reset();\n    this.draw();\n  }\n  \n  addTransaction(transaction) {\n    this._newTransactions.push(transaction);\n    return this;\n  }\n  \n  addTransactions(transactions) {\n    this._newTransactions = this._newTransactions.concat(transactions);\n    return this;\n  }\n  \n  draw() {\n    this._constructNodes();\n    this._constructLinks();\n    this._nodeView.draw();\n    \n    this._displayedTransactions = this._displayedTransactions.concat(this._newTransactions);\n    this._newTransactions = [];\n  }\n  \n  _constructNodes() {\n    this._newTransactions.forEach((transaction) => {\n      this._nodeIndices.set(transaction.hash, this._nodeIndices.size);\n      this._nodeView.addNode(\n        {\n          \"name\": transaction.displayName, \n          \"group\": 1,\n          \"hash\": transaction.hash\n        }\n      );\n    });\n  }\n  \n  _constructLinks() {\n    const allTransactions = this._displayedTransactions.concat(this._newTransactions);\n    \n    this._newTransactions.forEach((receiver) => {\n      receiver.inputs.forEach((input) => {\n        allTransactions.forEach((sender) => {\n          if (sender === receiver) {\n            return;\n          }\n          \n          if (!sender.outputs.hasOutput(input.hash)) {\n            return;\n          }\n          \n          this._nodeView.addLink(\n            {\n              \"source\": this._nodeIndices.get(sender.hash),\n              \"target\": this._nodeIndices.get(receiver.hash),\n              \"value\": input.amount\n            }\n          );\n        });\n      });\n    });\n  }\n  \n  _onNodeClick(node) {\n    if (!node || !node.hash) {\n      return;\n    }\n    \n    let transaction = null;\n    \n    this._displayedTransactions.forEach((tx) => {\n      if (transaction || tx.hash != node.hash) {\n        return;\n      }\n      \n      transaction = tx;\n    });\n    \n    if (!transaction) {\n      throw new Error(\"Cannot find transaction to display!\");\n    }\n    \n    lively.openComponentInWindow(\"blockchain-transaction\").then((comp) => {\n      if (!comp) {\n        return;\n      }\n      \n      comp.transaction = transaction;\n      return comp;\n    });\n  }\n}"]}