edge-currency-accountbased 3.2.8 → 3.3.0

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.
Files changed (64) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/android/src/main/assets/edge-currency-accountbased/4843.chunk.js +1 -1
  3. package/android/src/main/assets/edge-currency-accountbased/5336.chunk.js +2 -2
  4. package/android/src/main/assets/edge-currency-accountbased/7428.chunk.js +2 -2
  5. package/android/src/main/assets/edge-currency-accountbased/algorand.chunk.js +2 -2
  6. package/android/src/main/assets/edge-currency-accountbased/axelar.chunk.js +2 -2
  7. package/android/src/main/assets/edge-currency-accountbased/bnb.chunk.js +2 -2
  8. package/android/src/main/assets/edge-currency-accountbased/edge-currency-accountbased.js +2 -2
  9. package/android/src/main/assets/edge-currency-accountbased/eos.chunk.js +7 -7
  10. package/android/src/main/assets/edge-currency-accountbased/ethereum.chunk.js +6 -6
  11. package/android/src/main/assets/edge-currency-accountbased/filecoin.chunk.js +1 -1
  12. package/android/src/main/assets/edge-currency-accountbased/fio.chunk.js +2 -2
  13. package/android/src/main/assets/edge-currency-accountbased/hedera.chunk.js +1 -1
  14. package/android/src/main/assets/edge-currency-accountbased/polkadot.chunk.js +2 -2
  15. package/android/src/main/assets/edge-currency-accountbased/ripple.chunk.js +5 -5
  16. package/android/src/main/assets/edge-currency-accountbased/solana.chunk.js +1 -1
  17. package/android/src/main/assets/edge-currency-accountbased/stellar.chunk.js +1 -1
  18. package/android/src/main/assets/edge-currency-accountbased/tezos.chunk.js +1 -1
  19. package/android/src/main/assets/edge-currency-accountbased/tron.chunk.js +1 -1
  20. package/android/src/main/assets/edge-currency-accountbased/zcash.chunk.js +3 -3
  21. package/lib/algorand/AlgorandEngine.js +7 -1
  22. package/lib/binance/BinanceEngine.js +2 -0
  23. package/lib/common/CurrencyEngine.js +1 -0
  24. package/lib/cosmos/CosmosEngine.js +5 -2
  25. package/lib/eos/EosEngine.js +32 -8
  26. package/lib/ethereum/EthereumEngine.js +2 -1
  27. package/lib/ethereum/EthereumNetwork.js +0 -97
  28. package/lib/ethereum/ethereumTypes.js +0 -32
  29. package/lib/ethereum/info/arbitrumInfo.js +0 -1
  30. package/lib/ethereum/info/avalancheInfo.js +0 -1
  31. package/lib/ethereum/info/baseInfo.js +0 -1
  32. package/lib/ethereum/info/binancesmartchainInfo.js +0 -1
  33. package/lib/ethereum/info/celoInfo.js +0 -1
  34. package/lib/ethereum/info/ethDevInfo.js +0 -5
  35. package/lib/ethereum/info/ethereumInfo.js +0 -5
  36. package/lib/ethereum/info/ethereumclassicInfo.js +0 -1
  37. package/lib/ethereum/info/ethereumpowInfo.js +0 -1
  38. package/lib/ethereum/info/fantomInfo.js +0 -1
  39. package/lib/ethereum/info/filecoinFevmCalibrationInfo.js +0 -1
  40. package/lib/ethereum/info/filecoinFevmInfo.js +0 -1
  41. package/lib/ethereum/info/goerliInfo.js +0 -5
  42. package/lib/ethereum/info/kovanInfo.js +0 -5
  43. package/lib/ethereum/info/optimismInfo.js +0 -1
  44. package/lib/ethereum/info/polygonInfo.js +0 -1
  45. package/lib/ethereum/info/pulsechainInfo.js +0 -1
  46. package/lib/ethereum/info/rinkebyInfo.js +0 -5
  47. package/lib/ethereum/info/ropstenInfo.js +0 -5
  48. package/lib/ethereum/info/rskInfo.js +0 -1
  49. package/lib/ethereum/info/zksyncInfo.js +0 -1
  50. package/lib/ethereum/networkAdapters/EvmScanAdapter.js +9 -1
  51. package/lib/ethereum/networkAdapters/FilfoxAdapter.js +1 -0
  52. package/lib/ethereum/networkAdapters/PulsechainScanAdapter.js +9 -1
  53. package/lib/filecoin/FilecoinEngine.js +3 -0
  54. package/lib/fio/FioEngine.js +3 -0
  55. package/lib/hedera/HederaEngine.js +2 -0
  56. package/lib/piratechain/PiratechainEngine.js +2 -0
  57. package/lib/polkadot/PolkadotEngine.js +4 -2
  58. package/lib/ripple/RippleEngine.js +6 -1
  59. package/lib/solana/SolanaEngine.js +2 -0
  60. package/lib/stellar/StellarEngine.js +2 -0
  61. package/lib/tezos/TezosEngine.js +2 -0
  62. package/lib/tron/TronEngine.js +14 -1
  63. package/lib/zcash/ZcashEngine.js +2 -0
  64. package/package.json +2 -2
package/CHANGELOG.md CHANGED
@@ -2,6 +2,10 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## 3.3.0 (2024-03-25)
6
+
7
+ - changed: Upgrade edge-core-js to v1.14.0
8
+
5
9
  ## 3.2.8 (2024-03-22)
6
10
 
7
11
  - fixed: Added initOptions to FilecoinEngine for GLIF API key to fix sync issues
@@ -1,2 +1,2 @@
1
- (self.webpackChunkedge_currency_accountbased=self.webpackChunkedge_currency_accountbased||[]).push([[4843],{79014:function(V,H,c){"use strict";c.d(H,{Q:function(){return N},k:function(){return b}});var w=c(77591),x=c.n(w),L=c(24350),O=c(84564),z=c.n(O),B=c(76714),g=Object.defineProperty,U=Object.getOwnPropertySymbols,F=Object.prototype.hasOwnProperty,M=Object.prototype.propertyIsEnumerable,A=(a,f,p)=>f in a?g(a,f,{enumerable:!0,configurable:!0,writable:!0,value:p}):a[f]=p,C=(a,f)=>{for(var p in f||(f={}))F.call(f,p)&&A(a,p,f[p]);if(U)for(var p of U(f))M.call(f,p)&&A(a,p,f[p]);return a};function b(a,f,p,m,S=[]){const d=C({},z()(f,{},!0)),D=f.startsWith(`${a.pluginId}://`);if(d.protocol!=null&&(d.protocol=d.protocol.replace(":","")),d.protocol!=null&&d.protocol!==""&&!p[d.protocol])throw new Error(`Uri protocol '${d.protocol}' is not supported for ${a.pluginId}.`);if(d.host===""&&d.pathname==="")throw new Error("Path and host not found in uri.");const v={publicAddress:d.host!==""?d.host:d.pathname.split("/")[0]},K=d.query.label,P=d.query.message,y=d.query.category;(K!=null||P!=null||y!=null||D)&&(v.metadata={},v.metadata.name=K,v.metadata.notes=P,v.metadata.category=y,v.metadata.gateway=D!=null?D:!1);const E=d.query.amount;if(E!=null&&typeof E=="string"){m==null&&(m=a.currencyCode);const k=(0,B.Qs)(m!=null?m:"",a,S);if(k==null)throw new Error("InternalErrorInvalidCurrencyCode");let T=(0,w.mul)(E,k.multiplier);T=(0,w.toFixed)(T,0,0),v.nativeAmount=T,v.currencyCode=m}return{edgeParsedUri:v,parsedUri:d}}function N(a,f,p){if(a.publicAddress==null)throw new Error("InvalidPublicAddressError");if(p==null&&a.label==null&&a.message==null)return a.publicAddress;{let m="";p!=null&&(m+="amount="+p+"&"),(a.label!=null||a.message!=null)&&(typeof a.label=="string"&&(m+="label="+a.label+"&"),typeof a.message=="string"&&(m+="message="+a.message+"&")),m=m.substr(0,m.length-1);const S={scheme:f,path:a.publicAddress,query:m};return(0,L.qC)(S)}}},80504:function(V,H,c){"use strict";c.r(H),c.d(H,{PiratechainTools:function(){return W},makeCurrencyEngine:function(){return T},makeCurrencyTools:function(){return _}});var w=c(77591),x=c(2153),L=c(48764),O=c(62177),z=c(79014),B=c(76714),g=c(82448);const U=(0,g.su)({first:g.mH,last:g.mH}),F=(0,g.su)({alias:(0,g.Vk)(g.XC),blockRange:(0,g.Vk)(U,()=>({first:0,last:0}))}),M=(0,g.su)({birthdayHeight:g.mH,publicKey:g.XC}),A=(0,O.jd)(M),C=l=>{const t=(0,g.su)({[`${l}Mnemonic`]:g.XC,[`${l}BirthdayHeight`]:g.mH});return(0,g.W1)(e=>{const n=t(e);return{mnemonic:n[`${l}Mnemonic`],birthdayHeight:n[`${l}BirthdayHeight`]}},e=>({[`${l}Mnemonic`]:e.mnemonic,[`${l}BirthdayHeight`]:e.birthdayHeight}))};var b=c(94935),N=c(79325),a=c(84650),f=c(72681),p=Object.defineProperty,m=Object.getOwnPropertySymbols,S=Object.getPrototypeOf,d=Object.prototype.hasOwnProperty,D=Object.prototype.propertyIsEnumerable,$=Reflect.get,v=(l,t,e)=>t in l?p(l,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):l[t]=e,K=(l,t)=>{for(var e in t||(t={}))d.call(t,e)&&v(l,e,t[e]);if(m)for(var e of m(t))D.call(t,e)&&v(l,e,t[e]);return l},P=(l,t,e)=>$(S(l),e,t),y=(l,t,e)=>new Promise((n,r)=>{var o=s=>{try{h(e.next(s))}catch(u){r(u)}},i=s=>{try{h(e.throw(s))}catch(u){r(u)}},h=s=>s.done?n(s.value):Promise.resolve(s.value).then(o,i);h((e=e.apply(l,t)).next())});const E=3e4;class k extends a.P{constructor(t,e,n,r,o){super(t,e,n,r);const{networkInfo:i}=t;this.pluginId=this.currencyInfo.pluginId,this.networkInfo=i,this.makeSynchronizer=o,this.queryMutex=!1,this.started=!1,this.progressRatio=0}setOtherData(t){this.otherData=F(t)}initData(){const{birthdayHeight:t}=this.initializer;this.otherData.blockRange.first===0&&(this.otherData.blockRange={first:t,last:t}),this.initialNumBlocksToDownload=-1,this.synchronizerStatus="DISCONNECTED",this.availableZatoshi="0"}initSubscriptions(){this.synchronizer!=null&&(this.synchronizer.on("update",t=>y(this,null,function*(){const{lastDownloadedHeight:e,scanProgress:n,networkBlockHeight:r}=t;this.onUpdateBlockHeight(r),this.onUpdateProgress(e,n,r),yield this.queryAll()})),this.synchronizer.on("statusChanged",t=>y(this,null,function*(){this.synchronizerStatus=t.name,yield this.queryAll()})))}queryAll(){return y(this,null,function*(){if(this.lastUpdateFromSynchronizer=Date.now(),!this.queryMutex){this.queryMutex=!0;try{yield this.queryBalance(),yield this.queryTransactions(),this.onUpdateTransactions()}catch{}this.queryMutex=!1}})}onUpdateBlockHeight(t){this.walletLocalData.blockHeight!==t&&(this.walletLocalData.blockHeight=t,this.walletLocalDataDirty=!0,this.currencyEngineCallbacks.onBlockHeightChanged(this.walletLocalData.blockHeight))}onUpdateTransactions(){this.transactionsChangedArray.length>0&&(this.currencyEngineCallbacks.onTransactionsChanged(this.transactionsChangedArray),this.transactionsChangedArray=[])}onUpdateProgress(t,e,n){if(!this.addressesChecked&&!this.isSynced()){const r=e*.99,o=e*.8;this.tokenCheckBalanceStatus[this.currencyInfo.currencyCode]=r/100,this.tokenCheckTransactionsStatus[this.currencyInfo.currencyCode]=o/100;const i=(r+o)/2;i>this.progressRatio&&(this.progressRatio=i,this.log.warn(`Scan and download progress: ${Math.floor(i)}%`),this.updateOnAddressesChecked())}}bumpSynchronizer(){return y(this,null,function*(){var t;this.isSynced()||this.lastUpdateFromSynchronizer==null||Date.now()<this.lastUpdateFromSynchronizer+E||(this.log.warn("Haven't heard from the synchronizer in a while. Applying the Fonzie Method..."),yield(t=this.synchronizer)==null?void 0:t.stop(),this.stopSyncing!=null&&(yield this.stopSyncing(5e3),this.stopSyncing=void 0),this.log.warn("\u{1F44D} Ayyy \u{1F44D}"),this.lastUpdateFromSynchronizer=void 0)})}startEngine(){return y(this,null,function*(){this.engineOn=!0,this.started=!0,this.addToLoop("bumpSynchronizer",E).catch(()=>{}),yield P(k.prototype,this,"startEngine").call(this)})}isSynced(){return this.synchronizerStatus==="SYNCED"}queryBalance(){return y(this,null,function*(){if(!(!this.isSynced()||this.synchronizer==null))try{const t=yield this.synchronizer.getBalance();if(t.totalZatoshi==="-1")return;this.availableZatoshi=t.availableZatoshi,this.updateBalance(this.currencyInfo.currencyCode,t.totalZatoshi)}catch(t){this.warn("Failed to update balances",t),this.updateBalance(this.currencyInfo.currencyCode,"0")}})}queryTransactions(){return y(this,null,function*(){if(this.synchronizer!=null)try{let t=this.otherData.blockRange.first,e=this.otherData.blockRange.last;for(;this.isSynced()&&e<=this.walletLocalData.blockHeight;){if((yield this.synchronizer.getTransactions({first:t,last:e})).forEach(r=>this.processTransaction(r)),e===this.walletLocalData.blockHeight){t=this.walletLocalData.blockHeight,this.walletLocalDataDirty=!0,this.tokenCheckTransactionsStatus[this.currencyInfo.currencyCode]=1,this.updateOnAddressesChecked();break}t=e+1,e=e+this.networkInfo.transactionQueryLimit<this.walletLocalData.blockHeight?e+this.networkInfo.transactionQueryLimit:this.walletLocalData.blockHeight,this.otherData.blockRange={first:t,last:e},this.walletLocalDataDirty=!0}}catch(t){this.error(`Error querying ${this.currencyInfo.currencyCode} transactions `,t)}})}processTransaction(t){let e=t.value;const n=[];t.toAddress!=null?e=`-${(0,w.add)(e,this.networkInfo.defaultNetworkFee)}`:n.push(this.walletInfo.keys.publicKey);const r=t.memos.filter(i=>i!=="").map(i=>({memoName:"memo",type:"text",value:i})),o={blockHeight:t.minedHeight,currencyCode:this.currencyInfo.currencyCode,date:t.blockTimeInSeconds,isSend:e.startsWith("-"),memos:r,nativeAmount:e,networkFee:this.networkInfo.defaultNetworkFee,otherParams:{},ourReceiveAddresses:n,signedTx:"",txid:t.rawTransactionId,walletId:this.walletId};this.addTransaction(this.currencyInfo.currencyCode,o)}syncNetwork(t){return y(this,null,function*(){if(!this.started)return 1e3;const e=C(this.currencyInfo.pluginId)(t==null?void 0:t.privateKeys),{rpcNode:n}=this.networkInfo;return this.initializer=K({mnemonicSeed:e.mnemonic,birthdayHeight:e.birthdayHeight,alias:N.YU.stringify(N.US.parse(this.walletId))},n),this.synchronizer=yield this.makeSynchronizer(this.initializer),this.initData(),this.initSubscriptions(),yield new Promise(r=>{this.stopSyncing=r})})}killEngine(){return y(this,null,function*(){var t;this.started=!1,this.stopSyncing!=null&&(yield this.stopSyncing(1e3),this.stopSyncing=void 0),yield(t=this.synchronizer)==null?void 0:t.stop(),yield P(k.prototype,this,"killEngine").call(this)})}clearBlockchainCache(){return y(this,null,function*(){yield P(k.prototype,this,"clearBlockchainCache").call(this)})}resyncBlockchain(){return y(this,null,function*(){var t;yield P(k.prototype,this,"killEngine").call(this),yield this.clearBlockchainCache(),yield this.startEngine(),(t=this.synchronizer)==null||t.rescan().catch(e=>this.warn("resyncBlockchain failed: ",e)),this.initData(),this.progressRatio=0,this.synchronizerStatus="SYNCING"})}getMaxSpendable(){return y(this,null,function*(){const t=(0,w.sub)(this.availableZatoshi,this.networkInfo.defaultNetworkFee);if((0,w.lte)(t,"0"))throw new b.C_;return t})}makeSpend(t){return y(this,null,function*(){var e;if(t=(0,f.s)(t,this.currencyInfo),!this.isSynced())throw new Error("Cannot spend until wallet is synced");const{edgeSpendInfo:n,currencyCode:r}=this.makeSpendCheck(t),{memos:o=[]}=n,i=n.spendTargets[0],{publicAddress:h,nativeAmount:s}=i;if(h==null)throw new Error("makeSpend Missing publicAddress");if(s==null)throw new b.$D;if((0,w.eq)(s,"0"))throw new b.$D;const u=(0,w.add)(s,this.networkInfo.defaultNetworkFee);if((0,w.gt)(u,(e=this.walletLocalData.totalBalances[this.currencyInfo.currencyCode])!=null?e:"0"))throw new b.C_;if((0,w.gt)(u,this.availableZatoshi))throw new b.C_("Amount exceeds available balance");const R=(0,w.mul)(u,"-1");return{blockHeight:0,currencyCode:r,date:0,isSend:!0,memos:o,nativeAmount:R,networkFee:this.networkInfo.defaultNetworkFee,ourReceiveAddresses:[],signedTx:"",txid:"",walletId:this.walletId}})}signTx(t){return y(this,null,function*(){return t})}broadcastTx(t,e){return y(this,null,function*(){var n;if(this.synchronizer==null)throw new Error("Synchronizer undefined");const{memos:r}=t,o=C(this.pluginId)(e==null?void 0:e.privateKeys);if(t.spendTargets==null||t.spendTargets.length!==1)throw new Error("Invalid spend targets");const i=((n=r[0])==null?void 0:n.type)==="text"?r[0].value:"",h=t.spendTargets[0],s={zatoshi:(0,w.sub)((0,w.abs)(t.nativeAmount),t.networkFee),toAddress:h.publicAddress,memo:i,fromAccountIndex:0,mnemonicSeed:o.mnemonic};try{const u=yield this.synchronizer.sendToAddress(s);t.txid=u.txId,t.signedTx=u.raw,t.date=Date.now()/1e3,this.warn(`SUCCESS broadcastTx
1
+ (self.webpackChunkedge_currency_accountbased=self.webpackChunkedge_currency_accountbased||[]).push([[4843],{79014:function(V,H,c){"use strict";c.d(H,{Q:function(){return N},k:function(){return b}});var w=c(77591),x=c.n(w),L=c(24350),O=c(84564),z=c.n(O),B=c(76714),g=Object.defineProperty,U=Object.getOwnPropertySymbols,F=Object.prototype.hasOwnProperty,M=Object.prototype.propertyIsEnumerable,A=(a,f,p)=>f in a?g(a,f,{enumerable:!0,configurable:!0,writable:!0,value:p}):a[f]=p,C=(a,f)=>{for(var p in f||(f={}))F.call(f,p)&&A(a,p,f[p]);if(U)for(var p of U(f))M.call(f,p)&&A(a,p,f[p]);return a};function b(a,f,p,m,S=[]){const d=C({},z()(f,{},!0)),D=f.startsWith(`${a.pluginId}://`);if(d.protocol!=null&&(d.protocol=d.protocol.replace(":","")),d.protocol!=null&&d.protocol!==""&&!p[d.protocol])throw new Error(`Uri protocol '${d.protocol}' is not supported for ${a.pluginId}.`);if(d.host===""&&d.pathname==="")throw new Error("Path and host not found in uri.");const v={publicAddress:d.host!==""?d.host:d.pathname.split("/")[0]},K=d.query.label,P=d.query.message,y=d.query.category;(K!=null||P!=null||y!=null||D)&&(v.metadata={},v.metadata.name=K,v.metadata.notes=P,v.metadata.category=y,v.metadata.gateway=D!=null?D:!1);const E=d.query.amount;if(E!=null&&typeof E=="string"){m==null&&(m=a.currencyCode);const k=(0,B.Qs)(m!=null?m:"",a,S);if(k==null)throw new Error("InternalErrorInvalidCurrencyCode");let T=(0,w.mul)(E,k.multiplier);T=(0,w.toFixed)(T,0,0),v.nativeAmount=T,v.currencyCode=m}return{edgeParsedUri:v,parsedUri:d}}function N(a,f,p){if(a.publicAddress==null)throw new Error("InvalidPublicAddressError");if(p==null&&a.label==null&&a.message==null)return a.publicAddress;{let m="";p!=null&&(m+="amount="+p+"&"),(a.label!=null||a.message!=null)&&(typeof a.label=="string"&&(m+="label="+a.label+"&"),typeof a.message=="string"&&(m+="message="+a.message+"&")),m=m.substr(0,m.length-1);const S={scheme:f,path:a.publicAddress,query:m};return(0,L.qC)(S)}}},80504:function(V,H,c){"use strict";c.r(H),c.d(H,{PiratechainTools:function(){return W},makeCurrencyEngine:function(){return T},makeCurrencyTools:function(){return _}});var w=c(77591),x=c(2153),L=c(48764),O=c(62177),z=c(79014),B=c(76714),g=c(82448);const U=(0,g.su)({first:g.mH,last:g.mH}),F=(0,g.su)({alias:(0,g.Vk)(g.XC),blockRange:(0,g.Vk)(U,()=>({first:0,last:0}))}),M=(0,g.su)({birthdayHeight:g.mH,publicKey:g.XC}),A=(0,O.jd)(M),C=l=>{const t=(0,g.su)({[`${l}Mnemonic`]:g.XC,[`${l}BirthdayHeight`]:g.mH});return(0,g.W1)(e=>{const n=t(e);return{mnemonic:n[`${l}Mnemonic`],birthdayHeight:n[`${l}BirthdayHeight`]}},e=>({[`${l}Mnemonic`]:e.mnemonic,[`${l}BirthdayHeight`]:e.birthdayHeight}))};var b=c(94935),N=c(79325),a=c(84650),f=c(72681),p=Object.defineProperty,m=Object.getOwnPropertySymbols,S=Object.getPrototypeOf,d=Object.prototype.hasOwnProperty,D=Object.prototype.propertyIsEnumerable,$=Reflect.get,v=(l,t,e)=>t in l?p(l,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):l[t]=e,K=(l,t)=>{for(var e in t||(t={}))d.call(t,e)&&v(l,e,t[e]);if(m)for(var e of m(t))D.call(t,e)&&v(l,e,t[e]);return l},P=(l,t,e)=>$(S(l),e,t),y=(l,t,e)=>new Promise((n,r)=>{var o=s=>{try{h(e.next(s))}catch(u){r(u)}},i=s=>{try{h(e.throw(s))}catch(u){r(u)}},h=s=>s.done?n(s.value):Promise.resolve(s.value).then(o,i);h((e=e.apply(l,t)).next())});const E=3e4;class k extends a.P{constructor(t,e,n,r,o){super(t,e,n,r);const{networkInfo:i}=t;this.pluginId=this.currencyInfo.pluginId,this.networkInfo=i,this.makeSynchronizer=o,this.queryMutex=!1,this.started=!1,this.progressRatio=0}setOtherData(t){this.otherData=F(t)}initData(){const{birthdayHeight:t}=this.initializer;this.otherData.blockRange.first===0&&(this.otherData.blockRange={first:t,last:t}),this.initialNumBlocksToDownload=-1,this.synchronizerStatus="DISCONNECTED",this.availableZatoshi="0"}initSubscriptions(){this.synchronizer!=null&&(this.synchronizer.on("update",t=>y(this,null,function*(){const{lastDownloadedHeight:e,scanProgress:n,networkBlockHeight:r}=t;this.onUpdateBlockHeight(r),this.onUpdateProgress(e,n,r),yield this.queryAll()})),this.synchronizer.on("statusChanged",t=>y(this,null,function*(){this.synchronizerStatus=t.name,yield this.queryAll()})))}queryAll(){return y(this,null,function*(){if(this.lastUpdateFromSynchronizer=Date.now(),!this.queryMutex){this.queryMutex=!0;try{yield this.queryBalance(),yield this.queryTransactions(),this.onUpdateTransactions()}catch{}this.queryMutex=!1}})}onUpdateBlockHeight(t){this.walletLocalData.blockHeight!==t&&(this.walletLocalData.blockHeight=t,this.walletLocalDataDirty=!0,this.currencyEngineCallbacks.onBlockHeightChanged(this.walletLocalData.blockHeight))}onUpdateTransactions(){this.transactionsChangedArray.length>0&&(this.currencyEngineCallbacks.onTransactionsChanged(this.transactionsChangedArray),this.transactionsChangedArray=[])}onUpdateProgress(t,e,n){if(!this.addressesChecked&&!this.isSynced()){const r=e*.99,o=e*.8;this.tokenCheckBalanceStatus[this.currencyInfo.currencyCode]=r/100,this.tokenCheckTransactionsStatus[this.currencyInfo.currencyCode]=o/100;const i=(r+o)/2;i>this.progressRatio&&(this.progressRatio=i,this.log.warn(`Scan and download progress: ${Math.floor(i)}%`),this.updateOnAddressesChecked())}}bumpSynchronizer(){return y(this,null,function*(){var t;this.isSynced()||this.lastUpdateFromSynchronizer==null||Date.now()<this.lastUpdateFromSynchronizer+E||(this.log.warn("Haven't heard from the synchronizer in a while. Applying the Fonzie Method..."),yield(t=this.synchronizer)==null?void 0:t.stop(),this.stopSyncing!=null&&(yield this.stopSyncing(5e3),this.stopSyncing=void 0),this.log.warn("\u{1F44D} Ayyy \u{1F44D}"),this.lastUpdateFromSynchronizer=void 0)})}startEngine(){return y(this,null,function*(){this.engineOn=!0,this.started=!0,this.addToLoop("bumpSynchronizer",E).catch(()=>{}),yield P(k.prototype,this,"startEngine").call(this)})}isSynced(){return this.synchronizerStatus==="SYNCED"}queryBalance(){return y(this,null,function*(){if(!(!this.isSynced()||this.synchronizer==null))try{const t=yield this.synchronizer.getBalance();if(t.totalZatoshi==="-1")return;this.availableZatoshi=t.availableZatoshi,this.updateBalance(this.currencyInfo.currencyCode,t.totalZatoshi)}catch(t){this.warn("Failed to update balances",t),this.updateBalance(this.currencyInfo.currencyCode,"0")}})}queryTransactions(){return y(this,null,function*(){if(this.synchronizer!=null)try{let t=this.otherData.blockRange.first,e=this.otherData.blockRange.last;for(;this.isSynced()&&e<=this.walletLocalData.blockHeight;){if((yield this.synchronizer.getTransactions({first:t,last:e})).forEach(r=>this.processTransaction(r)),e===this.walletLocalData.blockHeight){t=this.walletLocalData.blockHeight,this.walletLocalDataDirty=!0,this.tokenCheckTransactionsStatus[this.currencyInfo.currencyCode]=1,this.updateOnAddressesChecked();break}t=e+1,e=e+this.networkInfo.transactionQueryLimit<this.walletLocalData.blockHeight?e+this.networkInfo.transactionQueryLimit:this.walletLocalData.blockHeight,this.otherData.blockRange={first:t,last:e},this.walletLocalDataDirty=!0}}catch(t){this.error(`Error querying ${this.currencyInfo.currencyCode} transactions `,t)}})}processTransaction(t){let e=t.value;const n=[];t.toAddress!=null?e=`-${(0,w.add)(e,this.networkInfo.defaultNetworkFee)}`:n.push(this.walletInfo.keys.publicKey);const r=t.memos.filter(i=>i!=="").map(i=>({memoName:"memo",type:"text",value:i})),o={blockHeight:t.minedHeight,currencyCode:this.currencyInfo.currencyCode,date:t.blockTimeInSeconds,isSend:e.startsWith("-"),memos:r,nativeAmount:e,networkFee:this.networkInfo.defaultNetworkFee,otherParams:{},ourReceiveAddresses:n,signedTx:"",tokenId:null,txid:t.rawTransactionId,walletId:this.walletId};this.addTransaction(this.currencyInfo.currencyCode,o)}syncNetwork(t){return y(this,null,function*(){if(!this.started)return 1e3;const e=C(this.currencyInfo.pluginId)(t==null?void 0:t.privateKeys),{rpcNode:n}=this.networkInfo;return this.initializer=K({mnemonicSeed:e.mnemonic,birthdayHeight:e.birthdayHeight,alias:N.YU.stringify(N.US.parse(this.walletId))},n),this.synchronizer=yield this.makeSynchronizer(this.initializer),this.initData(),this.initSubscriptions(),yield new Promise(r=>{this.stopSyncing=r})})}killEngine(){return y(this,null,function*(){var t;this.started=!1,this.stopSyncing!=null&&(yield this.stopSyncing(1e3),this.stopSyncing=void 0),yield(t=this.synchronizer)==null?void 0:t.stop(),yield P(k.prototype,this,"killEngine").call(this)})}clearBlockchainCache(){return y(this,null,function*(){yield P(k.prototype,this,"clearBlockchainCache").call(this)})}resyncBlockchain(){return y(this,null,function*(){var t;yield P(k.prototype,this,"killEngine").call(this),yield this.clearBlockchainCache(),yield this.startEngine(),(t=this.synchronizer)==null||t.rescan().catch(e=>this.warn("resyncBlockchain failed: ",e)),this.initData(),this.progressRatio=0,this.synchronizerStatus="SYNCING"})}getMaxSpendable(){return y(this,null,function*(){const t=(0,w.sub)(this.availableZatoshi,this.networkInfo.defaultNetworkFee);if((0,w.lte)(t,"0"))throw new b.C_;return t})}makeSpend(t){return y(this,null,function*(){var e;if(t=(0,f.s)(t,this.currencyInfo),!this.isSynced())throw new Error("Cannot spend until wallet is synced");const{edgeSpendInfo:n,currencyCode:r}=this.makeSpendCheck(t),{memos:o=[]}=n,i=n.spendTargets[0],{publicAddress:h,nativeAmount:s}=i;if(h==null)throw new Error("makeSpend Missing publicAddress");if(s==null)throw new b.$D;if((0,w.eq)(s,"0"))throw new b.$D;const u=(0,w.add)(s,this.networkInfo.defaultNetworkFee);if((0,w.gt)(u,(e=this.walletLocalData.totalBalances[this.currencyInfo.currencyCode])!=null?e:"0"))throw new b.C_;if((0,w.gt)(u,this.availableZatoshi))throw new b.C_("Amount exceeds available balance");const R=(0,w.mul)(u,"-1");return{blockHeight:0,currencyCode:r,date:0,isSend:!0,memos:o,nativeAmount:R,networkFee:this.networkInfo.defaultNetworkFee,ourReceiveAddresses:[],signedTx:"",tokenId:null,txid:"",walletId:this.walletId}})}signTx(t){return y(this,null,function*(){return t})}broadcastTx(t,e){return y(this,null,function*(){var n;if(this.synchronizer==null)throw new Error("Synchronizer undefined");const{memos:r}=t,o=C(this.pluginId)(e==null?void 0:e.privateKeys);if(t.spendTargets==null||t.spendTargets.length!==1)throw new Error("Invalid spend targets");const i=((n=r[0])==null?void 0:n.type)==="text"?r[0].value:"",h=t.spendTargets[0],s={zatoshi:(0,w.sub)((0,w.abs)(t.nativeAmount),t.networkFee),toAddress:h.publicAddress,memo:i,fromAccountIndex:0,mnemonicSeed:o.mnemonic};try{const u=yield this.synchronizer.sendToAddress(s);t.txid=u.txId,t.signedTx=u.raw,t.date=Date.now()/1e3,this.warn(`SUCCESS broadcastTx
2
2
  ${(0,B.oX)(t)}`)}catch(u){throw this.warn("FAILURE broadcastTx failed: ",u),u}return t})}getFreshAddress(){return y(this,null,function*(){if(this.synchronizer==null)throw new Error("Synchronizer undefined");return{publicAddress:(yield this.synchronizer.deriveUnifiedAddress()).saplingAddress}})}}function T(l,t,e,n){return y(this,null,function*(){const r=A(e),{makeSynchronizer:o}=l.nativeIo["edge-currency-accountbased"].piratechain,i=new k(l,t,r,n,o);return yield i.loadEngine(),i})}var I=(l,t,e)=>new Promise((n,r)=>{var o=s=>{try{h(e.next(s))}catch(u){r(u)}},i=s=>{try{h(e.throw(s))}catch(u){r(u)}},h=s=>s.done?n(s.value):Promise.resolve(s.value).then(o,i);h((e=e.apply(l,t)).next())});class W{constructor(t){const{builtinTokens:e,currencyInfo:n,io:r,networkInfo:o}=t;this.builtinTokens=e,this.currencyInfo=n,this.io=r,this.networkInfo=o;const i=t.nativeIo["edge-currency-accountbased"];if(i==null)throw new Error("Need opts");const{Tools:h}=i.piratechain;this.nativeTools=h}getDisplayPrivateKey(t){return I(this,null,function*(){const{pluginId:e}=this.currencyInfo;return C(e)(t.keys).mnemonic})}getDisplayPublicKey(t){return I(this,null,function*(){const{keys:e}=A(t);return e.publicKey})}getNewWalletBirthdayBlockheight(){return I(this,null,function*(){try{return yield this.nativeTools.getBirthdayHeight(this.networkInfo.rpcNode.defaultHost,this.networkInfo.rpcNode.defaultPort)}catch{return this.networkInfo.defaultBirthday}})}isValidAddress(t){return I(this,null,function*(){return yield this.nativeTools.isValidAddress(t)})}importPrivateKey(t){return I(this,arguments,function*(e,n={}){const{pluginId:r}=this.currencyInfo,o=(0,x.validateMnemonic)(e);if(e.split(" ").length!==24)throw new Error("Mnemonic must be 24 words");if(!o)throw new Error(`Invalid ${this.currencyInfo.currencyCode} mnemonic`);const i=yield this.getNewWalletBirthdayBlockheight();let h=i;const{birthdayHeight:s}=n;if(s!=null){(0,O.jD)(s);const u=parseInt(s);if(u>i)throw new Error("InvalidBirthdayHeight");h=u}return{[`${r}Mnemonic`]:e,[`${r}BirthdayHeight`]:h}})}createPrivateKey(t){return I(this,null,function*(){if(t!==this.currencyInfo.walletType)throw new Error("InvalidWalletType");const e=L.Buffer.from(this.io.random(32)).toString("hex"),n=(0,x.entropyToMnemonic)(e);return yield this.importPrivateKey(n)})}checkPublicKey(t){return I(this,null,function*(){try{return M(t),!0}catch{return!1}})}derivePublicKey(t){return I(this,null,function*(){const{pluginId:e}=this.currencyInfo,n=C(e)(t.keys);if(t.type!==this.currencyInfo.walletType)throw new Error("InvalidWalletType");const r=n.mnemonic;if(typeof r!="string")throw new Error("InvalidMnemonic");const o=yield this.nativeTools.deriveViewingKey(r,this.networkInfo.rpcNode.networkName);return{birthdayHeight:n.birthdayHeight,publicKey:o}})}parseUri(t,e,n){return I(this,null,function*(){const{pluginId:r}=this.currencyInfo,o={[r]:!0},{edgeParsedUri:i,edgeParsedUri:{publicAddress:h}}=(0,z.k)(this.currencyInfo,t,o,e!=null?e:this.currencyInfo.currencyCode,n);if(h==null||!(yield this.isValidAddress(h)))throw new Error("InvalidPublicAddressError");return i})}encodeUri(t){return I(this,arguments,function*(e,n=[]){const{pluginId:r}=this.currencyInfo,{nativeAmount:o,currencyCode:i,publicAddress:h}=e;if(!(yield this.isValidAddress(h)))throw new Error("InvalidPublicAddressError");let s;if(o!=null){const R=(0,B.Qs)(i!=null?i:this.currencyInfo.currencyCode,this.currencyInfo,n);if(R==null)throw new Error("InternalErrorInvalidCurrencyCode");s=(0,w.div)(o,R.multiplier,18)}return(0,z.Q)(e,`${r}`,s)})}}function _(l){return I(this,null,function*(){return new W(l)})}},52361:function(){},94616:function(){}}]);