edge-currency-accountbased 2.2.0 → 2.2.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 +10 -1
- package/android/src/main/assets/edge-currency-accountbased/edge-currency-accountbased.js +1 -1
- package/android/src/main/assets/edge-currency-accountbased/polkadot.chunk.js +2 -2
- package/lib/filecoin/filecoinInfo.js +2 -3
- package/lib/polkadot/PolkadotEngine.js +116 -55
- package/lib/polkadot/info/liberlandInfo.js +2 -1
- package/lib/polkadot/info/liberlandTestnetInfo.js +2 -1
- package/lib/polkadot/info/polkadotInfo.js +1 -0
- package/lib/polkadot/polkadotTypes.js +1 -0
- package/package.json +1 -1
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";(self.webpackChunkedge_currency_accountbased=self.webpackChunkedge_currency_accountbased||[]).push([[591],{79014:function(Z,D,h){h.d(D,{Q:function(){return Q},k:function(){return V}});var E=h(77591),_=h.n(E),N=h(24350),W=h(84564),p=h.n(W),M=h(76714),L=Object.defineProperty,T=Object.getOwnPropertySymbols,U=Object.prototype.hasOwnProperty,I=Object.prototype.propertyIsEnumerable,o=(c,f,m)=>f in c?L(c,f,{enumerable:!0,configurable:!0,writable:!0,value:m}):c[f]=m,X=(c,f)=>{for(var m in f||(f={}))U.call(f,m)&&o(c,m,f[m]);if(T)for(var m of T(f))I.call(f,m)&&o(c,m,f[m]);return c};function V(c,f,m,g,S=[]){const y=X({},p()(f,{},!0)),O=f.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,$=y.query.message,K=y.query.category;(H!=null||$!=null||K!=null||O)&&(C.metadata={},C.metadata.name=H,C.metadata.notes=$,C.metadata.category=K,C.metadata.gateway=O!=null?O:!1);const x=y.query.amount;if(x!=null&&typeof x=="string"){g==null&&(g=c.currencyCode);const R=(0,M.Qs)(g!=null?g:"",c,S);if(R==null)throw new Error("InternalErrorInvalidCurrencyCode");let B=(0,E.mul)(x,R.multiplier);B=(0,E.toFixed)(B,0,0),C.nativeAmount=B,C.currencyCode=g}return{edgeParsedUri:C,parsedUri:y}}function Q(c,f,m){if(c.publicAddress==null)throw new Error("InvalidPublicAddressError");if(m==null&&c.label==null&&c.message==null)return c.publicAddress;{let g="";m!=null&&(g+="amount="+m+"&"),(c.label!=null||c.message!=null)&&(typeof c.label=="string"&&(g+="label="+c.label+"&"),typeof c.message=="string"&&(g+="message="+c.message+"&")),g=g.substr(0,g.length-1);const S={scheme:f,path:c.publicAddress,query:g};return(0,N.qC)(S)}}},34765:function(Z,D,h){h.r(D),h.d(D,{PolkadotTools:function(){return J},makeCurrencyEngine:function(){return at},makeCurrencyTools:function(){return ut}});var E=h(58170),_=h(21293),N=h(18534),W=h(23670),p=h(77591),M=h(2153),L=h(48764),T=h(20918),U=h(79014),I=h(76714),o=h(82448),X=h(62177);const V=(0,o.Vk)((0,o.su)({balance:o.mH})),Q=(0,o.su)({txCount:(0,o.Vk)(o.mH,0)}),c=(0,o.su)({code:o.mH,message:o.XC,data:(0,o.Zz)((0,o.su)(o.JC))}),f=(0,o.su)({from:o.XC,to:o.XC,success:o.jK,hash:o.XC,block_num:o.mH,block_timestamp:o.mH,module:o.XC,amount:o.XC,fee:o.XC}),m=(0,o.su)({count:o.mH,transfers:(0,o.Vk)((0,o._2)(f),()=>[])}),g=X.BQ,S=l=>{const t=(0,o.su)({[`${l}Mnemonic`]:(0,o.Zz)(o.XC),[`${l}Key`]:o.XC});return(0,o.W1)(e=>{const s=t(e);return{mnemonic:s[`${l}Mnemonic`],privateKey:s[`${l}Key`]}},e=>({[`${l}Mnemonic`]:e.mnemonic,[`${l}Key`]:e.privateKey}))};var y=h(94935),O=h(35620),z=h(84650),C=Object.defineProperty,H=Object.defineProperties,$=Object.getOwnPropertyDescriptors,K=Object.getOwnPropertySymbols,x=Object.getPrototypeOf,R=Object.prototype.hasOwnProperty,B=Object.prototype.propertyIsEnumerable,tt=Reflect.get,G=(l,t,e)=>t in l?C(l,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):l[t]=e,et=(l,t)=>{for(var e in t||(t={}))R.call(t,e)&&G(l,e,t[e]);if(K)for(var e of K(t))B.call(t,e)&&G(l,e,t[e]);return l},nt=(l,t)=>H(l,$(t)),q=(l,t,e)=>tt(x(l),e,t),v=(l,t,e)=>new Promise((s,n)=>{var r=i=>{try{u(e.next(i))}catch(d){n(d)}},a=i=>{try{u(e.throw(i))}catch(d){n(d)}},u=i=>i.done?s(i.value):Promise.resolve(i.value).then(r,a);u((e=e.apply(l,t)).next())});const rt=5e3,st=2e4,ot=3e3,it=(0,I.jT)();class F extends z.P{constructor(t,e,s,n){super(t,e,s,n),this.getRecipientBalance=r=>v(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=Q(t)}fetchSubscan(t,e){return v(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 c(r)})}queryBalance(){return v(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 a=(0,T.Oj)(r.networkLocation);a!=null&&(t.push([this.api.query.assets.account,[a.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[a,u]of n.entries()){const i=e[a],d=V(u.toPrimitive());if(d==null){this.updateBalance(i.currencyCode,"0");return}this.updateBalance(i.currencyCode,d.balance.toString())}}))()})}queryBlockheight(){return v(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:a,block_timestamp:u,module:i,amount:d,fee:k}=t;if(!n||i!=="balances")return;const w=(0,I.aL)(this.currencyInfo.currencyCode,this.currencyInfo,this.allTokensMap);if(w==null)return;const A=[];let P=(0,p.mul)(d,w.multiplier);e===this.walletInfo.keys.publicKey?P=`-${(0,p.add)(P,k)}`:A.push(s);const j={txid:r,date:u,currencyCode:this.currencyInfo.currencyCode,blockHeight:a,nativeAmount:P,isSend:P.startsWith("-"),networkFee:k,ourReceiveAddresses:A,signedTx:"",walletId:this.walletId};this.addTransaction(this.currencyInfo.currencyCode,j)}queryTransactions(){return v(this,null,function*(){if(this.networkInfo.subscanBaseUrl==null){for(const t of this.enabledTokens)this.tokenCheckTransactionsStatus[t]=1;this.updateOnAddressesChecked();return}return yield it(()=>v(this,null,function*(){return yield this.queryTransactionsInner()}))})}queryTransactionsInner(){return v(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),a=m(r.data);s=a.count,n=a.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(n.forEach(r=>{try{this.processPolkadotTransaction(f(r))}catch{const u=r!=null&&typeof r.hash=="string"?r.hash:"";this.warn(`Ignoring invalid transfer ${u}`)}}),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.transactionsChangedArray.length>0&&(this.walletLocalDataDirty=!0,this.currencyEngineCallbacks.onTransactionsChanged(this.transactionsChangedArray),this.transactionsChangedArray=[])})}startEngine(){return v(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 q(F.prototype,this,"startEngine").call(this)})}killEngine(){return v(this,null,function*(){yield q(F.prototype,this,"killEngine").call(this),yield this.tools.disconnectApi(this.walletId)})}resyncBlockchain(){return v(this,null,function*(){yield this.killEngine(),yield this.clearBlockchainCache(),yield this.startEngine()})}getMaxSpendable(t){return v(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}),s=(0,p.sub)(e,this.api.consts.balances.existentialDeposit.toString()),n=[{publicAddress:t.spendTargets[0].publicAddress,nativeAmount:"0"}],r=nt(et({},t),{spendTargets:n}),u=(yield this.makeSpend(r)).networkFee,i=(d,k)=>{const w=(0,p.sub)(k,d);if((0,p.lte)(w,"1"))return d;const A=(0,p.add)(d,(0,p.div)(w,"2")),P=(0,I.X0)(A).replace("0x",""),j=P.length%2===1?`0${P}`:P,dt=(0,p.mul)((0,p.div)(j.length.toString(),"2"),this.networkInfo.lengthFeePerByte),ht=(0,p.add)((0,p.add)(dt,u),A);return(0,p.gt)(ht,s)?i(d,A):i(A,k)};return i("0",(0,p.add)(s,"1"))})}makeSpend(t){return v(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 y.$D;const a=this.getBalance({currencyCode:this.currencyInfo.currencyCode}),u=(0,p.sub)(a,this.api.consts.balances.existentialDeposit.toString());if((0,p.gt)(n,u))throw new y.C_;const d=yield(e.tokenId!=null?yield this.api.tx.assets.transferKeepAlive(parseInt(e.tokenId),r,n):yield this.api.tx.balances.transferKeepAlive(r,n)).paymentInfo(this.walletInfo.keys.publicKey),k=(0,p.sub)(d.partialFee.toString(),this.networkInfo.lengthFeePerByte),w=(0,p.add)(n,k);if((0,p.gt)(w,u))throw new y.C_;const A={publicAddress:r};return{txid:"",date:0,currencyCode:s,blockHeight:0,nativeAmount:(0,p.mul)(w,"-1"),isSend:!0,networkFee:k,ourReceiveAddresses:[],signedTx:"",otherParams:A,walletId:this.walletId}})}signTx(t,e){return v(this,null,function*(){const s=S(this.currencyInfo.pluginId)(e),{publicAddress:n}=(0,I.Xp)(t);if(n==null)throw new Error("Missing publicAddress from makeSpend");const r=(0,p.abs)((0,p.add)(t.nativeAmount,t.networkFee));yield this.checkRecipientMinimumBalance(this.getRecipientBalance,r,n);const a=this.allTokens.find(w=>w.currencyCode===t.currencyCode),u=(a==null?void 0:a.contractAddress)!=null?yield this.api.tx.assets.transferKeepAlive(parseInt(a.contractAddress),n,r):yield this.api.tx.balances.transferKeepAlive(n,r),i=this.api.createType("SignerPayload",{method:u,nonce:this.nonce,genesisHash:this.api.genesisHash,blockHash:this.api.genesisHash,runtimeVersion:this.api.runtimeVersion,version:this.api.extrinsicVersion}),d=this.api.createType("ExtrinsicPayload",i.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 w=O.YU.parse(s.privateKey);this.keypair.addFromSeed(w)}const k=d.sign(this.keypair.getPair(this.walletInfo.keys.publicKey));return u.addSignature(this.walletInfo.keys.publicKey,k.signature,i.toPayload()),t.signedTx=u.toHex(),t})}broadcastTx(t){return v(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 at(
|
|
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 at(u,t,e,s){return w(this,null,function*(){const n=k(e),r=new N(u,t,n,s);return yield r.loadEngine(),r})}var b=(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{ed25519PairFromSeed:ct,isAddress:Z,mnemonicToMiniSecret:lt}=X;class tt{constructor(t){const{builtinTokens:e,currencyInfo:s,io:n,networkInfo:r}=t;this.builtinTokens=e,this.currencyInfo=s,this.io=n,this.networkInfo=r,this.polkadotApiSubscribers=new Set}getDisplayPrivateKey(t){return b(this,null,function*(){var e;const{pluginId:s}=this.currencyInfo,n=T(s)(t.keys);return(e=n.mnemonic)!=null?e:n.privateKey})}getDisplayPublicKey(t){return b(this,null,function*(){const{keys:e}=k(t);return e.publicKey})}importPrivateKey(t){return b(this,null,function*(){const{pluginId:e}=this.currencyInfo;if((0,L.validateMnemonic)(t)){const s=lt(t),{secretKey:n}=ct(s);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)),s=(0,L.entropyToMnemonic)(e);return yield this.importPrivateKey(s)})}derivePublicKey(t){return b(this,null,function*(){const{pluginId:e}=this.currencyInfo;return{publicKey:new E.Y({ss58Format:0}).addFromUri(t.keys[`${e}Mnemonic`]).address}})}parseUri(t,e,s){return b(this,null,function*(){var n,r;const{pluginId:c}=this.currencyInfo,d={[c]:!0},{parsedUri:o,edgeParsedUri:l}=(0,F.k)(this.currencyInfo,t,d,e!=null?e:this.currencyInfo.currencyCode,s),y=(n=l.publicAddress)!=null?n:"";if(!Z(y))throw new Error("InvalidPublicAddressError");return l.uniqueIdentifier=(r=o.query.memo)!=null?r:void 0,l})}encodeUri(t){return b(this,arguments,function*(e,s=[]){const{pluginId:n}=this.currencyInfo,{nativeAmount:r,currencyCode:c,publicAddress:d}=e;if(!Z(d))throw new Error("InvalidPublicAddressError");let o;if(typeof r=="string"){const y=(0,I.Qs)(c!=null?c:this.currencyInfo.currencyCode,this.currencyInfo,s);if(y==null)throw new Error("InternalErrorInvalidCurrencyCode");o=(0,a.div)(r,y.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,S.Rp)(t);const e=(0,S.Oj)(t.networkLocation);if(e==null)throw new Error("ErrorInvalidContractAddress");return e.contractAddress})}}function ut(u){return b(this,null,function*(){return new tt(u)})}}}]);
|
|
@@ -24,9 +24,8 @@ const networkInfo = {
|
|
|
24
24
|
|
|
25
25
|
defaultSettings: {},
|
|
26
26
|
|
|
27
|
-
addressExplorer: 'https://
|
|
28
|
-
transactionExplorer:
|
|
29
|
-
'https://blockchair.com/filecoin/transaction/%s?from=edgeapp',
|
|
27
|
+
addressExplorer: 'https://filscan.io/en/address/%s',
|
|
28
|
+
transactionExplorer: 'https://filscan.io/en/message/%s',
|
|
30
29
|
|
|
31
30
|
denominations: [
|
|
32
31
|
// An array of Objects of the possible denominations for this currency
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});require('@polkadot/api-augment/polkadot');
|
|
2
2
|
|
|
3
3
|
var _api = require('@polkadot/api');
|
|
4
4
|
|
|
@@ -272,6 +272,10 @@ const queryTxMutex = _utils.makeMutex.call(void 0, )
|
|
|
272
272
|
}
|
|
273
273
|
}
|
|
274
274
|
|
|
275
|
+
// count is the total number of transactions ever for an account
|
|
276
|
+
// If we've already seen all the transfers we don't need to bother processing or page through older ones
|
|
277
|
+
if (count === this.otherData.txCount) break
|
|
278
|
+
|
|
275
279
|
// Process txs (newest first)
|
|
276
280
|
transfers.forEach(tx => {
|
|
277
281
|
try {
|
|
@@ -290,13 +294,14 @@ const queryTxMutex = _utils.makeMutex.call(void 0, )
|
|
|
290
294
|
Math.min(1, count === 0 ? 1 : this.otherData.txCount / count)
|
|
291
295
|
this.updateOnAddressesChecked()
|
|
292
296
|
|
|
293
|
-
// count is the total number of transactions ever for an account
|
|
294
|
-
// If we've already seen all the transfers we don't need to bother processing or page through older ones
|
|
295
297
|
if (count === this.otherData.txCount) break
|
|
296
298
|
|
|
297
299
|
page++
|
|
298
300
|
}
|
|
299
301
|
|
|
302
|
+
this.tokenCheckTransactionsStatus[this.currencyInfo.currencyCode] = 1
|
|
303
|
+
this.updateOnAddressesChecked()
|
|
304
|
+
|
|
300
305
|
if (this.transactionsChangedArray.length > 0) {
|
|
301
306
|
this.walletLocalDataDirty = true
|
|
302
307
|
this.currencyEngineCallbacks.onTransactionsChanged(
|
|
@@ -347,6 +352,19 @@ const queryTxMutex = _utils.makeMutex.call(void 0, )
|
|
|
347
352
|
const balance = this.getBalance({
|
|
348
353
|
currencyCode: spendInfo.currencyCode
|
|
349
354
|
})
|
|
355
|
+
|
|
356
|
+
if (spendInfo.currencyCode !== this.currencyInfo.currencyCode) {
|
|
357
|
+
const tempSpendTarget = [
|
|
358
|
+
{
|
|
359
|
+
publicAddress: spendInfo.spendTargets[0].publicAddress,
|
|
360
|
+
nativeAmount: balance
|
|
361
|
+
}
|
|
362
|
+
]
|
|
363
|
+
const maxSpendInfo = { ...spendInfo, spendTargets: tempSpendTarget }
|
|
364
|
+
await this.makeSpend(maxSpendInfo)
|
|
365
|
+
return balance
|
|
366
|
+
}
|
|
367
|
+
|
|
350
368
|
const spendableBalance = _biggystring.sub.call(void 0,
|
|
351
369
|
balance,
|
|
352
370
|
this.api.consts.balances.existentialDeposit.toString()
|
|
@@ -402,42 +420,82 @@ const queryTxMutex = _utils.makeMutex.call(void 0, )
|
|
|
402
420
|
if (nativeAmount == null) throw new (0, _types3.NoAmountSpecifiedError)()
|
|
403
421
|
|
|
404
422
|
const balance = this.getBalance({
|
|
405
|
-
currencyCode
|
|
423
|
+
currencyCode
|
|
406
424
|
})
|
|
407
|
-
const spendableBalance = _biggystring.sub.call(void 0,
|
|
408
|
-
balance,
|
|
409
|
-
this.api.consts.balances.existentialDeposit.toString()
|
|
410
|
-
)
|
|
411
425
|
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
}
|
|
426
|
+
let totalTxAmount
|
|
427
|
+
let nativeNetworkFee
|
|
415
428
|
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
nativeAmount
|
|
422
|
-
)
|
|
423
|
-
: await this.api.tx.balances.transferKeepAlive(
|
|
424
|
-
publicAddress,
|
|
425
|
-
nativeAmount
|
|
426
|
-
)
|
|
427
|
-
|
|
428
|
-
const paymentInfo = await transfer.paymentInfo(
|
|
429
|
-
this.walletInfo.keys.publicKey
|
|
430
|
-
)
|
|
429
|
+
if (edgeSpendInfo.tokenId == null) {
|
|
430
|
+
const spendableBalance = _biggystring.sub.call(void 0,
|
|
431
|
+
balance,
|
|
432
|
+
this.api.consts.balances.existentialDeposit.toString()
|
|
433
|
+
)
|
|
431
434
|
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
435
|
+
if (_biggystring.gt.call(void 0, nativeAmount, spendableBalance)) {
|
|
436
|
+
throw new (0, _types3.InsufficientFundsError)()
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
const transfer = await this.api.tx.balances.transferKeepAlive(
|
|
440
|
+
publicAddress,
|
|
441
|
+
nativeAmount
|
|
442
|
+
)
|
|
443
|
+
|
|
444
|
+
const paymentInfo = await transfer.paymentInfo(
|
|
445
|
+
this.walletInfo.keys.publicKey
|
|
446
|
+
)
|
|
447
|
+
|
|
448
|
+
// The fee returned from partial fee is always off by some length fee, because reasons
|
|
449
|
+
nativeNetworkFee = _biggystring.sub.call(void 0,
|
|
450
|
+
paymentInfo.partialFee.toString(),
|
|
451
|
+
_biggystring.mul.call(void 0,
|
|
452
|
+
this.networkInfo.lengthFeePerByte,
|
|
453
|
+
this.networkInfo.partialFeeOffsetMultiplier
|
|
454
|
+
)
|
|
455
|
+
)
|
|
437
456
|
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
457
|
+
totalTxAmount = _biggystring.add.call(void 0, nativeAmount, nativeNetworkFee)
|
|
458
|
+
|
|
459
|
+
if (_biggystring.gt.call(void 0, totalTxAmount, spendableBalance)) {
|
|
460
|
+
throw new (0, _types3.InsufficientFundsError)()
|
|
461
|
+
}
|
|
462
|
+
} else {
|
|
463
|
+
if (_biggystring.gt.call(void 0, nativeAmount, balance)) {
|
|
464
|
+
throw new (0, _types3.InsufficientFundsError)()
|
|
465
|
+
}
|
|
466
|
+
totalTxAmount = nativeAmount
|
|
467
|
+
const transfer = await this.api.tx.assets.transfer(
|
|
468
|
+
parseInt(edgeSpendInfo.tokenId),
|
|
469
|
+
publicAddress,
|
|
470
|
+
nativeAmount
|
|
471
|
+
)
|
|
472
|
+
|
|
473
|
+
const paymentInfo = await transfer.paymentInfo(
|
|
474
|
+
this.walletInfo.keys.publicKey
|
|
475
|
+
)
|
|
476
|
+
|
|
477
|
+
// The fee returned from partial fee is always off by some length fee, because reasons
|
|
478
|
+
nativeNetworkFee = _biggystring.sub.call(void 0,
|
|
479
|
+
paymentInfo.partialFee.toString(),
|
|
480
|
+
_biggystring.mul.call(void 0,
|
|
481
|
+
this.networkInfo.lengthFeePerByte,
|
|
482
|
+
this.networkInfo.partialFeeOffsetMultiplier
|
|
483
|
+
)
|
|
484
|
+
)
|
|
485
|
+
|
|
486
|
+
const feeBalance = this.getBalance({
|
|
487
|
+
currencyCode: this.currencyInfo.currencyCode
|
|
488
|
+
})
|
|
489
|
+
const spendableFeeBalance = _biggystring.sub.call(void 0,
|
|
490
|
+
feeBalance,
|
|
491
|
+
this.api.consts.balances.existentialDeposit.toString()
|
|
492
|
+
)
|
|
493
|
+
if (_biggystring.gt.call(void 0, nativeNetworkFee, spendableFeeBalance)) {
|
|
494
|
+
throw new (0, _types3.InsufficientFundsError)({
|
|
495
|
+
currencyCode: this.currencyInfo.currencyCode,
|
|
496
|
+
networkFee: nativeNetworkFee
|
|
497
|
+
})
|
|
498
|
+
}
|
|
441
499
|
}
|
|
442
500
|
|
|
443
501
|
const otherParams = {
|
|
@@ -474,31 +532,34 @@ const queryTxMutex = _utils.makeMutex.call(void 0, )
|
|
|
474
532
|
if (publicAddress == null)
|
|
475
533
|
throw new Error('Missing publicAddress from makeSpend')
|
|
476
534
|
|
|
477
|
-
const nativeAmount = _biggystring.abs.call(void 0,
|
|
478
|
-
_biggystring.add.call(void 0, edgeTransaction.nativeAmount, edgeTransaction.networkFee)
|
|
479
|
-
)
|
|
480
|
-
|
|
481
|
-
await this.checkRecipientMinimumBalance(
|
|
482
|
-
this.getRecipientBalance,
|
|
483
|
-
nativeAmount,
|
|
484
|
-
publicAddress
|
|
485
|
-
)
|
|
486
|
-
|
|
487
535
|
const edgeToken = this.allTokens.find(
|
|
488
536
|
token => token.currencyCode === edgeTransaction.currencyCode
|
|
489
537
|
)
|
|
490
538
|
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
539
|
+
let transfer
|
|
540
|
+
if (edgeToken == null) {
|
|
541
|
+
const nativeAmount = _biggystring.abs.call(void 0,
|
|
542
|
+
_biggystring.add.call(void 0, edgeTransaction.nativeAmount, edgeTransaction.networkFee)
|
|
543
|
+
)
|
|
544
|
+
await this.checkRecipientMinimumBalance(
|
|
545
|
+
this.getRecipientBalance,
|
|
546
|
+
nativeAmount,
|
|
547
|
+
publicAddress
|
|
548
|
+
)
|
|
549
|
+
transfer = await this.api.tx.balances.transferKeepAlive(
|
|
550
|
+
publicAddress,
|
|
551
|
+
nativeAmount
|
|
552
|
+
)
|
|
553
|
+
} else if (edgeToken.contractAddress != null) {
|
|
554
|
+
const nativeAmount = _biggystring.abs.call(void 0, edgeTransaction.nativeAmount)
|
|
555
|
+
transfer = await this.api.tx.assets.transfer(
|
|
556
|
+
parseInt(edgeToken.contractAddress),
|
|
557
|
+
publicAddress,
|
|
558
|
+
nativeAmount
|
|
559
|
+
)
|
|
560
|
+
} else {
|
|
561
|
+
throw new Error('Unrecognized asset')
|
|
562
|
+
}
|
|
502
563
|
|
|
503
564
|
const signer = this.api.createType('SignerPayload', {
|
|
504
565
|
method: transfer,
|
|
@@ -20,7 +20,8 @@ const networkInfo = {
|
|
|
20
20
|
rpcNodes: ['wss://mainnet.liberland.org/'],
|
|
21
21
|
subscanBaseUrl: undefined,
|
|
22
22
|
subscanQueryLimit: 100,
|
|
23
|
-
|
|
23
|
+
partialFeeOffsetMultiplier: '2',
|
|
24
|
+
lengthFeePerByte: '76800000'
|
|
24
25
|
}
|
|
25
26
|
|
|
26
27
|
const currencyInfo = {
|
|
@@ -20,7 +20,8 @@ const networkInfo = {
|
|
|
20
20
|
rpcNodes: ['wss://testchain.liberland.org/'],
|
|
21
21
|
subscanBaseUrl: undefined,
|
|
22
22
|
subscanQueryLimit: 100,
|
|
23
|
-
|
|
23
|
+
partialFeeOffsetMultiplier: '2',
|
|
24
|
+
lengthFeePerByte: '76800000'
|
|
24
25
|
}
|
|
25
26
|
|
|
26
27
|
const currencyInfo = {
|