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],{
|
|
2
|
-
${(0,
|
|
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
|
|
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',
|
|
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',
|
|
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',
|
|
374
|
-
, 'optionalAccess',
|
|
375
|
-
, 'access',
|
|
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',
|
|
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',
|
|
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,
|