edge-currency-accountbased 4.26.2 → 4.26.3
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 +5 -0
- package/android/src/main/assets/edge-currency-accountbased/cardano.chunk.js +2 -2
- package/android/src/main/assets/edge-currency-accountbased/edge-currency-accountbased.js +5 -5
- package/lib/cardano/CardanoEngine.js +50 -21
- package/lib/cardano/cardanoTypes.js +33 -31
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
## Unreleased
|
|
4
4
|
|
|
5
|
+
## 4.26.3 (2024-10-30)
|
|
6
|
+
|
|
7
|
+
- fixed: (ADA) Improved balance calculation by deriving from UTXO state.
|
|
8
|
+
- fixed: (ADA) Race condition between network queries and local transaction processing causing incorrect UTXO state.
|
|
9
|
+
|
|
5
10
|
## 4.26.2 (2024-10-29)
|
|
6
11
|
|
|
7
12
|
- fixed: (ADA) Fixed a bug in Blockfrost response handling that caused an error when processing successful non-JSON responses.
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
(self.webpackChunkedge_currency_accountbased=self.webpackChunkedge_currency_accountbased||[]).push([[651],{57157:function(V){function A(f){var r=new Error("Cannot find module '"+f+"'");throw r.code="MODULE_NOT_FOUND",r}A.keys=function(){return[]},A.resolve=A,A.id=57157,V.exports=A},52250:function(V,A,f){"use strict";f.r(A),f.d(A,{CardanoTools:function(){return X},makeCurrencyEngine:function(){return st},makeCurrencyTools:function(){return lt},updateInfoPayload:function(){return ut}});var r=f(46271),S=f(66001),O=f(90749),R=f(65828),U=f(96542),$=f(44276),m=f(43755),d=f(99818),M=f(82671),W=f(26277),v=f(62351),k=f(14171);const _=(...l)=>{let t=0,e;if(l.length===0)throw new Error("Expected one or more function argument");for(;t<l.length;){const n=l[t++];try{return n(e)}catch(s){e=s}}throw e};var g=f(36856);const I=(0,d.eB)({inputs:(0,d._j)((0,d.eB)({transaction_id:d.oJ,index:d.i})),outputs:(0,d._j)((0,d.eB)({address:d.oJ,amount:(0,d.eB)({coin:d.oJ})})),fee:d.oJ,ttl:d.oJ,certs:(0,d.H7)((0,d._j)((0,d.UH)((0,d.eB)({StakeRegistrationJSON:g.Z6}),(0,d.eB)({StakeDelegationJSON:g.Z6}),(0,d.eB)({StakeDeregistrationJSON:g.Z6})))),withdrawals:(0,d.H7)(g.Z6)}),N=l=>t=>{var e;const n=I(t);return n.outputs.forEach(s=>(0,d.E8)(l)(s.address)),(e=n.certs)==null||e.forEach(s=>(0,d.UH)((0,d.eB)({StakeRegistrationJSON:g.Z6}),(0,d.eB)({StakeDelegationJSON:g.Z6}))(s)),n};var E=f(48287).Buffer,C=Object.defineProperty,b=Object.defineProperties,T=Object.getOwnPropertyDescriptors,J=Object.getOwnPropertySymbols,H=Object.getPrototypeOf,G=Object.prototype.hasOwnProperty,q=Object.prototype.propertyIsEnumerable,tt=Reflect.get,z=(l,t,e)=>t in l?C(l,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):l[t]=e,j=(l,t)=>{for(var e in t||(t={}))G.call(t,e)&&z(l,e,t[e]);if(J)for(var e of J(t))q.call(t,e)&&z(l,e,t[e]);return l},Z=(l,t)=>b(l,T(t)),Q=(l,t,e)=>tt(H(l),e,t),p=(l,t,e)=>new Promise((n,s)=>{var a=o=>{try{i(e.next(o))}catch(u){s(u)}},c=o=>{try{i(e.throw(o))}catch(u){s(u)}},i=o=>o.done?n(o.value):Promise.resolve(o.value).then(a,c);i((e=e.apply(l,t)).next())});const et=(0,v.fi)(2e4),nt=(0,v.fi)(2e4),ot=(0,v.fi)(2e4);class F extends W.k{constructor(t,e,n,s,a){super(t,e,n,a),this.getStakeAddress=()=>p(this,null,function*(){const{bech32Address:c}=(0,m.rY)(this.walletInfo).keys,i=r.pVw.from_bech32(c),o=r.qK$.from_address(i);if(o==null)throw new Error("This address doesn't have staking rights");const u=o.stake_cred();return r.OTB.new(i.network_id(),u).to_address().to_bech32()}),this.decodeStakingTx=c=>p(this,null,function*(){const{bech32Address:i}=(0,m.rY)(this.walletInfo).keys,o=r.ZXm.from_hex(c),u=r.AeD(o.body()),y=o.to_js_value(),w=N(i)(y.body).withdrawals==null,x={isStakeTx:!0,unsignedTx:o.to_hex()},B=y.body.fee,L=w?"-2000000":(0,S.sub)("2000000",B);return{blockHeight:0,currencyCode:this.currencyInfo.currencyCode,date:0,isSend:w,memos:[],nativeAmount:L,networkFee:B,otherParams:x,ourReceiveAddresses:[],signedTx:"",tokenId:null,txid:u.to_hex(),walletId:this.walletId,assetAction:{assetActionType:w?"stake":"unstake"},savedAction:{actionType:"stake",pluginId:this.currencyInfo.pluginId,stakeAssets:[{pluginId:this.currencyInfo.pluginId,tokenId:null}]}}}),this.otherMethods={decodeStakingTx:this.decodeStakingTx,getStakeAddress:this.getStakeAddress},this.fetchCors=(0,$.CY)(t.io),this.initOptions=(0,m.Jv)(s),this.networkInfo=t.networkInfo,this.epochNumber=-1,this.slot=-1,this.utxos=[]}setOtherData(t){this.otherData=(0,m.AA)(t)}fetchKoios(t){return p(this,arguments,function*(e,n={},s=!1){const a=yield this.fetchCors(`${this.networkInfo.koiosServer}/api/v1/${e}`,Z(j({},n),{headers:j(j({},n.headers),s?{Authorization:`Bearer ${this.initOptions.koiosApiKey}`}:{})}));if(a.status===429&&!s)return yield this.fetchKoios(e,n,!0);if(!a.ok){const c=yield a.text();throw new Error(`Koios error: ${c}`)}return yield a.json()})}fetchPostKoios(t,e){return p(this,null,function*(){const n={method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify(e)};return yield this.fetchKoios(t,n)})}multiBroadcast(t){return p(this,null,function*(){const e={method:"POST",headers:{"content-type":"application/cbor"},body:t},n=(o,u,y)=>p(this,null,function*(){const h=yield this.fetchCors(u,Z(j({},e),{headers:j(j({},e.headers),y)})),w=yield h.text();if(!h.ok)throw new Error(`${o} error: ${w}`);return this.log.warn(`${o} broadcast success`),w}),s=()=>p(this,null,function*(){if(this.initOptions.koiosApiKey==null)throw new Error("Missing koiosApiKey");const o={Authorization:`Bearer ${this.initOptions.koiosApiKey}`};return(0,d.fI)(d.oJ)(yield n("Koios",`${this.networkInfo.koiosServer}/api/v1/submittx`,o))}),a=()=>p(this,null,function*(){if(this.initOptions.blockfrostProjectId==null)throw new Error("Missing blockfrostProjectId");const o={project_id:`${this.initOptions.blockfrostProjectId}`};return(0,d.fI)(d.oJ)(yield n("Blockfrost",`${this.networkInfo.blockfrostServer}/api/v0/tx/submit`,o))}),c=()=>p(this,null,function*(){if(this.initOptions.maestroApiKey==null)throw new Error("Missing maestroApiKey");const o={"api-key":`${this.initOptions.maestroApiKey}`};return yield n("Maestro",`${this.networkInfo.maestroServer}/v1/txmanager`,o)}),{values:i}=yield(0,k.JO)([a(),s(),c()]);return i[0]})}queryBlockheight(){return p(this,null,function*(){var t;try{const e=yield this.fetchKoios("tip"),n=(0,m.av)(e)[0],{abs_slot:s,block_no:a,epoch_no:c}=n;if(a>this.walletLocalData.blockHeight&&(this.walletLocalData.blockHeight=a,this.walletLocalDataDirty=!0,this.currencyEngineCallbacks.onBlockHeightChanged(this.walletLocalData.blockHeight)),this.epochNumber=c,this.slot=s,((t=this.tools.epochParams)==null?void 0:t.epoch_no)!==this.epochNumber){const i=yield this.fetchKoios(`epoch_params?_epoch_no=${this.epochNumber}`),o=(0,d.VA)(m.IA)(i);this.tools.epochParams=o[0]}}catch(e){this.log.warn("queryBlockheight error: ",e)}})}queryBalance(){return p(this,null,function*(){var t,e,n,s;try{const a=yield this.fetchPostKoios("address_info",{_addresses:[this.walletInfo.keys.bech32Address]}),c=(0,m.cX)(a),i=(e=(t=c[0])==null?void 0:t.balance)!=null?e:"0";this.updateBalance(this.currencyInfo.currencyCode,i),this.utxos=(s=(n=c[0])==null?void 0:n.utxo_set.map(o=>({asset_list:o.asset_list,tx_hash:o.tx_hash,tx_index:o.tx_index,value:o.value})))!=null?s:[]}catch(a){this.log.warn("queryBalance error: ",a)}})}queryTransactions(){return p(this,null,function*(){let t=this.otherData.latestQueryTransactionsBlockHeight,e=this.otherData.latestQueryTransactionsTxid;const n=[];for(;;){const i=yield this.fetchPostKoios("address_txs",{_addresses:[this.walletInfo.keys.bech32Address],_after_block_height:t}),o=(0,m.DF)(i),u=o[0];if(u==null||u.tx_hash===e)break;const y=o.filter(h=>h.block_height>=t).reverse().map(h=>(t=h.block_height,e=h.tx_hash,h.tx_hash));if(n.push(...y),y.length===0)break}const s=n.length;let a=0;const c=25;for(;n.length>0;){const i=yield this.fetchPostKoios("tx_info",{_inputs:!0,_tx_hashes:n.splice(0,c)}),o=(0,m.Vw)(i);for(let u=0;u<o.length;u++){const y=o[u],h=rt({currencyCode:this.currencyInfo.currencyCode,address:this.walletInfo.keys.bech32Address,tokenId:null,tx:y,walletId:this.walletId});this.addTransaction(this.currencyInfo.currencyCode,h),this.otherData.latestQueryTransactionsBlockHeight=y.block_height,this.otherData.latestQueryTransactionsTxid=y.tx_hash,a++}this.walletLocalDataDirty=!0,this.tokenCheckTransactionsStatus[this.currencyInfo.currencyCode]=a/s,this.updateOnAddressesChecked()}this.tokenCheckTransactionsStatus[this.currencyInfo.currencyCode]=1,this.updateOnAddressesChecked(),this.transactionsChangedArray.length>0&&(this.walletLocalDataDirty=!0,this.currencyEngineCallbacks.onTransactionsChanged(this.transactionsChangedArray),this.transactionsChangedArray=[])})}startEngine(){return p(this,null,function*(){this.engineOn=!0,this.addToLoop("queryBlockheight",nt).catch(()=>{}),this.addToLoop("queryBalance",et).catch(()=>{}),this.addToLoop("queryTransactions",ot).catch(()=>{}),yield Q(F.prototype,this,"startEngine").call(this)})}resyncBlockchain(){return p(this,null,function*(){yield this.killEngine(),yield this.clearBlockchainCache(),yield this.startEngine()})}composeTransaction(t,e){if(this.tools.epochParams==null)throw new Error("No network params");const{min_fee_a:n,min_fee_b:s,max_tx_size:a,key_deposit:c,pool_deposit:i,max_val_size:o,coins_per_utxo_size:u}=this.tools.epochParams,y=r.JLZ.new().fee_algo(r.kr0.new(r.tR8.from_str(n.toString()),r.tR8.from_str(s.toString()))).coins_per_utxo_byte(r.tR8.from_str(u)).max_value_size(o).max_tx_size(a).pool_deposit(r.tR8.from_str(i)).key_deposit(r.tR8.from_str(c)).build(),h=r.Qcz.new(y),w=r.pVw.from_bech32(t),x=r.pVw.from_bech32(this.walletInfo.keys.bech32Address);h.set_ttl_bignum(r.tR8.from_str(this.slot.toString()).checked_add(r.tR8.from_str("7200"))),h.add_output(r.Mw_.new(w,r.WTA.new(r.tR8.from_str(e))));const B=this.utxos.filter(D=>D.value!=="0"&&D.asset_list.length===0),L=r.aZV.new();for(const D of B){const dt=r.WTA.new(r.tR8.from_str(D.value)),ht=r.PNw.new(r.nQF.from_bytes(E.from(D.tx_hash,"hex")),D.tx_index),ft=r.Mw_.new(x,dt);L.add(r.Hlu.new(ht,ft))}try{h.add_inputs_from(L,r.tiU.LargestFirst)}catch(D){throw String(D).includes("UTxO Balance Insufficient")?new M.k5({tokenId:null}):D}h.add_change_if_needed(x);const P=h.build();switch(this.networkInfo.networkId){case 1:P.set_network_id(r.qqB.mainnet());break;case 0:P.set_network_id(r.qqB.testnet());break;default:throw new Error("Unknown networkId")}return P}makeSpend(t){return p(this,null,function*(){const{edgeSpendInfo:e,currencyCode:n}=this.makeSpendCheck(t),{memos:s=[],tokenId:a}=e,c=e.spendTargets[0],{publicAddress:i}=c;let{nativeAmount:o}=c;if(i==null)throw new Error("makeSpend Missing publicAddress");if(o==null)throw new M.ef;let u="0";const y={unsignedTx:""};if(o!=null&&o!=="0")try{const x=this.composeTransaction(i,o);u=x.fee().to_str(),y.unsignedTx=x.to_hex()}catch(x){throw this.log.warn("composeTransaction error: ",x),x instanceof Error?x:new Error(String(x))}const h=(0,S.add)(o,u);return o=(0,S.mul)(h,"-1"),{blockHeight:0,currencyCode:n,date:0,isSend:o.startsWith("-"),memos:s,nativeAmount:o,networkFee:u,otherParams:y,ourReceiveAddresses:[],signedTx:"",tokenId:a,txid:"",walletId:this.walletId}})}saveTx(t){return p(this,null,function*(){yield Q(F.prototype,this,"saveTx").call(this,t);const e=r.ZXm.from_hex(t.signedTx),n=r.AeD(e.body()).to_hex(),s=e.to_js_value(),a=new Set(s.body.inputs.map(i=>`${i.transaction_id}_${i.index}`));this.utxos=this.utxos.filter(i=>!a.has(`${i.tx_hash}_${i.tx_index}`));const c=this.walletInfo.keys.bech32Address;s.body.outputs.forEach((i,o)=>{if(i.address===c){if(i.amount.multiasset!=null)return;this.utxos.push({asset_list:[],tx_hash:n,tx_index:o,value:i.amount.coin})}})})}signTx(t,e){return p(this,null,function*(){const{unsignedTx:n,isStakeTx:s=!1}=(0,m.xZ)(t.otherParams),a=(0,m.kF)(this.currencyInfo.pluginId)(e),{accountKey:c}=yield this.tools.derivePrivateKeys(a),i=c.derive(0).derive(0),o=_(()=>r.LQ6.from_hex(n),()=>r.ZXm.from_hex(n).body()),u=r.AeD(o),y=r.SLq.new(),h=r.ToW.new(),w=r.Ju1(u,i.to_raw_key());if(h.add(w),s){const B=c.derive(2).derive(0),L=r.Ju1(u,B.to_raw_key());h.add(L)}y.set_vkeys(h);const x=r.ZXm.new(o,y,void 0);return t.signedTx=x.to_hex(),t})}broadcastTx(t){return p(this,null,function*(){if(t.signedTx==null)throw new Error("Missing signedTx");try{const e=yield this.multiBroadcast(R.xn.parse(t.signedTx));t.txid=e,t.date=Date.now()/1e3,this.warn(`SUCCESS broadcastTx
|
|
2
|
-
${(0,$.T5)(t)}`)}catch(e){throw this.warn("FAILURE broadcastTx failed: ",e),e}return t})}getFreshAddress(t){return p(this,null,function*(){const{bech32Address:e}=(0,m.rY)(this.walletInfo).keys;return{publicAddress:e}})}}function st(
|
|
1
|
+
(self.webpackChunkedge_currency_accountbased=self.webpackChunkedge_currency_accountbased||[]).push([[651],{57157:function(V){function A(f){var r=new Error("Cannot find module '"+f+"'");throw r.code="MODULE_NOT_FOUND",r}A.keys=function(){return[]},A.resolve=A,A.id=57157,V.exports=A},52250:function(V,A,f){"use strict";f.r(A),f.d(A,{CardanoTools:function(){return X},makeCurrencyEngine:function(){return st},makeCurrencyTools:function(){return lt},updateInfoPayload:function(){return ut}});var r=f(46271),S=f(66001),O=f(90749),L=f(65828),j=f(96542),$=f(44276),m=f(43755),d=f(99818),F=f(82671),W=f(26277),v=f(62351),k=f(14171);const _=(...c)=>{let t=0,e;if(c.length===0)throw new Error("Expected one or more function argument");for(;t<c.length;){const n=c[t++];try{return n(e)}catch(s){e=s}}throw e};var g=f(36856);const I=(0,d.eB)({inputs:(0,d._j)((0,d.eB)({transaction_id:d.oJ,index:d.i})),outputs:(0,d._j)((0,d.eB)({address:d.oJ,amount:(0,d.eB)({coin:d.oJ})})),fee:d.oJ,ttl:d.oJ,certs:(0,d.H7)((0,d._j)((0,d.UH)((0,d.eB)({StakeRegistrationJSON:g.Z6}),(0,d.eB)({StakeDelegationJSON:g.Z6}),(0,d.eB)({StakeDeregistrationJSON:g.Z6})))),withdrawals:(0,d.H7)(g.Z6)}),U=c=>t=>{var e;const n=I(t);return n.outputs.forEach(s=>(0,d.E8)(c)(s.address)),(e=n.certs)==null||e.forEach(s=>(0,d.UH)((0,d.eB)({StakeRegistrationJSON:g.Z6}),(0,d.eB)({StakeDelegationJSON:g.Z6}))(s)),n};var C=f(48287).Buffer,E=Object.defineProperty,b=Object.defineProperties,T=Object.getOwnPropertyDescriptors,J=Object.getOwnPropertySymbols,M=Object.getPrototypeOf,G=Object.prototype.hasOwnProperty,q=Object.prototype.propertyIsEnumerable,tt=Reflect.get,z=(c,t,e)=>t in c?E(c,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):c[t]=e,R=(c,t)=>{for(var e in t||(t={}))G.call(t,e)&&z(c,e,t[e]);if(J)for(var e of J(t))q.call(t,e)&&z(c,e,t[e]);return c},Z=(c,t)=>b(c,T(t)),Q=(c,t,e)=>tt(M(c),e,t),p=(c,t,e)=>new Promise((n,s)=>{var a=o=>{try{l(e.next(o))}catch(u){s(u)}},i=o=>{try{l(e.throw(o))}catch(u){s(u)}},l=o=>o.done?n(o.value):Promise.resolve(o.value).then(a,i);l((e=e.apply(c,t)).next())});const et=(0,v.fi)(2e4),nt=(0,v.fi)(2e4),ot=(0,v.fi)(2e4);class H extends W.k{constructor(t,e,n,s,a){super(t,e,n,a),this.seenVouts=new Set,this.utxos=[],this.getStakeAddress=()=>p(this,null,function*(){const{bech32Address:i}=(0,m.rY)(this.walletInfo).keys,l=r.pVw.from_bech32(i),o=r.qK$.from_address(l);if(o==null)throw new Error("This address doesn't have staking rights");const u=o.stake_cred();return r.OTB.new(l.network_id(),u).to_address().to_bech32()}),this.decodeStakingTx=i=>p(this,null,function*(){const{bech32Address:l}=(0,m.rY)(this.walletInfo).keys,o=r.ZXm.from_hex(i),u=r.AeD(o.body()),y=o.to_js_value(),w=U(l)(y.body).withdrawals==null,x={isStakeTx:!0,unsignedTx:o.to_hex()},B=y.body.fee,N=w?"-2000000":(0,S.sub)("2000000",B);return{blockHeight:0,currencyCode:this.currencyInfo.currencyCode,date:0,isSend:w,memos:[],nativeAmount:N,networkFee:B,otherParams:x,ourReceiveAddresses:[],signedTx:"",tokenId:null,txid:u.to_hex(),walletId:this.walletId,assetAction:{assetActionType:w?"stake":"unstake"},savedAction:{actionType:"stake",pluginId:this.currencyInfo.pluginId,stakeAssets:[{pluginId:this.currencyInfo.pluginId,tokenId:null}]}}}),this.otherMethods={decodeStakingTx:this.decodeStakingTx,getStakeAddress:this.getStakeAddress},this.fetchCors=(0,$.CY)(t.io),this.initOptions=(0,m.Jv)(s),this.networkInfo=t.networkInfo,this.epochNumber=-1,this.slot=-1}setOtherData(t){this.otherData=(0,m.AA)(t)}fetchKoios(t){return p(this,arguments,function*(e,n={},s=!1){const a=yield this.fetchCors(`${this.networkInfo.koiosServer}/api/v1/${e}`,Z(R({},n),{headers:R(R({},n.headers),s?{Authorization:`Bearer ${this.initOptions.koiosApiKey}`}:{})}));if(a.status===429&&!s)return yield this.fetchKoios(e,n,!0);if(!a.ok){const i=yield a.text();throw new Error(`Koios error: ${i}`)}return yield a.json()})}fetchPostKoios(t,e){return p(this,null,function*(){const n={method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify(e)};return yield this.fetchKoios(t,n)})}multiBroadcast(t){return p(this,null,function*(){const e={method:"POST",headers:{"content-type":"application/cbor"},body:t},n=(o,u,y)=>p(this,null,function*(){const h=yield this.fetchCors(u,Z(R({},e),{headers:R(R({},e.headers),y)})),w=yield h.text();if(!h.ok)throw new Error(`${o} error: ${w}`);return this.log.warn(`${o} broadcast success`),w}),s=()=>p(this,null,function*(){if(this.initOptions.koiosApiKey==null)throw new Error("Missing koiosApiKey");const o={Authorization:`Bearer ${this.initOptions.koiosApiKey}`};return(0,d.fI)(d.oJ)(yield n("Koios",`${this.networkInfo.koiosServer}/api/v1/submittx`,o))}),a=()=>p(this,null,function*(){if(this.initOptions.blockfrostProjectId==null)throw new Error("Missing blockfrostProjectId");const o={project_id:`${this.initOptions.blockfrostProjectId}`};return(0,d.fI)(d.oJ)(yield n("Blockfrost",`${this.networkInfo.blockfrostServer}/api/v0/tx/submit`,o))}),i=()=>p(this,null,function*(){if(this.initOptions.maestroApiKey==null)throw new Error("Missing maestroApiKey");const o={"api-key":`${this.initOptions.maestroApiKey}`};return yield n("Maestro",`${this.networkInfo.maestroServer}/v1/txmanager`,o)}),{values:l}=yield(0,k.JO)([a(),s(),i()]);return l[0]})}queryBlockheight(){return p(this,null,function*(){var t;try{const e=yield this.fetchKoios("tip"),n=(0,m.av)(e)[0],{abs_slot:s,block_no:a,epoch_no:i}=n;if(a>this.walletLocalData.blockHeight&&(this.walletLocalData.blockHeight=a,this.walletLocalDataDirty=!0,this.currencyEngineCallbacks.onBlockHeightChanged(this.walletLocalData.blockHeight)),this.epochNumber=i,this.slot=s,((t=this.tools.epochParams)==null?void 0:t.epoch_no)!==this.epochNumber){const l=yield this.fetchKoios(`epoch_params?_epoch_no=${this.epochNumber}`),o=(0,d.VA)(m.IA)(l);this.tools.epochParams=o[0]}}catch(e){this.log.warn("queryBlockheight error: ",e)}})}queryBalance(){return p(this,null,function*(){var t,e;try{const n=yield this.fetchPostKoios("address_info",{_addresses:[this.walletInfo.keys.bech32Address]}),a=(e=(t=(0,m.cX)(n)[0])==null?void 0:t.utxo_set)!=null?e:[];for(const i of a)this.addUnseenUtxo(i);this.updateBalanceFromUtxos(this.currencyInfo.currencyCode)}catch(n){this.log.warn("queryBalance error: ",n)}})}queryTransactions(){return p(this,null,function*(){let t=this.otherData.latestQueryTransactionsBlockHeight,e=this.otherData.latestQueryTransactionsTxid;const n=[];for(;;){const l=yield this.fetchPostKoios("address_txs",{_addresses:[this.walletInfo.keys.bech32Address],_after_block_height:t}),o=(0,m.DF)(l),u=o[0];if(u==null||u.tx_hash===e)break;const y=o.filter(h=>h.block_height>=t).reverse().map(h=>(t=h.block_height,e=h.tx_hash,h.tx_hash));if(n.push(...y),y.length===0)break}const s=n.length;let a=0;const i=25;for(;n.length>0;){const l=yield this.fetchPostKoios("tx_info",{_inputs:!0,_tx_hashes:n.splice(0,i)}),o=(0,m.Vw)(l);for(let u=0;u<o.length;u++){const y=o[u],h=rt({currencyCode:this.currencyInfo.currencyCode,address:this.walletInfo.keys.bech32Address,tokenId:null,tx:y,walletId:this.walletId});this.addTransaction(this.currencyInfo.currencyCode,h),this.otherData.latestQueryTransactionsBlockHeight=y.block_height,this.otherData.latestQueryTransactionsTxid=y.tx_hash,a++}this.walletLocalDataDirty=!0,this.tokenCheckTransactionsStatus[this.currencyInfo.currencyCode]=a/s,this.updateOnAddressesChecked()}this.tokenCheckTransactionsStatus[this.currencyInfo.currencyCode]=1,this.updateOnAddressesChecked(),this.transactionsChangedArray.length>0&&(this.walletLocalDataDirty=!0,this.currencyEngineCallbacks.onTransactionsChanged(this.transactionsChangedArray),this.transactionsChangedArray=[])})}startEngine(){return p(this,null,function*(){this.engineOn=!0,this.addToLoop("queryBlockheight",nt).catch(()=>{}),this.addToLoop("queryBalance",et).catch(()=>{}),this.addToLoop("queryTransactions",ot).catch(()=>{}),yield Q(H.prototype,this,"startEngine").call(this)})}resyncBlockchain(){return p(this,null,function*(){yield this.killEngine(),yield this.clearBlockchainCache(),yield this.startEngine()})}composeTransaction(t,e){if(this.tools.epochParams==null)throw new Error("No network params");const{min_fee_a:n,min_fee_b:s,max_tx_size:a,key_deposit:i,pool_deposit:l,max_val_size:o,coins_per_utxo_size:u}=this.tools.epochParams,y=r.JLZ.new().fee_algo(r.kr0.new(r.tR8.from_str(n.toString()),r.tR8.from_str(s.toString()))).coins_per_utxo_byte(r.tR8.from_str(u)).max_value_size(o).max_tx_size(a).pool_deposit(r.tR8.from_str(l)).key_deposit(r.tR8.from_str(i)).build(),h=r.Qcz.new(y),w=r.pVw.from_bech32(t),x=r.pVw.from_bech32(this.walletInfo.keys.bech32Address);h.set_ttl_bignum(r.tR8.from_str(this.slot.toString()).checked_add(r.tR8.from_str("7200"))),h.add_output(r.Mw_.new(w,r.WTA.new(r.tR8.from_str(e))));const B=this.utxos.filter(D=>D.value!=="0"&&D.asset_list.length===0),N=r.aZV.new();for(const D of B){const dt=r.WTA.new(r.tR8.from_str(D.value)),ht=r.PNw.new(r.nQF.from_bytes(C.from(D.tx_hash,"hex")),D.tx_index),ft=r.Mw_.new(x,dt);N.add(r.Hlu.new(ht,ft))}try{h.add_inputs_from(N,r.tiU.LargestFirst)}catch(D){throw String(D).includes("UTxO Balance Insufficient")?new F.k5({tokenId:null}):D}h.add_change_if_needed(x);const P=h.build();switch(this.networkInfo.networkId){case 1:P.set_network_id(r.qqB.mainnet());break;case 0:P.set_network_id(r.qqB.testnet());break;default:throw new Error("Unknown networkId")}return P}makeSpend(t){return p(this,null,function*(){const{edgeSpendInfo:e,currencyCode:n}=this.makeSpendCheck(t),{memos:s=[],tokenId:a}=e,i=e.spendTargets[0],{publicAddress:l}=i;let{nativeAmount:o}=i;if(l==null)throw new Error("makeSpend Missing publicAddress");if(o==null)throw new F.ef;let u="0";const y={unsignedTx:""};if(o!=null&&o!=="0")try{const x=this.composeTransaction(l,o);u=x.fee().to_str(),y.unsignedTx=x.to_hex()}catch(x){throw this.log.warn("composeTransaction error: ",x),x instanceof Error?x:new Error(String(x))}const h=(0,S.add)(o,u);return o=(0,S.mul)(h,"-1"),{blockHeight:0,currencyCode:n,date:0,isSend:o.startsWith("-"),memos:s,nativeAmount:o,networkFee:u,otherParams:y,ourReceiveAddresses:[],signedTx:"",tokenId:a,txid:"",walletId:this.walletId}})}saveTx(t){return p(this,null,function*(){yield Q(H.prototype,this,"saveTx").call(this,t);const e=r.ZXm.from_hex(t.signedTx),n=r.AeD(e.body()).to_hex(),s=e.to_js_value();this.removeUtxosByVouts(s.body.inputs.map(i=>`${i.transaction_id}_${i.index}`));const a=this.walletInfo.keys.bech32Address;s.body.outputs.forEach((i,l)=>{if(i.address===a){if(i.amount.multiasset!=null)return;this.addUnseenUtxo({asset_list:[],tx_hash:n,tx_index:l,value:i.amount.coin})}}),this.updateBalanceFromUtxos(this.currencyInfo.currencyCode)})}signTx(t,e){return p(this,null,function*(){const{unsignedTx:n,isStakeTx:s=!1}=(0,m.xZ)(t.otherParams),a=(0,m.kF)(this.currencyInfo.pluginId)(e),{accountKey:i}=yield this.tools.derivePrivateKeys(a),l=i.derive(0).derive(0),o=_(()=>r.LQ6.from_hex(n),()=>r.ZXm.from_hex(n).body()),u=r.AeD(o),y=r.SLq.new(),h=r.ToW.new(),w=r.Ju1(u,l.to_raw_key());if(h.add(w),s){const B=i.derive(2).derive(0),N=r.Ju1(u,B.to_raw_key());h.add(N)}y.set_vkeys(h);const x=r.ZXm.new(o,y,void 0);return t.signedTx=x.to_hex(),t})}broadcastTx(t){return p(this,null,function*(){if(t.signedTx==null)throw new Error("Missing signedTx");try{const e=yield this.multiBroadcast(L.xn.parse(t.signedTx));t.txid=e,t.date=Date.now()/1e3,this.warn(`SUCCESS broadcastTx
|
|
2
|
+
${(0,$.T5)(t)}`)}catch(e){throw this.warn("FAILURE broadcastTx failed: ",e),e}return t})}getFreshAddress(t){return p(this,null,function*(){const{bech32Address:e}=(0,m.rY)(this.walletInfo).keys;return{publicAddress:e}})}addUnseenUtxo(t){const e=`${t.tx_hash}_${t.tx_index}`;this.seenVouts.has(e)||(this.seenVouts.add(e),this.utxos.push(t))}removeUtxosByVouts(t){const e=new Set(t);this.utxos=this.utxos.filter(n=>!e.has(`${n.tx_hash}_${n.tx_index}`))}updateBalanceFromUtxos(t){const e=this.utxos.reduce((n,s)=>(0,S.add)(n,s.value),"0");this.updateBalance(t,e)}}function st(c,t,e,n){return p(this,null,function*(){const{initOptions:s}=c,a=(0,m.rY)(e),i=new H(c,t,a,s,n);return yield i.loadEngine(),i})}const rt=c=>{const{currencyCode:t,address:e,tokenId:n,tx:s,walletId:a}=c,{tx_hash:i,block_height:l,tx_timestamp:o,fee:u,inputs:y,outputs:h}=s;let w="0";const x=new Set;for(const P of y)P.payment_addr.bech32===e&&(w=(0,S.sub)(w,P.value));for(const P of h)P.payment_addr.bech32===e&&(w=(0,S.add)(w,P.value),x.add(e));const B=w.startsWith("-");return{blockHeight:l,currencyCode:t,date:o,isSend:B,memos:[],nativeAmount:w,networkFee:B?u:"0",ourReceiveAddresses:[...x.values()],signedTx:"",tokenId:n,txid:i,walletId:a}};var Y=Object.getOwnPropertySymbols,it=Object.prototype.hasOwnProperty,at=Object.prototype.propertyIsEnumerable,ct=(c,t)=>{var e={};for(var n in c)it.call(c,n)&&t.indexOf(n)<0&&(e[n]=c[n]);if(c!=null&&Y)for(var n of Y(c))t.indexOf(n)<0&&at.call(c,n)&&(e[n]=c[n]);return e},K=(c,t,e)=>new Promise((n,s)=>{var a=o=>{try{l(e.next(o))}catch(u){s(u)}},i=o=>{try{l(e.throw(o))}catch(u){s(u)}},l=o=>o.done?n(o.value):Promise.resolve(o.value).then(a,i);l((e=e.apply(c,t)).next())});class X{constructor(t){const{builtinTokens:e,currencyInfo:n,io:s,networkInfo:a}=t;this.builtinTokens=e,this.currencyInfo=n,this.io=s,this.networkInfo=a}derivePrivateKeys(t){if(t.accountKey!=null&&t.privateKey!=null)return{accountKey:r.DcE.from_bech32(t.accountKey),privateKey:r.DcE.from_bech32(t.privateKey)};const e=(0,O.mnemonicToEntropy)(t.mnemonic),n=r.DcE.from_bip39_entropy(L.xn.parse(e),new Uint8Array);function s(i){return 2147483648+i}return{accountKey:n.derive(s(1852)).derive(s(1815)).derive(s(0)),privateKey:n}}getDisplayPrivateKey(t){return K(this,null,function*(){const{pluginId:e}=this.currencyInfo;return(0,m.kF)(e)(t.keys).mnemonic})}getDisplayPublicKey(t){return K(this,null,function*(){const{keys:e}=(0,m.rY)(t);return e.publicKey})}importPrivateKey(t){return K(this,null,function*(){const{pluginId:e}=this.currencyInfo;if(!(0,O.validateMnemonic)(t))throw new Error("Invalid mnemonic");const s=(0,O.mnemonicToEntropy)(t);r.DcE.from_bip39_entropy(L.xn.parse(s),new Uint8Array);const{accountKey:a,privateKey:i}=yield this.derivePrivateKeys({mnemonic:t});return(0,m.hJ)(e)({mnemonic:t,accountKey:a.to_bech32(),privateKey:i.to_bech32()})})}createPrivateKey(t){return K(this,null,function*(){if(t!==this.currencyInfo.walletType)throw new Error("InvalidWalletType");const e=L.xn.stringify(this.io.random(32)),n=(0,O.entropyToMnemonic)(e);return yield this.importPrivateKey(n)})}derivePublicKey(t){return K(this,null,function*(){const{pluginId:e,walletType:n}=this.currencyInfo;if(t.type!==n)throw new Error("InvalidWalletType");const s=(0,m.kF)(e)(t.keys),{accountKey:a,privateKey:i}=this.derivePrivateKeys(s),l=a.derive(0).derive(0).to_public(),o=a.derive(2).derive(0).to_public();return{bech32Address:r.qK$.new(this.networkInfo.networkId,r.uGu.from_keyhash(l.to_raw_key().hash()),r.uGu.from_keyhash(o.to_raw_key().hash())).to_address().to_bech32(),publicKey:i.to_public().to_bech32()}})}parseUri(t,e,n){return K(this,null,function*(){var s;const a={cardano:!0},{parsedUri:i,edgeParsedUri:l}=yield(0,j.x)({currencyInfo:this.currencyInfo,uri:t,networks:a,builtinTokens:this.builtinTokens,currencyCode:e!=null?e:"ADA",customTokens:n});return r.pVw.from_bech32((s=l.publicAddress)!=null?s:""),l.uniqueIdentifier=i.query.memo,l})}encodeUri(t){return K(this,arguments,function*(e,n=[]){const{nativeAmount:s,currencyCode:a,publicAddress:i}=e;r.pVw.from_bech32(i!=null?i:"");let l;if(typeof s=="string"){const u=(0,$.FQ)(a!=null?a:this.currencyInfo.currencyCode,this.currencyInfo,n,this.builtinTokens);if(u==null)throw new Error("InternalErrorInvalidCurrencyCode");l=(0,S.div)(s,u.multiplier,18)}return(0,j.m)(e,"cardano",l)})}}function lt(c){return K(this,null,function*(){return new X(c)})}function ut(c,t){return K(this,null,function*(){const e=ct(t,[]);c.networkInfo=(0,$.wy)(c.networkInfo,e)})}},62351:function(V,A,f){"use strict";f.d(A,{Nn:function(){return d},Nt:function(){return F},fi:function(){return W},zp:function(){return $}});var r=f(14171),S=f(44276),O=(v,k,_)=>new Promise((g,I)=>{var U=b=>{try{E(_.next(b))}catch(T){I(T)}},C=b=>{try{E(_.throw(b))}catch(T){I(T)}},E=b=>b.done?g(b.value):Promise.resolve(b.value).then(U,C);E((_=_.apply(v,k)).next())});const L=["https://info1.edge.app","https://info2.edge.app"];function j(v,k,_){return O(this,arguments,function*(g,I,U,C=5e3,E=fetch){const b=g.map(T=>()=>O(this,null,function*(){const J=yield E(T+"/"+I,U);if(typeof J!="object"){const M=`Invalid return value ${I} in ${T}`;throw console.log(M),new Error(M)}return J}));return yield(0,r.NN)(b,C)})}function $(v,k,_,g,I=5e3,U){return O(this,null,function*(){const C=yield j((0,S.R3)(k),_,g,I,U);if(!C.ok){const T=yield C.text();throw console.error(T),new Error(`Error fetching ${_}: ${T}`)}const E=yield C.json();return v(E)})}function m(v,k,_,g=5e3,I){return O(this,null,function*(){return yield j((0,S.R3)(v),k,_,g,I)})}const d=(v,k,_,g)=>O(void 0,null,function*(){return yield m(L,v,k,_,g)}),F=v=>Object.keys(v).map(k=>{const _=v[k];return _==null?k:`${k}=${encodeURIComponent(_)}`}).join("&"),W=(v,k=5e3)=>v+Math.random()*k*2-k}}]);
|