UNPKG

debitisimpedit

Version:

adapte eos and eth, and adapte pluin - MateMask and Scatter

1 lines 23 kB
"use strict";var base;(function(t){t.SymbolType={eth:"eth",eos:"eos"};t.BaseEvent={EVENT_CBK:"event callback",ERROR_CBK:"error callback",ACCOUNT_CHANGED:"account changed",CONTRACT_CBK:"contract callbact",IDENTITY_CBK:"identity callback"};t.ErrorCode={PluginNotInit:1e3,AccountNotFound:1001,MissIdentity:1002,TranSactionError:1003,NetError:1004,AccountError:1005,NetNotReady:1006,UnknowError:-1};var e=function(){function t(t){this._url=t}Object.defineProperty(t.prototype,"url",{get:function(){return this._url},enumerable:true,configurable:true});Object.defineProperty(t.prototype,"host",{get:function(){return this._url.split(":")[1].replace(/\/\//g,"")},enumerable:true,configurable:true});Object.defineProperty(t.prototype,"port",{get:function(){return parseInt(this._url.split(":")[2]||"443",10)},enumerable:true,configurable:true});Object.defineProperty(t.prototype,"protocal",{get:function(){return this._url.split(":")[0]},enumerable:true,configurable:true});return t}();t.Net=e;var r=function(){function t(){this._createMap={};this._apiMap={}}t.prototype.generateKey=function(t,e){return t+"_"+e};t.prototype.initSdk=function(t,e,r,n){if(n===void 0){n=""}var o=this.generateKey(t,n);return this._API=this._apiMap[o]=this._createMap[t].generateAPI(e,r,n)};t.prototype.register=function(t,e){this._createMap[t]=e};Object.defineProperty(t.prototype,"API",{get:function(){return this._API},enumerable:true,configurable:true});Object.defineProperty(t.prototype,"symbolName",{get:function(){return this._API===undefined?"":this._API.getSymbol()},enumerable:true,configurable:true});Object.defineProperty(t.prototype,"plugin",{get:function(){return this._API===undefined?"":this._API.plugin()},enumerable:true,configurable:true});t.prototype.canUse=function(t,e){if(e===void 0){e=""}var r=this.generateKey(t,e);return this._apiMap[r]!==undefined};t.prototype.use=function(t,e){if(e===void 0){e=""}var r=this.generateKey(t,e);return this.canUse(t,e)?this._API=this._apiMap[r]:undefined};return t}();t.Base=r})(base||(base={}));"use strict";var base;(function(r){var t=function(){function t(t,e){this._mode=e;this._isRunning=false;this._tIndex=0;this.event_Map={};this.start()}Object.defineProperty(t.prototype,"core",{get:function(){return this._core},enumerable:true,configurable:true});Object.defineProperty(t.prototype,"mode",{get:function(){return this._mode},enumerable:true,configurable:true});Object.defineProperty(t.prototype,"isRunning",{get:function(){return this._isRunning},enumerable:true,configurable:true});t.prototype.addEventListener=function(t,e,r){if(this.event_Map[t]){var n=this.event_Map[t].find(function(t){return t.event_cbk===e&&(t.thisObj&&t.thisObj===r||!t.thisObj&&!r)});if(n)return this}else{this.event_Map[t]=[]}this.event_Map[t].push({event_cbk:e,thisObj:r});return this};t.prototype.onError=function(t,e){this.invorkEvent(r.BaseEvent.ERROR_CBK,{errorCode:t,detail:e});return this};t.prototype.onContract=function(t,e){this.invorkEvent(r.BaseEvent.CONTRACT_CBK,{errorCode:t,detail:e});return this};t.prototype.invorkEvent=function(t,e){var r=this.event_Map[t];if(r){for(var n=0;n<r.length;n++){var o=r[n];o.event_cbk.apply(o.thisObj||window,[{target:o.thisObj,data:e}])}}};t.prototype.removeEventListener=function(t,e,r){if(this.event_Map[t]){var n=this.event_Map[t].find(function(t){return t.event_cbk===e&&(t.thisObj&&t.thisObj===r||!t.thisObj&&!r)});var o=n?this.event_Map[t].indexOf(n):-1;if(o>-1){this.event_Map[t].splice(o,1)}}return this};t.prototype.getMode=function(){return this._mode};t.prototype.sleep=function(e){return new Promise(function(t){setTimeout(function(){t()},e)})};t.prototype.start=function(){this.updateStatus();if(!this.usePlugin()||this._isRunning)return;this._isRunning=true;var t=this;this._tIndex=window.setInterval(function(){if(!t._isRunning){clearInterval(t._tIndex)}t.updateStatus()},1e4)};t.prototype.stop=function(){this._isRunning=false};t.prototype.updateStatus=function(){};return t}();r.CustomApi=t})(base||(base={}));"use strict";"use strict";var eth;(function(t){t.EthEvent={NET_CHANGED:"net changed callback"}})(eth||(eth={}));"use strict";var __extends=this&&this.__extends||function(){var n=function(t,e){n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)if(e.hasOwnProperty(r))t[r]=e[r]};return n(t,e)};return function(t,e){n(t,e);function r(){this.constructor=t}t.prototype=e===null?Object.create(e):(r.prototype=e.prototype,new r)}}();var __awaiter=this&&this.__awaiter||function(i,s,u,a){return new(u||(u=Promise))(function(t,e){function r(t){try{o(a.next(t))}catch(t){e(t)}}function n(t){try{o(a["throw"](t))}catch(t){e(t)}}function o(e){e.done?t(e.value):new u(function(t){t(e.value)}).then(r,n)}o((a=a.apply(i,s||[])).next())})};var __generator=this&&this.__generator||function(t,r){var n={label:0,sent:function(){if(s[0]&1)throw s[1];return s[1]},trys:[],ops:[]},o,i,s,e;return e={next:u(0),throw:u(1),return:u(2)},typeof Symbol==="function"&&(e[Symbol.iterator]=function(){return this}),e;function u(e){return function(t){return a([e,t])}}function a(e){if(o)throw new TypeError("Generator is already executing.");while(n)try{if(o=1,i&&(s=e[0]&2?i["return"]:e[0]?i["throw"]||((s=i["return"])&&s.call(i),0):i.next)&&!(s=s.call(i,e[1])).done)return s;if(i=0,s)e=[e[0]&2,s.value];switch(e[0]){case 0:case 1:s=e;break;case 4:n.label++;return{value:e[1],done:false};case 5:n.label++;i=e[1];e=[0];continue;case 7:e=n.ops.pop();n.trys.pop();continue;default:if(!(s=n.trys,s=s.length>0&&s[s.length-1])&&(e[0]===6||e[0]===2)){n=0;continue}if(e[0]===3&&(!s||e[1]>s[0]&&e[1]<s[3])){n.label=e[1];break}if(e[0]===6&&n.label<s[1]){n.label=s[1];s=e;break}if(s&&n.label<s[2]){n.label=s[2];n.ops.push(e);break}if(s[2])n.ops.pop();n.trys.pop();continue}e=r.call(t,n)}catch(t){e=[6,t];i=0}finally{o=s=0}if(e[0]&5)throw e[1];return{value:e[0]?e[1]:void 0,done:true}}};var eth;(function(i){var t=function(h){__extends(t,h);function t(t,e,r){var n=h.call(this,t,r)||this;n._config=e;n._netId="";n._contractMap={};n._contractBMap={};var o=window;var i=o["ethereum"];var s=t;if(i){n._web3=new s(i);n.requireIdentity()}n._web3_browser=new s(new s.providers.HttpProvider(n._config.contractURL));var u=n._config.contracts instanceof Array?n._config.contracts:[n._config.contracts];for(var a=0,c=u;a<c.length;a++){var f=c[a];n._web3&&(n._contractMap[f.name]=n._web3.eth.contract(f.data).at(f.address));n._web3_browser&&(n._contractMap[f.name]=n._web3_browser.eth.contract(f.data).at(f.address))}return n}t.prototype.requireIdentity=function(){return __awaiter(this,void 0,void 0,function(){var e,r,n;return __generator(this,function(t){switch(t.label){case 0:e=window;r=e["ethereum"];if(!r)return[2];t.label=1;case 1:t.trys.push([1,3,,4]);return[4,r.enable()];case 2:t.sent();return[3,4];case 3:n=t.sent();this.onError(base.ErrorCode.MissIdentity,n);return[3,4];case 4:return[2]}})})};t.prototype.updateStatus=function(){var n=this;h.prototype.updateStatus.call(this);if(!this.isInitPlugin()){var t=window;var e=t["ethereum"];var r=this.core;if(e){this._web3=new r(e);this._web3_browser=new r(new r.providers.HttpProvider(this._config.contractURL));this.requireIdentity()}}var o=this._web3;if(!o)return;o.version.getNetwork(function(t,e){if(e!==n._netId){n.invorkEvent(i.EthEvent.NET_CHANGED,{netId:e,oldNetId:n._netId});n._netId=e}t&&n.onError(base.ErrorCode.NetError,t)});o.eth.getAccounts(function(t,e){if(e.length===0){return}var r=e[0];if(r!==n._account){n.invorkEvent(base.BaseEvent.ACCOUNT_CHANGED,{account:r,oldAccount:n._account});n._account=r}t&&n.onError(base.ErrorCode.AccountError,t)})};t.prototype.getSymbol=function(){return base.SymbolType.eth};t.prototype.plugin=function(){return"MateMask"};t.prototype.usePlugin=function(){return true};t.prototype.isInitPlugin=function(){return this._web3!==undefined};t.prototype.hasAccount=function(){return this._account!==undefined};t.prototype.defaultAccount=function(){return this._web3?this._web3.eth.defaultAccount:""};t.prototype.check=function(){if(this.isInitPlugin()){this.onError(base.ErrorCode.PluginNotInit);return false}else if(this.hasAccount()){this.onError(base.ErrorCode.AccountNotFound);return false}else if(!this._netId){this.onError(base.ErrorCode.NetNotReady);return false}return true};t.prototype.getBalance=function(){var e=this;var n=this;return new Promise(function(r,t){if(!n._web3){r(0);return}n._web3.eth.getBalance(e.defaultAccount(),function(t,e){r(t?0:e.toNumber())})})};t.prototype.getGasPrice=function(){var e=this;return new Promise(function(r,t){if(!e._web3){r(1);return}e._web3.eth.getGasPrice(function(t,e){r(t?1:e.toNumber())})})};t.prototype.hexCharCodeToStr=function(t){if(!t)return"";var e=t.trim();var r=e.substr(0,2).toLowerCase()==="0x"?e.substr(2):e;var n=r.length;if(n%2!==0){console.warn("Illegal Format ASCII Code!");return""}var o;var i=new Array;for(var s=0;s<n;s=s+2){o=parseInt(r.substr(s,2),16);var u=String.fromCharCode(o);if(u!=="\0")i.push(u)}return i.join("")};t.prototype.format2Eth=function(t){var e=t?t.toNumber():0;return e/Math.pow(10,18)};t.prototype.getTransactionReceiptByHash=function(t){var e=this;return new Promise(function(r,n){if(!t){n();return}if(!e._web3){n();return}e._web3.eth.getTransactionReceipt(t,function(t,e){if(t){n(t)}else{r(e)}})})};t.prototype.addEvent=function(t,e){};return t}(base.CustomApi);i.EthApi=t})(eth||(eth={}));"use strict";var __extends=this&&this.__extends||function(){var n=function(t,e){n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)if(e.hasOwnProperty(r))t[r]=e[r]};return n(t,e)};return function(t,e){n(t,e);function r(){this.constructor=t}t.prototype=e===null?Object.create(e):(r.prototype=e.prototype,new r)}}();var eos;(function(t){t.EosEvent={MISS_IDENTITY:"miss identity callback"};var e=function(o){__extends(t,o);function t(){var t=[];for(var e=0;e<arguments.length;e++){t[e]=arguments[e]}var r=o.call(this,t[0])||this;r._urls=[];for(var n=0;n<t.length;n++){r._urls[n]={url:t[n],dt:0}}return r}t.prototype.sort=function(){this._urls.sort(function(t,e){return t.dt-e.dt});this._urls.length>0&&(this._url=this._urls[0].url)};t.prototype.recorde=function(t){if(t===void 0){t=Number.POSITIVE_INFINITY}var e=this._urls[0];e&&(e.dt=t)&&this.sort()};return t}(base.Net);var r=function(){function t(t){this._setting=t;this._nets=new(e.bind.apply(e,[void 0].concat(typeof this._setting.nets==="string"?[this._setting.nets]:this._setting.nets)))}Object.defineProperty(t.prototype,"setting",{get:function(){return this._setting},enumerable:true,configurable:true});Object.defineProperty(t.prototype,"url",{get:function(){return this._nets.url},enumerable:true,configurable:true});Object.defineProperty(t.prototype,"httpEndpoint",{get:function(){return this._nets.url},enumerable:true,configurable:true});Object.defineProperty(t.prototype,"host",{get:function(){return this._nets.host},enumerable:true,configurable:true});Object.defineProperty(t.prototype,"port",{get:function(){return this._nets.port},enumerable:true,configurable:true});Object.defineProperty(t.prototype,"protocal",{get:function(){return this._nets.protocal},enumerable:true,configurable:true});Object.defineProperty(t.prototype,"privateKey",{get:function(){return this._setting.privateKey},enumerable:true,configurable:true});Object.defineProperty(t.prototype,"defaultContract",{get:function(){return this._setting.defaultContract},enumerable:true,configurable:true});Object.defineProperty(t.prototype,"chainId",{get:function(){return this._setting.chainId},enumerable:true,configurable:true});Object.defineProperty(t.prototype,"eosNetwork",{get:function(){return{blockchain:"eos",host:this._nets.host,port:this._nets.port,protocol:this._nets.protocal,chainId:this._setting.chainId}},enumerable:true,configurable:true});return t}();t.EOSConfig=r})(eos||(eos={}));"use strict";"use strict";var __extends=this&&this.__extends||function(){var n=function(t,e){n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)if(e.hasOwnProperty(r))t[r]=e[r]};return n(t,e)};return function(t,e){n(t,e);function r(){this.constructor=t}t.prototype=e===null?Object.create(e):(r.prototype=e.prototype,new r)}}();var __awaiter=this&&this.__awaiter||function(i,s,u,a){return new(u||(u=Promise))(function(t,e){function r(t){try{o(a.next(t))}catch(t){e(t)}}function n(t){try{o(a["throw"](t))}catch(t){e(t)}}function o(e){e.done?t(e.value):new u(function(t){t(e.value)}).then(r,n)}o((a=a.apply(i,s||[])).next())})};var __generator=this&&this.__generator||function(t,r){var n={label:0,sent:function(){if(s[0]&1)throw s[1];return s[1]},trys:[],ops:[]},o,i,s,e;return e={next:u(0),throw:u(1),return:u(2)},typeof Symbol==="function"&&(e[Symbol.iterator]=function(){return this}),e;function u(e){return function(t){return a([e,t])}}function a(e){if(o)throw new TypeError("Generator is already executing.");while(n)try{if(o=1,i&&(s=e[0]&2?i["return"]:e[0]?i["throw"]||((s=i["return"])&&s.call(i),0):i.next)&&!(s=s.call(i,e[1])).done)return s;if(i=0,s)e=[e[0]&2,s.value];switch(e[0]){case 0:case 1:s=e;break;case 4:n.label++;return{value:e[1],done:false};case 5:n.label++;i=e[1];e=[0];continue;case 7:e=n.ops.pop();n.trys.pop();continue;default:if(!(s=n.trys,s=s.length>0&&s[s.length-1])&&(e[0]===6||e[0]===2)){n=0;continue}if(e[0]===3&&(!s||e[1]>s[0]&&e[1]<s[3])){n.label=e[1];break}if(e[0]===6&&n.label<s[1]){n.label=s[1];s=e;break}if(s&&n.label<s[2]){n.label=s[2];n.ops.push(e);break}if(s[2])n.ops.pop();n.trys.pop();continue}e=r.call(t,n)}catch(t){e=[6,t];i=0}finally{o=s=0}if(e[0]&5)throw e[1];return{value:e[0]?e[1]:void 0,done:true}}};var eos;(function(s){var t=function(i){__extends(t,i);function t(t,e,r){var n=i.call(this,t,r)||this;n._config=new s.EOSConfig(e);var o=window;n._scatter=o["scatter"];if(n._scatter){n._scatter.requireVersion(3);n._eos=n._scatter.eos(n._config.eosNetwork,t,{},n._config.protocal)}else{n._eos=undefined}return n}t.prototype.formatEos=function(t){return parseFloat(t)};Object.defineProperty(t.prototype,"eos",{get:function(){return this._eos},enumerable:true,configurable:true});t.prototype.getSymbol=function(){return base.SymbolType.eos};t.prototype.plugin=function(){return"Scatter"};t.prototype.usePlugin=function(){return true};t.prototype.isInitPlugin=function(){return this._eos!==undefined};t.prototype.hasAccount=function(){return this._account!==undefined};t.prototype.defaultAccount=function(){return this._account?this._account.name:""};t.prototype.check=function(){if(this.isInitPlugin()){this.onError(base.ErrorCode.PluginNotInit);return false}else if(this.hasAccount()){this.onError(base.ErrorCode.AccountNotFound);return false}else if(!this.identity){this.onError(base.ErrorCode.MissIdentity);this.invorkEvent(s.EosEvent.MISS_IDENTITY,{});return false}return true};Object.defineProperty(t.prototype,"identity",{get:function(){return this._scatter?this._scatter.identity:undefined},enumerable:true,configurable:true});t.prototype.addEvent=function(t,e){};t.prototype.forgetIdentity=function(){this._scatter&&this._scatter.forgetIdentity()};t.prototype.updateStatus=function(){i.prototype.updateStatus.call(this);var t=window;if(!this._scatter){t["scatter"]&&(this._scatter=t["scatter"]);if(this._scatter){this._scatter.requireVersion(3);this._eos=this._scatter.eos(this._config.eosNetwork,this.core,{},this._config.protocal)}}if(this.identity){var e=this.defaultAccount();this._account=this.identity.accounts.find(function(t){return t.blockchain==="eos"});if(e!==this.defaultAccount()){this.invorkEvent(base.BaseEvent.ACCOUNT_CHANGED,{account:this.defaultAccount(),oldAccount:e})}}};t.prototype.encode=function(t){return this.core.modules.format.encodeName(t,false)};t.prototype.decode=function(t){return this.core.modules.format.decodeName(t.toString(),false)};t.prototype.requireIdentity=function(){return __awaiter(this,void 0,void 0,function(){var e,r;return __generator(this,function(t){switch(t.label){case 0:if(!this._scatter){this.onError(base.ErrorCode.PluginNotInit);throw{errorCode:base.ErrorCode.PluginNotInit}}t.label=1;case 1:t.trys.push([1,3,,4]);return[4,this._scatter.getIdentity({accounts:[this._config.eosNetwork]})];case 2:e=t.sent();if(e){this._account=e.accounts.find(function(t){return t.blockchain==="eos"});return[2,e]}else{this.onError(base.ErrorCode.AccountNotFound);throw{errorCode:base.ErrorCode.AccountNotFound}}return[3,4];case 3:r=t.sent();throw r;case 4:return[2]}})})};t.prototype.getBalance=function(){return __awaiter(this,void 0,void 0,function(){var e,r;return __generator(this,function(t){switch(t.label){case 0:e=this.eos;if(!e)return[2,0];return[4,e.getCurrencyBalance("eosio.token",this.defaultAccount(),this.getSymbol().toUpperCase())];case 1:r=t.sent();return[2,r&&r.length>0?parseFloat(r[0]):0]}})})};t.prototype.getAccountInfo=function(){var t=this.eos;if(!t)return undefined;return t.getAccount(this.defaultAccount())};t.prototype.transaction=function(t,e,r,n){if(n===void 0){n=""}var o=this.eos;if(!o)return undefined;return o.transaction({actions:[{account:"eosio.token",name:"transfer",authorization:[{actor:t.name,permission:t.authority}],data:{from:t.name,to:e,quantity:r,memo:n}}]},{broadcast:true,sign:true})};t.prototype.getAuthorization=function(){var t=this._account;return t?t.name+"@"+t.authority:""};t.prototype.doAction=function(i,s,u){var a=[];for(var t=3;t<arguments.length;t++){a[t-3]=arguments[t]}return __awaiter(this,void 0,void 0,function(){var e,r,n,o;return __generator(this,function(t){switch(t.label){case 0:e=this.eos;if(!e)return[2,undefined];r={authorization:typeof u==="string"?[u]:u};return[4,e.contract(i)];case 1:n=t.sent();if(!n)return[2,undefined];return[4,n[s].apply(window,a.concat(r))];case 2:o=t.sent();return[2,o]}})})};t.prototype.doSimpleAction=function(r){var n=[];for(var t=1;t<arguments.length;t++){n[t-1]=arguments[t]}return __awaiter(this,void 0,void 0,function(){var e;return __generator(this,function(t){switch(t.label){case 0:e=undefined;if(!this._config.defaultContract)return[3,2];return[4,this.doAction.apply(this,[this._config.defaultContract,r,this.getAuthorization()].concat(n))];case 1:e=t.sent();t.label=2;case 2:return[2,e]}})})};t.prototype.getTableRows=function(n,o,i,s,u,a){return __awaiter(this,void 0,void 0,function(){var e,r;return __generator(this,function(t){switch(t.label){case 0:if(!i){if(!this._config.defaultContract)return[2,{rows:[],more:false}];i=this._config.defaultContract}t.label=1;case 1:t.trys.push([1,3,,4]);e={code:i,scope:o,table:n,json:true,lower_bound:u};s&&(e["limit"]=s);a&&(e["table_key"]=a);if(!this.eos)return[2,{rows:[],more:false}];return[4,this.eos.getTableRows(e)];case 2:return[2,t.sent()];case 3:r=t.sent();throw r;case 4:return[2]}})})};t.prototype.getAllTableRows=function(s,u,a,c){return __awaiter(this,void 0,void 0,function(){var e,r,n,o,i;return __generator(this,function(t){switch(t.label){case 0:if(!c){if(!this._config.defaultContract)return[2,[]];c=this._config.defaultContract}if(!s)return[2,[]];e=new Array;r=10;n=0;t.label=1;case 1:if(!true)return[3,3];return[4,this.getTableRows(u,s.toString(),c,r,n,a)];case 2:o=t.sent();if(!o)return[3,3];if(o.rows&&o.rows.length>0){for(i=0;i<o.rows.length;i++){e.push(o.rows[i])}n+=o.rows.length;if(!o.more)return[3,3]}else{return[3,3]}return[3,1];case 3:return[2,e]}})})};t.prototype.getGlobalData=function(){return __awaiter(this,void 0,void 0,function(){var e;return __generator(this,function(t){switch(t.label){case 0:return[4,this.getTableRows("eosio","global","eosio")];case 1:e=t.sent();if(e&&e.rows&&e.rows.length>0)return[2,e.rows[0]];return[2,null]}})})};t.prototype.getRamPrice=function(){return __awaiter(this,void 0,void 0,function(){var e;return __generator(this,function(t){switch(t.label){case 0:return[4,this.getTableRows("eosio","rammarket","eosio")];case 1:e=t.sent();if(e&&e.rows&&e.rows.length>0){return[2,this.formatEos(e.rows[0].quote.balance)/this.formatEos(e.rows[0].base.balance)*1024]}return[2,0]}})})};t.prototype.buyRam=function(n){return __awaiter(this,void 0,void 0,function(){var e,r;return __generator(this,function(t){switch(t.label){case 0:t.trys.push([0,2,3,4]);this.onContract(0);return[4,this.doAction("eosio","buyrambytes",this.defaultAccount(),this.defaultAccount(),n)];case 1:e=t.sent();this.onContract(1,e);return[2,e];case 2:r=t.sent();this.handleError(r);throw r;case 3:this.onContract(3);return[7];case 4:return[2]}})})};t.prototype.getNetCpuPrice=function(){return __awaiter(this,void 0,void 0,function(){var e,r,n,o,i,s,u;return __generator(this,function(t){switch(t.label){case 0:return[4,this.getAccountInfo()];case 1:e=t.sent();r=0;n=0;if(e){o=e.net_weight/1e4;i=e.net_limit.max/1024;r=o/i/3;console.log(o,i,r);s=e.cpu_weight/1e4;u=e.cpu_limit.max/1024;n=s/u/3}return[2,{netPrice:r,cpuPrice:n}]}})})};t.prototype.sellRam=function(n){return __awaiter(this,void 0,void 0,function(){var e,r;return __generator(this,function(t){switch(t.label){case 0:t.trys.push([0,2,3,4]);this.onContract(0);return[4,this.doAction("eosio","sellram",this.defaultAccount(),n)];case 1:e=t.sent();this.onContract(1,e);return[2,e];case 2:r=t.sent();this.handleError(r);throw r;case 3:this.onContract(3);return[7];case 4:return[2]}})})};t.prototype.delegatebw=function(n,o){return __awaiter(this,void 0,void 0,function(){var e,r;return __generator(this,function(t){switch(t.label){case 0:t.trys.push([0,2,3,4]);this.onContract(0);return[4,this.doAction("eosio","delegatebw",this.defaultAccount(),this.defaultAccount(),n.toFixed(4)+" EOS",o.toFixed(4)+" EOS",0)];case 1:e=t.sent();this.onContract(1,e);return[2,e];case 2:r=t.sent();this.handleError(r);throw r;case 3:this.onContract(3);return[7];case 4:return[2]}})})};t.prototype.undelegatebw=function(n,o){return __awaiter(this,void 0,void 0,function(){var e,r;return __generator(this,function(t){switch(t.label){case 0:t.trys.push([0,2,3,4]);this.onContract(0);return[4,this.doAction("eosio","undelegatebw",this.defaultAccount(),this.defaultAccount(),n.toFixed(4)+" EOS",o.toFixed(4)+" EOS")];case 1:e=t.sent();this.onContract(1,e);return[2,e];case 2:r=t.sent();this.handleError(r);throw r;case 3:this.onContract(3);return[7];case 4:return[2]}})})};t.prototype.handleError=function(t){if(!t)return;if(typeof t==="string"){try{var e=JSON.parse(t);typeof e==="object"&&e&&(t=e)}catch(t){}}t.error&&t.error.details?this.onError(base.ErrorCode.TranSactionError,t):this.onError(base.ErrorCode.UnknowError,t)};return t}(base.CustomApi);s.EosApi=t})(eos||(eos={}));"use strict";Object.defineProperty(exports,"__esModule",{value:true});var _base=new base.Base;_base.register(base.SymbolType.eos,new(function(){function t(){}t.prototype.generateAPI=function(t,e,r){return new eos.EosApi(t,e,r)};return t}()));_base.register(base.SymbolType.eth,new(function(){function t(){}t.prototype.generateAPI=function(t,e,r){return new eth.EthApi(t,e,r)};return t}()));exports.soeth=_base;exports.API=_base.API;