edge-currency-accountbased 4.25.0 → 4.25.1

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 CHANGED
@@ -2,6 +2,10 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## 4.25.1 (2024-09-27)
6
+
7
+ - removed: (Piratechain) Removed `bumpSynchronizer` loop. Engine will now rely on critical errors reported from react-native-piratechain for synchronizer management.
8
+
5
9
  ## 4.25.0 (2024-09-25)
6
10
 
7
11
  - changed: (Zcash) Replace `sendToAddress` with `createTransfer`
@@ -1,6 +1,6 @@
1
- (self.webpackChunkedge_currency_accountbased=self.webpackChunkedge_currency_accountbased||[]).push([[4163],{62351:function(L,H,y){"use strict";y.d(H,{Nn:function(){return I},Nt:function(){return P},fi:function(){return B},zp:function(){return O}});var f=y(44276),C=(p,u,d)=>new Promise((w,v)=>{var E=g=>{try{S(d.next(g))}catch(k){v(k)}},b=g=>{try{S(d.throw(g))}catch(k){v(k)}},S=g=>g.done?w(g.value):Promise.resolve(g.value).then(E,b);S((d=d.apply(p,u)).next())});const x=["https://info1.edge.app","https://info2.edge.app"];function N(p,u,d){return C(this,arguments,function*(w,v,E,b=5e3,S=fetch){const g=w.map(k=>()=>C(this,null,function*(){const T=yield S(k+"/"+v,E);if(typeof T!="object"){const l=`Invalid return value ${v} in ${k}`;throw console.log(l),new Error(l)}return T}));return yield(0,f.NN)(g,b)})}function O(p,u,d,w,v=5e3,E){return C(this,null,function*(){const b=yield N((0,f.R3)(u),d,w,v,E);if(!b.ok){const k=yield b.text();throw console.error(k),new Error(`Error fetching ${d}: ${k}`)}const S=yield b.json();return p(S)})}function z(p,u,d,w=5e3,v){return C(this,null,function*(){return yield N((0,f.R3)(p),u,d,w,v)})}const I=(p,u,d,w)=>C(void 0,null,function*(){return yield z(x,p,u,d,w)}),P=p=>Object.keys(p).map(u=>{const d=p[u];return d==null?u:`${u}=${encodeURIComponent(d)}`}).join("&"),B=(p,u=5e3)=>p+Math.random()*u*2-u},99649:function(L,H,y){"use strict";y.r(H),y.d(H,{PiratechainTools:function(){return U},makeCurrencyEngine:function(){return K},makeCurrencyTools:function(){return V},updateInfoPayload:function(){return W}});var f=y(66001),C=y(90749),x=y(48287),N=y(36856),O=y(96542),z=y(44276),I=y(62071),P=y(82671),B=y(65828),p=y(26277),u=y(62351),d=Object.defineProperty,w=Object.getOwnPropertySymbols,v=Object.getPrototypeOf,E=Object.prototype.hasOwnProperty,b=Object.prototype.propertyIsEnumerable,S=Reflect.get,g=(s,t,e)=>t in s?d(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e,k=(s,t)=>{for(var e in t||(t={}))E.call(t,e)&&g(s,e,t[e]);if(w)for(var e of w(t))b.call(t,e)&&g(s,e,t[e]);return s},T=(s,t,e)=>S(v(s),e,t),l=(s,t,e)=>new Promise((n,r)=>{var o=a=>{try{c(e.next(a))}catch(h){r(h)}},i=a=>{try{c(e.throw(a))}catch(h){r(h)}},c=a=>a.done?n(a.value):Promise.resolve(a.value).then(o,i);c((e=e.apply(s,t)).next())});const R=(0,u.fi)(3e4);class D extends p.k{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=(0,I.Gb)(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=>l(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=>l(this,null,function*(){this.synchronizerStatus=t.name,yield this.queryAll()})),this.synchronizer.on("error",t=>l(this,null,function*(){this.log.warn(`Synchronizer error: ${t.message}`),t.level==="critical"&&(yield this.killEngine(),this.lastUpdateFromSynchronizer=void 0,yield this.startEngine())})))}queryAll(){return l(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 l(this,null,function*(){var t;this.isSynced()||this.lastUpdateFromSynchronizer==null||Date.now()<this.lastUpdateFromSynchronizer+R||(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 l(this,null,function*(){this.engineOn=!0,this.started=!0,this.addToLoop("bumpSynchronizer",R).catch(()=>{}),yield T(D.prototype,this,"startEngine").call(this)})}isSynced(){return this.synchronizerStatus==="SYNCED"}queryBalance(){return l(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 l(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,f.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 l(this,null,function*(){if(!this.started)return 1e3;const e=(0,I.cl)(this.currencyInfo.pluginId)(t==null?void 0:t.privateKeys),{rpcNode:n}=this.networkInfo;this.initializer=k({mnemonicSeed:e.mnemonic,birthdayHeight:e.birthdayHeight,alias:B.xn.stringify(B.K3.parse(this.walletId))},n);try{this.synchronizer=yield this.makeSynchronizer(this.initializer)}catch(r){if(String(r)==="Invariant Violation: `new NativeEventEmitter()` requires a non-null argument.")this.log.warn("SDK not present");else throw r}return this.initData(),this.initSubscriptions(),yield new Promise(r=>{this.stopSyncing=r})})}killEngine(){return l(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 T(D.prototype,this,"killEngine").call(this)})}clearBlockchainCache(){return l(this,null,function*(){yield T(D.prototype,this,"clearBlockchainCache").call(this)})}resyncBlockchain(){return l(this,null,function*(){var t;yield T(D.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 l(this,null,function*(){const t=(0,f.sub)(this.availableZatoshi,this.networkInfo.defaultNetworkFee);if((0,f.lte)(t,"0"))throw new P.k5({tokenId:null});return t})}makeSpend(t){return l(this,null,function*(){var e;if(!this.isSynced())throw new Error("Cannot spend until wallet is synced");const{edgeSpendInfo:n,currencyCode:r}=this.makeSpendCheck(t),{memos:o=[],tokenId:i}=n,c=n.spendTargets[0],{publicAddress:a,nativeAmount:h}=c;if(a==null)throw new Error("makeSpend Missing publicAddress");if(h==null)throw new P.ef;if((0,f.eq)(h,"0"))throw new P.ef;const A=(0,f.add)(h,this.networkInfo.defaultNetworkFee);if((0,f.gt)(A,(e=this.walletLocalData.totalBalances[this.currencyInfo.currencyCode])!=null?e:"0"))throw new P.k5({tokenId:i});if((0,f.gt)(A,this.availableZatoshi))throw new P.k5({tokenId:i});const Z=(0,f.mul)(A,"-1");return{blockHeight:0,currencyCode:r,date:0,isSend:!0,memos:o,nativeAmount:Z,networkFee:this.networkInfo.defaultNetworkFee,ourReceiveAddresses:[],signedTx:"",tokenId:i,txid:"",walletId:this.walletId}})}signTx(t){return l(this,null,function*(){return t})}broadcastTx(t,e){return l(this,null,function*(){var n;if(this.synchronizer==null)throw new Error("Synchronizer undefined");const{memos:r}=t,o=(0,I.cl)(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:"",c=t.spendTargets[0],a={zatoshi:(0,f.sub)((0,f.abs)(t.nativeAmount),t.networkFee),toAddress:c.publicAddress,memo:i,mnemonicSeed:o.mnemonic};try{const h=yield this.synchronizer.sendToAddress(a);t.txid=h.txId,t.signedTx=h.raw,t.date=Date.now()/1e3,this.warn(`SUCCESS broadcastTx
2
- ${(0,z.T5)(t)}`)}catch(h){throw this.warn("FAILURE broadcastTx failed: ",h),h}return t})}getFreshAddress(){return l(this,null,function*(){const t=()=>l(this,null,function*(){if(this.synchronizer==null)throw new Error("Synchronizer undefined");const{saplingAddress:e}=yield this.synchronizer.deriveUnifiedAddress();return this.otherData.cachedAddress=e,this.walletLocalDataDirty=!0,{publicAddress:e}});return this.otherData.cachedAddress==null?yield t():(t().catch(e=>{throw e}),{publicAddress:this.otherData.cachedAddress})})}}function K(s,t,e,n){return l(this,null,function*(){const r=(0,I.xH)(e),{makeSynchronizer:o}=s.nativeIo["edge-currency-accountbased"].piratechain,i=new D(s,t,r,n,o);return yield i.loadEngine(),i})}var F=Object.getOwnPropertySymbols,M=Object.prototype.hasOwnProperty,$=Object.prototype.propertyIsEnumerable,j=(s,t)=>{var e={};for(var n in s)M.call(s,n)&&t.indexOf(n)<0&&(e[n]=s[n]);if(s!=null&&F)for(var n of F(s))t.indexOf(n)<0&&$.call(s,n)&&(e[n]=s[n]);return e},m=(s,t,e)=>new Promise((n,r)=>{var o=a=>{try{c(e.next(a))}catch(h){r(h)}},i=a=>{try{c(e.throw(a))}catch(h){r(h)}},c=a=>a.done?n(a.value):Promise.resolve(a.value).then(o,i);c((e=e.apply(s,t)).next())});class U{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:c}=i.piratechain;this.nativeTools=c}getDisplayPrivateKey(t){return m(this,null,function*(){const{pluginId:e}=this.currencyInfo,n=(0,I.cl)(e)(t.keys);return`Seed Phrase:
1
+ (self.webpackChunkedge_currency_accountbased=self.webpackChunkedge_currency_accountbased||[]).push([[4163],{99649:function(j,k,u){"use strict";u.r(k),u.d(k,{PiratechainTools:function(){return A},makeCurrencyEngine:function(){return U},makeCurrencyTools:function(){return M},updateInfoPayload:function(){return $}});var y=u(66001),I=u(90749),E=u(48287),D=u(36856),b=u(96542),v=u(44276),f=u(62071),w=u(82671),S=u(65828),H=u(26277),z=Object.defineProperty,C=Object.getOwnPropertySymbols,B=Object.getPrototypeOf,N=Object.prototype.hasOwnProperty,O=Object.prototype.propertyIsEnumerable,x=Reflect.get,T=(s,t,e)=>t in s?z(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e,K=(s,t)=>{for(var e in t||(t={}))N.call(t,e)&&T(s,e,t[e]);if(C)for(var e of C(t))O.call(t,e)&&T(s,e,t[e]);return s},m=(s,t,e)=>x(B(s),e,t),h=(s,t,e)=>new Promise((n,r)=>{var o=a=>{try{l(e.next(a))}catch(c){r(c)}},i=a=>{try{l(e.throw(a))}catch(c){r(c)}},l=a=>a.done?n(a.value):Promise.resolve(a.value).then(o,i);l((e=e.apply(s,t)).next())});class p extends H.k{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=(0,f.Gb)(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=>h(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=>h(this,null,function*(){this.synchronizerStatus=t.name,yield this.queryAll()})),this.synchronizer.on("error",t=>h(this,null,function*(){this.log.warn(`Synchronizer error: ${t.message}`),t.level==="critical"&&(yield this.killEngine(),this.lastUpdateFromSynchronizer=void 0,yield this.startEngine())})))}queryAll(){return h(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())}}startEngine(){return h(this,null,function*(){this.engineOn=!0,this.started=!0,yield m(p.prototype,this,"startEngine").call(this)})}isSynced(){return this.synchronizerStatus==="SYNCED"}queryBalance(){return h(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 h(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,y.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 h(this,null,function*(){if(!this.started)return 1e3;const e=(0,f.cl)(this.currencyInfo.pluginId)(t==null?void 0:t.privateKeys),{rpcNode:n}=this.networkInfo;this.initializer=K({mnemonicSeed:e.mnemonic,birthdayHeight:e.birthdayHeight,alias:S.xn.stringify(S.K3.parse(this.walletId))},n);try{this.synchronizer=yield this.makeSynchronizer(this.initializer)}catch(r){if(String(r)==="Invariant Violation: `new NativeEventEmitter()` requires a non-null argument.")this.log.warn("SDK not present");else throw r}return this.initData(),this.initSubscriptions(),yield new Promise(r=>{this.stopSyncing=r})})}killEngine(){return h(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 m(p.prototype,this,"killEngine").call(this)})}clearBlockchainCache(){return h(this,null,function*(){yield m(p.prototype,this,"clearBlockchainCache").call(this)})}resyncBlockchain(){return h(this,null,function*(){var t;yield m(p.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 h(this,null,function*(){const t=(0,y.sub)(this.availableZatoshi,this.networkInfo.defaultNetworkFee);if((0,y.lte)(t,"0"))throw new w.k5({tokenId:null});return t})}makeSpend(t){return h(this,null,function*(){var e;if(!this.isSynced())throw new Error("Cannot spend until wallet is synced");const{edgeSpendInfo:n,currencyCode:r}=this.makeSpendCheck(t),{memos:o=[],tokenId:i}=n,l=n.spendTargets[0],{publicAddress:a,nativeAmount:c}=l;if(a==null)throw new Error("makeSpend Missing publicAddress");if(c==null)throw new w.ef;if((0,y.eq)(c,"0"))throw new w.ef;const g=(0,y.add)(c,this.networkInfo.defaultNetworkFee);if((0,y.gt)(g,(e=this.walletLocalData.totalBalances[this.currencyInfo.currencyCode])!=null?e:"0"))throw new w.k5({tokenId:i});if((0,y.gt)(g,this.availableZatoshi))throw new w.k5({tokenId:i});const V=(0,y.mul)(g,"-1");return{blockHeight:0,currencyCode:r,date:0,isSend:!0,memos:o,nativeAmount:V,networkFee:this.networkInfo.defaultNetworkFee,ourReceiveAddresses:[],signedTx:"",tokenId:i,txid:"",walletId:this.walletId}})}signTx(t){return h(this,null,function*(){return t})}broadcastTx(t,e){return h(this,null,function*(){var n;if(this.synchronizer==null)throw new Error("Synchronizer undefined");const{memos:r}=t,o=(0,f.cl)(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:"",l=t.spendTargets[0],a={zatoshi:(0,y.sub)((0,y.abs)(t.nativeAmount),t.networkFee),toAddress:l.publicAddress,memo:i,mnemonicSeed:o.mnemonic};try{const c=yield this.synchronizer.sendToAddress(a);t.txid=c.txId,t.signedTx=c.raw,t.date=Date.now()/1e3,this.warn(`SUCCESS broadcastTx
2
+ ${(0,v.T5)(t)}`)}catch(c){throw this.warn("FAILURE broadcastTx failed: ",c),c}return t})}getFreshAddress(){return h(this,null,function*(){const t=()=>h(this,null,function*(){if(this.synchronizer==null)throw new Error("Synchronizer undefined");const{saplingAddress:e}=yield this.synchronizer.deriveUnifiedAddress();return this.otherData.cachedAddress=e,this.walletLocalDataDirty=!0,{publicAddress:e}});return this.otherData.cachedAddress==null?yield t():(t().catch(e=>{throw e}),{publicAddress:this.otherData.cachedAddress})})}}function U(s,t,e,n){return h(this,null,function*(){const r=(0,f.xH)(e),{makeSynchronizer:o}=s.nativeIo["edge-currency-accountbased"].piratechain,i=new p(s,t,r,n,o);return yield i.loadEngine(),i})}var P=Object.getOwnPropertySymbols,L=Object.prototype.hasOwnProperty,R=Object.prototype.propertyIsEnumerable,F=(s,t)=>{var e={};for(var n in s)L.call(s,n)&&t.indexOf(n)<0&&(e[n]=s[n]);if(s!=null&&P)for(var n of P(s))t.indexOf(n)<0&&R.call(s,n)&&(e[n]=s[n]);return e},d=(s,t,e)=>new Promise((n,r)=>{var o=a=>{try{l(e.next(a))}catch(c){r(c)}},i=a=>{try{l(e.throw(a))}catch(c){r(c)}},l=a=>a.done?n(a.value):Promise.resolve(a.value).then(o,i);l((e=e.apply(s,t)).next())});class A{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:l}=i.piratechain;this.nativeTools=l}getDisplayPrivateKey(t){return d(this,null,function*(){const{pluginId:e}=this.currencyInfo,n=(0,f.cl)(e)(t.keys);return`Seed Phrase:
3
3
  ${n.mnemonic}
4
4
 
5
5
  Birthday Height:
6
- ${n.birthdayHeight}`})}getDisplayPublicKey(t){return m(this,null,function*(){const{keys:e}=(0,I.xH)(t);return e.publicKey})}getNewWalletBirthdayBlockheight(){return m(this,null,function*(){return yield this.nativeTools.getBirthdayHeight(this.networkInfo.rpcNode.defaultHost,this.networkInfo.rpcNode.defaultPort)})}isValidAddress(t){return m(this,null,function*(){return yield this.nativeTools.isValidAddress(t)})}importPrivateKey(t){return m(this,arguments,function*(e,n={}){const{pluginId:r}=this.currencyInfo,o=(0,C.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 c=i;const{birthdayHeight:a}=n;if(a!=null){(0,N.ym)(a);const h=parseInt(a);if(h>i)throw new Error("InvalidBirthdayHeight");c=h}return{[`${r}Mnemonic`]:e,[`${r}BirthdayHeight`]:c}})}createPrivateKey(t){return m(this,null,function*(){if(t!==this.currencyInfo.walletType)throw new Error("InvalidWalletType");const e=x.Buffer.from(this.io.random(32)).toString("hex"),n=(0,C.entropyToMnemonic)(e);return yield this.importPrivateKey(n)})}checkPublicKey(t){return m(this,null,function*(){try{return(0,I.QC)(t).publicKey.length>0}catch{return!1}})}derivePublicKey(t){return m(this,null,function*(){const{pluginId:e}=this.currencyInfo,n=(0,I.cl)(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 m(this,null,function*(){const{pluginId:r}=this.currencyInfo,o={[r]:!0},{edgeParsedUri:i,edgeParsedUri:{publicAddress:c}}=yield(0,O.x)({currencyInfo:this.currencyInfo,uri:t,networks:o,builtinTokens:this.builtinTokens,currencyCode:e!=null?e:this.currencyInfo.currencyCode,customTokens:n});if(c==null||!(yield this.isValidAddress(c)))throw new Error("InvalidPublicAddressError");return i})}encodeUri(t){return m(this,arguments,function*(e,n=[]){const{pluginId:r}=this.currencyInfo,{nativeAmount:o,currencyCode:i,publicAddress:c}=e;if(!(yield this.isValidAddress(c)))throw new Error("InvalidPublicAddressError");let a;if(o!=null){const A=(0,z.FQ)(i!=null?i:this.currencyInfo.currencyCode,this.currencyInfo,n,this.builtinTokens);if(A==null)throw new Error("InternalErrorInvalidCurrencyCode");a=(0,f.div)(o,A.multiplier,18)}return(0,O.m)(e,`${r}`,a)})}}function V(s){return m(this,null,function*(){return new U(s)})}function W(s,t){return m(this,null,function*(){const e=j(t,[]);s.networkInfo=(0,z.wy)(s.networkInfo,e)})}},15340:function(){},79838:function(){}}]);
6
+ ${n.birthdayHeight}`})}getDisplayPublicKey(t){return d(this,null,function*(){const{keys:e}=(0,f.xH)(t);return e.publicKey})}getNewWalletBirthdayBlockheight(){return d(this,null,function*(){return yield this.nativeTools.getBirthdayHeight(this.networkInfo.rpcNode.defaultHost,this.networkInfo.rpcNode.defaultPort)})}isValidAddress(t){return d(this,null,function*(){return yield this.nativeTools.isValidAddress(t)})}importPrivateKey(t){return d(this,arguments,function*(e,n={}){const{pluginId:r}=this.currencyInfo,o=(0,I.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 l=i;const{birthdayHeight:a}=n;if(a!=null){(0,D.ym)(a);const c=parseInt(a);if(c>i)throw new Error("InvalidBirthdayHeight");l=c}return{[`${r}Mnemonic`]:e,[`${r}BirthdayHeight`]:l}})}createPrivateKey(t){return d(this,null,function*(){if(t!==this.currencyInfo.walletType)throw new Error("InvalidWalletType");const e=E.Buffer.from(this.io.random(32)).toString("hex"),n=(0,I.entropyToMnemonic)(e);return yield this.importPrivateKey(n)})}checkPublicKey(t){return d(this,null,function*(){try{return(0,f.QC)(t).publicKey.length>0}catch{return!1}})}derivePublicKey(t){return d(this,null,function*(){const{pluginId:e}=this.currencyInfo,n=(0,f.cl)(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 d(this,null,function*(){const{pluginId:r}=this.currencyInfo,o={[r]:!0},{edgeParsedUri:i,edgeParsedUri:{publicAddress:l}}=yield(0,b.x)({currencyInfo:this.currencyInfo,uri:t,networks:o,builtinTokens:this.builtinTokens,currencyCode:e!=null?e:this.currencyInfo.currencyCode,customTokens:n});if(l==null||!(yield this.isValidAddress(l)))throw new Error("InvalidPublicAddressError");return i})}encodeUri(t){return d(this,arguments,function*(e,n=[]){const{pluginId:r}=this.currencyInfo,{nativeAmount:o,currencyCode:i,publicAddress:l}=e;if(!(yield this.isValidAddress(l)))throw new Error("InvalidPublicAddressError");let a;if(o!=null){const g=(0,v.FQ)(i!=null?i:this.currencyInfo.currencyCode,this.currencyInfo,n,this.builtinTokens);if(g==null)throw new Error("InternalErrorInvalidCurrencyCode");a=(0,y.div)(o,g.multiplier,18)}return(0,b.m)(e,`${r}`,a)})}}function M(s){return d(this,null,function*(){return new A(s)})}function $(s,t){return d(this,null,function*(){const e=F(t,[]);s.networkInfo=(0,v.wy)(s.networkInfo,e)})}},15340:function(){},79838:function(){}}]);
@@ -21,7 +21,6 @@ var _rfc4648 = require('rfc4648');
21
21
 
22
22
  var _CurrencyEngine = require('../common/CurrencyEngine');
23
23
 
24
- var _network = require('../common/network');
25
24
  var _utils = require('../common/utils');
26
25
 
27
26
 
@@ -34,8 +33,6 @@ var _utils = require('../common/utils');
34
33
 
35
34
  var _piratechainTypes = require('./piratechainTypes');
36
35
 
37
- const BUMP_SYNCHRONIZER_POLL_MILLISECONDS = _network.getRandomDelayMs.call(void 0, 30000)
38
-
39
36
  class PiratechainEngine extends _CurrencyEngine.CurrencyEngine
40
37
 
41
38
 
@@ -183,38 +180,9 @@ const BUMP_SYNCHRONIZER_POLL_MILLISECONDS = _network.getRandomDelayMs.call(void
183
180
  }
184
181
  }
185
182
 
186
- // Sometimes the synchronizer block downloader just kind of stops. If we
187
- // haven't heard from it in a while we can give a bump to encourage it to
188
- // continue.
189
- async bumpSynchronizer() {
190
- if (
191
- this.isSynced() ||
192
- this.lastUpdateFromSynchronizer == null ||
193
- Date.now() <
194
- this.lastUpdateFromSynchronizer + BUMP_SYNCHRONIZER_POLL_MILLISECONDS
195
- ) {
196
- return
197
- }
198
-
199
- this.log.warn(
200
- `Haven't heard from the synchronizer in a while. Applying the Fonzie Method...`
201
- )
202
- await _optionalChain([this, 'access', _ => _.synchronizer, 'optionalAccess', _2 => _2.stop, 'call', _3 => _3()])
203
- if (this.stopSyncing != null) {
204
- await this.stopSyncing(5000)
205
- this.stopSyncing = undefined
206
- }
207
- this.log.warn('👍 Ayyy 👍')
208
- this.lastUpdateFromSynchronizer = undefined
209
- }
210
-
211
183
  async startEngine() {
212
184
  this.engineOn = true
213
185
  this.started = true
214
- this.addToLoop(
215
- 'bumpSynchronizer',
216
- BUMP_SYNCHRONIZER_POLL_MILLISECONDS
217
- ).catch(() => {})
218
186
  await super.startEngine()
219
187
  }
220
188
 
@@ -322,7 +290,7 @@ const BUMP_SYNCHRONIZER_POLL_MILLISECONDS = _network.getRandomDelayMs.call(void
322
290
 
323
291
  const piratechainPrivateKeys = _piratechainTypes.asPiratechainPrivateKeys.call(void 0,
324
292
  this.currencyInfo.pluginId
325
- )(_optionalChain([opts, 'optionalAccess', _4 => _4.privateKeys]))
293
+ )(_optionalChain([opts, 'optionalAccess', _ => _.privateKeys]))
326
294
 
327
295
  const { rpcNode } = this.networkInfo
328
296
  this.initializer = {
@@ -357,7 +325,7 @@ const BUMP_SYNCHRONIZER_POLL_MILLISECONDS = _network.getRandomDelayMs.call(void
357
325
  await this.stopSyncing(1000)
358
326
  this.stopSyncing = undefined
359
327
  }
360
- await _optionalChain([this, 'access', _5 => _5.synchronizer, 'optionalAccess', _6 => _6.stop, 'call', _7 => _7()])
328
+ await _optionalChain([this, 'access', _2 => _2.synchronizer, 'optionalAccess', _3 => _3.stop, 'call', _4 => _4()])
361
329
  await super.killEngine()
362
330
  }
363
331
 
@@ -370,9 +338,9 @@ const BUMP_SYNCHRONIZER_POLL_MILLISECONDS = _network.getRandomDelayMs.call(void
370
338
  await super.killEngine()
371
339
  await this.clearBlockchainCache()
372
340
  await this.startEngine()
373
- _optionalChain([this, 'access', _8 => _8.synchronizer
374
- , 'optionalAccess', _9 => _9.rescan, 'call', _10 => _10()
375
- , 'access', _11 => _11.catch, 'call', _12 => _12((e) => this.warn('resyncBlockchain failed: ', e))])
341
+ _optionalChain([this, 'access', _5 => _5.synchronizer
342
+ , 'optionalAccess', _6 => _6.rescan, 'call', _7 => _7()
343
+ , 'access', _8 => _8.catch, 'call', _9 => _9((e) => this.warn('resyncBlockchain failed: ', e))])
376
344
  this.initData()
377
345
  this.progressRatio = 0
378
346
  this.synchronizerStatus = 'SYNCING'
@@ -453,7 +421,7 @@ const BUMP_SYNCHRONIZER_POLL_MILLISECONDS = _network.getRandomDelayMs.call(void
453
421
  if (this.synchronizer == null) throw new Error('Synchronizer undefined')
454
422
  const { memos } = edgeTransaction
455
423
  const piratechainPrivateKeys = _piratechainTypes.asPiratechainPrivateKeys.call(void 0, this.pluginId)(
456
- _optionalChain([opts, 'optionalAccess', _13 => _13.privateKeys])
424
+ _optionalChain([opts, 'optionalAccess', _10 => _10.privateKeys])
457
425
  )
458
426
  if (
459
427
  edgeTransaction.spendTargets == null ||
@@ -461,7 +429,7 @@ const BUMP_SYNCHRONIZER_POLL_MILLISECONDS = _network.getRandomDelayMs.call(void
461
429
  )
462
430
  throw new Error('Invalid spend targets')
463
431
 
464
- const memo = _optionalChain([memos, 'access', _14 => _14[0], 'optionalAccess', _15 => _15.type]) === 'text' ? memos[0].value : ''
432
+ const memo = _optionalChain([memos, 'access', _11 => _11[0], 'optionalAccess', _12 => _12.type]) === 'text' ? memos[0].value : ''
465
433
  const spendTarget = edgeTransaction.spendTargets[0]
466
434
  const txParams = {
467
435
  zatoshi: _biggystring.sub.call(void 0,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "edge-currency-accountbased",
3
- "version": "4.25.0",
3
+ "version": "4.25.1",
4
4
  "description": "Edge currency plugin for account based currencies",
5
5
  "homepage": "https://edge.app/",
6
6
  "repository": {