edge-currency-accountbased 1.2.11 → 1.2.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +9 -0
- package/android/src/main/assets/edge-currency-accountbased/fio.chunk.js +2 -2
- package/android/src/main/assets/piratesaplingtree/mainnet/2420000.json +7 -0
- package/android/src/main/assets/saplingtree/mainnet/2100000.json +7 -0
- package/lib/fio/FioEngine.js +5 -12
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
# edge-currency-accountbased
|
|
2
2
|
|
|
3
|
+
## 1.2.13 (2023-06-02)
|
|
4
|
+
|
|
5
|
+
- FIO: Fix unstake method insufficient funds checking
|
|
6
|
+
|
|
7
|
+
## 1.2.12 (2023-06-02)
|
|
8
|
+
|
|
9
|
+
- FIO: Change `getMaxSpendable` to use available balance
|
|
10
|
+
- Update ZEC/ARRR checkpoints
|
|
11
|
+
|
|
3
12
|
## 1.2.11 (2023-06-01)
|
|
4
13
|
|
|
5
14
|
- EVM: Re-enable token transaction acceleration
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
(self.webpackChunkedge_currency_accountbased=self.webpackChunkedge_currency_accountbased||[]).push([[805],{79014:function(ye,Q,w){"use strict";w.d(Q,{Q:function(){return z},k:function(){return h}});var T=w(77591),he=w.n(T),P=w(24350),ie=w(84564),ee=w.n(ie),D=w(76714),c=Object.defineProperty,E=Object.getOwnPropertySymbols,te=Object.prototype.hasOwnProperty,R=Object.prototype.propertyIsEnumerable,G=(v,x,F)=>x in v?c(v,x,{enumerable:!0,configurable:!0,writable:!0,value:F}):v[x]=F,ae=(v,x)=>{for(var F in x||(x={}))te.call(x,F)&&G(v,F,x[F]);if(E)for(var F of E(x))R.call(x,F)&&G(v,F,x[F]);return v};function h(v,x,F,B,J){const u=ae({},ee()(x,{},!0)),W=x.startsWith(`${v.pluginId}://`);if(u.protocol!=null&&(u.protocol=u.protocol.replace(":","")),u.protocol!=null&&u.protocol!==""&&!F[u.protocol])throw new Error(`Uri protocol '${u.protocol}' is not supported for ${v.pluginId}.`);if(u.host===""&&u.pathname==="")throw new Error("Path and host not found in uri.");const U={publicAddress:u.host!==""?u.host:u.pathname.split("/")[0]},$=u.query.label,se=u.query.message,Y=u.query.category;($!=null||se!=null||Y!=null||W)&&(U.metadata={},U.metadata.name=$,U.metadata.notes=se,U.metadata.category=Y,U.metadata.gateway=W!=null?W:!1);const X=u.query.amount;if(X!=null&&typeof X=="string"){B==null&&(B=v.currencyCode);const ne=(0,D.cp)(v,B!=null?B:"",J);if(ne==null)throw new Error("InternalErrorInvalidCurrencyCode");let V=(0,T.mul)(X,ne.multiplier);V=(0,T.toFixed)(V,0,0),U.nativeAmount=V,U.currencyCode=B}return{edgeParsedUri:U,parsedUri:u}}function z(v,x,F){if(v.publicAddress==null)throw new Error("InvalidPublicAddressError");if(F==null&&v.label==null&&v.message==null)return v.publicAddress;{let B="";F!=null&&(B+="amount="+F+"&"),(v.label!=null||v.message!=null)&&(typeof v.label=="string"&&(B+="label="+v.label+"&"),typeof v.message=="string"&&(B+="message="+v.message+"&")),B=B.substr(0,B.length-1);const J={scheme:x,path:v.publicAddress,query:B};return(0,P.qC)(J)}}},44285:function(ye,Q,w){"use strict";w.r(Q),w.d(Q,{FioTools:function(){return me},checkAddress:function(){return ue},makeCurrencyEngine:function(){return De},makeCurrencyTools:function(){return Ae}});var T=w(93491),he=w(45234),P=w(77591),ie=w(2153),ee=w(79014),D=w(76714),c=w(5607),E=w(24827),te=w(50857),R=w(37858),G=w(82626),ae=w(37297),h=w(82448),z=w(94935),v=w(50215);const x=(0,h.su)({fio_domains:(0,h._2)((0,h.su)({fio_domain:h.XC,expiration:h.XC,is_public:h.mH})),fio_addresses:(0,h._2)((0,h.su)({fio_address:h.XC,remaining_bundled_tx:h.mH}))}),F=(0,h.su)({account_action_seq:h.mH,block_num:h.mH,block_time:h.XC,action_trace:(0,h.su)({receiver:h.XC,act:(0,h.su)({account:h.XC,name:h.XC,authorization:(0,h._2)((0,h.su)({actor:h.XC,permission:h.XC})),data:(0,h.su)({payee_public_key:(0,h.Zz)(h.XC),amount:(0,h.Zz)(h.mH),max_fee:(0,h.Zz)(h.mH),actor:(0,h.Zz)(h.XC),tpid:(0,h.Zz)(h.XC),quantity:(0,h.Zz)(h.XC),memo:(0,h.Zz)(h.XC),to:(0,h.Zz)(h.XC),from:(0,h.Zz)(h.XC)}),hex_data:h.XC}),trx_id:h.XC,block_num:h.mH,block_time:h.XC,producer_block_id:h.XC})}),B=(0,h.su)({actions:(0,h._2)(F)}),J=(0,h.su)({balance:h.mH,available:h.mH,staked:h.mH,srps:h.mH,roe:h.XC});var u=w(3559),W=Object.defineProperty,fe=Object.defineProperties,U=Object.getOwnPropertyDescriptors,$=Object.getOwnPropertySymbols,se=Object.getPrototypeOf,Y=Object.prototype.hasOwnProperty,X=Object.prototype.propertyIsEnumerable,ne=Reflect.get,V=(g,e,s)=>e in g?W(g,e,{enumerable:!0,configurable:!0,writable:!0,value:s}):g[e]=s,O=(g,e)=>{for(var s in e||(e={}))Y.call(e,s)&&V(g,s,e[s]);if($)for(var s of $(e))X.call(e,s)&&V(g,s,e[s]);return g},j=(g,e)=>fe(g,U(e)),pe=(g,e)=>{var s={};for(var t in g)Y.call(g,t)&&e.indexOf(t)<0&&(s[t]=g[t]);if(g!=null&&$)for(var t of $(g))e.indexOf(t)<0&&X.call(g,t)&&(s[t]=g[t]);return s},le=(g,e,s)=>ne(se(g),s,e),p=(g,e,s)=>new Promise((t,a)=>{var o=n=>{try{i(s.next(n))}catch(r){a(r)}},l=n=>{try{i(s.throw(n))}catch(r){a(r)}},i=n=>n.done?t(n.value):Promise.resolve(n.value).then(o,l);i((s=s.apply(g,e)).next())});const ge=1e4,_e=15e3,ke=1e4,be=[c.BP[c.aO.transferTokens],c.BP[c.aO.unStakeFioTokens],"regaddress"],we=1e4;class Z extends v.P{constructor(e,s,t,a,o){super(e,s,t,a),this.fioRequestsListChanged=(i,n)=>{function r(d,f){for(const I of d)if(f.findIndex(k=>k.fio_request_id===I.fio_request_id)<0)return!0;return!1}return!!(r(i,n)||r(n,i))},this.removeFioRequest=(i,n)=>{const r=this.otherData.fioRequests[n].findIndex(d=>d.fio_request_id===`${i}`);r>-1&&this.otherData.fioRequests[n].splice(r,1)};const l=(0,D.zR)(e);this.fetchCors=l,this.tpid=o,this.networkInfo=e.networkInfo,this.refBlock={expiration:"",ref_block_num:0,ref_block_prefix:0},this.fees=new Map,this.actor=T.rn.accountHash(this.walletInfo.keys.publicKey).accountnm,this.obtData=[],this.otherMethods={fioAction:(i,n)=>p(this,null,function*(){return yield this.multicastServers(i,n)}),getFioAddresses:()=>p(this,null,function*(){return this.otherData.fioAddresses}),getFioAddressNames:()=>p(this,null,function*(){return this.otherData.fioAddresses.map(i=>i.name)}),getFioDomains:()=>p(this,null,function*(){return this.otherData.fioDomains}),getFioRequests:(i,n,r=50)=>p(this,null,function*(){const d=r*(n-1),f=r*n;return this.otherData.fioRequests[i].sort((I,k)=>I.time_stamp<k.time_stamp?1:-1).slice(d,f)}),getObtData:()=>p(this,null,function*(){return this.obtData})}}localDataDirty(){this.walletLocalDataDirty=!0}setOtherData(e){this.otherData=(0,c.CL)(e)}getUTCDate(e){const s=new Date(e);return Date.UTC(s.getFullYear(),s.getMonth(),s.getDate(),s.getHours(),s.getMinutes(),s.getSeconds())}getUnlockDate(e){const s=Math.floor(e.getTime()/c.qj)*c.qj;return new Date(s+c.dm)}loadEngine(e,s,t){return p(this,null,function*(){yield le(Z.prototype,this,"loadEngine").call(this,e,s,t)})}checkBlockchainInnerLoop(){return p(this,null,function*(){try{const e=yield this.multicastServers("getChainInfo"),s=e.head_block_num;this.walletLocalData.blockHeight!==s&&(this.checkDroppedTransactionsThrottled(),this.walletLocalData.blockHeight=s,this.localDataDirty(),this.currencyEngineCallbacks.onBlockHeightChanged(this.walletLocalData.blockHeight));const t=yield this.multicastServers("getBlock",e),a=new Date(`${e.head_block_time}Z`);a.setSeconds(a.getSeconds()+180);const o=a.toISOString();this.refBlock={expiration:o.substring(0,o.length-1),ref_block_num:t.block_num&65535,ref_block_prefix:t.ref_block_prefix}}catch(e){this.error("checkBlockchainInnerLoop Error fetching height: ",e)}})}getBalance(e){return super.getBalance(e)}doInitialBalanceCallback(){var e;super.doInitialBalanceCallback();const s=this.networkInfo.balanceCurrencyCodes;for(const t of Object.values(s))try{this.currencyEngineCallbacks.onBalanceChanged(t,(e=this.walletLocalData.totalBalances[t])!=null?e:"0")}catch(a){this.log.error("doInitialBalanceCallback Error for currencyCode",t,a)}try{this.currencyEngineCallbacks.onStakingStatusChanged(O({},this.otherData.stakingStatus))}catch(t){this.error("doInitialBalanceCallback onStakingStatusChanged",t)}}checkUnStakeTx(e){return e.name===c.BP[c.aO.unStakeFioTokens]||e.data!=null&&e.data.memo===c.Nd}updateStakingStatus(e,s,t,a){const o=this.getUnlockDate(new Date(this.getUTCDate(s))),l=this.otherData.stakingStatus.stakedAmounts.findIndex(i=>{var n;return((n=i.unlockDate)==null?void 0:n.getTime())===o.getTime()});if(l<0){const i=this.otherData.stakingStatus.stakedAmounts.findIndex(r=>{var d,f;return o.getTime()>=((f=(d=r.unlockDate)==null?void 0:d.getTime())!=null?f:0)}),n=i<0?this.otherData.stakingStatus.stakedAmounts.length:i;this.otherData.stakingStatus.stakedAmounts.splice(n,0,{nativeAmount:e,unlockDate:o,otherParams:{date:new Date(s),txs:[{txId:t,nativeAmount:e,blockTime:s,txName:a}]}})}else{const i=j(O({},this.otherData.stakingStatus.stakedAmounts[l]),{nativeAmount:"0"}),n=i.otherParams.txs.findIndex(({txId:r,txName:d})=>r===t&&d===a);n<0?i.otherParams.txs.push({txId:t,nativeAmount:e,blockTime:s,txName:a}):i.otherParams.txs[n]={txId:t,nativeAmount:e,blockTime:s,txName:a};for(const r of i.otherParams.txs)i.nativeAmount=(0,P.add)(i.nativeAmount,r.nativeAmount);this.otherData.stakingStatus.stakedAmounts[l]=i}this.localDataDirty();try{this.currencyEngineCallbacks.onStakingStatusChanged(O({},this.otherData.stakingStatus))}catch{this.error("onStakingStatusChanged error")}}getStakingStatus(){return p(this,null,function*(){return O({},this.otherData.stakingStatus)})}processTransaction(e,s,t=this.currencyInfo.currencyCode){var a,o,l,i,n,r,d,f,I;const{act:{name:k,data:_,account:y,authorization:C}}=e.action_trace;let S,m,b="0",A={account:y,name:k,authorization:C,data:_,meta:{}};const N=[];if(e.block_num<=this.otherData.highestTxHeight)return e.block_num;if(be.includes(k)){S="0",k==="regaddress"&&e.action_trace.act.authorization.some(K=>K.actor===this.actor)&&(b=String((a=e.action_trace.act.data.max_fee)!=null?a:0),S=`-${b}`),k===c.BP[c.aO.transferTokens]&&_.amount!=null&&(S=_.amount.toString(),m=_.actor,_.payee_public_key===this.walletInfo.keys.publicKey?(N.push(this.walletInfo.keys.publicKey),m===s&&(S="0")):S=`-${S}`);const L=this.findTransaction(t,e.action_trace.trx_id);if(L>-1){const K=this.transactionList[t][L];if(A=j(O(O({},K.otherParams),A),{data:O(O({},(l=(o=K.otherParams)==null?void 0:o.data)!=null?l:{}),A.data),meta:O(O({},(n=(i=K.otherParams)==null?void 0:i.meta)!=null?n:{}),A.meta)}),A.meta.isTransferProcessed!=null)return e.block_num;A.meta.isFeeProcessed!=null?k===c.BP[c.aO.transferTokens]?(S=(0,P.sub)(S,K.networkFee),b=K.networkFee):(S=K.nativeAmount,b="0"):this.error("processTransaction error - existing spend transaction should have isTransferProcessed or isFeeProcessed set")}this.checkUnStakeTx(A)&&this.updateStakingStatus(_.amount!=null?_.amount.toString():"0",e.block_time,e.action_trace.trx_id,k),A.meta.isTransferProcessed=!0;const H={txid:e.action_trace.trx_id,date:this.getUTCDate(e.block_time)/1e3,currencyCode:t,blockHeight:e.block_num>0?e.block_num:0,nativeAmount:S,isSend:S.startsWith("-"),networkFee:b,ourReceiveAddresses:N,signedTx:"",otherParams:A,walletId:this.walletId};this.addTransaction(t,H)}if(k===c.BP.transfer&&_.quantity!=null){const[L]=_.quantity.split(" "),H=L.toString();let K=(0,D.cp)(this.currencyInfo,t);if(K==null&&(K=(0,D.cp)(this.currencyInfo,this.currencyInfo.currencyCode),K==null))return this.error(`Received unsupported currencyCode: ${t}`),0;const M=(0,P.mul)(H,K.multiplier);_.to===s?(S=`${M}`,b=`-${M}`):(S=`-${M}`,b=M);const re=this.findTransaction(t,e.action_trace.trx_id);if(re>-1){const oe=this.transactionList[t][re];if(A=j(O(O({},A),oe.otherParams),{data:O(O({},A.data),(d=(r=oe.otherParams)==null?void 0:r.data)!=null?d:{}),meta:O(O({},A.meta),(I=(f=oe.otherParams)==null?void 0:f.meta)!=null?I:{})}),A.meta.isFeeProcessed!=null)return e.block_num;A.meta.isTransferProcessed!=null?_.to!==s?S=(0,P.sub)(oe.nativeAmount,b):b="0":this.error("processTransaction error - existing spend transaction should have isTransferProcessed or isFeeProcessed set")}this.checkUnStakeTx(A)&&this.updateStakingStatus(M,e.block_time,e.action_trace.trx_id,k),A.meta.isFeeProcessed=!0;const Pe={txid:e.action_trace.trx_id,date:this.getUTCDate(e.block_time)/1e3,currencyCode:t,blockHeight:e.block_num>0?e.block_num:0,nativeAmount:S,isSend:S.startsWith("-"),networkFee:b,signedTx:"",ourReceiveAddresses:[],otherParams:A,walletId:this.walletId};this.addTransaction(t,Pe)}return e.block_num}checkTransactions(e=0){return p(this,null,function*(){var s,t,a;if(this.networkInfo.historyNodeUrls[e]==null)return!1;let o=this.otherData.highestTxHeight,l=0;try{const r=yield this.requestHistory(e,{account_name:this.actor,pos:-1},c.pg.getActions);if(((s=r==null?void 0:r.error)==null?void 0:s.noNodeForIndex)!=null)return!1;if(B(r),r.actions.length>0)l=r.actions[r.actions.length-1].account_action_seq;else return!0}catch{return yield this.checkTransactions(++e)}let i=Math.max(0,l-c.eG),n=!1;for(;!n&&!(i<0);){let r;try{if(r=yield this.requestHistory(e,{account_name:this.actor,pos:i,offset:c.eG-1},c.pg.getActions),((t=r.error)==null?void 0:t.noNodeForIndex)!=null)return!1;let d=[];if(((a=r.actions)==null?void 0:a.length)>0)d=r.actions;else break;for(let f=d.length-1;f>-1;f--){const I=d[f];F(I);const k=this.processTransaction(I,this.actor);if(k>o)o=k;else if(k===o&&f===c.eG-1||k<this.otherData.highestTxHeight){n=!0;break}}if(d.length<c.eG)break;i-=c.eG}catch{return yield this.checkTransactions(++e)}}return o>this.otherData.highestTxHeight&&(this.otherData.highestTxHeight=o,this.localDataDirty()),!0})}checkTransactionsInnerLoop(){return p(this,null,function*(){let e;try{e=yield this.checkTransactions()}catch(s){this.error("checkTransactionsInnerLoop fetches failed with error: ",s);return}e&&(this.tokenCheckTransactionsStatus.FIO=1,this.updateOnAddressesChecked()),this.transactionsChangedArray.length>0&&(this.currencyEngineCallbacks.onTransactionsChanged(this.transactionsChangedArray),this.transactionsChangedArray=[])})}requestHistory(e,s,t){return p(this,null,function*(){if(this.networkInfo.historyNodeUrls[e]==null)return{error:{noNodeForIndex:!0}};const a=this.networkInfo.historyNodeUrls[e],o=JSON.stringify(s);return yield(yield fetch(`${a}history/${t}`,{method:"POST",headers:{"Content-Length":(o.length*2).toString(),Accept:"application/json","Content-Type":"application/json"},body:o})).json()})}fioApiRequest(e,s,t,a=!1){return p(this,null,function*(){var o,l,i,n;const r=new T.rn("",this.walletInfo.keys.publicKey,e,this.fetchCors,void 0,this.tpid,a);let d;try{switch(s){case"getChainInfo":d=yield r.transactions.getChainInfo();break;case"getBlock":d=yield r.transactions.getBlock(t);break;case"getObtData":case"getPendingFioRequests":case"getSentFioRequests":{const{endpoint:f,body:I}=t;d=yield r.transactions.executeCall(f,JSON.stringify(I));break}default:d=yield r.genericAction(s,t)}}catch(f){if(f.errorCode!=null&&E.lI.includes(f.errorCode))((i=(l=(o=f.json)==null?void 0:o.fields)==null?void 0:l[0])==null?void 0:i.error)!=null&&(f.message=f.json.fields[0].error),d={isError:!0,data:{code:f.errorCode,message:(n=f.message)!=null?n:(0,D.HY)(f),json:f.json,list:f.list}},f.errorCode!==404&&this.log(`fioApiRequest error. actionName: ${s} - apiUrl: ${e} - message: ${JSON.stringify(f.json)}`);else throw this.log(`fioApiRequest error. actionName: ${s} - apiUrl: ${e} - message: `,f),f}return d})}executePreparedTrx(e,s,t){return p(this,null,function*(){var a,o,l;const i=new T.rn("",this.walletInfo.keys.publicKey,e,this.fetchCors,void 0,this.tpid,!0);let n;this.warn(`executePreparedTrx. preparedTrx: ${JSON.stringify(t)} - apiUrl: ${e}`);try{n=yield i.executePreparedTrx(s,t),this.warn(`executePreparedTrx. res: ${JSON.stringify(n)} - apiUrl: ${e} - endpoint: ${s}`)}catch(r){throw r.errorCode!=null&&E.lI.includes(r.errorCode)?(this.log(`executePreparedTrx error. requestParams: ${JSON.stringify(t)} - apiUrl: ${e} - endpoint: ${s} - message: ${JSON.stringify(r.json)}`),((l=(o=(a=r.json)==null?void 0:a.fields)==null?void 0:o[0])==null?void 0:l.error)!=null&&(r.message=r.json.fields[0].error),r):(this.log(`executePreparedTrx error. requestParams: ${JSON.stringify(t)} - apiUrl: ${e} - endpoint: ${s} - message: `,r),r)}return n})}multicastServers(e,s){return p(this,null,function*(){var t,a,o,l,i;let n;if(c.K1[e]){const r=(0,u.h0)(s);if(this.warn(`multicastServers executePreparedTrx. actionName: ${e} - res: ${JSON.stringify(r)}`),n=yield(0,D.Wp)((0,D.Sy)(this.networkInfo.apiUrls.map(d=>p(this,null,function*(){return yield this.executePreparedTrx(d,R.EndPoint[c.VW[e]],r)})))),this.warn(`multicastServers res. actionName: ${e} - res: ${JSON.stringify(n)}`),n==null)throw new Error("Service is unavailable")}else e==="getFioNames"?(n=yield(0,D.ml)(this.networkInfo.apiUrls.map(r=>p(this,null,function*(){return yield(0,D.Vs)(this.fioApiRequest(r,e,s),1e4)})),r=>{const d=(0,u.$K)(c.Mi)(r);return d!=null?d.data.json.message:(0,u.e1)(r)},2),((a=(t=n==null?void 0:n.data)==null?void 0:t.json)==null?void 0:a.message)===c.Mi&&(n={fio_domains:[],fio_addresses:[]})):e==="getFioBalance"?(n=yield(0,D.ml)(this.networkInfo.apiUrls.map(r=>p(this,null,function*(){return yield(0,D.Vs)(this.fioApiRequest(r,e,s),1e4)})),r=>{const d=(0,u.$K)(c.d9)(r);return d!=null?d.data.json.message:(0,u.sq)(r)},2),((l=(o=n==null?void 0:n.data)==null?void 0:o.json)==null?void 0:l.message)===c.d9&&(n={balance:0,available:0,staked:0,srps:0,roe:""})):e==="getFees"?n=yield(0,D.QJ)((0,D.Sy)(this.networkInfo.apiUrls.map(r=>()=>p(this,null,function*(){const d=new T.rn("",this.walletInfo.keys.publicKey,r,this.fetchCors,void 0,this.tpid),{endpoint:f,param:I}=s,k=yield d.getFee(f,I);return(0,u.lZ)(k).fee.toString()})))):n=yield(0,D.QJ)((0,D.Sy)(this.networkInfo.apiUrls.map(r=>()=>p(this,null,function*(){return yield this.fioApiRequest(r,e,s)}))));if(n.isError!=null){const r=new E.OU((i=n.errorMessage)!=null?i:n.data.message);throw r.json=n.data.json,r.list=n.data.list,r.errorCode=n.data.code,r}return n})}checkAccountInnerLoop(){return p(this,null,function*(){const e=this.currencyInfo.currencyCode,s=this.networkInfo.balanceCurrencyCodes;typeof this.walletLocalData.totalBalances[e]>"u"&&this.updateBalance(e,"0");try{const t={staked:"0",locked:"0"},{balance:a,available:o,staked:l,srps:i,roe:n}=J(yield this.multicastServers("getFioBalance")),r=String(a);t.staked=String(l),t.locked=(0,P.sub)(r,String(o)),this.otherData.srps=i,this.otherData.stakingRoe=n,this.updateBalance(e,r),this.updateBalance(s.staked,t.staked),this.updateBalance(s.locked,t.locked)}catch(t){this.log.warn("checkAccountInnerLoop getFioBalance error: ",t)}try{const t=x(yield this.multicastServers("getFioNames",{fioPublicKey:this.walletInfo.keys.publicKey}));let a=!1,o=!1,l=!1;if(t.fio_addresses.length!==this.otherData.fioAddresses.length)o=!0;else{for(const i of t.fio_addresses){const n=this.otherData.fioAddresses.find(r=>r.name===i.fio_address);if(n!=null){if(n.bundledTxs!==i.remaining_bundled_tx){o=!0;break}}else{o=!0;break}}if(!o){for(const i of this.otherData.fioAddresses)if(t.fio_addresses.findIndex(n=>n.fio_address===i.name)<0){o=!0;break}}}if(t.fio_domains.length!==this.otherData.fioDomains.length)l=!0;else{for(const i of t.fio_domains){const n=this.otherData.fioDomains.find(r=>r.name===i.fio_domain);if(n!=null){if(n.expiration!==i.expiration){l=!0;break}if(n.isPublic!==(i.is_public===1)){l=!0;break}}else{l=!0;break}}if(!l){for(const i of this.otherData.fioDomains)if(t.fio_domains.findIndex(n=>n.fio_domain===i.name)<0){l=!0;break}}}o&&(a=!0,this.otherData.fioAddresses=t.fio_addresses.map(i=>({name:i.fio_address,bundledTxs:i.remaining_bundled_tx}))),l&&(a=!0,this.otherData.fioDomains=t.fio_domains.map(i=>({name:i.fio_domain,expiration:i.expiration,isPublic:i.is_public===1}))),a&&this.localDataDirty()}catch(t){this.warn("checkAccountInnerLoop getFioNames error: ",t)}})}fetchEncryptedFioRequests(e,s){return p(this,null,function*(){const a=e==="PENDING"?"getPendingFioRequests":"getSentFioRequests";let o=100,l=1;const i=[];for(;o===100;)try{const n=yield this.multicastServers(a,{endpoint:s.getEndPoint(),body:{fio_public_key:this.walletInfo.keys.publicKey,limit:100,offset:(l-1)*100}}),r=(0,u.S_)(n),{requests:d,more:f}=r;if(i.push(...d),f===0)break;l++,o=d.length}catch(n){const r=(0,h.Vk)(u.Pq)(n.json);(r==null?void 0:r.message)!=="No FIO Requests"&&this.error("fetchEncryptedFioRequests error: ",n);break}return i})}fetchEncryptedObtData(e,s){return p(this,null,function*(){let a=100,o=1;const l=[];for(;a===100;){let i;try{i=yield this.multicastServers(e,{endpoint:s.getEndPoint(),body:{fio_public_key:this.walletInfo.keys.publicKey,limit:100,offset:(o-1)*100}});const n=(0,u._v)(i),{obt_data_records:r,more:d}=n;if(l.push(...r),d===0)break;o++,a=r.length}catch(n){const r=(0,h.Vk)(u.Pq)(n.json);(r==null?void 0:r.message)!=="No FIO Requests"&&this.error("fetchEncryptedObtData error: ",n);break}}return l})}syncNetwork(e){return p(this,null,function*(){var s;const t=(0,u.UW)(e==null?void 0:e.privateKeys);let a=!1;const o=(r,d)=>p(this,null,function*(){var f;const I=yield this.fetchEncryptedFioRequests(r,d);d.privateKey=t.fioKey,d.publicKey=this.walletInfo.keys.publicKey;const k=(f=d.decrypt({requests:I}))!=null?f:{requests:[]};this.fioRequestsListChanged(this.otherData.fioRequests[r],k.requests)&&(this.otherData.fioRequests[r]=[...k.requests],a=!0)});yield o("PENDING",new G.PendingFioRequests(this.walletInfo.keys.publicKey)),yield o("SENT",new G.SentFioRequests(this.walletInfo.keys.publicKey)),a&&this.localDataDirty();const l=new G.GetObtData(this.walletInfo.keys.publicKey),i=yield this.fetchEncryptedObtData("getObtData",l);l.privateKey=t.fioKey,l.publicKey=this.walletInfo.keys.publicKey;const n=(s=l.decrypt({obt_data_records:i}))!=null?s:{obt_data_records:[]};return this.obtData=n.obt_data_records,we})}getFee(e,s){return p(this,null,function*(){let t=this.fees.get(e);if(t==null||t.expiration+30*1e3<Date.now()){const o={fee:yield this.multicastServers("getFees",{endpoint:e,param:s}),expiration:Date.now()};this.fees.set(e,o),t=o}return t.fee})}startEngine(){return p(this,null,function*(){this.engineOn=!0,this.addToLoop("checkBlockchainInnerLoop",_e).catch(()=>{}),this.addToLoop("checkAccountInnerLoop",ge).catch(()=>{}),this.addToLoop("checkTransactionsInnerLoop",ke).catch(()=>{}),yield le(Z.prototype,this,"startEngine").call(this)})}resyncBlockchain(){return p(this,null,function*(){yield this.killEngine(),yield this.clearBlockchainCache(),yield this.startEngine()})}getMaxSpendable(e){return p(this,null,function*(){var s;const t=this.getBalance({currencyCode:e.currencyCode}),a=yield this.getStakingStatus();let o="0";for(const n of a.stakedAmounts)new Date((s=n.unlockDate)!=null?s:0)>new Date&&(o=(0,P.add)(o,n.nativeAmount));e.spendTargets[0].nativeAmount="1";const l=yield this.makeSpend(e),i=(0,P.sub)((0,P.sub)(t,l.networkFee),o);if((0,P.lt)(i,"0"))throw new z.C_({networkFee:l.networkFee});return i})}makeSpend(e){return p(this,null,function*(){var s,t;const{edgeSpendInfo:a,nativeBalance:o,currencyCode:l}=this.makeSpendCheck(e),i=(s=this.walletLocalData.totalBalances[this.networkInfo.balanceCurrencyCodes.locked])!=null?s:"0",n=(0,P.sub)(o,i),r=a.spendTargets[0],{publicAddress:d}=r,{nativeAmount:f}=r;if(d==null)throw new Error("makeSpend Missing publicAddress");if(f==null)throw new z.$D;let{otherParams:I}=a;(I==null||Object.keys(I).length===0)&&(I={action:{name:c.aO.transferTokens,params:{payeeFioPublicKey:d,amount:f,maxFee:0}}});const{name:k,params:_}=(0,u.iR)(I.action);let y,C;switch(k){case c.aO.transferTokens:{y=yield this.getFee(R.EndPoint.transferTokens),C={account:"fio.token",action:c.BP[c.aO.transferTokens],data:{payee_public_key:d,amount:f,max_fee:y}};break}case c.aO.stakeFioTokens:{const{fioAddress:m}=(0,u.NB)(_);y=yield this.getFee(R.EndPoint.stakeFioTokens,m),C={account:"fio.staking",action:c.BP[k],data:{amount:f,fio_address:m,actor:this.actor,max_fee:y}};break}case c.aO.unStakeFioTokens:{const{fioAddress:m}=(0,u.NB)(_);y=yield this.getFee(R.EndPoint.unStakeFioTokens,m),C={account:"fio.staking",action:c.BP[k],data:{amount:f,fio_address:m,actor:this.actor,max_fee:y}};const b=this.getUnlockDate(new Date),A=(t=this.walletLocalData.totalBalances[this.networkInfo.balanceCurrencyCodes.staked])!=null?t:"0";if((0,P.gt)(f,A)||(0,P.gt)((0,P.add)(f,`${y}`),n))throw new z.C_;const N=(0,P.mul)((0,P.mul)((0,P.div)(f,A,18),`${this.otherData.srps}`),this.otherData.stakingRoe),L=(0,P.max)((0,P.sub)(N,f),"0");I.ui={accrued:N,estReward:L,unlockDate:b};break}case c.aO.transferFioAddress:{const{fioAddress:m}=(0,u.NB)(_);y=yield this.getFee(R.EndPoint.transferFioAddress,m),C={account:"fio.address",action:"xferaddress",data:{fio_address:m,new_owner_fio_public_key:d,actor:this.actor,max_fee:y}};break}case c.aO.transferFioDomain:{const{fioDomain:m}=(0,u.L2)(_);y=yield this.getFee(R.EndPoint.transferFioDomain),C={account:"fio.address",action:"xferdomain",data:{fio_domain:m,new_owner_fio_public_key:d,actor:this.actor,max_fee:y}};break}case c.aO.addPublicAddresses:{const{fioAddress:m,publicAddresses:b}=(0,u.PH)(_);y=yield this.getFee(R.EndPoint.addPubAddress,m),C={account:"fio.address",action:"addaddress",data:{fio_address:m,public_addresses:b,actor:this.actor,max_fee:y}};break}case c.aO.removePublicAddresses:{const{fioAddress:m,publicAddresses:b}=(0,u.PH)(_);y=yield this.getFee(R.EndPoint.removePubAddress,m),C={account:"fio.address",action:"remaddress",data:{fio_address:m,public_addresses:b,actor:this.actor,max_fee:y}};break}case c.aO.registerFioAddress:{const{fioAddress:m}=(0,u.NB)(_);y=yield this.getFee(R.EndPoint.registerFioAddress),C={account:"fio.address",action:"regaddress",data:{fio_address:m,owner_fio_public_key:this.walletInfo.keys.publicKey,max_fee:y,actor:this.actor}};break}case c.aO.registerFioDomain:{const{fioDomain:m}=(0,u.AJ)(_);y=yield this.getFee(R.EndPoint.registerFioDomain),C={account:"fio.address",action:"regdomain",data:{fio_domain:m,owner_fio_public_key:this.walletInfo.keys.publicKey,max_fee:y,actor:this.actor}};break}case c.aO.renewFioDomain:{const{fioDomain:m}=(0,u.AJ)(_);y=yield this.getFee(R.EndPoint.renewFioDomain),C={account:"fio.address",action:"renewdomain",data:{fio_domain:m,max_fee:y,actor:this.actor}};break}case c.aO.addBundledTransactions:{const{bundleSets:m,fioAddress:b}=(0,u.Ej)(_);y=yield this.getFee(R.EndPoint.addBundledTransactions,b),C={account:"fio.address",action:"addbundles",data:{fio_address:b,bundle_sets:m,actor:this.actor,max_fee:y}};break}case c.aO.setFioDomainPublic:{const{fioDomain:m,isPublic:b}=(0,u.oY)(_);y=yield this.getFee(R.EndPoint.setFioDomainPublic),C={account:"fio.address",action:"setdomainpub",data:{fio_domain:m,is_public:b?1:0,max_fee:y,actor:this.actor}};break}case c.aO.rejectFundsRequest:{const{fioRequestId:m,payerFioAddress:b}=(0,u.OR)(_);y=yield this.getFee(R.EndPoint.rejectFundsRequest,b),C={account:"fio.reqobt",action:"rejectfndreq",data:{fio_request_id:m,max_fee:y,actor:this.actor}};break}case c.aO.cancelFundsRequest:{const{fioAddress:m,fioRequestId:b}=(0,u.mO)(_);y=yield this.getFee(R.EndPoint.cancelFundsRequest,m),C={account:"fio.reqobt",action:"cancelfndreq",data:{fio_request_id:b,max_fee:y,actor:this.actor}};break}case c.aO.recordObtData:{const{payerFioAddress:m}=(0,u.XB)(_);y=yield this.getFee(R.EndPoint.recordObtData,m);break}case c.aO.requestFunds:{const{payeeFioAddress:m}=(0,u.Vd)(_);y=yield this.getFee(R.EndPoint.newFundsRequest,m);break}default:throw new Error("Unrecognized FIO action")}return{txid:"",date:0,currencyCode:l,blockHeight:0,nativeAmount:(0,P.sub)(`-${f}`,`${y}`),isSend:!0,networkFee:`${y}`,ourReceiveAddresses:[],signedTx:"",otherParams:j(O({},I),{txParams:C}),walletId:this.walletId}})}signTx(e,s){return p(this,null,function*(){const t=(0,u.UW)(s),a=(0,D.Xp)(e);let o=(0,h.Vk)(u.B3)(a.txParams);const l=new ae.Transactions;if(o==null){const{name:f,params:I}=(0,u.iR)(a.action),{networkFee:k}=e;switch(f){case c.aO.recordObtData:{const{payerFioAddress:_,payeeFioAddress:y,payerPublicAddress:C,payeePublicAddress:S,amount:m,tokenCode:b,chainCode:A,obtId:N,memo:L,status:H,fioRequestId:K}=(0,u.XB)(I),M={payer_public_address:C,payee_public_address:S,amount:m,chain_code:A,token_code:b,status:H,obt_id:N,memo:L,hash:void 0,offline_url:void 0},re=l.getCipherContent("record_obt_data_content",M,t.fioKey,C);o={account:"fio.reqobt",action:"recordobt",data:{payer_fio_address:_,payee_fio_address:y,content:re,fio_request_id:K,max_fee:k,actor:this.actor}};break}case c.aO.requestFunds:{const{payerFioAddress:_,payerFioPublicKey:y,payeeFioAddress:C,payeeTokenPublicAddress:S,amount:m,chainCode:b,tokenCode:A,memo:N}=(0,u.Vd)(I),L={payee_public_address:S,amount:m,chain_code:b,token_code:A,memo:N,hash:void 0,offline_url:void 0},H=l.getCipherContent("new_funds_content",L,t.fioKey,y);o={account:"fio.reqobt",action:"newfundsreq",data:{payer_fio_address:_,payee_fio_address:C,content:H,max_fee:k,actor:this.actor}};break}default:throw new Error("Unknown FIO action")}}const i=yield l.createRawTransaction({action:o.action,account:o.account,data:j(O({},o.data),{tpid:this.tpid}),publicKey:this.walletInfo.keys.publicKey,chainData:this.refBlock}),{serializedContextFreeData:n,serializedTransaction:r}=yield l.serialize({chainId:this.networkInfo.chainId,transaction:i}),d=yield l.sign({chainId:this.networkInfo.chainId,privateKeys:[t.fioKey],transaction:i,serializedTransaction:r,serializedContextFreeData:n});return e.otherParams=j(O({},e.otherParams),{signedTx:d}),e})}broadcastTx(e){return p(this,null,function*(){var s;const t=(0,D.Xp)(e);if(((s=t.action)==null?void 0:s.name)==null)throw new Error('Action is not set, "action" prop of otherParams is required for FIO actions');const a=(0,u.h0)(t.signedTx),o=(0,u.Yd)(yield this.multicastServers(t.action.name,a));e.metadata={notes:o.transaction_id},e.txid=o.transaction_id,e.date=Date.now()/1e3,e.blockHeight=o.block_num,this.warn(`SUCCESS broadcastTx
|
|
2
|
-
${(0,D.oX)(e)}`);const l=o,{block_num:i,block_time:n,transaction_id:r}=l,d=pe(l,["block_num","block_time","transaction_id"]);return e.otherParams=j(
|
|
1
|
+
(self.webpackChunkedge_currency_accountbased=self.webpackChunkedge_currency_accountbased||[]).push([[805],{79014:function(ye,Q,w){"use strict";w.d(Q,{Q:function(){return z},k:function(){return h}});var T=w(77591),he=w.n(T),O=w(24350),ie=w(84564),ee=w.n(ie),D=w(76714),c=Object.defineProperty,P=Object.getOwnPropertySymbols,te=Object.prototype.hasOwnProperty,R=Object.prototype.propertyIsEnumerable,G=(v,x,F)=>x in v?c(v,x,{enumerable:!0,configurable:!0,writable:!0,value:F}):v[x]=F,ae=(v,x)=>{for(var F in x||(x={}))te.call(x,F)&&G(v,F,x[F]);if(P)for(var F of P(x))R.call(x,F)&&G(v,F,x[F]);return v};function h(v,x,F,B,J){const u=ae({},ee()(x,{},!0)),W=x.startsWith(`${v.pluginId}://`);if(u.protocol!=null&&(u.protocol=u.protocol.replace(":","")),u.protocol!=null&&u.protocol!==""&&!F[u.protocol])throw new Error(`Uri protocol '${u.protocol}' is not supported for ${v.pluginId}.`);if(u.host===""&&u.pathname==="")throw new Error("Path and host not found in uri.");const U={publicAddress:u.host!==""?u.host:u.pathname.split("/")[0]},$=u.query.label,se=u.query.message,Y=u.query.category;($!=null||se!=null||Y!=null||W)&&(U.metadata={},U.metadata.name=$,U.metadata.notes=se,U.metadata.category=Y,U.metadata.gateway=W!=null?W:!1);const X=u.query.amount;if(X!=null&&typeof X=="string"){B==null&&(B=v.currencyCode);const ne=(0,D.cp)(v,B!=null?B:"",J);if(ne==null)throw new Error("InternalErrorInvalidCurrencyCode");let V=(0,T.mul)(X,ne.multiplier);V=(0,T.toFixed)(V,0,0),U.nativeAmount=V,U.currencyCode=B}return{edgeParsedUri:U,parsedUri:u}}function z(v,x,F){if(v.publicAddress==null)throw new Error("InvalidPublicAddressError");if(F==null&&v.label==null&&v.message==null)return v.publicAddress;{let B="";F!=null&&(B+="amount="+F+"&"),(v.label!=null||v.message!=null)&&(typeof v.label=="string"&&(B+="label="+v.label+"&"),typeof v.message=="string"&&(B+="message="+v.message+"&")),B=B.substr(0,B.length-1);const J={scheme:x,path:v.publicAddress,query:B};return(0,O.qC)(J)}}},44285:function(ye,Q,w){"use strict";w.r(Q),w.d(Q,{FioTools:function(){return me},checkAddress:function(){return ue},makeCurrencyEngine:function(){return De},makeCurrencyTools:function(){return Ae}});var T=w(93491),he=w(45234),O=w(77591),ie=w(2153),ee=w(79014),D=w(76714),c=w(5607),P=w(24827),te=w(50857),R=w(37858),G=w(82626),ae=w(37297),h=w(82448),z=w(94935),v=w(50215);const x=(0,h.su)({fio_domains:(0,h._2)((0,h.su)({fio_domain:h.XC,expiration:h.XC,is_public:h.mH})),fio_addresses:(0,h._2)((0,h.su)({fio_address:h.XC,remaining_bundled_tx:h.mH}))}),F=(0,h.su)({account_action_seq:h.mH,block_num:h.mH,block_time:h.XC,action_trace:(0,h.su)({receiver:h.XC,act:(0,h.su)({account:h.XC,name:h.XC,authorization:(0,h._2)((0,h.su)({actor:h.XC,permission:h.XC})),data:(0,h.su)({payee_public_key:(0,h.Zz)(h.XC),amount:(0,h.Zz)(h.mH),max_fee:(0,h.Zz)(h.mH),actor:(0,h.Zz)(h.XC),tpid:(0,h.Zz)(h.XC),quantity:(0,h.Zz)(h.XC),memo:(0,h.Zz)(h.XC),to:(0,h.Zz)(h.XC),from:(0,h.Zz)(h.XC)}),hex_data:h.XC}),trx_id:h.XC,block_num:h.mH,block_time:h.XC,producer_block_id:h.XC})}),B=(0,h.su)({actions:(0,h._2)(F)}),J=(0,h.su)({balance:h.mH,available:h.mH,staked:h.mH,srps:h.mH,roe:h.XC});var u=w(3559),W=Object.defineProperty,fe=Object.defineProperties,U=Object.getOwnPropertyDescriptors,$=Object.getOwnPropertySymbols,se=Object.getPrototypeOf,Y=Object.prototype.hasOwnProperty,X=Object.prototype.propertyIsEnumerable,ne=Reflect.get,V=(g,e,s)=>e in g?W(g,e,{enumerable:!0,configurable:!0,writable:!0,value:s}):g[e]=s,S=(g,e)=>{for(var s in e||(e={}))Y.call(e,s)&&V(g,s,e[s]);if($)for(var s of $(e))X.call(e,s)&&V(g,s,e[s]);return g},j=(g,e)=>fe(g,U(e)),pe=(g,e)=>{var s={};for(var t in g)Y.call(g,t)&&e.indexOf(t)<0&&(s[t]=g[t]);if(g!=null&&$)for(var t of $(g))e.indexOf(t)<0&&X.call(g,t)&&(s[t]=g[t]);return s},le=(g,e,s)=>ne(se(g),s,e),p=(g,e,s)=>new Promise((t,a)=>{var o=n=>{try{i(s.next(n))}catch(r){a(r)}},l=n=>{try{i(s.throw(n))}catch(r){a(r)}},i=n=>n.done?t(n.value):Promise.resolve(n.value).then(o,l);i((s=s.apply(g,e)).next())});const ge=1e4,_e=15e3,ke=1e4,be=[c.BP[c.aO.transferTokens],c.BP[c.aO.unStakeFioTokens],"regaddress"],we=1e4;class Z extends v.P{constructor(e,s,t,a,o){super(e,s,t,a),this.fioRequestsListChanged=(i,n)=>{function r(d,f){for(const I of d)if(f.findIndex(k=>k.fio_request_id===I.fio_request_id)<0)return!0;return!1}return!!(r(i,n)||r(n,i))},this.removeFioRequest=(i,n)=>{const r=this.otherData.fioRequests[n].findIndex(d=>d.fio_request_id===`${i}`);r>-1&&this.otherData.fioRequests[n].splice(r,1)};const l=(0,D.zR)(e);this.fetchCors=l,this.tpid=o,this.networkInfo=e.networkInfo,this.refBlock={expiration:"",ref_block_num:0,ref_block_prefix:0},this.fees=new Map,this.actor=T.rn.accountHash(this.walletInfo.keys.publicKey).accountnm,this.obtData=[],this.otherMethods={fioAction:(i,n)=>p(this,null,function*(){return yield this.multicastServers(i,n)}),getFioAddresses:()=>p(this,null,function*(){return this.otherData.fioAddresses}),getFioAddressNames:()=>p(this,null,function*(){return this.otherData.fioAddresses.map(i=>i.name)}),getFioDomains:()=>p(this,null,function*(){return this.otherData.fioDomains}),getFioRequests:(i,n,r=50)=>p(this,null,function*(){const d=r*(n-1),f=r*n;return this.otherData.fioRequests[i].sort((I,k)=>I.time_stamp<k.time_stamp?1:-1).slice(d,f)}),getObtData:()=>p(this,null,function*(){return this.obtData})}}localDataDirty(){this.walletLocalDataDirty=!0}setOtherData(e){this.otherData=(0,c.CL)(e)}getUTCDate(e){const s=new Date(e);return Date.UTC(s.getFullYear(),s.getMonth(),s.getDate(),s.getHours(),s.getMinutes(),s.getSeconds())}getUnlockDate(e){const s=Math.floor(e.getTime()/c.qj)*c.qj;return new Date(s+c.dm)}loadEngine(e,s,t){return p(this,null,function*(){yield le(Z.prototype,this,"loadEngine").call(this,e,s,t)})}checkBlockchainInnerLoop(){return p(this,null,function*(){try{const e=yield this.multicastServers("getChainInfo"),s=e.head_block_num;this.walletLocalData.blockHeight!==s&&(this.checkDroppedTransactionsThrottled(),this.walletLocalData.blockHeight=s,this.localDataDirty(),this.currencyEngineCallbacks.onBlockHeightChanged(this.walletLocalData.blockHeight));const t=yield this.multicastServers("getBlock",e),a=new Date(`${e.head_block_time}Z`);a.setSeconds(a.getSeconds()+180);const o=a.toISOString();this.refBlock={expiration:o.substring(0,o.length-1),ref_block_num:t.block_num&65535,ref_block_prefix:t.ref_block_prefix}}catch(e){this.error("checkBlockchainInnerLoop Error fetching height: ",e)}})}getBalance(e){return super.getBalance(e)}doInitialBalanceCallback(){var e;super.doInitialBalanceCallback();const s=this.networkInfo.balanceCurrencyCodes;for(const t of Object.values(s))try{this.currencyEngineCallbacks.onBalanceChanged(t,(e=this.walletLocalData.totalBalances[t])!=null?e:"0")}catch(a){this.log.error("doInitialBalanceCallback Error for currencyCode",t,a)}try{this.currencyEngineCallbacks.onStakingStatusChanged(S({},this.otherData.stakingStatus))}catch(t){this.error("doInitialBalanceCallback onStakingStatusChanged",t)}}checkUnStakeTx(e){return e.name===c.BP[c.aO.unStakeFioTokens]||e.data!=null&&e.data.memo===c.Nd}updateStakingStatus(e,s,t,a){const o=this.getUnlockDate(new Date(this.getUTCDate(s))),l=this.otherData.stakingStatus.stakedAmounts.findIndex(i=>{var n;return((n=i.unlockDate)==null?void 0:n.getTime())===o.getTime()});if(l<0){const i=this.otherData.stakingStatus.stakedAmounts.findIndex(r=>{var d,f;return o.getTime()>=((f=(d=r.unlockDate)==null?void 0:d.getTime())!=null?f:0)}),n=i<0?this.otherData.stakingStatus.stakedAmounts.length:i;this.otherData.stakingStatus.stakedAmounts.splice(n,0,{nativeAmount:e,unlockDate:o,otherParams:{date:new Date(s),txs:[{txId:t,nativeAmount:e,blockTime:s,txName:a}]}})}else{const i=j(S({},this.otherData.stakingStatus.stakedAmounts[l]),{nativeAmount:"0"}),n=i.otherParams.txs.findIndex(({txId:r,txName:d})=>r===t&&d===a);n<0?i.otherParams.txs.push({txId:t,nativeAmount:e,blockTime:s,txName:a}):i.otherParams.txs[n]={txId:t,nativeAmount:e,blockTime:s,txName:a};for(const r of i.otherParams.txs)i.nativeAmount=(0,O.add)(i.nativeAmount,r.nativeAmount);this.otherData.stakingStatus.stakedAmounts[l]=i}this.localDataDirty();try{this.currencyEngineCallbacks.onStakingStatusChanged(S({},this.otherData.stakingStatus))}catch{this.error("onStakingStatusChanged error")}}getStakingStatus(){return p(this,null,function*(){return S({},this.otherData.stakingStatus)})}processTransaction(e,s,t=this.currencyInfo.currencyCode){var a,o,l,i,n,r,d,f,I;const{act:{name:k,data:_,account:y,authorization:E}}=e.action_trace;let C,m,b="0",A={account:y,name:k,authorization:E,data:_,meta:{}};const N=[];if(e.block_num<=this.otherData.highestTxHeight)return e.block_num;if(be.includes(k)){C="0",k==="regaddress"&&e.action_trace.act.authorization.some(K=>K.actor===this.actor)&&(b=String((a=e.action_trace.act.data.max_fee)!=null?a:0),C=`-${b}`),k===c.BP[c.aO.transferTokens]&&_.amount!=null&&(C=_.amount.toString(),m=_.actor,_.payee_public_key===this.walletInfo.keys.publicKey?(N.push(this.walletInfo.keys.publicKey),m===s&&(C="0")):C=`-${C}`);const L=this.findTransaction(t,e.action_trace.trx_id);if(L>-1){const K=this.transactionList[t][L];if(A=j(S(S({},K.otherParams),A),{data:S(S({},(l=(o=K.otherParams)==null?void 0:o.data)!=null?l:{}),A.data),meta:S(S({},(n=(i=K.otherParams)==null?void 0:i.meta)!=null?n:{}),A.meta)}),A.meta.isTransferProcessed!=null)return e.block_num;A.meta.isFeeProcessed!=null?k===c.BP[c.aO.transferTokens]?(C=(0,O.sub)(C,K.networkFee),b=K.networkFee):(C=K.nativeAmount,b="0"):this.error("processTransaction error - existing spend transaction should have isTransferProcessed or isFeeProcessed set")}this.checkUnStakeTx(A)&&this.updateStakingStatus(_.amount!=null?_.amount.toString():"0",e.block_time,e.action_trace.trx_id,k),A.meta.isTransferProcessed=!0;const H={txid:e.action_trace.trx_id,date:this.getUTCDate(e.block_time)/1e3,currencyCode:t,blockHeight:e.block_num>0?e.block_num:0,nativeAmount:C,isSend:C.startsWith("-"),networkFee:b,ourReceiveAddresses:N,signedTx:"",otherParams:A,walletId:this.walletId};this.addTransaction(t,H)}if(k===c.BP.transfer&&_.quantity!=null){const[L]=_.quantity.split(" "),H=L.toString();let K=(0,D.cp)(this.currencyInfo,t);if(K==null&&(K=(0,D.cp)(this.currencyInfo,this.currencyInfo.currencyCode),K==null))return this.error(`Received unsupported currencyCode: ${t}`),0;const M=(0,O.mul)(H,K.multiplier);_.to===s?(C=`${M}`,b=`-${M}`):(C=`-${M}`,b=M);const re=this.findTransaction(t,e.action_trace.trx_id);if(re>-1){const oe=this.transactionList[t][re];if(A=j(S(S({},A),oe.otherParams),{data:S(S({},A.data),(d=(r=oe.otherParams)==null?void 0:r.data)!=null?d:{}),meta:S(S({},A.meta),(I=(f=oe.otherParams)==null?void 0:f.meta)!=null?I:{})}),A.meta.isFeeProcessed!=null)return e.block_num;A.meta.isTransferProcessed!=null?_.to!==s?C=(0,O.sub)(oe.nativeAmount,b):b="0":this.error("processTransaction error - existing spend transaction should have isTransferProcessed or isFeeProcessed set")}this.checkUnStakeTx(A)&&this.updateStakingStatus(M,e.block_time,e.action_trace.trx_id,k),A.meta.isFeeProcessed=!0;const Pe={txid:e.action_trace.trx_id,date:this.getUTCDate(e.block_time)/1e3,currencyCode:t,blockHeight:e.block_num>0?e.block_num:0,nativeAmount:C,isSend:C.startsWith("-"),networkFee:b,signedTx:"",ourReceiveAddresses:[],otherParams:A,walletId:this.walletId};this.addTransaction(t,Pe)}return e.block_num}checkTransactions(e=0){return p(this,null,function*(){var s,t,a;if(this.networkInfo.historyNodeUrls[e]==null)return!1;let o=this.otherData.highestTxHeight,l=0;try{const r=yield this.requestHistory(e,{account_name:this.actor,pos:-1},c.pg.getActions);if(((s=r==null?void 0:r.error)==null?void 0:s.noNodeForIndex)!=null)return!1;if(B(r),r.actions.length>0)l=r.actions[r.actions.length-1].account_action_seq;else return!0}catch{return yield this.checkTransactions(++e)}let i=Math.max(0,l-c.eG),n=!1;for(;!n&&!(i<0);){let r;try{if(r=yield this.requestHistory(e,{account_name:this.actor,pos:i,offset:c.eG-1},c.pg.getActions),((t=r.error)==null?void 0:t.noNodeForIndex)!=null)return!1;let d=[];if(((a=r.actions)==null?void 0:a.length)>0)d=r.actions;else break;for(let f=d.length-1;f>-1;f--){const I=d[f];F(I);const k=this.processTransaction(I,this.actor);if(k>o)o=k;else if(k===o&&f===c.eG-1||k<this.otherData.highestTxHeight){n=!0;break}}if(d.length<c.eG)break;i-=c.eG}catch{return yield this.checkTransactions(++e)}}return o>this.otherData.highestTxHeight&&(this.otherData.highestTxHeight=o,this.localDataDirty()),!0})}checkTransactionsInnerLoop(){return p(this,null,function*(){let e;try{e=yield this.checkTransactions()}catch(s){this.error("checkTransactionsInnerLoop fetches failed with error: ",s);return}e&&(this.tokenCheckTransactionsStatus.FIO=1,this.updateOnAddressesChecked()),this.transactionsChangedArray.length>0&&(this.currencyEngineCallbacks.onTransactionsChanged(this.transactionsChangedArray),this.transactionsChangedArray=[])})}requestHistory(e,s,t){return p(this,null,function*(){if(this.networkInfo.historyNodeUrls[e]==null)return{error:{noNodeForIndex:!0}};const a=this.networkInfo.historyNodeUrls[e],o=JSON.stringify(s);return yield(yield fetch(`${a}history/${t}`,{method:"POST",headers:{"Content-Length":(o.length*2).toString(),Accept:"application/json","Content-Type":"application/json"},body:o})).json()})}fioApiRequest(e,s,t,a=!1){return p(this,null,function*(){var o,l,i,n;const r=new T.rn("",this.walletInfo.keys.publicKey,e,this.fetchCors,void 0,this.tpid,a);let d;try{switch(s){case"getChainInfo":d=yield r.transactions.getChainInfo();break;case"getBlock":d=yield r.transactions.getBlock(t);break;case"getObtData":case"getPendingFioRequests":case"getSentFioRequests":{const{endpoint:f,body:I}=t;d=yield r.transactions.executeCall(f,JSON.stringify(I));break}default:d=yield r.genericAction(s,t)}}catch(f){if(f.errorCode!=null&&P.lI.includes(f.errorCode))((i=(l=(o=f.json)==null?void 0:o.fields)==null?void 0:l[0])==null?void 0:i.error)!=null&&(f.message=f.json.fields[0].error),d={isError:!0,data:{code:f.errorCode,message:(n=f.message)!=null?n:(0,D.HY)(f),json:f.json,list:f.list}},f.errorCode!==404&&this.log(`fioApiRequest error. actionName: ${s} - apiUrl: ${e} - message: ${JSON.stringify(f.json)}`);else throw this.log(`fioApiRequest error. actionName: ${s} - apiUrl: ${e} - message: `,f),f}return d})}executePreparedTrx(e,s,t){return p(this,null,function*(){var a,o,l;const i=new T.rn("",this.walletInfo.keys.publicKey,e,this.fetchCors,void 0,this.tpid,!0);let n;this.warn(`executePreparedTrx. preparedTrx: ${JSON.stringify(t)} - apiUrl: ${e}`);try{n=yield i.executePreparedTrx(s,t),this.warn(`executePreparedTrx. res: ${JSON.stringify(n)} - apiUrl: ${e} - endpoint: ${s}`)}catch(r){throw r.errorCode!=null&&P.lI.includes(r.errorCode)?(this.log(`executePreparedTrx error. requestParams: ${JSON.stringify(t)} - apiUrl: ${e} - endpoint: ${s} - message: ${JSON.stringify(r.json)}`),((l=(o=(a=r.json)==null?void 0:a.fields)==null?void 0:o[0])==null?void 0:l.error)!=null&&(r.message=r.json.fields[0].error),r):(this.log(`executePreparedTrx error. requestParams: ${JSON.stringify(t)} - apiUrl: ${e} - endpoint: ${s} - message: `,r),r)}return n})}multicastServers(e,s){return p(this,null,function*(){var t,a,o,l,i;let n;if(c.K1[e]){const r=(0,u.h0)(s);if(this.warn(`multicastServers executePreparedTrx. actionName: ${e} - res: ${JSON.stringify(r)}`),n=yield(0,D.Wp)((0,D.Sy)(this.networkInfo.apiUrls.map(d=>p(this,null,function*(){return yield this.executePreparedTrx(d,R.EndPoint[c.VW[e]],r)})))),this.warn(`multicastServers res. actionName: ${e} - res: ${JSON.stringify(n)}`),n==null)throw new Error("Service is unavailable")}else e==="getFioNames"?(n=yield(0,D.ml)(this.networkInfo.apiUrls.map(r=>p(this,null,function*(){return yield(0,D.Vs)(this.fioApiRequest(r,e,s),1e4)})),r=>{const d=(0,u.$K)(c.Mi)(r);return d!=null?d.data.json.message:(0,u.e1)(r)},2),((a=(t=n==null?void 0:n.data)==null?void 0:t.json)==null?void 0:a.message)===c.Mi&&(n={fio_domains:[],fio_addresses:[]})):e==="getFioBalance"?(n=yield(0,D.ml)(this.networkInfo.apiUrls.map(r=>p(this,null,function*(){return yield(0,D.Vs)(this.fioApiRequest(r,e,s),1e4)})),r=>{const d=(0,u.$K)(c.d9)(r);return d!=null?d.data.json.message:(0,u.sq)(r)},2),((l=(o=n==null?void 0:n.data)==null?void 0:o.json)==null?void 0:l.message)===c.d9&&(n={balance:0,available:0,staked:0,srps:0,roe:""})):e==="getFees"?n=yield(0,D.QJ)((0,D.Sy)(this.networkInfo.apiUrls.map(r=>()=>p(this,null,function*(){const d=new T.rn("",this.walletInfo.keys.publicKey,r,this.fetchCors,void 0,this.tpid),{endpoint:f,param:I}=s,k=yield d.getFee(f,I);return(0,u.lZ)(k).fee.toString()})))):n=yield(0,D.QJ)((0,D.Sy)(this.networkInfo.apiUrls.map(r=>()=>p(this,null,function*(){return yield this.fioApiRequest(r,e,s)}))));if(n.isError!=null){const r=new P.OU((i=n.errorMessage)!=null?i:n.data.message);throw r.json=n.data.json,r.list=n.data.list,r.errorCode=n.data.code,r}return n})}checkAccountInnerLoop(){return p(this,null,function*(){const e=this.currencyInfo.currencyCode,s=this.networkInfo.balanceCurrencyCodes;typeof this.walletLocalData.totalBalances[e]>"u"&&this.updateBalance(e,"0");try{const t={staked:"0",locked:"0"},{balance:a,available:o,staked:l,srps:i,roe:n}=J(yield this.multicastServers("getFioBalance")),r=String(a);t.staked=String(l),t.locked=(0,O.sub)(r,String(o)),this.otherData.srps=i,this.otherData.stakingRoe=n,this.updateBalance(e,r),this.updateBalance(s.staked,t.staked),this.updateBalance(s.locked,t.locked)}catch(t){this.log.warn("checkAccountInnerLoop getFioBalance error: ",t)}try{const t=x(yield this.multicastServers("getFioNames",{fioPublicKey:this.walletInfo.keys.publicKey}));let a=!1,o=!1,l=!1;if(t.fio_addresses.length!==this.otherData.fioAddresses.length)o=!0;else{for(const i of t.fio_addresses){const n=this.otherData.fioAddresses.find(r=>r.name===i.fio_address);if(n!=null){if(n.bundledTxs!==i.remaining_bundled_tx){o=!0;break}}else{o=!0;break}}if(!o){for(const i of this.otherData.fioAddresses)if(t.fio_addresses.findIndex(n=>n.fio_address===i.name)<0){o=!0;break}}}if(t.fio_domains.length!==this.otherData.fioDomains.length)l=!0;else{for(const i of t.fio_domains){const n=this.otherData.fioDomains.find(r=>r.name===i.fio_domain);if(n!=null){if(n.expiration!==i.expiration){l=!0;break}if(n.isPublic!==(i.is_public===1)){l=!0;break}}else{l=!0;break}}if(!l){for(const i of this.otherData.fioDomains)if(t.fio_domains.findIndex(n=>n.fio_domain===i.name)<0){l=!0;break}}}o&&(a=!0,this.otherData.fioAddresses=t.fio_addresses.map(i=>({name:i.fio_address,bundledTxs:i.remaining_bundled_tx}))),l&&(a=!0,this.otherData.fioDomains=t.fio_domains.map(i=>({name:i.fio_domain,expiration:i.expiration,isPublic:i.is_public===1}))),a&&this.localDataDirty()}catch(t){this.warn("checkAccountInnerLoop getFioNames error: ",t)}})}fetchEncryptedFioRequests(e,s){return p(this,null,function*(){const a=e==="PENDING"?"getPendingFioRequests":"getSentFioRequests";let o=100,l=1;const i=[];for(;o===100;)try{const n=yield this.multicastServers(a,{endpoint:s.getEndPoint(),body:{fio_public_key:this.walletInfo.keys.publicKey,limit:100,offset:(l-1)*100}}),r=(0,u.S_)(n),{requests:d,more:f}=r;if(i.push(...d),f===0)break;l++,o=d.length}catch(n){const r=(0,h.Vk)(u.Pq)(n.json);(r==null?void 0:r.message)!=="No FIO Requests"&&this.error("fetchEncryptedFioRequests error: ",n);break}return i})}fetchEncryptedObtData(e,s){return p(this,null,function*(){let a=100,o=1;const l=[];for(;a===100;){let i;try{i=yield this.multicastServers(e,{endpoint:s.getEndPoint(),body:{fio_public_key:this.walletInfo.keys.publicKey,limit:100,offset:(o-1)*100}});const n=(0,u._v)(i),{obt_data_records:r,more:d}=n;if(l.push(...r),d===0)break;o++,a=r.length}catch(n){const r=(0,h.Vk)(u.Pq)(n.json);(r==null?void 0:r.message)!=="No FIO Requests"&&this.error("fetchEncryptedObtData error: ",n);break}}return l})}syncNetwork(e){return p(this,null,function*(){var s;const t=(0,u.UW)(e==null?void 0:e.privateKeys);let a=!1;const o=(r,d)=>p(this,null,function*(){var f;const I=yield this.fetchEncryptedFioRequests(r,d);d.privateKey=t.fioKey,d.publicKey=this.walletInfo.keys.publicKey;const k=(f=d.decrypt({requests:I}))!=null?f:{requests:[]};this.fioRequestsListChanged(this.otherData.fioRequests[r],k.requests)&&(this.otherData.fioRequests[r]=[...k.requests],a=!0)});yield o("PENDING",new G.PendingFioRequests(this.walletInfo.keys.publicKey)),yield o("SENT",new G.SentFioRequests(this.walletInfo.keys.publicKey)),a&&this.localDataDirty();const l=new G.GetObtData(this.walletInfo.keys.publicKey),i=yield this.fetchEncryptedObtData("getObtData",l);l.privateKey=t.fioKey,l.publicKey=this.walletInfo.keys.publicKey;const n=(s=l.decrypt({obt_data_records:i}))!=null?s:{obt_data_records:[]};return this.obtData=n.obt_data_records,we})}getFee(e,s){return p(this,null,function*(){let t=this.fees.get(e);if(t==null||t.expiration+30*1e3<Date.now()){const o={fee:yield this.multicastServers("getFees",{endpoint:e,param:s}),expiration:Date.now()};this.fees.set(e,o),t=o}return t.fee})}startEngine(){return p(this,null,function*(){this.engineOn=!0,this.addToLoop("checkBlockchainInnerLoop",_e).catch(()=>{}),this.addToLoop("checkAccountInnerLoop",ge).catch(()=>{}),this.addToLoop("checkTransactionsInnerLoop",ke).catch(()=>{}),yield le(Z.prototype,this,"startEngine").call(this)})}resyncBlockchain(){return p(this,null,function*(){yield this.killEngine(),yield this.clearBlockchainCache(),yield this.startEngine()})}getMaxSpendable(e){return p(this,null,function*(){var s;const t=this.getBalance({currencyCode:e.currencyCode}),a=(s=this.walletLocalData.totalBalances[this.networkInfo.balanceCurrencyCodes.locked])!=null?s:"0";e.spendTargets[0].nativeAmount="1";const o=yield this.makeSpend(e),l=(0,O.sub)((0,O.sub)(t,o.networkFee),a);if((0,O.lt)(l,"0"))throw new z.C_({networkFee:o.networkFee});return l})}makeSpend(e){return p(this,null,function*(){var s,t;const{edgeSpendInfo:a,nativeBalance:o,currencyCode:l}=this.makeSpendCheck(e),i=(s=this.walletLocalData.totalBalances[this.networkInfo.balanceCurrencyCodes.locked])!=null?s:"0",n=(0,O.sub)(o,i),r=a.spendTargets[0],{publicAddress:d}=r,{nativeAmount:f}=r;if(d==null)throw new Error("makeSpend Missing publicAddress");if(f==null)throw new z.$D;let{otherParams:I}=a;(I==null||Object.keys(I).length===0)&&(I={action:{name:c.aO.transferTokens,params:{payeeFioPublicKey:d,amount:f,maxFee:0}}});const{name:k,params:_}=(0,u.iR)(I.action);let y,E;switch(k){case c.aO.transferTokens:{y=yield this.getFee(R.EndPoint.transferTokens),E={account:"fio.token",action:c.BP[c.aO.transferTokens],data:{payee_public_key:d,amount:f,max_fee:y}};break}case c.aO.stakeFioTokens:{const{fioAddress:m}=(0,u.NB)(_);y=yield this.getFee(R.EndPoint.stakeFioTokens,m),E={account:"fio.staking",action:c.BP[k],data:{amount:f,fio_address:m,actor:this.actor,max_fee:y}};break}case c.aO.unStakeFioTokens:{const{fioAddress:m}=(0,u.NB)(_);y=yield this.getFee(R.EndPoint.unStakeFioTokens,m),E={account:"fio.staking",action:c.BP[k],data:{amount:f,fio_address:m,actor:this.actor,max_fee:y}};const b=this.getUnlockDate(new Date),A=(t=this.walletLocalData.totalBalances[this.networkInfo.balanceCurrencyCodes.staked])!=null?t:"0";if((0,O.gt)(f,A)||(0,O.gt)(`${y}`,n))throw new z.C_;const N=(0,O.mul)((0,O.mul)((0,O.div)(f,A,18),`${this.otherData.srps}`),this.otherData.stakingRoe),L=(0,O.max)((0,O.sub)(N,f),"0");I.ui={accrued:N,estReward:L,unlockDate:b};break}case c.aO.transferFioAddress:{const{fioAddress:m}=(0,u.NB)(_);y=yield this.getFee(R.EndPoint.transferFioAddress,m),E={account:"fio.address",action:"xferaddress",data:{fio_address:m,new_owner_fio_public_key:d,actor:this.actor,max_fee:y}};break}case c.aO.transferFioDomain:{const{fioDomain:m}=(0,u.L2)(_);y=yield this.getFee(R.EndPoint.transferFioDomain),E={account:"fio.address",action:"xferdomain",data:{fio_domain:m,new_owner_fio_public_key:d,actor:this.actor,max_fee:y}};break}case c.aO.addPublicAddresses:{const{fioAddress:m,publicAddresses:b}=(0,u.PH)(_);y=yield this.getFee(R.EndPoint.addPubAddress,m),E={account:"fio.address",action:"addaddress",data:{fio_address:m,public_addresses:b,actor:this.actor,max_fee:y}};break}case c.aO.removePublicAddresses:{const{fioAddress:m,publicAddresses:b}=(0,u.PH)(_);y=yield this.getFee(R.EndPoint.removePubAddress,m),E={account:"fio.address",action:"remaddress",data:{fio_address:m,public_addresses:b,actor:this.actor,max_fee:y}};break}case c.aO.registerFioAddress:{const{fioAddress:m}=(0,u.NB)(_);y=yield this.getFee(R.EndPoint.registerFioAddress),E={account:"fio.address",action:"regaddress",data:{fio_address:m,owner_fio_public_key:this.walletInfo.keys.publicKey,max_fee:y,actor:this.actor}};break}case c.aO.registerFioDomain:{const{fioDomain:m}=(0,u.AJ)(_);y=yield this.getFee(R.EndPoint.registerFioDomain),E={account:"fio.address",action:"regdomain",data:{fio_domain:m,owner_fio_public_key:this.walletInfo.keys.publicKey,max_fee:y,actor:this.actor}};break}case c.aO.renewFioDomain:{const{fioDomain:m}=(0,u.AJ)(_);y=yield this.getFee(R.EndPoint.renewFioDomain),E={account:"fio.address",action:"renewdomain",data:{fio_domain:m,max_fee:y,actor:this.actor}};break}case c.aO.addBundledTransactions:{const{bundleSets:m,fioAddress:b}=(0,u.Ej)(_);y=yield this.getFee(R.EndPoint.addBundledTransactions,b),E={account:"fio.address",action:"addbundles",data:{fio_address:b,bundle_sets:m,actor:this.actor,max_fee:y}};break}case c.aO.setFioDomainPublic:{const{fioDomain:m,isPublic:b}=(0,u.oY)(_);y=yield this.getFee(R.EndPoint.setFioDomainPublic),E={account:"fio.address",action:"setdomainpub",data:{fio_domain:m,is_public:b?1:0,max_fee:y,actor:this.actor}};break}case c.aO.rejectFundsRequest:{const{fioRequestId:m,payerFioAddress:b}=(0,u.OR)(_);y=yield this.getFee(R.EndPoint.rejectFundsRequest,b),E={account:"fio.reqobt",action:"rejectfndreq",data:{fio_request_id:m,max_fee:y,actor:this.actor}};break}case c.aO.cancelFundsRequest:{const{fioAddress:m,fioRequestId:b}=(0,u.mO)(_);y=yield this.getFee(R.EndPoint.cancelFundsRequest,m),E={account:"fio.reqobt",action:"cancelfndreq",data:{fio_request_id:b,max_fee:y,actor:this.actor}};break}case c.aO.recordObtData:{const{payerFioAddress:m}=(0,u.XB)(_);y=yield this.getFee(R.EndPoint.recordObtData,m);break}case c.aO.requestFunds:{const{payeeFioAddress:m}=(0,u.Vd)(_);y=yield this.getFee(R.EndPoint.newFundsRequest,m);break}default:throw new Error("Unrecognized FIO action")}return{txid:"",date:0,currencyCode:l,blockHeight:0,nativeAmount:(0,O.sub)(`-${f}`,`${y}`),isSend:!0,networkFee:`${y}`,ourReceiveAddresses:[],signedTx:"",otherParams:j(S({},I),{txParams:E}),walletId:this.walletId}})}signTx(e,s){return p(this,null,function*(){const t=(0,u.UW)(s),a=(0,D.Xp)(e);let o=(0,h.Vk)(u.B3)(a.txParams);const l=new ae.Transactions;if(o==null){const{name:f,params:I}=(0,u.iR)(a.action),{networkFee:k}=e;switch(f){case c.aO.recordObtData:{const{payerFioAddress:_,payeeFioAddress:y,payerPublicAddress:E,payeePublicAddress:C,amount:m,tokenCode:b,chainCode:A,obtId:N,memo:L,status:H,fioRequestId:K}=(0,u.XB)(I),M={payer_public_address:E,payee_public_address:C,amount:m,chain_code:A,token_code:b,status:H,obt_id:N,memo:L,hash:void 0,offline_url:void 0},re=l.getCipherContent("record_obt_data_content",M,t.fioKey,E);o={account:"fio.reqobt",action:"recordobt",data:{payer_fio_address:_,payee_fio_address:y,content:re,fio_request_id:K,max_fee:k,actor:this.actor}};break}case c.aO.requestFunds:{const{payerFioAddress:_,payerFioPublicKey:y,payeeFioAddress:E,payeeTokenPublicAddress:C,amount:m,chainCode:b,tokenCode:A,memo:N}=(0,u.Vd)(I),L={payee_public_address:C,amount:m,chain_code:b,token_code:A,memo:N,hash:void 0,offline_url:void 0},H=l.getCipherContent("new_funds_content",L,t.fioKey,y);o={account:"fio.reqobt",action:"newfundsreq",data:{payer_fio_address:_,payee_fio_address:E,content:H,max_fee:k,actor:this.actor}};break}default:throw new Error("Unknown FIO action")}}const i=yield l.createRawTransaction({action:o.action,account:o.account,data:j(S({},o.data),{tpid:this.tpid}),publicKey:this.walletInfo.keys.publicKey,chainData:this.refBlock}),{serializedContextFreeData:n,serializedTransaction:r}=yield l.serialize({chainId:this.networkInfo.chainId,transaction:i}),d=yield l.sign({chainId:this.networkInfo.chainId,privateKeys:[t.fioKey],transaction:i,serializedTransaction:r,serializedContextFreeData:n});return e.otherParams=j(S({},e.otherParams),{signedTx:d}),e})}broadcastTx(e){return p(this,null,function*(){var s;const t=(0,D.Xp)(e);if(((s=t.action)==null?void 0:s.name)==null)throw new Error('Action is not set, "action" prop of otherParams is required for FIO actions');const a=(0,u.h0)(t.signedTx),o=(0,u.Yd)(yield this.multicastServers(t.action.name,a));e.metadata={notes:o.transaction_id},e.txid=o.transaction_id,e.date=Date.now()/1e3,e.blockHeight=o.block_num,this.warn(`SUCCESS broadcastTx
|
|
2
|
+
${(0,D.oX)(e)}`);const l=o,{block_num:i,block_time:n,transaction_id:r}=l,d=pe(l,["block_num","block_time","transaction_id"]);return e.otherParams=j(S({},t),{broadcastResult:d}),e})}saveTx(e){return p(this,null,function*(){var s;const t=(0,D.Xp)(e),{broadcastResult:a={},action:o}=t,{name:l,params:i}=(0,u.iR)(o);try{switch(l){case c.aO.transferFioDomain:{const n=this.otherData.fioDomains.findIndex(({name:r})=>r===i.fioDomain);n>=0&&(this.otherData.fioDomains.splice(n,1),this.localDataDirty());break}case c.aO.transferFioAddress:{const n=this.otherData.fioAddresses.findIndex(({name:r})=>r===i.fioAddress);n>=0&&(this.otherData.fioAddresses.splice(n,1),this.localDataDirty());break}case c.aO.registerFioAddress:{const{fioAddress:n}=(0,u.NB)(i);this.otherData.fioAddresses.find(({name:d})=>d===n)==null&&(this.otherData.fioAddresses.push({name:n,bundledTxs:void 0}),this.localDataDirty());break}case c.aO.registerFioDomain:{const{fioDomain:n}=(0,u.AJ)(i);if(a.expiration==null)throw new Error("expiration not present");const r=this.otherData.fioDomains.find(({name:d})=>d===n);r!=null&&(r.expiration=a.expiration,this.localDataDirty());break}case c.aO.renewFioDomain:{const{fioDomain:n}=(0,u.AJ)(i);if(a.expiration==null)throw new Error("expiration not present");const r=this.otherData.fioDomains.find(({name:d})=>d===n);r!=null&&(r.expiration=a.expiration,this.localDataDirty());break}case c.aO.addBundledTransactions:{const{fioAddress:n}=(0,u.Ej)(i),r=this.otherData.fioAddresses.find(({name:d})=>d===n);if(r==null)throw new P.OU("Fio Address is not found in engine");r.bundledTxs=((s=r.bundledTxs)!=null?s:0)+c.BB,this.localDataDirty();break}case c.aO.rejectFundsRequest:{const{fioRequestId:n}=(0,u.OR)(i);typeof n=="string"&&(this.removeFioRequest(n,"PENDING"),this.localDataDirty());break}case c.aO.cancelFundsRequest:{const{fioRequestId:n}=(0,u.mO)(i);typeof n=="string"&&(this.removeFioRequest(n,"SENT"),this.localDataDirty());break}case c.aO.recordObtData:{const{fioRequestId:n}=(0,u.XB)(i);n!=null&&a.status==="sent_to_blockchain"&&(this.removeFioRequest(n,"PENDING"),this.localDataDirty());break}}}catch(n){this.log.warn(`Error attempting post-broadcast action ${l}:`,n)}yield le(Z.prototype,this,"saveTx").call(this,e)})}getFreshAddress(e){return p(this,null,function*(){return{publicAddress:this.walletInfo.keys.publicKey}})}getDisplayPrivateSeed(e){return(0,u.UW)(e).fioKey}getDisplayPublicSeed(){return this.walletInfo.keys.publicKey}}function De(g,e,s,t){return p(this,null,function*(){const{tpid:a="finance@edge"}=g.initOptions,o=(0,u.RB)(s),l=new Z(g,e,o,t,a);return yield l.loadEngine(e,o,t),l})}var ve=w(48764).Buffer,q=(g,e,s)=>new Promise((t,a)=>{var o=n=>{try{i(s.next(n))}catch(r){a(r)}},l=n=>{try{i(s.throw(n))}catch(r){a(r)}},i=n=>n.done?t(n.value):Promise.resolve(n.value).then(o,l);i((s=s.apply(g,e)).next())});const ce="FIO",de="fio",Ie="";function ue(g){const e=g.startsWith(ce),s=g.length===53;return e&&s}class me{constructor(e){const{builtinTokens:s,currencyInfo:t,initOptions:a,io:o,networkInfo:l}=e;this.builtinTokens=s,this.currencyInfo=t,this.io=o,this.networkInfo=l;const{tpid:i="finance@edge",fioRegApiToken:n=Ie}=a;this.fetchCors=(0,D.zR)(e),this.fioRegApiToken=n,this.tpid=i;for(const r of this.networkInfo.apiUrls)new T.rn("","",r,this.fetchCors,void 0,i)}importPrivateKey(e){return q(this,null,function*(){const{pluginId:s}=this.currencyInfo,t={};if(/[0-9a-zA-Z]{51}$/.test(e))he._q.fromString(e),t.fioKey=e;else{if(!(0,ie.validateMnemonic)(e))throw new Error("Invalid input");const o=yield T.rn.createPrivateKeyMnemonic(e);t.fioKey=o.fioKey,t.mnemonic=o.mnemonic}const a=yield this.derivePublicKey({type:`wallet:${s}`,id:"fake",keys:t});return t.publicKey=a.publicKey,t})}createPrivateKey(e){return q(this,null,function*(){if(e.replace("wallet:","")===de){const t=ve.from(this.io.random(32));return yield T.rn.createPrivateKey(t)}else throw new Error("InvalidWalletType")})}derivePublicKey(e){return q(this,null,function*(){if(e.type.replace("wallet:","")===de)return T.rn.derivedPublicKey(e.keys.fioKey);throw new Error("InvalidWalletType")})}parseUri(e){return q(this,null,function*(){var s;const{edgeParsedUri:t}=(0,ee.k)(te.j,e,{fio:!0},ce);if(!ue((s=t.publicAddress)!=null?s:""))throw new Error("InvalidPublicAddressError");return t})}encodeUri(e){return q(this,null,function*(){if(!ue(e.publicAddress))throw new Error("InvalidPublicAddressError");let t;if(typeof e.nativeAmount=="string"){const o=ce,l=e.nativeAmount,i=(0,D.cp)(te.j,o);if(i==null)throw new Error("InternalErrorInvalidCurrencyCode");t=(0,O.div)(l,i.multiplier,16)}return(0,ee.Q)(e,de,t)})}getConnectedPublicAddress(e,s,t){return q(this,null,function*(){var a;try{T.rn.isFioAddressValid(e)}catch{throw new P.OU("",400,this.networkInfo.errorCodes.INVALID_FIO_ADDRESS)}try{if((yield this.multicastServers("isAvailable",{fioName:e})).is_registered===0)throw new P.OU("",404,this.networkInfo.errorCodes.FIO_ADDRESS_IS_NOT_EXIST)}catch(o){throw o.name==="FioError"&&((a=o.json)==null?void 0:a.fields)!=null&&o.errorCode===400&&(o.labelCode=this.networkInfo.errorCodes.INVALID_FIO_ADDRESS),o}try{const o=yield this.multicastServers("getPublicAddress",{fioAddress:e,chainCode:s,tokenCode:t});if(o.public_address==null||o.public_address==="0")throw new P.OU("",404,this.networkInfo.errorCodes.FIO_ADDRESS_IS_NOT_LINKED);return o}catch(o){throw o.name==="FioError"&&o.labelCode===this.networkInfo.errorCodes.FIO_ADDRESS_IS_NOT_LINKED||o.errorCode===404?new P.OU("",404,this.networkInfo.errorCodes.FIO_ADDRESS_IS_NOT_LINKED):o}})}isFioAddressValid(e){return q(this,null,function*(){try{return T.rn.isFioAddressValid(e)}catch{return!1}})}validateAccount(e,s=!1){return q(this,null,function*(){var t;try{if(s){if(!T.rn.isFioDomainValid(e))return!1}else if(!T.rn.isFioAddressValid(e))return!1}catch{throw new P.OU("",400,this.networkInfo.errorCodes.INVALID_FIO_ADDRESS)}try{return(yield this.multicastServers("isAvailable",{fioName:e})).is_registered===0}catch(a){throw a.name==="FioError"&&((t=a.json)==null?void 0:t.fields)!=null&&a.errorCode===400&&(a.labelCode=this.networkInfo.errorCodes.INVALID_FIO_ADDRESS),a}})}isDomainPublic(e){return q(this,null,function*(){if((yield this.multicastServers("isAvailable",{fioName:e})).is_registered===0)throw new P.OU("",400,this.networkInfo.errorCodes.FIO_DOMAIN_IS_NOT_EXIST);const t=yield this.fetchCors(`${this.networkInfo.fioRegApiUrl}${c.n3.isDomainPublic}/${e}`,{method:"GET"});if(!t.ok){const o=yield t.json();throw new P.OU("",t.status,this.networkInfo.errorCodes.IS_DOMAIN_PUBLIC_ERROR,o)}const{isPublic:a}=yield t.json();return a})}doesAccountExist(e){return q(this,null,function*(){try{if(!T.rn.isFioAddressValid(e))return!1}catch{return!1}try{return(yield this.multicastServers("isAvailable",{fioName:e})).is_registered===1}catch(s){return this.error("doesAccountExist error: ",s),!1}})}buyAddressRequest(e,s=!1){return q(this,null,function*(){const t={Accept:"application/json","Content-Type":"application/json"};s&&(e.apiToken=this.fioRegApiToken);try{const a=yield this.fetchCors(`${this.networkInfo.fioRegApiUrl}${c.n3.buyAddress}`,{method:"POST",headers:t,body:JSON.stringify(e)});if(!a.ok){const o=yield a.json();throw this.networkInfo.errorCodes[o.errorCode]!=null?new P.OU(o.error,a.status,this.networkInfo.errorCodes[o.errorCode],o):o.error==="Already registered"?new P.OU(o.error,a.status,this.networkInfo.errorCodes.ALREADY_REGISTERED,o):new Error(o.error)}return yield a.json()}catch(a){throw a.labelCode!=null?a:new P.OU((0,D.HY)(a),500,this.networkInfo.errorCodes.SERVER_ERROR)}})}getDomains(e=""){return q(this,null,function*(){e==null&&(e=this.networkInfo.defaultRef);try{const s=yield this.fetchCors(`${this.networkInfo.fioRegApiUrl}${c.n3.getDomains}/${e}`,{method:"GET"}),t=yield s.json();if(!s.ok)throw this.networkInfo.errorCodes[t.errorCode]!=null?new P.OU(t.error,s.status,this.networkInfo.errorCodes[t.errorCode],t):new Error(t.error);return t.domains}catch(s){throw s.labelCode!=null?s:new P.OU((0,D.HY)(s),500,this.networkInfo.errorCodes.SERVER_ERROR)}})}getStakeEstReturn(){return q(this,null,function*(){try{const e=yield this.fetchCors(`${this.networkInfo.fioStakingApyUrl}`,{method:"GET"}),s=yield e.json();if(!e.ok)throw new Error(this.networkInfo.errorCodes.SERVER_ERROR);const t=s.historical_apr["7day"];return t!=null&&t>c.OT||t==null?c.OT:t}catch(e){throw e.labelCode!=null?e:new P.OU(e.message,500,this.networkInfo.errorCodes.SERVER_ERROR)}})}multicastServers(e,s){return q(this,null,function*(){const t=yield(0,D.QJ)((0,D.Sy)(this.networkInfo.apiUrls.map(a=>()=>q(this,null,function*(){let o;const l=new T.rn("","",a,this.fetchCors,void 0,this.tpid);try{o=yield l.genericAction(e,s)}catch(i){if(i.errorCode!=null&&P.lI.includes(i.errorCode))o={isError:!0,data:{code:i.errorCode,message:(0,D.HY)(i),json:i.json,list:i.list}};else throw i}return o}))));if(t.isError!=null){const a=new P.OU(t.errorMessage);throw a.json=t.data.json,a.list=t.data.list,a.errorCode=t.data.code,a}return t})}}function Ae(g){return q(this,null,function*(){return new me(g)})}},89214:function(){},52361:function(){},94616:function(){}}]);
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"network": "main",
|
|
3
|
+
"height": "2420000",
|
|
4
|
+
"hash": "0000000082cc3f256c36696a7734e8c14fcdf49e95017cddc2ae46d19f3493ca",
|
|
5
|
+
"time": 1685459957,
|
|
6
|
+
"tree": "012e381bfcb8045443e61402d85b97729e03f66f0cf0259e38f717da8a190d9a5600160000015f3d80555467f8e376f6be779c216e12a1cb2f0d416d92fe33bd776c779b2648019b930f5395098a9b71eef40103fecae29f26298e9c9f90d615f4bc8a237c9b2501ca23f5335802969abcd06850453058d36bca474a230c951039c0a150193f68560001b3fb4695c07d9dc0f4297d61e844b9a513033b5eb8964c31a77fe116e1cab80e015f53666b68301327ee151ace90ca93539068532c20e51cda519e5881ca03f96200000001c21b88de5a0d19c04c26a7787749850ab0e4fed658379f38a804e9ecaeb21c100162a77e99925231fd51c1490fc0faccd88a3a3ecba4ab2deb45f25390a4df2048016f075f2c6bb2339864bc9f9ffba8fc4e4677dfe5d29f1017ba00f504e5afd064015d24e09ef39e2fc42889dadc9ea94d627b2095a61c49a6d4b3457af1466a234401dd905dcb9771a3f6335a20631deebb05b1476ed4e20c44e666d0e4f648c0df1b000160572a707445e6b455ce8424754846cf8ecff73c2c54b1516ac056e6d3f7f46b0142cecf7947fc45e642b8a7037cafa8aea7b0eea399004201661f75bdfcbffe0f00000142380298196ed6f9abece6970296f762f7b2d6a367ca7df2b3e201aa10ed090f"
|
|
7
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"network": "main",
|
|
3
|
+
"height": "2100000",
|
|
4
|
+
"hash": "0000000001a0310259c41131eb341342d005abd482f63fa346fe385f9e0089f2",
|
|
5
|
+
"time": 1685142064,
|
|
6
|
+
"tree": "01eb398020830573835ea2cb8ed7012bedf16ba55fee9e54c824ab4d33f2d90c60019ec77624a47bb8ea10d3a5d9e616d0a29ca86008b5979dcd52803585cb9212521a0001f5d9e81fb57bb180a6b5cf134976a98f35fda4307a85be6f68ceb217a85d7067017bd411c9a5580d1e38ce6f5e6576501a65352ddfa9b026ed46ef9ce2c4b39d620000019298a730a41cb62d45ea4d785dc3c4959088ff9502e1a571c452d6d466786e53000001cb78937db4b5dc5e5e1064af6bcf513b8b625c7b9c89b460c26b41013dd2bd1e0129ddc4039df05fe8f7e963ac19855ac7620baf9bb648674730dab259ba0d156f00012014bb08a44ed8a24a22753e0c9eff193bbb571d0a9e2082e5f48b18a5970310000001671883df514f0a1e5e600828c3993a7a9293459f51ff212ef1b91aa2de2e522c00000001e1c882101803f4307fef0296028169358d583e3c2f95e37973aa8078e3f5550a0000011619f99023a69bb647eab2d2aa1a73c3673c74bb033c3c4930eacda19e6fd93b0000000160272b134ca494b602137d89e528c751c06d3ef4a87a45f33af343c15060cc1e"
|
|
7
|
+
}
|
package/lib/fio/FioEngine.js
CHANGED
|
@@ -1339,14 +1339,10 @@ const SYNC_NETWORK_INTERVAL = 10000
|
|
|
1339
1339
|
currencyCode: spendInfo.currencyCode
|
|
1340
1340
|
})
|
|
1341
1341
|
|
|
1342
|
-
const
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
if (new Date(_nullishCoalesce(status.unlockDate, () => ( 0))) > new Date()) {
|
|
1347
|
-
lockedAmount = _biggystring.add.call(void 0, lockedAmount, status.nativeAmount)
|
|
1348
|
-
}
|
|
1349
|
-
}
|
|
1342
|
+
const lockedAmount =
|
|
1343
|
+
_nullishCoalesce(this.walletLocalData.totalBalances[
|
|
1344
|
+
this.networkInfo.balanceCurrencyCodes.locked
|
|
1345
|
+
], () => ( '0'))
|
|
1350
1346
|
|
|
1351
1347
|
spendInfo.spendTargets[0].nativeAmount = '1'
|
|
1352
1348
|
const edgeTx = await this.makeSpend(spendInfo)
|
|
@@ -1443,10 +1439,7 @@ const SYNC_NETWORK_INTERVAL = 10000
|
|
|
1443
1439
|
_nullishCoalesce(this.walletLocalData.totalBalances[
|
|
1444
1440
|
this.networkInfo.balanceCurrencyCodes.staked
|
|
1445
1441
|
], () => ( '0'))
|
|
1446
|
-
if (
|
|
1447
|
-
_biggystring.gt.call(void 0, quantity, stakedBalance) ||
|
|
1448
|
-
_biggystring.gt.call(void 0, _biggystring.add.call(void 0, quantity, `${fee}`), availableBalance)
|
|
1449
|
-
) {
|
|
1442
|
+
if (_biggystring.gt.call(void 0, quantity, stakedBalance) || _biggystring.gt.call(void 0, `${fee}`, availableBalance)) {
|
|
1450
1443
|
throw new (0, _types.InsufficientFundsError)()
|
|
1451
1444
|
}
|
|
1452
1445
|
|