edge-currency-accountbased 2.2.1 → 2.2.2
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 +10 -6
- package/android/src/main/assets/edge-currency-accountbased/223.chunk.js +2 -2
- package/android/src/main/assets/edge-currency-accountbased/polkadot.chunk.js +2 -2
- package/lib/polkadot/PolkadotEngine.js +21 -44
- package/lib/polkadot/polkadotTypes.js +0 -9
- package/package.json +1 -1
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";(self.webpackChunkedge_currency_accountbased=self.webpackChunkedge_currency_accountbased||[]).push([[591],{79014:function(et,M,f){f.d(M,{Q:function(){return _},k:function(){return Q}});var E=f(77591),j=f.n(E),W=f(24350),X=f(84564),a=f.n(X),L=f(76714),U=Object.defineProperty,S=Object.getOwnPropertySymbols,F=Object.prototype.hasOwnProperty,I=Object.prototype.propertyIsEnumerable,i=(h,m,g)=>m in h?U(h,m,{enumerable:!0,configurable:!0,writable:!0,value:g}):h[m]=g,V=(h,m)=>{for(var g in m||(m={}))F.call(m,g)&&i(h,g,m[g]);if(S)for(var g of S(m))I.call(m,g)&&i(h,g,m[g]);return h};function Q(h,m,g,k,T=[]){const p=V({},a()(m,{},!0)),O=m.startsWith(`${h.pluginId}://`);if(p.protocol!=null&&(p.protocol=p.protocol.replace(":","")),p.protocol!=null&&p.protocol!==""&&!g[p.protocol])throw new Error(`Uri protocol '${p.protocol}' is not supported for ${h.pluginId}.`);if(p.host===""&&p.pathname==="")throw new Error("Path and host not found in uri.");const C={publicAddress:p.host!==""?p.host:p.pathname.split("/")[0]},H=p.query.label,$=p.query.message,B=p.query.category;(H!=null||$!=null||B!=null||O)&&(C.metadata={},C.metadata.name=H,C.metadata.notes=$,C.metadata.category=B,C.metadata.gateway=O!=null?O:!1);const x=p.query.amount;if(x!=null&&typeof x=="string"){k==null&&(k=h.currencyCode);const R=(0,L.Qs)(k!=null?k:"",h,T);if(R==null)throw new Error("InternalErrorInvalidCurrencyCode");let D=(0,E.mul)(x,R.multiplier);D=(0,E.toFixed)(D,0,0),C.nativeAmount=D,C.currencyCode=k}return{edgeParsedUri:C,parsedUri:p}}function _(h,m,g){if(h.publicAddress==null)throw new Error("InvalidPublicAddressError");if(g==null&&h.label==null&&h.message==null)return h.publicAddress;{let k="";g!=null&&(k+="amount="+g+"&"),(h.label!=null||h.message!=null)&&(typeof h.label=="string"&&(k+="label="+h.label+"&"),typeof h.message=="string"&&(k+="message="+h.message+"&")),k=k.substr(0,k.length-1);const T={scheme:m,path:h.publicAddress,query:k};return(0,W.qC)(T)}}},34765:function(et,M,f){f.r(M),f.d(M,{PolkadotTools:function(){return tt},makeCurrencyEngine:function(){return at},makeCurrencyTools:function(){return ut}});var E=f(58170),j=f(21293),W=f(18534),X=f(23670),a=f(77591),L=f(2153),U=f(48764),S=f(20918),F=f(79014),I=f(76714),i=f(82448),V=f(62177);const Q=(0,i.Vk)((0,i.su)({balance:i.mH})),_=(0,i.su)({txCount:(0,i.Vk)(i.mH,0)}),h=(0,i.su)({code:i.mH,message:i.XC,data:(0,i.Zz)((0,i.su)(i.JC))}),m=(0,i.su)({from:i.XC,to:i.XC,success:i.jK,hash:i.XC,block_num:i.mH,block_timestamp:i.mH,module:i.XC,amount:i.XC,fee:i.XC}),g=(0,i.su)({count:i.mH,transfers:(0,i.Vk)((0,i._2)(m),()=>[])}),k=V.BQ,T=u=>{const t=(0,i.su)({[`${u}Mnemonic`]:(0,i.Zz)(i.XC),[`${u}Key`]:i.XC});return(0,i.W1)(e=>{const s=t(e);return{mnemonic:s[`${u}Mnemonic`],privateKey:s[`${u}Key`]}},e=>({[`${u}Mnemonic`]:e.mnemonic,[`${u}Key`]:e.privateKey}))};var p=f(94935),O=f(35620),z=f(84650),C=Object.defineProperty,H=Object.defineProperties,$=Object.getOwnPropertyDescriptors,B=Object.getOwnPropertySymbols,x=Object.getPrototypeOf,R=Object.prototype.hasOwnProperty,D=Object.prototype.propertyIsEnumerable,nt=Reflect.get,G=(u,t,e)=>t in u?C(u,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):u[t]=e,q=(u,t)=>{for(var e in t||(t={}))R.call(t,e)&&G(u,e,t[e]);if(B)for(var e of B(t))D.call(t,e)&&G(u,e,t[e]);return u},Y=(u,t)=>H(u,$(t)),J=(u,t,e)=>nt(x(u),e,t),w=(u,t,e)=>new Promise((s,n)=>{var r=o=>{try{d(e.next(o))}catch(l){n(l)}},c=o=>{try{d(e.throw(o))}catch(l){n(l)}},d=o=>o.done?s(o.value):Promise.resolve(o.value).then(r,c);d((e=e.apply(u,t)).next())});const rt=5e3,st=2e4,ot=3e3,it=(0,I.jT)();class N extends z.P{constructor(t,e,s,n){super(t,e,s,n),this.getRecipientBalance=r=>w(this,null,function*(){try{return(yield this.api.query.system.account(r)).data.free.toString()}catch{return this.minimumAddressBalance}}),this.fetchCors=(0,I.zR)(t.io),this.networkInfo=t.networkInfo,this.nonce=0}setOtherData(t){this.otherData=_(t)}fetchSubscan(t,e){return w(this,null,function*(){if(this.networkInfo.subscanBaseUrl==null)throw new Error("Missing subscan url");const s={method:"POST",headers:{Accept:"application/json","Content-Type":"application/json"},body:JSON.stringify(e)},n=yield this.fetchCors(this.networkInfo.subscanBaseUrl+t,s);if(!n.ok||n.status===429)throw new Error(`Subscan ${t} failed with ${n.status}`);const r=yield n.json();return h(r)})}queryBalance(){return w(this,null,function*(){const t=[[this.api.query.system.account,this.walletInfo.keys.publicKey]],e=[];for(const n of this.enabledTokenIds){const r=this.allTokensMap[n];if(r==null)continue;const c=(0,S.Oj)(r.networkLocation);c!=null&&(t.push([this.api.query.assets.account,[c.contractAddress,this.walletInfo.keys.publicKey]]),e.push(r))}(yield this.api.queryMulti(t,n=>{if(n.length===0)throw new Error("No balances returned");const r=n.shift();this.nonce=r.nonce.toNumber(),this.updateBalance(this.currencyInfo.currencyCode,r.data.free.toString());for(const[c,d]of n.entries()){const o=e[c],l=Q(d.toPrimitive());if(l==null){this.updateBalance(o.currencyCode,"0");return}this.updateBalance(o.currencyCode,l.balance.toString())}}))()})}queryBlockheight(){return w(this,null,function*(){try{const e=(yield this.api.rpc.chain.getBlock()).block.header.number.toNumber();e>this.walletLocalData.blockHeight&&(this.walletLocalData.blockHeight=e,this.walletLocalDataDirty=!0,this.currencyEngineCallbacks.onBlockHeightChanged(this.walletLocalData.blockHeight))}catch(t){this.warn("queryBlockheight failed with error: ",t)}})}processPolkadotTransaction(t){const{from:e,to:s,success:n,hash:r,block_num:c,block_timestamp:d,module:o,amount:l,fee:y}=t;if(!n||o!=="balances")return;const P=(0,I.aL)(this.currencyInfo.currencyCode,this.currencyInfo,this.allTokensMap);if(P==null)return;const A=[];let v=(0,a.mul)(l,P.multiplier);e===this.walletInfo.keys.publicKey?v=`-${(0,a.add)(v,y)}`:A.push(s);const K={txid:r,date:d,currencyCode:this.currencyInfo.currencyCode,blockHeight:c,nativeAmount:v,isSend:v.startsWith("-"),networkFee:y,ourReceiveAddresses:A,signedTx:"",walletId:this.walletId};this.addTransaction(this.currencyInfo.currencyCode,K)}queryTransactions(){return w(this,null,function*(){if(this.networkInfo.subscanBaseUrl==null){for(const t of this.enabledTokens)this.tokenCheckTransactionsStatus[t]=1;this.updateOnAddressesChecked();return}return yield it(()=>w(this,null,function*(){return yield this.queryTransactionsInner()}))})}queryTransactionsInner(){return w(this,null,function*(){let t=Math.floor(this.otherData.txCount/this.networkInfo.subscanQueryLimit);for(;;){const e={row:this.networkInfo.subscanQueryLimit,page:t,address:this.walletInfo.keys.publicKey};let s=0,n=[];try{const r=yield this.fetchSubscan("/scan/transfers",e),c=g(r.data);s=c.count,n=c.transfers}catch(r){if(r instanceof Error&&r.message.includes("Subscan /scan/transfers failed with 429")){this.log(r.message);continue}else throw r}if(s===this.otherData.txCount||(n.forEach(r=>{try{this.processPolkadotTransaction(m(r))}catch{const d=r!=null&&typeof r.hash=="string"?r.hash:"";this.warn(`Ignoring invalid transfer ${d}`)}}),this.otherData.txCount=t*this.networkInfo.subscanQueryLimit+n.length,this.tokenCheckTransactionsStatus[this.currencyInfo.currencyCode]=Math.min(1,s===0?1:this.otherData.txCount/s),this.updateOnAddressesChecked(),s===this.otherData.txCount))break;t++}this.tokenCheckTransactionsStatus[this.currencyInfo.currencyCode]=1,this.updateOnAddressesChecked(),this.transactionsChangedArray.length>0&&(this.walletLocalDataDirty=!0,this.currencyEngineCallbacks.onTransactionsChanged(this.transactionsChangedArray),this.transactionsChangedArray=[])})}startEngine(){return w(this,null,function*(){this.engineOn=!0,yield this.tools.connectApi(this.walletId),this.api=this.tools.polkadotApi,this.minimumAddressBalance=this.api.consts.balances.existentialDeposit.toString(),this.addToLoop("queryBlockheight",st).catch(()=>{}),this.addToLoop("queryBalance",rt).catch(()=>{}),this.addToLoop("queryTransactions",ot).catch(()=>{}),yield J(N.prototype,this,"startEngine").call(this)})}killEngine(){return w(this,null,function*(){yield J(N.prototype,this,"killEngine").call(this),yield this.tools.disconnectApi(this.walletId)})}resyncBlockchain(){return w(this,null,function*(){yield this.killEngine(),yield this.clearBlockchainCache(),yield this.startEngine()})}getMaxSpendable(t){return w(this,null,function*(){if(t.spendTargets.length===0||t.spendTargets[0].publicAddress==null)throw new Error("Missing public address");const e=this.getBalance({currencyCode:t.currencyCode});if(t.currencyCode!==this.currencyInfo.currencyCode){const l=[{publicAddress:t.spendTargets[0].publicAddress,nativeAmount:e}],y=Y(q({},t),{spendTargets:l});return yield this.makeSpend(y),e}const s=(0,a.sub)(e,this.api.consts.balances.existentialDeposit.toString()),n=[{publicAddress:t.spendTargets[0].publicAddress,nativeAmount:"0"}],r=Y(q({},t),{spendTargets:n}),d=(yield this.makeSpend(r)).networkFee,o=(l,y)=>{const P=(0,a.sub)(y,l);if((0,a.lte)(P,"1"))return l;const A=(0,a.add)(l,(0,a.div)(P,"2")),v=(0,I.X0)(A).replace("0x",""),K=v.length%2===1?`0${v}`:v,dt=(0,a.mul)((0,a.div)(K.length.toString(),"2"),this.networkInfo.lengthFeePerByte),ht=(0,a.add)((0,a.add)(dt,d),A);return(0,a.gt)(ht,s)?o(l,A):o(A,y)};return o("0",(0,a.add)(s,"1"))})}makeSpend(t){return w(this,null,function*(){const{edgeSpendInfo:e,currencyCode:s}=this.makeSpendCheck(t);if(e.spendTargets.length!==1)throw new Error("Error: only one output allowed");const{nativeAmount:n,publicAddress:r}=e.spendTargets[0];if(r==null)throw new Error("makeSpend Missing publicAddress");if(n==null)throw new p.$D;const c=this.getBalance({currencyCode:s});let d,o;if(e.tokenId==null){const P=(0,a.sub)(c,this.api.consts.balances.existentialDeposit.toString());if((0,a.gt)(n,P))throw new p.C_;const v=yield(yield this.api.tx.balances.transferKeepAlive(r,n)).paymentInfo(this.walletInfo.keys.publicKey);if(o=(0,a.sub)(v.partialFee.toString(),(0,a.mul)(this.networkInfo.lengthFeePerByte,this.networkInfo.partialFeeOffsetMultiplier)),d=(0,a.add)(n,o),(0,a.gt)(d,P))throw new p.C_}else{if((0,a.gt)(n,c))throw new p.C_;d=n;const A=yield(yield this.api.tx.assets.transfer(parseInt(e.tokenId),r,n)).paymentInfo(this.walletInfo.keys.publicKey);o=(0,a.sub)(A.partialFee.toString(),(0,a.mul)(this.networkInfo.lengthFeePerByte,this.networkInfo.partialFeeOffsetMultiplier));const v=this.getBalance({currencyCode:this.currencyInfo.currencyCode}),K=(0,a.sub)(v,this.api.consts.balances.existentialDeposit.toString());if((0,a.gt)(o,K))throw new p.C_({currencyCode:this.currencyInfo.currencyCode,networkFee:o})}const l={publicAddress:r};return{txid:"",date:0,currencyCode:s,blockHeight:0,nativeAmount:(0,a.mul)(d,"-1"),isSend:!0,networkFee:o,ourReceiveAddresses:[],signedTx:"",otherParams:l,walletId:this.walletId}})}signTx(t,e){return w(this,null,function*(){const s=T(this.currencyInfo.pluginId)(e),{publicAddress:n}=(0,I.Xp)(t);if(n==null)throw new Error("Missing publicAddress from makeSpend");const r=this.allTokens.find(y=>y.currencyCode===t.currencyCode);let c;if(r==null){const y=(0,a.abs)((0,a.add)(t.nativeAmount,t.networkFee));yield this.checkRecipientMinimumBalance(this.getRecipientBalance,y,n),c=yield this.api.tx.balances.transferKeepAlive(n,y)}else if(r.contractAddress!=null){const y=(0,a.abs)(t.nativeAmount);c=yield this.api.tx.assets.transfer(parseInt(r.contractAddress),n,y)}else throw new Error("Unrecognized asset");const d=this.api.createType("SignerPayload",{method:c,nonce:this.nonce,genesisHash:this.api.genesisHash,blockHash:this.api.genesisHash,runtimeVersion:this.api.runtimeVersion,version:this.api.extrinsicVersion}),o=this.api.createType("ExtrinsicPayload",d.toPayload(),{version:this.api.extrinsicVersion});if(this.keypair==null)if(this.keypair=new E.Y({ss58Format:0}),s.mnemonic!=null)this.keypair.addFromUri(s.mnemonic);else{const y=O.YU.parse(s.privateKey);this.keypair.addFromSeed(y)}const l=o.sign(this.keypair.getPair(this.walletInfo.keys.publicKey));return c.addSignature(this.walletInfo.keys.publicKey,l.signature,d.toPayload()),t.signedTx=c.toHex(),t})}broadcastTx(t){return w(this,null,function*(){try{const e=yield this.api.rpc.author.submitExtrinsic(t.signedTx);t.txid=e.toHex(),t.date=Date.now()/1e3,this.warn(`SUCCESS broadcastTx
|
|
2
|
-
${(0,I.oX)(t)}`)}catch(e){throw this.warn("FAILURE broadcastTx failed: ",e),e}return t})}}function
|
|
1
|
+
"use strict";(self.webpackChunkedge_currency_accountbased=self.webpackChunkedge_currency_accountbased||[]).push([[591],{79014:function(et,M,d){d.d(M,{Q:function(){return _},k:function(){return V}});var S=d(77591),j=d.n(S),W=d(24350),X=d(84564),i=d.n(X),L=d(76714),U=Object.defineProperty,T=Object.getOwnPropertySymbols,F=Object.prototype.hasOwnProperty,I=Object.prototype.propertyIsEnumerable,a=(c,g,m)=>g in c?U(c,g,{enumerable:!0,configurable:!0,writable:!0,value:m}):c[g]=m,Q=(c,g)=>{for(var m in g||(g={}))F.call(g,m)&&a(c,m,g[m]);if(T)for(var m of T(g))I.call(g,m)&&a(c,m,g[m]);return c};function V(c,g,m,k,P=[]){const y=Q({},i()(g,{},!0)),O=g.startsWith(`${c.pluginId}://`);if(y.protocol!=null&&(y.protocol=y.protocol.replace(":","")),y.protocol!=null&&y.protocol!==""&&!m[y.protocol])throw new Error(`Uri protocol '${y.protocol}' is not supported for ${c.pluginId}.`);if(y.host===""&&y.pathname==="")throw new Error("Path and host not found in uri.");const C={publicAddress:y.host!==""?y.host:y.pathname.split("/")[0]},H=y.query.label,x=y.query.message,R=y.query.category;(H!=null||x!=null||R!=null||O)&&(C.metadata={},C.metadata.name=H,C.metadata.notes=x,C.metadata.category=R,C.metadata.gateway=O!=null?O:!1);const B=y.query.amount;if(B!=null&&typeof B=="string"){k==null&&(k=c.currencyCode);const $=(0,L.Qs)(k!=null?k:"",c,P);if($==null)throw new Error("InternalErrorInvalidCurrencyCode");let D=(0,S.mul)(B,$.multiplier);D=(0,S.toFixed)(D,0,0),C.nativeAmount=D,C.currencyCode=k}return{edgeParsedUri:C,parsedUri:y}}function _(c,g,m){if(c.publicAddress==null)throw new Error("InvalidPublicAddressError");if(m==null&&c.label==null&&c.message==null)return c.publicAddress;{let k="";m!=null&&(k+="amount="+m+"&"),(c.label!=null||c.message!=null)&&(typeof c.label=="string"&&(k+="label="+c.label+"&"),typeof c.message=="string"&&(k+="message="+c.message+"&")),k=k.substr(0,k.length-1);const P={scheme:g,path:c.publicAddress,query:k};return(0,W.qC)(P)}}},34765:function(et,M,d){d.r(M),d.d(M,{PolkadotTools:function(){return tt},makeCurrencyEngine:function(){return it},makeCurrencyTools:function(){return ct}});var S=d(58170),j=d(21293),W=d(18534),X=d(23670),i=d(77591),L=d(2153),U=d(48764),T=d(20918),F=d(79014),I=d(76714),a=d(82448),Q=d(62177);const V=(0,a.su)({txCount:(0,a.Vk)(a.mH,0)}),_=(0,a.su)({code:a.mH,message:a.XC,data:(0,a.Zz)((0,a.su)(a.JC))}),c=(0,a.su)({from:a.XC,to:a.XC,success:a.jK,hash:a.XC,block_num:a.mH,block_timestamp:a.mH,module:a.XC,amount:a.XC,fee:a.XC}),g=(0,a.su)({count:a.mH,transfers:(0,a.Vk)((0,a._2)(c),()=>[])}),m=Q.BQ,k=u=>{const t=(0,a.su)({[`${u}Mnemonic`]:(0,a.Zz)(a.XC),[`${u}Key`]:a.XC});return(0,a.W1)(e=>{const r=t(e);return{mnemonic:r[`${u}Mnemonic`],privateKey:r[`${u}Key`]}},e=>({[`${u}Mnemonic`]:e.mnemonic,[`${u}Key`]:e.privateKey}))};var P=d(94935),y=d(35620),O=d(84650),z=Object.defineProperty,C=Object.defineProperties,H=Object.getOwnPropertyDescriptors,x=Object.getOwnPropertySymbols,R=Object.getPrototypeOf,B=Object.prototype.hasOwnProperty,$=Object.prototype.propertyIsEnumerable,D=Reflect.get,G=(u,t,e)=>t in u?z(u,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):u[t]=e,Y=(u,t)=>{for(var e in t||(t={}))B.call(t,e)&&G(u,e,t[e]);if(x)for(var e of x(t))$.call(t,e)&&G(u,e,t[e]);return u},J=(u,t)=>C(u,H(t)),Z=(u,t,e)=>D(R(u),e,t),w=(u,t,e)=>new Promise((r,n)=>{var s=o=>{try{h(e.next(o))}catch(f){n(f)}},l=o=>{try{h(e.throw(o))}catch(f){n(f)}},h=o=>o.done?r(o.value):Promise.resolve(o.value).then(s,l);h((e=e.apply(u,t)).next())});const nt=5e3,rt=2e4,st=3e3,ot=(0,I.jT)();class N extends O.P{constructor(t,e,r,n){super(t,e,r,n),this.getRecipientBalance=s=>w(this,null,function*(){try{return(yield this.api.query.system.account(s)).data.free.toString()}catch{return this.minimumAddressBalance}}),this.fetchCors=(0,I.zR)(t.io),this.networkInfo=t.networkInfo,this.nonce=0}setOtherData(t){this.otherData=V(t)}fetchSubscan(t,e){return w(this,null,function*(){if(this.networkInfo.subscanBaseUrl==null)throw new Error("Missing subscan url");const r={method:"POST",headers:{Accept:"application/json","Content-Type":"application/json"},body:JSON.stringify(e)},n=yield this.fetchCors(this.networkInfo.subscanBaseUrl+t,r);if(!n.ok||n.status===429)throw new Error(`Subscan ${t} failed with ${n.status}`);const s=yield n.json();return _(s)})}queryBalance(){return w(this,null,function*(){const t=yield this.api.query.system.account(this.walletInfo.keys.publicKey);this.nonce=t.nonce.toNumber(),this.updateBalance(this.currencyInfo.currencyCode,t.data.free.toString());for(const e of this.enabledTokenIds){const r=this.allTokensMap[e];if(r==null)continue;const n=(0,T.Oj)(r.networkLocation);if(n==null)continue;const s=yield this.api.query.assets.account(n.contractAddress,this.walletInfo.keys.publicKey);let l="0";s.isSome&&(l=s.unwrap().balance.toString()),this.updateBalance(r.currencyCode,l)}})}queryBlockheight(){return w(this,null,function*(){try{const e=(yield this.api.rpc.chain.getBlock()).block.header.number.toNumber();e>this.walletLocalData.blockHeight&&(this.walletLocalData.blockHeight=e,this.walletLocalDataDirty=!0,this.currencyEngineCallbacks.onBlockHeightChanged(this.walletLocalData.blockHeight))}catch(t){this.warn("queryBlockheight failed with error: ",t)}})}processPolkadotTransaction(t){const{from:e,to:r,success:n,hash:s,block_num:l,block_timestamp:h,module:o,amount:f,fee:p}=t;if(!n||o!=="balances")return;const E=(0,I.aL)(this.currencyInfo.currencyCode,this.currencyInfo,this.allTokensMap);if(E==null)return;const A=[];let v=(0,i.mul)(f,E.multiplier);e===this.walletInfo.keys.publicKey?v=`-${(0,i.add)(v,p)}`:A.push(r);const K={txid:s,date:h,currencyCode:this.currencyInfo.currencyCode,blockHeight:l,nativeAmount:v,isSend:v.startsWith("-"),networkFee:p,ourReceiveAddresses:A,signedTx:"",walletId:this.walletId};this.addTransaction(this.currencyInfo.currencyCode,K)}queryTransactions(){return w(this,null,function*(){if(this.networkInfo.subscanBaseUrl==null){for(const t of this.enabledTokens)this.tokenCheckTransactionsStatus[t]=1;this.updateOnAddressesChecked();return}return yield ot(()=>w(this,null,function*(){return yield this.queryTransactionsInner()}))})}queryTransactionsInner(){return w(this,null,function*(){let t=Math.floor(this.otherData.txCount/this.networkInfo.subscanQueryLimit);for(;;){const e={row:this.networkInfo.subscanQueryLimit,page:t,address:this.walletInfo.keys.publicKey};let r=0,n=[];try{const s=yield this.fetchSubscan("/scan/transfers",e),l=g(s.data);r=l.count,n=l.transfers}catch(s){if(s instanceof Error&&s.message.includes("Subscan /scan/transfers failed with 429")){this.log(s.message);continue}else throw s}if(r===this.otherData.txCount||(n.forEach(s=>{try{this.processPolkadotTransaction(c(s))}catch{const h=s!=null&&typeof s.hash=="string"?s.hash:"";this.warn(`Ignoring invalid transfer ${h}`)}}),this.otherData.txCount=t*this.networkInfo.subscanQueryLimit+n.length,this.tokenCheckTransactionsStatus[this.currencyInfo.currencyCode]=Math.min(1,r===0?1:this.otherData.txCount/r),this.updateOnAddressesChecked(),r===this.otherData.txCount))break;t++}this.tokenCheckTransactionsStatus[this.currencyInfo.currencyCode]=1,this.updateOnAddressesChecked(),this.transactionsChangedArray.length>0&&(this.walletLocalDataDirty=!0,this.currencyEngineCallbacks.onTransactionsChanged(this.transactionsChangedArray),this.transactionsChangedArray=[])})}startEngine(){return w(this,null,function*(){this.engineOn=!0,yield this.tools.connectApi(this.walletId),this.api=this.tools.polkadotApi,this.minimumAddressBalance=this.api.consts.balances.existentialDeposit.toString(),this.addToLoop("queryBlockheight",rt).catch(()=>{}),this.addToLoop("queryBalance",nt).catch(()=>{}),this.addToLoop("queryTransactions",st).catch(()=>{}),yield Z(N.prototype,this,"startEngine").call(this)})}killEngine(){return w(this,null,function*(){yield Z(N.prototype,this,"killEngine").call(this),yield this.tools.disconnectApi(this.walletId)})}resyncBlockchain(){return w(this,null,function*(){yield this.killEngine(),yield this.clearBlockchainCache(),yield this.startEngine()})}getMaxSpendable(t){return w(this,null,function*(){if(t.spendTargets.length===0||t.spendTargets[0].publicAddress==null)throw new Error("Missing public address");const e=this.getBalance({currencyCode:t.currencyCode});if(t.currencyCode!==this.currencyInfo.currencyCode){const f=[{publicAddress:t.spendTargets[0].publicAddress,nativeAmount:e}],p=J(Y({},t),{spendTargets:f});return yield this.makeSpend(p),e}const r=(0,i.sub)(e,this.api.consts.balances.existentialDeposit.toString()),n=[{publicAddress:t.spendTargets[0].publicAddress,nativeAmount:"0"}],s=J(Y({},t),{spendTargets:n}),h=(yield this.makeSpend(s)).networkFee,o=(f,p)=>{const E=(0,i.sub)(p,f);if((0,i.lte)(E,"1"))return f;const A=(0,i.add)(f,(0,i.div)(E,"2")),v=(0,I.X0)(A).replace("0x",""),K=v.length%2===1?`0${v}`:v,ut=(0,i.mul)((0,i.div)(K.length.toString(),"2"),this.networkInfo.lengthFeePerByte),dt=(0,i.add)((0,i.add)(ut,h),A);return(0,i.gt)(dt,r)?o(f,A):o(A,p)};return o("0",(0,i.add)(r,"1"))})}makeSpend(t){return w(this,null,function*(){const{edgeSpendInfo:e,currencyCode:r}=this.makeSpendCheck(t);if(e.spendTargets.length!==1)throw new Error("Error: only one output allowed");const{nativeAmount:n,publicAddress:s}=e.spendTargets[0];if(s==null)throw new Error("makeSpend Missing publicAddress");if(n==null)throw new P.$D;const l=this.getBalance({currencyCode:r});let h,o;if(e.tokenId==null){const E=(0,i.sub)(l,this.api.consts.balances.existentialDeposit.toString());if((0,i.gt)(n,E))throw new P.C_;const v=yield(yield this.api.tx.balances.transferKeepAlive(s,n)).paymentInfo(this.walletInfo.keys.publicKey);if(o=(0,i.sub)(v.partialFee.toString(),(0,i.mul)(this.networkInfo.lengthFeePerByte,this.networkInfo.partialFeeOffsetMultiplier)),h=(0,i.add)(n,o),(0,i.gt)(h,E))throw new P.C_}else{if((0,i.gt)(n,l))throw new P.C_;h=n;const A=yield(yield this.api.tx.assets.transfer(parseInt(e.tokenId),s,n)).paymentInfo(this.walletInfo.keys.publicKey);o=(0,i.sub)(A.partialFee.toString(),(0,i.mul)(this.networkInfo.lengthFeePerByte,this.networkInfo.partialFeeOffsetMultiplier));const v=this.getBalance({currencyCode:this.currencyInfo.currencyCode}),K=(0,i.sub)(v,this.api.consts.balances.existentialDeposit.toString());if((0,i.gt)(o,K))throw new P.C_({currencyCode:this.currencyInfo.currencyCode,networkFee:o})}const f={publicAddress:s};return{txid:"",date:0,currencyCode:r,blockHeight:0,nativeAmount:(0,i.mul)(h,"-1"),isSend:!0,networkFee:o,ourReceiveAddresses:[],signedTx:"",otherParams:f,walletId:this.walletId}})}signTx(t,e){return w(this,null,function*(){const r=k(this.currencyInfo.pluginId)(e),{publicAddress:n}=(0,I.Xp)(t);if(n==null)throw new Error("Missing publicAddress from makeSpend");const s=this.allTokens.find(p=>p.currencyCode===t.currencyCode);let l;if(s==null){const p=(0,i.abs)((0,i.add)(t.nativeAmount,t.networkFee));yield this.checkRecipientMinimumBalance(this.getRecipientBalance,p,n),l=yield this.api.tx.balances.transferKeepAlive(n,p)}else if(s.contractAddress!=null){const p=(0,i.abs)(t.nativeAmount);l=yield this.api.tx.assets.transfer(parseInt(s.contractAddress),n,p)}else throw new Error("Unrecognized asset");const h=this.api.createType("SignerPayload",{method:l,nonce:this.nonce,genesisHash:this.api.genesisHash,blockHash:this.api.genesisHash,runtimeVersion:this.api.runtimeVersion,version:this.api.extrinsicVersion}),o=this.api.createType("ExtrinsicPayload",h.toPayload(),{version:this.api.extrinsicVersion});if(this.keypair==null)if(this.keypair=new S.Y({ss58Format:0}),r.mnemonic!=null)this.keypair.addFromUri(r.mnemonic);else{const p=y.YU.parse(r.privateKey);this.keypair.addFromSeed(p)}const f=o.sign(this.keypair.getPair(this.walletInfo.keys.publicKey));return l.addSignature(this.walletInfo.keys.publicKey,f.signature,h.toPayload()),t.signedTx=l.toHex(),t})}broadcastTx(t){return w(this,null,function*(){try{const e=yield this.api.rpc.author.submitExtrinsic(t.signedTx);t.txid=e.toHex(),t.date=Date.now()/1e3,this.warn(`SUCCESS broadcastTx
|
|
2
|
+
${(0,I.oX)(t)}`)}catch(e){throw this.warn("FAILURE broadcastTx failed: ",e),e}return t})}}function it(u,t,e,r){return w(this,null,function*(){const n=m(e),s=new N(u,t,n,r);return yield s.loadEngine(),s})}var b=(u,t,e)=>new Promise((r,n)=>{var s=o=>{try{h(e.next(o))}catch(f){n(f)}},l=o=>{try{h(e.throw(o))}catch(f){n(f)}},h=o=>o.done?r(o.value):Promise.resolve(o.value).then(s,l);h((e=e.apply(u,t)).next())});const{ed25519PairFromSeed:at,isAddress:q,mnemonicToMiniSecret:lt}=X;class tt{constructor(t){const{builtinTokens:e,currencyInfo:r,io:n,networkInfo:s}=t;this.builtinTokens=e,this.currencyInfo=r,this.io=n,this.networkInfo=s,this.polkadotApiSubscribers=new Set}getDisplayPrivateKey(t){return b(this,null,function*(){var e;const{pluginId:r}=this.currencyInfo,n=k(r)(t.keys);return(e=n.mnemonic)!=null?e:n.privateKey})}getDisplayPublicKey(t){return b(this,null,function*(){const{keys:e}=m(t);return e.publicKey})}importPrivateKey(t){return b(this,null,function*(){const{pluginId:e}=this.currencyInfo;if((0,L.validateMnemonic)(t)){const r=lt(t),{secretKey:n}=at(r);return{[`${e}Mnemonic`]:t,[`${e}Key`]:U.Buffer.from(n).toString("hex")}}else{if((0,I.vq)(t))return{[`${e}Key`]:t};throw new Error("InvalidPrivateKey")}})}createPrivateKey(t){return b(this,null,function*(){if(t!==this.currencyInfo.walletType)throw new Error("InvalidWalletType");const e=U.Buffer.from(this.io.random(32)),r=(0,L.entropyToMnemonic)(e);return yield this.importPrivateKey(r)})}derivePublicKey(t){return b(this,null,function*(){const{pluginId:e}=this.currencyInfo;return{publicKey:new S.Y({ss58Format:0}).addFromUri(t.keys[`${e}Mnemonic`]).address}})}parseUri(t,e,r){return b(this,null,function*(){var n,s;const{pluginId:l}=this.currencyInfo,h={[l]:!0},{parsedUri:o,edgeParsedUri:f}=(0,F.k)(this.currencyInfo,t,h,e!=null?e:this.currencyInfo.currencyCode,r),p=(n=f.publicAddress)!=null?n:"";if(!q(p))throw new Error("InvalidPublicAddressError");return f.uniqueIdentifier=(s=o.query.memo)!=null?s:void 0,f})}encodeUri(t){return b(this,arguments,function*(e,r=[]){const{pluginId:n}=this.currencyInfo,{nativeAmount:s,currencyCode:l,publicAddress:h}=e;if(!q(h))throw new Error("InvalidPublicAddressError");let o;if(typeof s=="string"){const p=(0,I.Qs)(l!=null?l:this.currencyInfo.currencyCode,this.currencyInfo,r);if(p==null)throw new Error("InternalErrorInvalidCurrencyCode");o=(0,i.div)(s,p.multiplier,10)}return(0,F.Q)(e,n,o)})}connectApi(t){return b(this,null,function*(){return this.polkadotApi==null&&(this.polkadotApi=yield j.G.create({initWasm:!1,provider:new W.U(this.networkInfo.rpcNodes[0])})),this.polkadotApiSubscribers.add(t),this.polkadotApi})}disconnectApi(t){return b(this,null,function*(){this.polkadotApiSubscribers.delete(t),this.polkadotApiSubscribers.size===0&&(yield this.polkadotApi.disconnect(),this.polkadotApi=void 0)})}getTokenId(t){return b(this,null,function*(){(0,T.Rp)(t);const e=(0,T.Oj)(t.networkLocation);if(e==null)throw new Error("ErrorInvalidContractAddress");return e.contractAddress})}}function ct(u){return b(this,null,function*(){return new tt(u)})}}}]);
|
|
@@ -14,8 +14,7 @@ var _biggystring = require('biggystring');
|
|
|
14
14
|
|
|
15
15
|
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
var _types3 = require('edge-core-js/types');
|
|
17
|
+
var _types = require('edge-core-js/types');
|
|
19
18
|
var _rfc4648 = require('rfc4648');
|
|
20
19
|
|
|
21
20
|
var _CurrencyEngine = require('../common/CurrencyEngine');
|
|
@@ -42,7 +41,6 @@ var _utils = require('../common/utils');
|
|
|
42
41
|
|
|
43
42
|
|
|
44
43
|
|
|
45
|
-
|
|
46
44
|
var _polkadotTypes = require('./polkadotTypes');
|
|
47
45
|
|
|
48
46
|
const ACCOUNT_POLL_MILLISECONDS = 5000
|
|
@@ -115,10 +113,14 @@ const queryTxMutex = _utils.makeMutex.call(void 0, )
|
|
|
115
113
|
}
|
|
116
114
|
|
|
117
115
|
async queryBalance() {
|
|
118
|
-
const
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
116
|
+
const accountBalanceRes = await this.api.query.system.account(
|
|
117
|
+
this.walletInfo.keys.publicKey
|
|
118
|
+
)
|
|
119
|
+
this.nonce = accountBalanceRes.nonce.toNumber()
|
|
120
|
+
this.updateBalance(
|
|
121
|
+
this.currencyInfo.currencyCode,
|
|
122
|
+
accountBalanceRes.data.free.toString()
|
|
123
|
+
)
|
|
122
124
|
|
|
123
125
|
for (const tokenId of this.enabledTokenIds) {
|
|
124
126
|
const token = this.allTokensMap[tokenId]
|
|
@@ -126,41 +128,16 @@ const queryTxMutex = _utils.makeMutex.call(void 0, )
|
|
|
126
128
|
const networkLocation = _tokenHelpers.asMaybeContractLocation.call(void 0, token.networkLocation)
|
|
127
129
|
if (networkLocation == null) continue
|
|
128
130
|
|
|
129
|
-
|
|
130
|
-
this.api.query.assets.account,
|
|
131
|
-
[networkLocation.contractAddress, this.walletInfo.keys.publicKey]
|
|
132
|
-
]) // returns Option<PalletAssetsAssetAccount>
|
|
133
|
-
edgeTokenArray.push(token)
|
|
134
|
-
}
|
|
131
|
+
const tokenBalanceRes = await this.api.query.assets.account
|
|
135
132
|
|
|
136
|
-
|
|
137
|
-
if (balances.length === 0) {
|
|
138
|
-
throw new Error('No balances returned')
|
|
139
|
-
}
|
|
133
|
+
(networkLocation.contractAddress, this.walletInfo.keys.publicKey)
|
|
140
134
|
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
this.updateBalance(
|
|
145
|
-
this.currencyInfo.currencyCode,
|
|
146
|
-
accountBalance.data.free.toString()
|
|
147
|
-
)
|
|
148
|
-
|
|
149
|
-
// Assets
|
|
150
|
-
for (const [i, assetBalanceRaw] of balances.entries()) {
|
|
151
|
-
const token = edgeTokenArray[i]
|
|
152
|
-
const assetBalance = _polkadotTypes.asMaybeAssetsPalletBalance.call(void 0,
|
|
153
|
-
assetBalanceRaw.toPrimitive()
|
|
154
|
-
)
|
|
155
|
-
if (assetBalance == null) {
|
|
156
|
-
this.updateBalance(token.currencyCode, '0')
|
|
157
|
-
return
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
this.updateBalance(token.currencyCode, assetBalance.balance.toString())
|
|
135
|
+
let tokenBalance = '0'
|
|
136
|
+
if (tokenBalanceRes.isSome) {
|
|
137
|
+
tokenBalance = tokenBalanceRes.unwrap().balance.toString()
|
|
161
138
|
}
|
|
162
|
-
|
|
163
|
-
|
|
139
|
+
this.updateBalance(token.currencyCode, tokenBalance)
|
|
140
|
+
}
|
|
164
141
|
}
|
|
165
142
|
|
|
166
143
|
async queryBlockheight() {
|
|
@@ -417,7 +394,7 @@ const queryTxMutex = _utils.makeMutex.call(void 0, )
|
|
|
417
394
|
|
|
418
395
|
if (publicAddress == null)
|
|
419
396
|
throw new Error('makeSpend Missing publicAddress')
|
|
420
|
-
if (nativeAmount == null) throw new (0,
|
|
397
|
+
if (nativeAmount == null) throw new (0, _types.NoAmountSpecifiedError)()
|
|
421
398
|
|
|
422
399
|
const balance = this.getBalance({
|
|
423
400
|
currencyCode
|
|
@@ -433,7 +410,7 @@ const queryTxMutex = _utils.makeMutex.call(void 0, )
|
|
|
433
410
|
)
|
|
434
411
|
|
|
435
412
|
if (_biggystring.gt.call(void 0, nativeAmount, spendableBalance)) {
|
|
436
|
-
throw new (0,
|
|
413
|
+
throw new (0, _types.InsufficientFundsError)()
|
|
437
414
|
}
|
|
438
415
|
|
|
439
416
|
const transfer = await this.api.tx.balances.transferKeepAlive(
|
|
@@ -457,11 +434,11 @@ const queryTxMutex = _utils.makeMutex.call(void 0, )
|
|
|
457
434
|
totalTxAmount = _biggystring.add.call(void 0, nativeAmount, nativeNetworkFee)
|
|
458
435
|
|
|
459
436
|
if (_biggystring.gt.call(void 0, totalTxAmount, spendableBalance)) {
|
|
460
|
-
throw new (0,
|
|
437
|
+
throw new (0, _types.InsufficientFundsError)()
|
|
461
438
|
}
|
|
462
439
|
} else {
|
|
463
440
|
if (_biggystring.gt.call(void 0, nativeAmount, balance)) {
|
|
464
|
-
throw new (0,
|
|
441
|
+
throw new (0, _types.InsufficientFundsError)()
|
|
465
442
|
}
|
|
466
443
|
totalTxAmount = nativeAmount
|
|
467
444
|
const transfer = await this.api.tx.assets.transfer(
|
|
@@ -491,7 +468,7 @@ const queryTxMutex = _utils.makeMutex.call(void 0, )
|
|
|
491
468
|
this.api.consts.balances.existentialDeposit.toString()
|
|
492
469
|
)
|
|
493
470
|
if (_biggystring.gt.call(void 0, nativeNetworkFee, spendableFeeBalance)) {
|
|
494
|
-
throw new (0,
|
|
471
|
+
throw new (0, _types.InsufficientFundsError)({
|
|
495
472
|
currencyCode: this.currencyInfo.currencyCode,
|
|
496
473
|
networkFee: nativeNetworkFee
|
|
497
474
|
})
|
|
@@ -13,15 +13,6 @@ var _cleaners = require('cleaners');
|
|
|
13
13
|
|
|
14
14
|
var _types = require('../common/types');
|
|
15
15
|
|
|
16
|
-
const asMaybeAssetsPalletBalance = _cleaners.asMaybe.call(void 0,
|
|
17
|
-
_cleaners.asObject.call(void 0, {
|
|
18
|
-
balance: _cleaners.asNumber
|
|
19
|
-
// status: 'Liquid',
|
|
20
|
-
// reason: { sufficient: null },
|
|
21
|
-
// extra: null
|
|
22
|
-
})
|
|
23
|
-
); exports.asMaybeAssetsPalletBalance = asMaybeAssetsPalletBalance
|
|
24
|
-
|
|
25
16
|
|
|
26
17
|
|
|
27
18
|
|