UNPKG

@windingtree/wt-js-libs

Version:

Javascript libraries to interact with the Winding Tree contracts

1 lines 62.9 kB
!function(t,e){for(var n in e)t[n]=e[n]}(exports,function(t){var e={};function n(r){if(e[r])return e[r].exports;var a=e[r]={i:r,l:!1,exports:{}};return t[r].call(a.exports,a,a.exports,n),a.l=!0,a.exports}return n.m=t,n.c=e,n.d=function(t,e,r){n.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:r})},n.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},n.t=function(t,e){if(1&e&&(t=n(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var a in t)n.d(r,a,function(e){return t[e]}.bind(null,a));return r},n.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return n.d(e,"a",e),e},n.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},n.p="",n(n.s=19)}([function(t,e){t.exports=require("@babel/runtime/regenerator")},function(t,e){t.exports=require("@babel/runtime/helpers/asyncToGenerator")},function(t,e){t.exports=require("@babel/runtime/helpers/classCallCheck")},function(t,e){t.exports=require("@babel/runtime/helpers/createClass")},function(t,e){t.exports=require("@babel/runtime/helpers/possibleConstructorReturn")},function(t,e){t.exports=require("@babel/runtime/helpers/getPrototypeOf")},function(t,e){t.exports=require("@babel/runtime/helpers/inherits")},function(t,e){t.exports=require("web3-utils")},function(t,e){t.exports=require("web3-eth")},function(t,e){t.exports=require("@babel/runtime/helpers/defineProperty")},function(t,e){t.exports=require("lodash.clonedeep")},function(t,e){t.exports=require("@babel/runtime/helpers/toConsumableArray")},function(t,e){t.exports=require("@windingtree/wt-contracts/build/contracts/AbstractSegmentDirectory.json")},function(t,e){t.exports=require("@windingtree/wt-contracts/build/contracts/OrganizationInterface.json")},function(t,e){t.exports=require("@windingtree/wt-contracts/build/contracts/AbstractOrganizationFactory.json")},function(t,e){t.exports=require("@windingtree/wt-contracts/build/contracts/WindingTreeEntrypoint.json")},function(t,e){t.exports=require("@babel/runtime/helpers/typeof")},function(t,e){t.exports=require("@windingtree/wt-contracts/build/contracts/Organization.json")},function(t,e){t.exports=require("@babel/runtime/helpers/assertThisInitialized")},function(t,e,n){"use strict";n.r(e);var r=n(0),a=n.n(r),s=n(1),i=n.n(s),o=n(2),c=n.n(o),u=n(3),h=n.n(u),f=n(11),l=n.n(f),p=n(9),d=n.n(p),w=n(8),g=n.n(w),y=n(7),v=n.n(y),b=function(){function t(e,n){c()(this,t),this.gasModifiers=e,this.provider=n,this.web3Eth=new g.a(n)}var e,n,r,s;return h()(t,null,[{key:"createInstance",value:function(e,n){return new t(e,n)}}]),h()(t,[{key:"isZeroAddress",value:function(t){return!t||!v.a.isAddress(t)||"0x0000000000000000000000000000000000000000"===String(t)}},{key:"applyGasModifier",value:function(t){if(this.gasModifiers){if(this.gasModifiers.gasMargin)return Math.ceil(t+this.gasModifiers.gasMargin);if(this.gasModifiers.gasCoefficient)return Math.ceil(t*this.gasModifiers.gasCoefficient)}return t}},{key:"getCurrentBlockNumber",value:(s=i()(a.a.mark(function t(){return a.a.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.abrupt("return",this.web3Eth.getBlockNumber());case 1:case"end":return t.stop()}},t,this)})),function(){return s.apply(this,arguments)})},{key:"checkAddressChecksum",value:function(t){return v.a.checkAddressChecksum(t)}},{key:"getSoliditySha3Hash",value:function(t){return v.a.soliditySha3(t)}},{key:"determineCurrentAddressNonce",value:(r=i()(a.a.mark(function t(e){return a.a.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.abrupt("return",this.web3Eth.getTransactionCount(e));case 1:case"end":return t.stop()}},t,this)})),function(t){return r.apply(this,arguments)})},{key:"getTransactionReceipt",value:(n=i()(a.a.mark(function t(e){return a.a.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.abrupt("return",this.web3Eth.getTransactionReceipt(e));case 1:case"end":return t.stop()}},t,this)})),function(t){return n.apply(this,arguments)})},{key:"getTransaction",value:(e=i()(a.a.mark(function t(e){return a.a.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.abrupt("return",this.web3Eth.getTransaction(e));case 1:case"end":return t.stop()}},t,this)})),function(t){return e.apply(this,arguments)})}]),t}(),k=n(12),m=n.n(k),x=n(13),_=n.n(x),C=n(17),O=n.n(C),D=n(14),I=n.n(D),z=n(15),E=n.n(z),A=n(4),S=n.n(A),J=n(5),U=n.n(J),T=n(6),j=n.n(T),P=n(18),H=n.n(P);var M=function(t){function e(t,n){var r;return c()(this,e),(r=S()(this,U()(e).call(this,t))).name=r.constructor.name,r.originalError=n,Error.captureStackTrace(H()(r),r.constructor),r}return j()(e,t),e}(function(t){function e(){var e=Reflect.construct(t,Array.from(arguments));return Object.setPrototypeOf(e,Object.getPrototypeOf(this)),e}return e.prototype=Object.create(t.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t,e}(Error)),R=function(t){function e(){return c()(this,e),S()(this,U()(e).apply(this,arguments))}return j()(e,t),e}(M),F=function(t){function e(){return c()(this,e),S()(this,U()(e).apply(this,arguments))}return j()(e,t),e}(M),N=function(t){function e(){return c()(this,e),S()(this,U()(e).apply(this,arguments))}return j()(e,t),e}(M),L=function(t){function e(){return c()(this,e),S()(this,U()(e).apply(this,arguments))}return j()(e,t),e}(M),K=function(t){function e(){return c()(this,e),S()(this,U()(e).apply(this,arguments))}return j()(e,t),e}(M),q=function(t){function e(){return c()(this,e),S()(this,U()(e).apply(this,arguments))}return j()(e,t),e}(K),G=function(t){function e(){return c()(this,e),S()(this,U()(e).apply(this,arguments))}return j()(e,t),e}(K),W=function(t){function e(){return c()(this,e),S()(this,U()(e).apply(this,arguments))}return j()(e,t),e}(M),B=function(t){function e(){return c()(this,e),S()(this,U()(e).apply(this,arguments))}return j()(e,t),e}(M),V=function(){function t(e){c()(this,t),this.provider=e,this.web3Eth=new g.a(e),this.contractsCache={}}var e,n,r,s,o,u;return h()(t,null,[{key:"createInstance",value:function(e){return new t(e)}}]),h()(t,[{key:"_getInstance",value:(u=i()(a.a.mark(function t(e,n,r){var s;return a.a.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(v.a.isAddress(r)){t.next=2;break}throw new F("Cannot get "+e+" instance at an invalid address "+r);case 2:if(this.contractsCache["".concat(e,":").concat(r)]){t.next=9;break}return t.next=5,this.web3Eth.getCode(r);case 5:if("0x0"!==(s=t.sent)&&"0x"!==s){t.next=8;break}throw new F("Cannot get "+e+" instance at an address with no code on "+r);case 8:this.contractsCache["".concat(e,":").concat(r)]=new this.web3Eth.Contract(n,r);case 9:return t.abrupt("return",this.contractsCache["".concat(e,":").concat(r)]);case 10:case"end":return t.stop()}},t,this)})),function(t,e,n){return u.apply(this,arguments)})},{key:"getSegmentDirectoryInstance",value:(o=i()(a.a.mark(function t(e){return a.a.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.abrupt("return",this._getInstance("segmentDirectory",m.a.abi,e));case 1:case"end":return t.stop()}},t,this)})),function(t){return o.apply(this,arguments)})},{key:"getOrganizationInstance",value:(s=i()(a.a.mark(function t(e){return a.a.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.abrupt("return",this._getInstance("organization",_.a.abi,e));case 1:case"end":return t.stop()}},t,this)})),function(t){return s.apply(this,arguments)})},{key:"getUpdateableOrganizationInstance",value:(r=i()(a.a.mark(function t(e){return a.a.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.abrupt("return",this._getInstance("organization",O.a.abi,e));case 1:case"end":return t.stop()}},t,this)})),function(t){return r.apply(this,arguments)})},{key:"getOrganizationFactoryInstance",value:(n=i()(a.a.mark(function t(e){return a.a.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.abrupt("return",this._getInstance("organizationFactory",I.a.abi,e));case 1:case"end":return t.stop()}},t,this)})),function(t){return n.apply(this,arguments)})},{key:"getEntrypointInstance",value:(e=i()(a.a.mark(function t(e){return a.a.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.abrupt("return",this._getInstance("entrypoint",E.a.abi,e));case 1:case"end":return t.stop()}},t,this)})),function(t){return e.apply(this,arguments)})},{key:"_initEventRegistry",value:function(){function t(t){var e=t.filter(function(t){return"event"===t.type}),n={},r=!0,a=!1,s=void 0;try{for(var i,o=e[Symbol.iterator]();!(r=(i=o.next()).done);r=!0){var c=i.value;n[v.a.sha3(c.name+"("+c.inputs.map(function(t){return t.type}).join(",")+")")]=c}}catch(t){a=!0,s=t}finally{try{r||null==o.return||o.return()}finally{if(a)throw s}}return n}return this.eventRegistry||(this.eventRegistry=Object.assign({},t(_.a.abi),t(I.a.abi),t(m.a.abi),t(E.a.abi))),this.eventRegistry}},{key:"decodeLogs",value:function(t){var e=this,n=[],r=this._initEventRegistry(),a=!0,s=!1,i=void 0;try{for(var o,c=t[Symbol.iterator]();!(a=(o=c.next()).done);a=!0){var u=o.value;u.topics&&u.topics[0]&&r[u.topics[0]]&&function(){var t=r[u.topics[0]],a=u.topics;t.anonymous||(a=u.topics.slice(1));var s=e.web3Eth.abi.decodeLog(t.inputs,u.data,a),i=t.inputs.map(function(t){return{name:t.name,type:t.type,value:s[t.name]}});n.push({event:t.name,address:u.address,attributes:i})}()}}catch(t){s=!0,i=t}finally{try{a||null==c.return||c.return()}finally{if(s)throw i}}return n}}]),t}(),Z=n(10),Y=n.n(Z),Q=function(){function t(){c()(this,t),this._obsoleteFlag=!1,this._deployedFlag=!1,this._localData={},this._remoteData={},this._fieldStates={},this._fieldKeys=[],this._syncing=null}var e,n,r,s;return h()(t,null,[{key:"createInstance",value:function(){return new t}}]),h()(t,[{key:"bindProperties",value:function(t,e){var n=this;this._options=t,this._fieldKeys=Object.keys(t.fields);for(var r=function(t){var r,s=n._fieldKeys[t];n._fieldStates[s]="unsynced",Object.defineProperty(e,s,{configurable:!1,enumerable:!0,get:(r=i()(a.a.mark(function t(){return a.a.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.abrupt("return",n._genericGetter(s));case 1:case"end":return t.stop()}},t)})),function(){return r.apply(this,arguments)}),set:function(t){n._genericSetter(s,t)}})},s=0;s<this._fieldKeys.length;s++)r(s)}},{key:"isObsolete",value:function(){return this._obsoleteFlag}},{key:"markObsolete",value:function(){this._obsoleteFlag=!0}},{key:"isDeployed",value:function(){return this._deployedFlag}},{key:"markDeployed",value:function(){this._deployedFlag=!0}},{key:"_genericGetter",value:(s=i()(a.a.mark(function t(e){var n=this;return a.a.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(!this.isObsolete()){t.next=2;break}throw new q("This object was destroyed in a remote storage!");case 2:if(!this.isDeployed()||"unsynced"!==this._fieldStates[e]){t.next=4;break}return t.abrupt("return",this._syncRemoteData().then(function(){return n._localData[e]}));case 4:return t.abrupt("return",this._localData[e]);case 5:case"end":return t.stop()}},t,this)})),function(t){return s.apply(this,arguments)})},{key:"_genericSetter",value:function(t,e){if(this.isObsolete())throw new q("This object was destroyed in a remote storage!");this._localData[t]===e&&"unsynced"!==this._fieldStates[t]||(this._localData[t]=e,this._fieldStates[t]="dirty")}},{key:"_fetchRemoteData",value:(r=i()(a.a.mark(function t(){var e,n,r,s,i,o,c;return a.a.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(this.isDeployed()){t.next=2;break}throw new q("Cannot fetch undeployed object");case 2:for(e=[],n=0;n<this._fieldKeys.length;n++)(r=this._options.fields[this._fieldKeys[n]].remoteGetter)&&"unsynced"===this._fieldStates[this._fieldKeys[n]]&&e.push({field:this._fieldKeys[n],fn:r()});if(s=e.map(function(t){return t.field}),i=e.map(function(t){return t.fn}),!s.length){t.next=11;break}return t.next=9,Promise.all(i);case 9:for(o=t.sent,c=0;c<s.length;c++)this._remoteData[s[c]]=o[c];case 11:return t.abrupt("return",this._remoteData);case 12:case"end":return t.stop()}},t,this)})),function(){return r.apply(this,arguments)})},{key:"_syncRemoteData",value:(n=i()(a.a.mark(function t(){var e=this;return a.a.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return this._syncing||(this._syncing=i()(a.a.mark(function t(){var n;return a.a.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.prev=0,t.next=3,e._fetchRemoteData();case 3:for(n=0;n<e._fieldKeys.length;n++)e._remoteData[e._fieldKeys[n]]!==e._localData[e._fieldKeys[n]]&&"dirty"!==e._fieldStates[e._fieldKeys[n]]&&(e._localData[e._fieldKeys[n]]=e._remoteData[e._fieldKeys[n]],e._fieldStates[e._fieldKeys[n]]="synced");t.next=9;break;case 6:throw t.prev=6,t.t0=t.catch(0),new G("Cannot sync remote data: "+t.t0.message);case 9:case"end":return t.stop()}},t,null,[[0,6]])}))()),t.abrupt("return",this._syncing);case 2:case"end":return t.stop()}},t,this)})),function(){return n.apply(this,arguments)})},{key:"getFieldState",value:function(t){return this._fieldStates[t]}},{key:"_hashCode",value:function(t){var e,n=0;for(e=0;e<t.length;e++)n=(n<<5)-n+t.charCodeAt(e),n|=0;return n}},{key:"updateRemoteData",value:(e=i()(a.a.mark(function t(e){var n,r,s,i,o=this;return a.a.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this._syncRemoteData();case 2:for(n=[],r={},s=function(t){var a=o._options.fields[o._fieldKeys[t]].remoteSetter;if(a&&"dirty"===o._fieldStates[o._fieldKeys[t]]){var s=o._hashCode(a.toString());r[s]||(r[s]=!0,n.push(a(Y()(e)).then(function(e){e.eventCallbacks=e.eventCallbacks||{};var n=e.eventCallbacks.onReceipt;return e.eventCallbacks.onReceipt=function(e){if(o._fieldStates[o._fieldKeys[t]]="synced",n)return n(e)},e})))}},i=0;i<this._fieldKeys.length;i++)s(i);return t.abrupt("return",Promise.all(n));case 7:case"end":return t.stop()}},t,this)})),function(t){return e.apply(this,arguments)})}]),t}(),X=n(16),$=n.n(X),tt=function(t){function e(){return c()(this,e),S()(this,U()(e).apply(this,arguments))}return j()(e,t),e}(M),et=function(t){function e(){return c()(this,e),S()(this,U()(e).apply(this,arguments))}return j()(e,t),e}(tt),nt=function(t){function e(){return c()(this,e),S()(this,U()(e).apply(this,arguments))}return j()(e,t),e}(tt),rt=function(){function t(){c()(this,t)}return h()(t,null,[{key:"setup",value:function(e){t.adapters={},t.options=e||{};for(var n=0,r=Object.keys(t.options.adapters||{});n<r.length;n++){var a=r[n],s=a.toLowerCase();if(t.adapters[s])throw new et("Adapter declared twice: ".concat(s));t.adapters[s]=t.options.adapters[a]}}},{key:"_reset",value:function(){t.options={},t.adapters={}}},{key:"getAdapter",value:function(e){if(!(e=e&&e.toLowerCase())||!t.adapters[e])throw new nt("Unsupported data storage type: ".concat(e||"null"));var n=t.adapters[e];return n.create(n.options)}}]),t}(),at=rt,st=function(){function t(e,n){c()(this,t),this.ref=e,this._downloaded=!1,this._data={},this._children=n||[]}var e,n,r,s;return h()(t,null,[{key:"createInstance",value:function(e,n){if(!e)throw new L("Cannot instantiate StoragePointer without uri");var r={};for(var a in n=n||{}){if(r[a.toLowerCase()])throw new L("Cannot create instance: Conflict in field names.");void 0===n[a].required&&(n[a].required=!0),r[a.toLowerCase()]=1}return new t(e,n)}}]),h()(t,[{key:"reset",value:(s=i()(a.a.mark(function t(){return a.a.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this._downloading||Promise.resolve();case 2:delete this._downloading,this._downloaded=!1;case 4:case"end":return t.stop()}},t,this)})),function(){return s.apply(this,arguments)})},{key:"_detectSchema",value:function(t){var e=t.match(/([a-zA-Z-]+):\/\//i);return e?e[1]:null}},{key:"_getOffChainDataClient",value:function(){return this._adapter||(this._adapter=at.getAdapter(this._detectSchema(this.ref))),this._adapter}},{key:"_initFromStorage",value:function(e){for(var n in this._data=Y()(e),this._children){var r=this._data[n],a=this._children[n],s=a.nested?"object":"string";if(a.required&&!r)throw new L("Cannot access field '".concat(n,"' which is required."));if(r){if(!Array.isArray(r)&&$()(r)!==s){var i=r?r.toString():"undefined";throw new L("Cannot access field '".concat(n,"' on '").concat(i,"' which does not appear to be of type ").concat(s," but ").concat($()(r),"."))}if(a.nested){if(Array.isArray(r))throw new L("Cannot access field '".concat(n,"'. Nested pointer cannot be an Array."));for(var o={},c=0,u=Object.keys(r);c<u.length;c++){var h=u[c];if("string"!=typeof r[h])throw new L("Cannot access field '".concat(n,".").concat(h,"' which does not appear to be of type string."));o[h]=t.createInstance(r[h],a.children||{})}this._data[n]=o}else if(Array.isArray(r)){this._data[n]=[];for(var f=0;f<r.length;f++)for(var l in this._data[n].push(r[f]),a.children)r[f][l].ref&&r[f][l].contents||(this._data[n][f][l]=t.createInstance(r[f][l],a.children[l].children))}else this._data[n]=t.createInstance(r,a.children||{})}}}},{key:"_downloadFromStorage",value:(r=i()(a.a.mark(function t(){var e=this;return a.a.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return this._downloading||(this._downloading=i()(a.a.mark(function t(){var n,r;return a.a.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return n=e._getOffChainDataClient(),t.prev=1,t.next=4,n.download(e.ref);case 4:r=t.sent,e._initFromStorage(r?JSON.parse(r):{}),e._downloaded=!0,t.next=14;break;case 9:if(t.prev=9,t.t0=t.catch(1),!(t.t0 instanceof L)){t.next=13;break}throw t.t0;case 13:throw new L("Cannot download data: "+t.t0.message,t.t0);case 14:case"end":return t.stop()}},t,null,[[1,9]])}))()),t.abrupt("return",this._downloading);case 2:case"end":return t.stop()}},t,this)})),function(){return r.apply(this,arguments)})},{key:"downloadRaw",value:(n=i()(a.a.mark(function t(){var e,n;return a.a.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return e=this._getOffChainDataClient(),t.prev=1,t.next=4,e.download(this.ref);case 4:return n=t.sent,t.abrupt("return",n);case 8:if(t.prev=8,t.t0=t.catch(1),!(t.t0 instanceof L)){t.next=12;break}throw t.t0;case 12:throw new L("Cannot download data: "+t.t0.message,t.t0);case 13:case"end":return t.stop()}},t,this,[[1,8]])})),function(){return n.apply(this,arguments)})},{key:"toPlainObject",value:(e=i()(a.a.mark(function t(e){var n,r,s,i,o,c,u,h,f,l,p,d,w,g,y,v,b,k,m,x,_,C=arguments;return a.a.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return n=C.length>1&&void 0!==C[1]?C[1]:9999,t.next=3,this._downloadFromStorage();case 3:if(r={},s={},!e){t.next=25;break}for(i=!0,o=!1,c=void 0,t.prev=9,u=e[Symbol.iterator]();!(i=(h=u.next()).done);i=!0)f=h.value,l=void 0,p=void 0,-1===f.indexOf(".")?l=f:(l=f.substring(0,f.indexOf(".")),p=f.substring(f.indexOf(".")+1)),p?(s[l]||(s[l]=[]),s[l].push(p)):s[l]=void 0;t.next=17;break;case 13:t.prev=13,t.t0=t.catch(9),o=!0,c=t.t0;case 17:t.prev=17,t.prev=18,i||null==u.return||u.return();case 20:if(t.prev=20,!o){t.next=23;break}throw c;case 23:return t.finish(20);case 24:return t.finish(17);case 25:return t.next=27,this.contents;case 27:if(d=t.sent,!Array.isArray(d)){t.next=32;break}r=d,t.next=85;break;case 32:t.t1=a.a.keys(this._data);case 33:if((t.t2=t.t1()).done){t.next=85;break}if(w=t.t2.value,this._children&&this._children[w]){t.next=38;break}return this._data&&this._data.hasOwnProperty(w)&&(r[w]=d[w]),t.abrupt("continue",33);case 38:if(g=!e&&n>0||s.hasOwnProperty(w),!(this._children&&this._children[w].nested)){t.next=56;break}r[w]={},y=0,v=Object.keys(d[w]);case 42:if(!(y<v.length)){t.next=54;break}if(b=v[y],!(g&&n>1)){t.next=50;break}return t.next=47,d[w][b].toPlainObject(s[w],n-2);case 47:r[w][b]=t.sent,t.next=51;break;case 50:r[w][b]=d[w][b].ref;case 51:y++,t.next=42;break;case 54:t.next=83;break;case 56:if(!g){t.next=82;break}if(!Array.isArray(d[w])){t.next=77;break}r[w]=[],k=0;case 60:if(!(k<d[w].length)){t.next=75;break}r[w].push(d[w][k]),m=0,x=Object.keys(d[w][k]);case 63:if(!(m<x.length)){t.next=72;break}if(_=x[m],!(d[w][k][_].toPlainObject&&n>1)){t.next=69;break}return t.next=68,d[w][k][_].toPlainObject(s[w],n-2);case 68:r[w][k][_]=t.sent;case 69:m++,t.next=63;break;case 72:k++,t.next=60;break;case 75:t.next=80;break;case 77:return t.next=79,d[w].toPlainObject(s[w],n-1);case 79:r[w]=t.sent;case 80:t.next=83;break;case 82:r[w]=this._data[w].ref;case 83:t.next=33;break;case 85:return t.abrupt("return",{ref:this.ref,contents:r});case 86:case"end":return t.stop()}},t,this,[[9,13,17,25],[18,,20,24]])})),function(t){return e.apply(this,arguments)})},{key:"contents",get:function(){var t=this;return i()(a.a.mark(function e(){return a.a.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(t._downloaded){e.next=3;break}return e.next=3,t._downloadFromStorage();case 3:return e.abrupt("return",t._data);case 4:case"end":return e.stop()}},e)}))()}}]),t}(),it=function(){function t(e,n,r){c()(this,t),this.address=r,this.web3Utils=e,this.web3Contracts=n}var e,n,r,s,o;return h()(t,[{key:"initialize",value:function(){var t,e,n,r,s=this;this.onChainDataset=Q.createInstance(),this.onChainDataset.bindProperties({fields:{_orgJsonUri:{remoteGetter:(r=i()(a.a.mark(function t(){return a.a.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,s._getContractInstance();case 2:return t.abrupt("return",t.sent.methods.getOrgJsonUri().call());case 3:case"end":return t.stop()}},t)})),function(){return r.apply(this,arguments)})},_orgJsonHash:{remoteGetter:(n=i()(a.a.mark(function t(){return a.a.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,s._getContractInstance();case 2:return t.abrupt("return",t.sent.methods.getOrgJsonHash().call());case 3:case"end":return t.stop()}},t)})),function(){return n.apply(this,arguments)})},_owner:{remoteGetter:(e=i()(a.a.mark(function t(){return a.a.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,s._getContractInstance();case 2:return t.abrupt("return",t.sent.methods.owner().call());case 3:case"end":return t.stop()}},t)})),function(){return e.apply(this,arguments)})},_associatedKeys:{remoteGetter:(t=i()(a.a.mark(function t(){return a.a.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,s._getContractInstance();case 2:return t.abrupt("return",t.sent.methods.getAssociatedKeys().call());case 3:case"end":return t.stop()}},t)})),function(){return t.apply(this,arguments)})}}},this),this._initialized=!0,this.address&&this.onChainDataset.markDeployed()}},{key:"validateOrgJsonHash",value:(o=i()(a.a.mark(function t(){var e,n,r;return a.a.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.orgJson;case 2:return e=t.sent,t.next=5,e.downloadRaw();case 5:if(n=t.sent){t.next=8;break}return t.abrupt("return",!1);case 8:return r=this.web3Utils.getSoliditySha3Hash(n),t.t0=r,t.next=12,this.orgJsonHash;case 12:return t.t1=t.sent,t.abrupt("return",t.t0===t.t1);case 14:case"end":return t.stop()}},t,this)})),function(){return o.apply(this,arguments)})},{key:"toPlainObject",value:(s=i()(a.a.mark(function t(e,n){var r,s,i;return a.a.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.orgJson;case 2:return r=t.sent,s=r.toPlainObject(e,n),t.next=6,this.owner;case 6:return t.t0=t.sent,t.next=9,this.associatedKeys;case 9:return t.t1=t.sent,t.t2=this.address,t.next=13,s;case 13:return t.t3=t.sent,t.next=16,this.orgJsonHash;case 16:return t.t4=t.sent,i={owner:t.t0,associatedKeys:t.t1,address:t.t2,orgJsonUri:t.t3,orgJsonHash:t.t4},t.abrupt("return",i);case 19:case"end":return t.stop()}},t,this)})),function(t,e){return s.apply(this,arguments)})},{key:"getWindingTreeApi",value:(r=i()(a.a.mark(function t(){var e,n,r,s,i=this;return a.a.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:e={hotel:[],airline:[]},n=a.a.mark(function t(){var n,o;return a.a.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return n=s[r],t.next=3,i.toPlainObject(["orgJsonUri.".concat(n)]);case 3:t.t0=n,(o=t.sent.orgJsonUri.contents[t.t0])&&o.apis&&o.apis.filter(function(t){return"windingtree"===t.format}).map(function(t){"hotel"===n?e.hotel.push(st.createInstance(t.entrypoint,{descriptionUri:{required:!0},ratePlansUri:{required:!1},availabilityUri:{required:!1}})):"airline"===n&&e.airline.push(st.createInstance(t.entrypoint,{descriptionUri:{required:!0},flightsUri:{required:!1,children:{items:{children:{flightInstancesUri:{required:!1}}}}}}))});case 6:case"end":return t.stop()}},t)}),r=0,s=["hotel","airline"];case 3:if(!(r<s.length)){t.next=8;break}return t.delegateYield(n(),"t0",5);case 5:r++,t.next=3;break;case 8:return t.abrupt("return",e);case 9:case"end":return t.stop()}},t)})),function(){return r.apply(this,arguments)})},{key:"_getContractInstance",value:(n=i()(a.a.mark(function t(){return a.a.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(this.address){t.next=2;break}throw new F("Cannot get Organization instance without address");case 2:if(this.contractInstance){t.next=6;break}return t.next=5,this.web3Contracts.getOrganizationInstance(this.address);case 5:this.contractInstance=t.sent;case 6:return t.abrupt("return",this.contractInstance);case 7:case"end":return t.stop()}},t,this)})),function(){return n.apply(this,arguments)})},{key:"hasAssociatedKey",value:(e=i()(a.a.mark(function t(e){var n,r,s=arguments;return a.a.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return n=s.length>1&&void 0!==s[1]?s[1]:{},t.next=3,this._getContractInstance();case 3:return r=t.sent,t.abrupt("return",r.methods.hasAssociatedKey(e).call(n));case 5:case"end":return t.stop()}},t,this)})),function(t){return e.apply(this,arguments)})},{key:"orgJson",get:function(){var t=this;return i()(a.a.mark(function e(){return a.a.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(t._orgJson){e.next=7;break}return e.t0=st,e.next=4,t.orgJsonUri;case 4:e.t1=e.sent,e.t2={},t._orgJson=e.t0.createInstance.call(e.t0,e.t1,e.t2);case 7:return e.abrupt("return",t._orgJson);case 8:case"end":return e.stop()}},e)}))()}},{key:"orgJsonUri",get:function(){var t=this;if(this._initialized)return i()(a.a.mark(function e(){var n;return a.a.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,t._orgJsonUri;case 2:return n=e.sent,e.abrupt("return",n);case 4:case"end":return e.stop()}},e)}))()}},{key:"orgJsonHash",get:function(){var t=this;if(this._initialized)return i()(a.a.mark(function e(){var n;return a.a.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,t._orgJsonHash;case 2:return n=e.sent,e.abrupt("return",n);case 4:case"end":return e.stop()}},e)}))()}},{key:"owner",get:function(){var t=this;if(this._initialized)return i()(a.a.mark(function e(){var n;return a.a.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,t._owner;case 2:return n=e.sent,e.abrupt("return",n);case 4:case"end":return e.stop()}},e)}))()}},{key:"associatedKeys",get:function(){var t=this;if(this._initialized)return i()(a.a.mark(function e(){var n;return a.a.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,t._associatedKeys;case 2:return n=e.sent,e.abrupt("return",n);case 4:case"end":return e.stop()}},e)}))()}}],[{key:"createInstance",value:function(e,n,r){var a=new t(e,n,r);return a.initialize(),a}}]),t}(),ot=function(){function t(e,n,r){c()(this,t),this.address=e,this.web3Utils=n,this.web3Contracts=r}var e,n,r,s,o,u,f,l,p;return h()(t,null,[{key:"createInstance",value:function(e,n,r){return new t(e,n,r)}}]),h()(t,[{key:"_getDeployedDirectory",value:(p=i()(a.a.mark(function t(){return a.a.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(this.deployedDirectory){t.next=4;break}return t.next=3,this.web3Contracts.getSegmentDirectoryInstance(this.address);case 3:this.deployedDirectory=t.sent;case 4:return t.abrupt("return",this.deployedDirectory);case 5:case"end":return t.stop()}},t,this)})),function(){return p.apply(this,arguments)})},{key:"add",value:(l=i()(a.a.mark(function t(e){var n,r,s,i,o;return a.a.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(e.address){t.next=2;break}throw new N("Cannot add Organization without address.");case 2:return t.next=4,e.owner;case 4:if(n=t.sent){t.next=7;break}throw new N("Cannot add Organization without owner.");case 7:return t.prev=7,t.next=10,this._getDeployedDirectory();case 10:return r=t.sent,s=r.methods.add(e.address).encodeABI(),i=r.methods.add(e.address).estimateGas({from:n}),t.next=15,this.web3Utils.determineCurrentAddressNonce(n);case 15:return t.t0=t.sent,t.t1=s,t.t2=n,t.t3=this.address,t.t4=this.web3Utils,t.next=22,i;case 22:return t.t5=t.sent,t.t6=t.t4.applyGasModifier.call(t.t4,t.t5),o={nonce:t.t0,data:t.t1,from:t.t2,to:t.t3,gas:t.t6},t.abrupt("return",{transactionData:o,eventCallbacks:{onReceipt:function(){}}});case 28:throw t.prev=28,t.t7=t.catch(7),new M("Cannot add Organization: ".concat(t.t7.message),t.t7);case 31:case"end":return t.stop()}},t,this,[[7,28]])})),function(t){return l.apply(this,arguments)})},{key:"remove",value:(f=i()(a.a.mark(function t(e){var n,r,s,i,o;return a.a.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(e.address){t.next=2;break}throw new N("Cannot remove Organization without address.");case 2:return t.next=4,e.owner;case 4:if(n=t.sent){t.next=7;break}throw new N("Cannot remove Organization without owner.");case 7:return t.prev=7,t.next=10,this._getDeployedDirectory();case 10:return r=t.sent,s=r.methods.remove(e.address).encodeABI(),i=r.methods.remove(e.address).estimateGas({from:n}),t.next=15,this.web3Utils.determineCurrentAddressNonce(n);case 15:return t.t0=t.sent,t.t1=s,t.t2=n,t.t3=this.address,t.t4=this.web3Utils,t.next=22,i;case 22:return t.t5=t.sent,t.t6=t.t4.applyGasModifier.call(t.t4,t.t5),o={nonce:t.t0,data:t.t1,from:t.t2,to:t.t3,gas:t.t6},t.abrupt("return",{transactionData:o,eventCallbacks:{onReceipt:function(){}}});case 28:throw t.prev=28,t.t7=t.catch(7),new M("Cannot remove Organization: ".concat(t.t7.message),t.t7);case 31:case"end":return t.stop()}},t,this,[[7,28]])})),function(t){return f.apply(this,arguments)})},{key:"getOrganization",value:(u=i()(a.a.mark(function t(e){var n;return a.a.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.prev=0,t.next=3,this.getOrganizationIndex(e);case 3:n=t.sent,t.next=9;break;case 6:throw t.prev=6,t.t0=t.catch(0),new M("Cannot find Organization at ".concat(e,": ").concat(t.t0.message),t.t0);case 9:if(n){t.next=13;break}throw new W("Cannot find Organization at ".concat(e,": Not found in Organization list"));case 13:return t.prev=13,t.abrupt("return",it.createInstance(this.web3Utils,this.web3Contracts,e));case 17:throw t.prev=17,t.t1=t.catch(13),new B("Cannot instantiate Organization at ".concat(e,": ").concat(t.t1.message),t.t1);case 20:case"end":return t.stop()}},t,this,[[0,6],[13,17]])})),function(t){return u.apply(this,arguments)})},{key:"getOrganizationIndex",value:(o=i()(a.a.mark(function t(e){var n;return a.a.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this._getDeployedDirectory();case 2:return n=t.sent,t.t0=parseInt,t.next=6,n.methods.organizationsIndex(e).call();case 6:return t.t1=t.sent,t.abrupt("return",(0,t.t0)(t.t1,10));case 8:case"end":return t.stop()}},t,this)})),function(t){return o.apply(this,arguments)})},{key:"getOrganizationByIndex",value:(s=i()(a.a.mark(function t(e){var n,r;return a.a.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this._getDeployedDirectory();case 2:return n=t.sent,t.next=5,n.methods.organizations(e).call();case 5:return r=t.sent,t.abrupt("return",this.getOrganization(r));case 7:case"end":return t.stop()}},t,this)})),function(t){return s.apply(this,arguments)})},{key:"getOrganizations",value:(r=i()(a.a.mark(function t(){var e,n,r,s,i=this;return a.a.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this._getDeployedDirectory();case 2:return e=t.sent,t.next=5,e.methods.getOrganizations().call();case 5:return n=t.sent,r=n.filter(function(t){return!i.web3Utils.isZeroAddress(t)}).map(function(t){return i.getOrganization(t).catch(function(t){return null})}),t.next=9,Promise.all(r);case 9:return s=t.sent,t.abrupt("return",s.filter(function(t){return null!=t}));case 11:case"end":return t.stop()}},t,this)})),function(){return r.apply(this,arguments)})},{key:"getLifTokenAddress",value:(n=i()(a.a.mark(function t(){var e;return a.a.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this._getDeployedDirectory();case 2:return e=t.sent,t.abrupt("return",e.methods.getLifToken().call());case 4:case"end":return t.stop()}},t,this)})),function(){return n.apply(this,arguments)})},{key:"getSegment",value:(e=i()(a.a.mark(function t(){var e,n,r=arguments;return a.a.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return e=r.length>0&&void 0!==r[0]?r[0]:{},t.next=3,this._getDeployedDirectory();case 3:return n=t.sent,t.abrupt("return",n.methods.getSegment().call(e));case 5:case"end":return t.stop()}},t,this)})),function(){return e.apply(this,arguments)})}]),t}(),ct=function(t){function e(){return c()(this,e),S()(this,U()(e).apply(this,arguments))}var n,r,s,o;return j()(e,t),h()(e,[{key:"initialize",value:function(){var t,e,n,r,s=this;this.onChainDataset=Q.createInstance(),this.onChainDataset.bindProperties({fields:{_orgJsonUri:{remoteGetter:(r=i()(a.a.mark(function t(){return a.a.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,s._getContractInstance();case 2:return t.abrupt("return",t.sent.methods.getOrgJsonUri().call());case 3:case"end":return t.stop()}},t)})),function(){return r.apply(this,arguments)}),remoteSetter:this._editOrgJsonDataOnChain("orgJsonUri","changeOrgJsonUri").bind(this)},_orgJsonHash:{remoteGetter:(n=i()(a.a.mark(function t(){return a.a.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,s._getContractInstance();case 2:return t.abrupt("return",t.sent.methods.getOrgJsonHash().call());case 3:case"end":return t.stop()}},t)})),function(){return n.apply(this,arguments)}),remoteSetter:this._editOrgJsonDataOnChain("orgJsonHash","changeOrgJsonHash").bind(this)},_owner:{remoteGetter:(e=i()(a.a.mark(function t(){return a.a.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,s._getContractInstance();case 2:return t.abrupt("return",t.sent.methods.owner().call());case 3:case"end":return t.stop()}},t)})),function(){return e.apply(this,arguments)})},_associatedKeys:{remoteGetter:(t=i()(a.a.mark(function t(){return a.a.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,s._getContractInstance();case 2:return t.abrupt("return",t.sent.methods.getAssociatedKeys().call());case 3:case"end":return t.stop()}},t)})),function(){return t.apply(this,arguments)})}}},this),this._initialized=!0,this.address&&this.onChainDataset.markDeployed()}},{key:"_getContractInstance",value:(o=i()(a.a.mark(function t(){return a.a.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(this.address){t.next=2;break}throw new F("Cannot get Organization instance without address");case 2:if(this.contractInstance){t.next=6;break}return t.next=5,this.web3Contracts.getUpdateableOrganizationInstance(this.address);case 5:this.contractInstance=t.sent;case 6:return t.abrupt("return",this.contractInstance);case 7:case"end":return t.stop()}},t,this)})),function(){return o.apply(this,arguments)})},{key:"setLocalData",value:(s=i()(a.a.mark(function t(e){var n,r;return a.a.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,e.orgJsonUri;case 2:return(n=t.sent)&&(this.orgJsonUri=n),t.next=6,e.orgJsonHash;case 6:(r=t.sent)&&(this.orgJsonHash=r);case 8:case"end":return t.stop()}},t,this)})),function(t){return s.apply(this,arguments)})},{key:"_editOrgJsonDataOnChain",value:function(t,e){var n=this,r=function(){var t=i()(a.a.mark(function t(e,r,s){return a.a.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if("dirty"!==n.onChainDataset.getFieldState("_orgJsonUri")||"dirty"!==n.onChainDataset.getFieldState("_orgJsonHash")){t.next=9;break}return t.t0=e.methods,t.next=4,n.orgJsonUri;case 4:return t.t1=t.sent,t.next=7,n.orgJsonHash;case 7:return t.t2=t.sent,t.abrupt("return",t.t0.changeOrgJsonUriAndHash.call(t.t0,t.t1,t.t2));case 9:return t.t3=e.methods,t.t4=s,t.next=13,n[r];case 13:return t.t5=t.sent,t.abrupt("return",t.t3[t.t4].call(t.t3,t.t5));case 15:case"end":return t.stop()}},t)}));return function(e,n,r){return t.apply(this,arguments)}}();return function(){var n=i()(a.a.mark(function n(s){var i,o,c,u,h;return a.a.wrap(function(n){for(;;)switch(n.prev=n.next){case 0:return n.next=2,this._getContractInstance();case 2:return i=n.sent,n.next=5,r(i,t,e);case 5:return o=n.sent,c=o.estimateGas({from:s.from}),u=o.encodeABI({from:s.from}),n.next=10,this.web3Utils.determineCurrentAddressNonce(s.from);case 10:return n.t0=n.sent,n.t1=u,n.t2=s.from,n.t3=this.address,n.t4=this.web3Utils,n.next=17,c;case 17:return n.t5=n.sent,n.t6=n.t4.applyGasModifier.call(n.t4,n.t5),h={nonce:n.t0,data:n.t1,from:n.t2,to:n.t3,gas:n.t6},n.abrupt("return",{organization:this,transactionData:h});case 21:case"end":return n.stop()}},n,this)}));return function(t){return n.apply(this,arguments)}}()}},{key:"updateOnChainData",value:(r=i()(a.a.mark(function t(e){return a.a.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this._getContractInstance();case 2:return t.abrupt("return",this.onChainDataset.updateRemoteData(Object.assign({},e)));case 3:case"end":return t.stop()}},t,this)})),function(t){return r.apply(this,arguments)})},{key:"transferOnChainOwnership",value:(n=i()(a.a.mark(function t(e,n){var r,s,i,o,c,u=this;return a.a.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(this.onChainDataset.isDeployed()){t.next=2;break}throw new F("Cannot transfer Organization: not deployed");case 2:return t.next=4,this._getContractInstance();case 4:return r=t.sent,s=r.methods.transferOwnership(e).estimateGas(),i=r.methods.transferOwnership(e).encodeABI(),t.next=9,this.web3Utils.determineCurrentAddressNonce(n.from);case 9:return t.t0=t.sent,t.t1=i,t.t2=n.from,t.t3=this.address,t.t4=this.web3Utils,t.next=16,s;case 16:return t.t5=t.sent,t.t6=t.t4.applyGasModifier.call(t.t4,t.t5),o={nonce:t.t0,data:t.t1,from:t.t2,to:t.t3,gas:t.t6},c={onReceipt:function(t){u._owner=e}},t.abrupt("return",{organization:this,transactionData:o,eventCallbacks:c});case 21:case"end":return t.stop()}},t,this)})),function(t,e){return n.apply(this,arguments)})},{key:"orgJson",get:function(){var t=this;return i()(a.a.mark(function e(){return a.a.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(t._orgJson){e.next=7;break}return e.t0=st,e.next=4,t.orgJsonUri;case 4:e.t1=e.sent,e.t2={},t._orgJson=e.t0.createInstance.call(e.t0,e.t1,e.t2);case 7:return e.abrupt("return",t._orgJson);case 8:case"end":return e.stop()}},e)}))()}},{key:"orgJsonUri",get:function(){var t=this;if(this._initialized)return i()(a.a.mark(function e(){var n;return a.a.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,t._orgJsonUri;case 2:return n=e.sent,e.abrupt("return",n);case 4:case"end":return e.stop()}},e)}))()},set:function(t){if(!t)throw new N("Cannot update Organization: Cannot set orgJsonUri when it is not provided");if("string"==typeof t&&!t.match(/([a-z-]+):\/\//))throw new N("Cannot update Organization: Cannot set orgJsonUri with invalid format");t!==this._orgJsonUri&&(this._orgJson=null),this._orgJsonUri=t}},{key:"orgJsonHash",get:function(){var t=this;if(this._initialized)return i()(a.a.mark(function e(){var n;return a.a.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,t._orgJsonHash;case 2:return n=e.sent,e.abrupt("return",n);case 4:case"end":return e.stop()}},e)}))()},set:function(t){if(!t)throw new N("Cannot update Organization: Cannot set orgJsonHash when it is not provided");if("string"==typeof t&&!t.match(/^0x/))throw new N("Cannot update Organization: Cannot set orgJsonHash with invalid format");this._orgJsonHash=t}},{key:"owner",get:function(){var t=this;if(this._initialized)return i()(a.a.mark(function e(){var n;return a.a.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,t._owner;case 2:return n=e.sent,e.abrupt("return",n);case 4:case"end":return e.stop()}},e)}))()}},{key:"associatedKeys",get:function(){var t=this;if(this._initialized)return i()(a.a.mark(function e(){var n;return a.a.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,t._associatedKeys;case 2:return n=e.sent,e.abrupt("return",n);case 4:case"end":return e.stop()}},e)}))()}}],[{key:"createInstance",value:function(t,n,r){var a=new e(t,n,r);return a.initialize(),a}}]),e}(it),ut=function(){function t(e,n,r){c()(this,t),this.address=e,this.web3Utils=n,this.web3Contracts=r}var e,n,r,s;return h()(t,null,[{key:"createInstance",value:function(e,n,r){return new t(e,n,r)}}]),h()(t,[{key:"_getDeployedFactory",value:(s=i()(a.a.mark(function t(){return a.a.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(this.deployedFactory){t.next=4;break}return t.next=3,this.web3Contracts.getOrganizationFactoryInstance(this.address);case 3:this.deployedFactory=t.sent;case 4:return t.abrupt("return",this.deployedFactory);case 5:case"end":return t.stop()}},t,this)})),function(){return s.apply(this,arguments)})},{key:"createAndAddOrganization",value:(r=i()(a.a.mark(function t(e,n){var r,s,i,o,c;return a.a.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,e.orgJsonUri;case 2:if(r=t.sent){t.next=5;break}throw new N("Cannot create and add Organization: Missing orgJsonUri");case 5:return t.next=7,e.orgJsonHash;case 7:if(s=t.sent){t.next=10;break}throw new N("Cannot create and add Organization: Missing orgJsonHash");case 10:return t.next=12,e.owner;case 12:if(i=t.sent){t.next=15;break}throw new N("Cannot create and add Organization: Missing owner");case 15:if(n){t.next=17;break}throw new N("Cannot create and add Organization: Missing directory address");case 17:return t.prev=17,t.next=20,this._getDeployedFactory();case 20:return o=t.sent,c=o.methods.createAndAddToDirectory(r,s,n),t.abrupt("return",this._callContract(c,i));case 25:throw t.prev=25,t.t0=t.catch(17),new M("Cannot create and add Organization: ".concat(t.t0.message),t.t0);case 28:case"end":return t.stop()}},t,this,[[17,25]])})),function(t,e){return r.apply(this,arguments)})},{key:"createOrganization",value:(n=i()(a.a.mark(function t(e){var n,r,s,i,o;return a.a.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,e.orgJsonUri;case 2:if(n=t.sent){t.next=5;break}throw new N("Cannot create Organization: Missing orgJsonUri");case 5:return t.next=7,e.orgJsonHash;case 7:if(r=t.sent){t.next=10;break}throw new N("Cannot create Organization: Missing orgJsonHash");case 10:return t.next=12,e.owner;case 12:if(s=t.sent){t.next=15;break}throw new N("Cannot create Organization: Missing owner");case 15:return t.prev=15,t.next=18,this._getDeployedFactory();case 18:return i=t.sent,o=i.methods.create(n,r),t.abrupt("return",this._callContract(o,s));case 23:throw t.prev=23,t.t0=t.catch(15),new M("Cannot create Organization: ".concat(t.t0.message),t.t0);case 26:case"end":return t.stop()}},t,this,[[15,23]])})),function(t){return n.apply(this,arguments)})},{key:"_callContract",value:(e=i()(a.a.mark(function t(e,n){var r,s,i,o,c,u,h=this;return a.a.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return r=e.encodeABI(),s=e.estimateGas({from:n}),t.next=4,this.web3Utils.determineCurrentAddressNonce(n);case 4:return t.t0=t.sent,t.t1=r,t.t2=n,t.t3=this.address,t.t4=this.web3Utils,t.next=11,s;case 11:return t.t5=t.sent,t.t6=t.t4.applyGasModifier.call(t.t4,t.t5),i={nonce:t.t0,data:t.t1,from:t.t2,to:t.t3,gas:t.t6},u=new Promise(function(t,e){o=t,c=e}),t.abrupt("return",{transactionData:i,organization:u,eventCallbacks:{onReceipt:function(t){try{var e=lt.web3Contracts.decodeLogs(t.logs)[1].attributes[0].value,n=ct.createInstance(h.web3Utils,h.web3Contracts,e);o(n)}catch(t){c(t)}}}});case 16:case"end":return t.stop()}},t,this)})),function(t,n){return e.apply(this,arguments)})}]),t}(),ht=function(){function t(e,n,r){c()(this,t),this.address=e,this.web3Utils=n,this.web3Contracts=r,this._segmentAddresses={},this._cache={},this._factoryAddress=void 0,this._deployedEntrypoint=void 0}var e,n,r,s,o,u,f;return h()(t,null,[{key:"createInstance",value:function(e,n,r){return new t(e,n,r)}}]),h()(t,[{key:"_getDeployedEntrypoint",value:(f=i()(a.a.mark(function t(){return a.a.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(this._deployedEntrypoint){t.next=4;break}return t.next=3,this.web3Contracts.getEntrypointInstance(this.address);case 3:this._deployedEntrypoint=t.sent;case 4:return t.abrupt("return",this._deployedEntrypoint);case 5:case"end":return t.stop()}},t,this)})),function(){return f.apply(this,arguments)})},{key:"_getCachedInstance",value:function(t,e){return this._cache[t]||(this._cache[t]=e.createInstance(t,this.web3Utils,this.web3Contracts)),this._cache[t]}},{key:"getSegments",value:(u=i()(a.a.mark(function t(){var e,n,r,s;return a.a.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this._getDeployedEntrypoint();case 2:return e=t.sent,t.next=5,e.methods.getSegmentsLength().call();case 5:for(n=t.sent,r=[],s=1;s<n;s++)r.push(e.methods.getSegmentName(s).call());return t.abrupt("return",Promise.all(r).then(function(t){return t.filter(function(t){return!!t})}));case 9:case"end":return t.stop()}},t,this)})),function(){return u.apply(this,arguments)})},{key:"getOwner",value:(o=i()(a.a.mark(function t(){var e;return a.a.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this._getDeployedEntrypoint();case 2:return e=t.sent,t.abrupt("return",e.methods.owner().call());case 4:case"end":return t.stop()}},t,this)})),function(){return o.apply(this,arguments)})},{key:"getLifTokenAddress",value:(s=i()(a.a.mark(function t(){var e;return a.a.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this._getDeployedEntrypoint();case 2:return e=t.sent,t.abrupt("return",e.methods.LifToken().call());case 4:case"end":return t.stop()}},t,this)})),function(){return s.apply(this,arguments)})},{key:"getSegmentAddress",value:(r=i()(a.a.mark(function t(e){var n;return a.a.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this._getDeployedEntrypoint();case 2:return n=t.sent,t.abrupt("return",n.methods.getSegment(e).call());case 4:case"end":return t.stop()}},t,this)})),function(t){return r.apply(this,arguments)})},{key:"getSegmentDirectory",value:(n=i()(a.a.mark(function t(e){var n;return a.a.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(this._segmentAddresses[e]){t.next=7;break}return t.next=3,this.getSegmentAddress(e);case 3:if(n=t.sent,!this.web3Utils.isZeroAddress(n)){t.next=6;break}throw new R("Cannot find segment ".concat(e," in entrypoint at ").concat(this.address));case 6:this._segmentAddresses[e]=n;case 7:return t.abrupt("return",this._getCachedInstance(this._segmentAddresses[e],ot));case 8:case"end":return t.stop()}},t,this)})),function(t){return n.apply(this,arguments)})},{key:"getOrganizationFactory",value:(e=i()(a.a.mark(function t(e){var n,r;return a.a.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(this._factoryAddress){t.next=10;break}return t.next=3,this._getDeployedEntrypoint();case 3:return n=t.sent,t.next=6,n.methods.getOrganizationFactory().call();case 6:if(r=t.sent,!this.web3Utils.isZeroAddress(r)){t.next=9;break}throw new R("Cannot find organization factory in entrypoint at ".concat(this.address));case 9:this._factoryAddress=r;case 10:return t.abrupt("return",this._getCachedInstance(this._factoryAddress,ut));case 11:case"end":return t.stop()}},t,this)})),function(t){return e.apply(this,arguments)})}]),t}(),ft=function(){function t(){c()(this,t)}var e;return h()(t,null,[{key:"setup",value:function(e){(e=e||{}).gasMargin||e.gasCoefficient||(e.gasCoefficient=2),t.entrypoints={},t.options=e,t.web3Utils=b.createInstance({gasCoefficient:t.options.gasCoefficient,gasMargin:t.options.gasMargin},t.options.provider),t.web3Contracts=V.createInstance(t.options.provider)}},{key:"_reset",value:function(){t.options={},t.entrypoints={}}},{key:"getEntrypoint",value:function(e){return t.entrypoints[e]||(t.entrypoints[e]=ht.createInstance(e,t.web3Utils,t.web3Contracts)),t.entrypoints[e]}},{key:"getUpdateableOrganization",value:function(e){return ct.createInstance(t.web3Utils,t.web3Contracts,e)}},{key:"getOrganization",value:function(e){return it.createInstance(t.web3Utils,t.web3Contracts,e)}},{key:"getTransactionsStatus",value:(e=i()(a.a.mark(function e(n){var r,s,i,o,c,u,h,f,p,d,w,g,y,v,b,k,m,x,_;return a.a.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:for(r=[],s=[],i=!0,o=!1,c=void 0,e.prev=5,u=n[Symbol.iterator]();!(i=(h=u.next()).done);i=!0)f=h.value,r.push(t.web3Utils.getTransactionReceipt(f)),s.push(t.web3Utils.getTransaction(f));e.next=13;break;case 9:e.prev=9,e.t0=e.catch(5),o=!0,c=e.t0;case 13:e.prev=13,e.prev=14,i||null==u.return||u.return();case 16:if(e.prev=16,!o){e.next=19;break}throw c;case 19:return e.finish(16);case 20:return e.finish(13);case 21:return p=t.web3Utils.getCurrentBlockNumber(),e.next=24,Promise.all(r);case 24:return d=e.sent,e.next=27,Promise.all(s);case 27:w=e.sent,g={},y=!0,v=!1,b=void 0,e.prev=32,k=a.a.mark(function e(){var n,r,s;return a.a.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(n=x.value){e.next=3;break}return e.abrupt("return","continue");case 3:return r=t.web3Contracts.decodeLogs(n.logs),s=w.find(function(t){return t.hash===n.transactionHash}),e.t0=n.transactionHash,e.next=8,p;case 8:e.t1=e.sent,e.t2=n.blockNumber,e.t3=e.t1-e.t2,e.t4=r,e.t5=s&&s.from,e.t6=s&&s.to,e.t7=n,g[n.transactionHash]={transactionHash:e.t0,blockAge:e.t3,decodedLogs:e.t4,from:e.t5,to:e.t6,raw:e.t7};case 16:case"end":return e.stop()}},e)}),m=d[Symbol.iterator]();case 35:if(y=(x=m.next()).done){e.next=43;break}return e.delegateYield(k(),"t1",37);case 37:if("continue"!==e.t1){e.next=40;break}return e.abrupt("continue"