Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

aelf-sdk-cross-chain

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

aelf-sdk-cross-chain - npm Package Compare versions

Comparing version 1.0.12 to 1.0.13

4

dist/aelf-cross-chain.umd.js
/*!
* aelf-sdk-cross-chain.js v1.0.12
* aelf-sdk-cross-chain.js v1.0.13
* (c) 2019-2020 AElf
* Released under MIT License
*/
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define("AElfCrossChain",[],e):"object"==typeof exports?exports.AElfCrossChain=e():t.AElfCrossChain=e()}(this,function(){return function(t){var e={};function r(n){if(e[n])return e[n].exports;var i=e[n]={i:n,l:!1,exports:{}};return t[n].call(i.exports,i,i.exports,r),i.l=!0,i.exports}return r.m=t,r.c=e,r.d=function(t,e,n){r.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:n})},r.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},r.t=function(t,e){if(1&e&&(t=r(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var i in t)r.d(n,i,function(e){return t[e]}.bind(null,i));return n},r.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return r.d(e,"a",e),e},r.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},r.p="",r(r.s=21)}([function(t,e,r){t.exports=r(17)},function(t,e){function r(t,e,r,n,i,o,a){try{var s=t[o](a),c=s.value}catch(t){return void r(t)}s.done?e(c):Promise.resolve(c).then(n,i)}t.exports=function(t){return function(){var e=this,n=arguments;return new Promise(function(i,o){var a=t.apply(e,n);function s(t){r(a,i,o,s,c,"next",t)}function c(t){r(a,i,o,s,c,"throw",t)}s(void 0)})}}},function(t,e,r){"use strict";(function(t){r.d(e,"a",function(){return C});var n=r(6),i=r.n(n),o=r(8),a=r.n(o),s=r(0),c=r.n(s),u=r(9),h=r.n(u),f=r(1),l=r.n(f),p=r(3),d=r.n(p),g=r(4),y=r.n(g),v=r(5);function w(t,e){var r=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);e&&(n=n.filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable})),r.push.apply(r,n)}return r}function m(t){for(var e=1;e<arguments.length;e++){var r=null!=arguments[e]?arguments[e]:{};e%2?w(r,!0).forEach(function(e){a()(t,e,r[e])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(r)):w(r).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(r,e))})}return t}var C=function(){function e(t){var r=t.AElfUtils,n=t.sendInstance,i=t.receiveInstance,o=t.mainChainId,a=void 0===o?9992731:o,s=t.issueChainId,c=void 0===s?9992731:s,u=t.tokenContractName,h=void 0===u?"AElf.ContractNames.Token":u,f=t.crossChainContractName,l=void 0===f?"AElf.ContractNames.CrossChain":f,p=t.reQueryInterval,g=void 0===p?5e3:p,y=t.queryLimit,v=void 0===y?100:y;d()(this,e),this.aelfInstance={sendInstance:n,receiveInstance:i};var w=r.sha256,m=r.chainIdConvertor;this.tokenContractName=h,this.crossChainContractName=l,this.mainChainId="string"==typeof a?m.base58ToChainId(a):a,this.issueChainId="string"==typeof c?m.base58ToChainId(c):c,this.reQueryInterval=g,this.getBoundParentChainHeightAndMerklePathByHeightLimit=v,this.getBoundParentChainHeightAndMerklePathByHeightCount=0,this.getBoundParentChainHeightAndMerklePathByHeightError=null,this.sha256=w,this.chainIdConvertor=m}var r,n,o,a,s,u,f,p;return y()(e,[{key:"init",value:(p=l()(c.a.mark(function t(e){var r,n,i,o,a,s,u,f,l,p,d,g,y,w,m,C,b,I,T,x,A,P,k,E;return c.a.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return r=e.wallet,n=e.contractAddresses,i=void 0===n?null:n,o=e.chainIds,a=void 0===o?null:o,s=this.aelfInstance,u=s.sendInstance,f=s.receiveInstance,l=this.tokenContractName,p=this.crossChainContractName,d=this.sha256,t.next=5,Object(v.b)({contractAddresses:i,chainIds:a,sendInstance:u,receiveInstance:f,wallet:r,sha256:d,tokenContractName:l,crossChainContractName:p});case 5:return g=t.sent,y=g.tokenContractAddressSend,w=g.crossChainContractAddressSend,m=g.tokenContractAddressReceive,C=g.crossChainContractAddressReceive,b=g.chainIdSend,I=g.chainIdReceive,t.next=14,Promise.all([u.chain.contractAt(y,r),u.chain.contractAt(w,r),f.chain.contractAt(m,r),f.chain.contractAt(C,r)]);case 14:return T=t.sent,x=h()(T,4),A=x[0],P=x[1],k=x[2],E=x[3],this.aelfInstance.tokenContractSend=A,this.aelfInstance.tokenContractReceive=k,this.aelfInstance.crossChainContractSend=P,this.aelfInstance.crossChainContractReceive=E,this.chainIdSendBase58=b,this.chainIdReceiveBase58=I,t.abrupt("return",{tokenContractSend:A,tokenContractReceive:k,crossChainContractSend:P,crossChainContractReceive:E,chainIdSend:b,chainIdReceive:I});case 27:case"end":return t.stop()}},t,this)})),function(t){return p.apply(this,arguments)})},{key:"send",value:(f=l()(c.a.mark(function t(e,r){var n,i,o,a,s,u;return c.a.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return n=this.chainIdConvertor,i=e.tokenContractSend,o=e.chainIdReceive,(a=m({},r,{toChainId:n.base58ToChainId(o),issueChainId:this.issueChainId})).memo=a.memo||null,t.next=6,i.CrossChainTransfer(a);case 6:return s=t.sent,u=s.TransactionId,t.abrupt("return",{toChainId:a.toChainId,issueChainId:a.issueChainId,crossTransferTxId:u});case 9:case"end":return t.stop()}},t,this)})),function(t,e){return f.apply(this,arguments)})},{key:"getCrossTransferRawTx",value:(u=l()(c.a.mark(function t(e){var r,n,i,o,a,s,u,h=this;return c.a.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return r=e.aelfInstance,n=e.aelfInstanceTokenContract,i=e.transactionId,t.next=3,r.chain.getTxResult(i);case 3:if(o=t.sent,!(a=o.Status)||"MINED"===a){t.next=9;break}if("pending"!==a.toLowerCase()){t.next=8;break}return t.abrupt("return",new Promise(function(t){setTimeout(l()(c.a.mark(function e(){return c.a.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.t0=t,e.next=3,h.getCrossTransferRawTx({aelfInstance:r,aelfInstanceTokenContract:n,transactionId:i});case 3:e.t1=e.sent,(0,e.t0)(e.t1);case 5:case"end":return e.stop()}},e)})),h.reQueryInterval)}));case 8:throw Error(JSON.stringify({error:1,message:"".concat(i," is not MINED.[").concat(a,"]"),canReceive:!1}));case 9:return t.next=11,r.chain.getBlockByHeight(o.Transaction.RefBlockNumber,!1);case 11:return s=t.sent,u=n.CrossChainTransfer.getSignedTx(JSON.parse(o.Transaction.Params),{height:s.Header.Height,hash:s.BlockHash}),t.abrupt("return",{crossTransferTxInfo:o,crossTransferRawTx:u});case 14:case"end":return t.stop()}},t)})),function(t){return u.apply(this,arguments)})},{key:"getBoundParentChainHeightAndMerklePathByHeight",value:(s=l()(c.a.mark(function t(e){var r,n,i,o,a,s=this;return c.a.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(r=e.crossChainContractSend,n=e.crossTransferTxBlockHeight,!(this.getBoundParentChainHeightAndMerklePathByHeightCount>=this.getBoundParentChainHeightAndMerklePathByHeightLimit)){t.next=3;break}return t.abrupt("return",Promise.reject(this.getBoundParentChainHeightAndMerklePathByHeightError));case 3:return t.prev=3,t.next=6,r.GetBoundParentChainHeightAndMerklePathByHeight.call({value:n});case 6:return i=t.sent,o=i.merklePathFromParentChain,a=i.boundParentChainHeight,this.getBoundParentChainHeightAndMerklePathByHeightCount=0,t.abrupt("return",{merklePathFromParentChain:o,boundParentChainHeight:a});case 13:return t.prev=13,t.t0=t.catch(3),this.getBoundParentChainHeightAndMerklePathByHeightError=t.t0,this.getBoundParentChainHeightAndMerklePathByHeightCount++,t.abrupt("return",new Promise(function(t,e){setTimeout(function(){s.getBoundParentChainHeightAndMerklePathByHeight({crossChainContractSend:r,crossTransferTxBlockHeight:n}).then(t).catch(e)},s.reQueryInterval)}));case 18:case"end":return t.stop()}},t,this,[[3,13]])})),function(t){return s.apply(this,arguments)})},{key:"getMerklePath",value:(a=l()(c.a.mark(function e(r){var n,o,a,s,u,h,f,l,p,d,g,y;return c.a.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return n=r.sendInstance,o=r.crossChainContractSend,a=r.crossTransferTxId,s=r.crossTransferTxBlockHeight,u=r.isFromMainChain,h=void 0!==u&&u,e.next=3,n.chain.getMerklePathByTxId(a);case 3:if(f=e.sent,(l={merklePathNodes:i()(f.MerklePathNodes)}).merklePathNodes=l.merklePathNodes.map(function(e){return{hash:{value:t.from(e.Hash,"hex").toString("base64")},isLeftChildNode:e.IsLeftChildNode}}),p=-1,h){e.next=15;break}return e.next=10,this.getBoundParentChainHeightAndMerklePathByHeight({crossChainContractSend:o,crossTransferTxBlockHeight:s});case 10:d=e.sent,g=d.merklePathFromParentChain,y=d.boundParentChainHeight,p=y,l.merklePathNodes=[].concat(i()(l.merklePathNodes),i()(g.merklePathNodes));case 15:return e.abrupt("return",{boundParentChainHeight:p,merklePath:l});case 16:case"end":return e.stop()}},e,this)})),function(t){return a.apply(this,arguments)})},{key:"recevieInit",value:(o=l()(c.a.mark(function t(e){var r,n,i,o,a,s,u,h,f,l,p,d,g,y,v;return c.a.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(r=e.crossTransferTxId,n=this.chainIdConvertor,i=this.aelfInstance,o=i.sendInstance,a=i.tokenContractSend,i.tokenContractReceive&&a){t.next=5;break}throw Error(JSON.stringify({error:1,message:"Please call tokenCrossChain.init to get tokenContractReceive & tokenContractSend at first.",canReceive:!1}));case 5:return t.next=7,o.chain.getChainStatus();case 7:return s=t.sent,u=s.LastIrreversibleBlockHeight,t.next=11,this.getCrossTransferRawTx({aelfInstance:o,aelfInstanceTokenContract:a,transactionId:r});case 11:return h=t.sent,f=h.crossTransferTxInfo,l=h.crossTransferRawTx,p=f.BlockNumber,d=n.base58ToChainId(this.chainIdSendBase58),g=n.base58ToChainId(this.chainIdReceiveBase58),y=d===this.mainChainId,v=g===this.mainChainId,t.abrupt("return",{lastIrreversibleBlockHeight:u,crossTransferTxInfo:f,crossTransferRawTx:l,crossTransferTxBlockHeight:p,chainIdSend:d,chainIdReceive:g,isFromMainChain:y,isToMainChain:v});case 20:case"end":return t.stop()}},t,this)})),function(t){return o.apply(this,arguments)})},{key:"isChainReadyToReceive",value:(n=l()(c.a.mark(function t(e){var r,n,i,o,a,s,u,h,f,l,p,d,g,y,v,w,m,C,b,I,T,x,A;return c.a.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return r=e.crossTransferTxId,n=this.aelfInstance,i=n.sendInstance,o=n.crossChainContractSend,a=n.crossChainContractReceive,t.next=4,this.recevieInit({crossTransferTxId:r});case 4:if(s=t.sent,u=s.lastIrreversibleBlockHeight,h=s.crossTransferTxInfo,f=s.crossTransferRawTx,l=s.crossTransferTxBlockHeight,p=s.chainIdSend,d=s.isFromMainChain,g=s.isToMainChain,!(u>=l)){t.next=52;break}if(!h.Status||"MINED"!==h.Status){t.next=49;break}return t.next=16,this.getMerklePath({sendInstance:i,crossChainContractSend:o,crossTransferTxId:r,crossTransferTxBlockHeight:l,isFromMainChain:d});case 16:if(y=t.sent,v=y.boundParentChainHeight,w=y.merklePath,m=l,!d){t.next=30;break}return t.next=23,a.GetParentChainHeight.call();case 23:if(C=t.sent,b=C.value,!((b=parseInt(b,10))>=0&&b<l)){t.next=28;break}throw Error(JSON.stringify({error:1,message:"the parent chain block at height of ".concat(l)+"is not recorded, please waiting.",canReceive:!0}));case 28:t.next=48;break;case 30:if(!g){t.next=40;break}return m=v,t.next=34,a.GetSideChainHeight.call({value:p});case 34:if(I=t.sent,!((T=I.value)<l)){t.next=38;break}throw Error(JSON.stringify({error:1,message:"The side chains are not ready to receive tx.\n The height of the side chain recorded in main chain is ".concat(T,".\n sideChainHeightInMainChain need >= ").concat(l,"."),canReceive:!0}));case 38:t.next=48;break;case 40:return t.next=42,a.GetParentChainHeight.call();case 42:if(x=t.sent,A=x.value,A=parseInt(A,10),!(v>A)){t.next=47;break}throw Error(JSON.stringify({error:1,message:"The side chains are not ready to receive tx.\n The boundParentChainHeight of crossChainTransfer is ".concat(v,"\n The parentChainHeight of the chain which receives the tx is ").concat(A,"."),canReceive:!0}));case 47:m=v;case 48:return t.abrupt("return",{isReady:!0,crossTransferRawTx:f,chainIdSend:p,merklePath:w,crossTransferTxParentBlockHeight:m});case 49:throw Error(JSON.stringify({error:3,message:"The transaction ".concat(r," of CrossChainTransfer\n is ").concat(h.Status,"."),canReceive:!0}));case 52:throw Error(JSON.stringify({error:2,message:"Please waiting until the lastIrreversibleBlockHeight[".concat(u,"]\n >= 'the height[").concat(l,"] of transaction of tokenCrossChainInstance.send()'\n "),canReceive:!0}));case 53:case"end":return t.stop()}},t,this)})),function(t){return n.apply(this,arguments)})},{key:"receive",value:(r=l()(c.a.mark(function e(r){var n,i,o,a,s,u,h,f;return c.a.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return n=r.crossTransferTxId,e.next=3,this.isChainReadyToReceive({crossTransferTxId:n});case 3:return i=e.sent,o=i.crossTransferRawTx,a=i.chainIdSend,s=i.merklePath,u=i.crossTransferTxParentBlockHeight,h=this.aelfInstance.tokenContractReceive,e.next=11,h.CrossChainReceiveToken({fromChainId:a,parentChainHeight:u,transferTransactionBytes:t.from(o,"hex"),merklePath:s});case 11:return f=e.sent,e.abrupt("return",f);case 13:case"end":return e.stop()}},e,this)})),function(t){return r.apply(this,arguments)})}]),e}()}).call(this,r(7).Buffer)},function(t,e){t.exports=function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}},function(t,e){function r(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}t.exports=function(t,e,n){return e&&r(t.prototype,e),n&&r(t,n),t}},function(t,e,r){"use strict";(function(t){r.d(e,"b",function(){return s});var n=r(0),i=r.n(n),o=r(1),a=r.n(o);function s(t){return c.apply(this,arguments)}function c(){return(c=a()(i.a.mark(function t(e){var r,n,o,a,s,c,u,h,f,l,p,d,g,y,v,w,m,C,b,I,T,x,A,P,k,E,R,B;return i.a.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(r=e.contractAddresses,n=e.chainIds,o=e.sendInstance,a=e.receiveInstance,s=e.wallet,c=e.sha256,u=e.tokenContractName,h=e.crossChainContractName,!r||!n){t.next=9;break}if(f=r.tokenContractAddressSend,l=r.crossChainContractAddressSend,p=r.tokenContractAddressReceive,d=r.crossChainContractAddressReceive,g=n.chainIdSend,y=n.chainIdReceive,v={tokenContractAddressSend:f,crossChainContractAddressSend:l,tokenContractAddressReceive:p,crossChainContractAddressReceive:d,chainIdSend:g,chainIdReceive:y},w=!0,Object.keys(v).forEach(function(t){v[t]||(w=!1)}),!w){t.next=9;break}return t.abrupt("return",v);case 9:return t.next=11,o.chain.getChainStatus();case 11:return m=t.sent,C=m.GenesisContractAddress,b=m.ChainId,t.next=16,a.chain.getChainStatus();case 16:return I=t.sent,T=I.GenesisContractAddress,x=I.ChainId,t.next=21,o.chain.contractAt(C,s);case 21:return A=t.sent,t.next=24,a.chain.contractAt(T,s);case 24:return P=t.sent,t.next=27,A.GetContractAddressByName.call(c(u));case 27:return k=t.sent,t.next=30,A.GetContractAddressByName.call(c(h));case 30:return E=t.sent,t.next=33,P.GetContractAddressByName.call(c(u));case 33:return R=t.sent,t.next=36,P.GetContractAddressByName.call(c(h));case 36:return B=t.sent,t.abrupt("return",{tokenContractAddressSend:k,crossChainContractAddressSend:E,tokenContractAddressReceive:R,crossChainContractAddressReceive:B,chainIdSend:b,chainIdReceive:x});case 38:case"end":return t.stop()}},t)}))).apply(this,arguments)}}).call(this,r(7).Buffer)},function(t,e,r){var n=r(14),i=r(15),o=r(16);t.exports=function(t){return n(t)||i(t)||o()}},function(t,e,r){"use strict";(function(t){
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define("AElfCrossChain",[],e):"object"==typeof exports?exports.AElfCrossChain=e():t.AElfCrossChain=e()}(this,function(){return function(t){var e={};function r(n){if(e[n])return e[n].exports;var i=e[n]={i:n,l:!1,exports:{}};return t[n].call(i.exports,i,i.exports,r),i.l=!0,i.exports}return r.m=t,r.c=e,r.d=function(t,e,n){r.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:n})},r.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},r.t=function(t,e){if(1&e&&(t=r(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var i in t)r.d(n,i,function(e){return t[e]}.bind(null,i));return n},r.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return r.d(e,"a",e),e},r.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},r.p="",r(r.s=21)}([function(t,e,r){t.exports=r(17)},function(t,e){function r(t,e,r,n,i,o,a){try{var s=t[o](a),c=s.value}catch(t){return void r(t)}s.done?e(c):Promise.resolve(c).then(n,i)}t.exports=function(t){return function(){var e=this,n=arguments;return new Promise(function(i,o){var a=t.apply(e,n);function s(t){r(a,i,o,s,c,"next",t)}function c(t){r(a,i,o,s,c,"throw",t)}s(void 0)})}}},function(t,e,r){"use strict";(function(t){r.d(e,"a",function(){return C});var n=r(6),i=r.n(n),o=r(8),a=r.n(o),s=r(0),c=r.n(s),u=r(9),h=r.n(u),f=r(1),l=r.n(f),p=r(3),d=r.n(p),g=r(4),y=r.n(g),v=r(5);function w(t,e){var r=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);e&&(n=n.filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable})),r.push.apply(r,n)}return r}function m(t){for(var e=1;e<arguments.length;e++){var r=null!=arguments[e]?arguments[e]:{};e%2?w(r,!0).forEach(function(e){a()(t,e,r[e])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(r)):w(r).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(r,e))})}return t}var C=function(){function e(t){var r=t.AElfUtils,n=t.sendInstance,i=t.receiveInstance,o=t.mainChainId,a=void 0===o?9992731:o,s=t.issueChainId,c=void 0===s?9992731:s,u=t.tokenContractName,h=void 0===u?"AElf.ContractNames.Token":u,f=t.crossChainContractName,l=void 0===f?"AElf.ContractNames.CrossChain":f,p=t.reQueryInterval,g=void 0===p?5e3:p,y=t.queryLimit,v=void 0===y?100:y;d()(this,e),this.aelfInstance={sendInstance:n,receiveInstance:i};var w=r.sha256,m=r.chainIdConvertor;this.tokenContractName=h,this.crossChainContractName=l,this.mainChainId="string"==typeof a?m.base58ToChainId(a):a,this.issueChainId="string"==typeof c?m.base58ToChainId(c):c,this.reQueryInterval=g,this.getBoundParentChainHeightAndMerklePathByHeightLimit=v,this.getBoundParentChainHeightAndMerklePathByHeightCount=0,this.getBoundParentChainHeightAndMerklePathByHeightError=null,this.sha256=w,this.chainIdConvertor=m}var r,n,o,a,s,u,f,p;return y()(e,[{key:"init",value:(p=l()(c.a.mark(function t(e){var r,n,i,o,a,s,u,f,l,p,d,g,y,w,m,C,b,I,T,x,A,P,k,E;return c.a.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return r=e.wallet,n=e.contractAddresses,i=void 0===n?null:n,o=e.chainIds,a=void 0===o?null:o,s=this.aelfInstance,u=s.sendInstance,f=s.receiveInstance,l=this.tokenContractName,p=this.crossChainContractName,d=this.sha256,t.next=5,Object(v.b)({contractAddresses:i,chainIds:a,sendInstance:u,receiveInstance:f,wallet:r,sha256:d,tokenContractName:l,crossChainContractName:p});case 5:return g=t.sent,y=g.tokenContractAddressSend,w=g.crossChainContractAddressSend,m=g.tokenContractAddressReceive,C=g.crossChainContractAddressReceive,b=g.chainIdSend,I=g.chainIdReceive,t.next=14,Promise.all([u.chain.contractAt(y,r),u.chain.contractAt(w,r),f.chain.contractAt(m,r),f.chain.contractAt(C,r)]);case 14:return T=t.sent,x=h()(T,4),A=x[0],P=x[1],k=x[2],E=x[3],this.aelfInstance.tokenContractSend=A,this.aelfInstance.tokenContractReceive=k,this.aelfInstance.crossChainContractSend=P,this.aelfInstance.crossChainContractReceive=E,this.chainIdSendBase58=b,this.chainIdReceiveBase58=I,t.abrupt("return",{tokenContractSend:A,tokenContractReceive:k,crossChainContractSend:P,crossChainContractReceive:E,chainIdSend:b,chainIdReceive:I});case 27:case"end":return t.stop()}},t,this)})),function(t){return p.apply(this,arguments)})},{key:"send",value:(f=l()(c.a.mark(function t(e,r){var n,i,o,a,s,u;return c.a.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return n=this.chainIdConvertor,i=e.tokenContractSend,o=e.chainIdReceive,(a=m({},r,{toChainId:n.base58ToChainId(o),issueChainId:this.issueChainId})).memo=a.memo||null,t.next=6,i.CrossChainTransfer(a);case 6:return s=t.sent,u=s.TransactionId,t.abrupt("return",{toChainId:a.toChainId,issueChainId:a.issueChainId,crossTransferTxId:u});case 9:case"end":return t.stop()}},t,this)})),function(t,e){return f.apply(this,arguments)})},{key:"getCrossTransferRawTx",value:(u=l()(c.a.mark(function t(e){var r,n,i,o,a,s,u,h=this;return c.a.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return r=e.aelfInstance,n=e.aelfInstanceTokenContract,i=e.transactionId,t.next=3,r.chain.getTxResult(i);case 3:if(o=t.sent,!(a=o.Status)||"MINED"===a){t.next=9;break}if("pending"!==a.toLowerCase()){t.next=8;break}return t.abrupt("return",new Promise(function(t){setTimeout(l()(c.a.mark(function e(){return c.a.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.t0=t,e.next=3,h.getCrossTransferRawTx({aelfInstance:r,aelfInstanceTokenContract:n,transactionId:i});case 3:e.t1=e.sent,(0,e.t0)(e.t1);case 5:case"end":return e.stop()}},e)})),h.reQueryInterval)}));case 8:throw Error(JSON.stringify({error:1,message:"".concat(i," is not MINED.[").concat(a,"]"),canReceive:!1}));case 9:return t.next=11,r.chain.getBlockByHeight(o.Transaction.RefBlockNumber,!1);case 11:return s=t.sent,u=n.CrossChainTransfer.getSignedTx(JSON.parse(o.Transaction.Params),{height:s.Header.Height,hash:s.BlockHash}),t.abrupt("return",{crossTransferTxInfo:o,crossTransferRawTx:u});case 14:case"end":return t.stop()}},t)})),function(t){return u.apply(this,arguments)})},{key:"getBoundParentChainHeightAndMerklePathByHeight",value:(s=l()(c.a.mark(function t(e){var r,n,i,o,a,s=this;return c.a.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(r=e.crossChainContractSend,n=e.crossTransferTxBlockHeight,!(this.getBoundParentChainHeightAndMerklePathByHeightCount>=this.getBoundParentChainHeightAndMerklePathByHeightLimit)){t.next=3;break}return t.abrupt("return",Promise.reject(this.getBoundParentChainHeightAndMerklePathByHeightError));case 3:return t.prev=3,t.next=6,r.GetBoundParentChainHeightAndMerklePathByHeight.call({value:n});case 6:return i=t.sent,o=i.merklePathFromParentChain,a=i.boundParentChainHeight,this.getBoundParentChainHeightAndMerklePathByHeightCount=0,t.abrupt("return",{merklePathFromParentChain:o,boundParentChainHeight:a});case 13:return t.prev=13,t.t0=t.catch(3),this.getBoundParentChainHeightAndMerklePathByHeightError=t.t0,this.getBoundParentChainHeightAndMerklePathByHeightCount++,t.abrupt("return",new Promise(function(t,e){setTimeout(function(){s.getBoundParentChainHeightAndMerklePathByHeight({crossChainContractSend:r,crossTransferTxBlockHeight:n}).then(t).catch(e)},s.reQueryInterval)}));case 18:case"end":return t.stop()}},t,this,[[3,13]])})),function(t){return s.apply(this,arguments)})},{key:"getMerklePath",value:(a=l()(c.a.mark(function e(r){var n,o,a,s,u,h,f,l,p,d,g,y;return c.a.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return n=r.sendInstance,o=r.crossChainContractSend,a=r.crossTransferTxId,s=r.crossTransferTxBlockHeight,u=r.isFromMainChain,h=void 0!==u&&u,e.next=3,n.chain.getMerklePathByTxId(a);case 3:if(f=e.sent,(l={merklePathNodes:i()(f.MerklePathNodes)}).merklePathNodes=l.merklePathNodes.map(function(e){return{hash:{value:t.from(e.Hash,"hex").toString("base64")},isLeftChildNode:e.IsLeftChildNode}}),p=-1,h){e.next=15;break}return e.next=10,this.getBoundParentChainHeightAndMerklePathByHeight({crossChainContractSend:o,crossTransferTxBlockHeight:s});case 10:d=e.sent,g=d.merklePathFromParentChain,y=d.boundParentChainHeight,p=y,l.merklePathNodes=[].concat(i()(l.merklePathNodes),i()(g.merklePathNodes));case 15:return e.abrupt("return",{boundParentChainHeight:p,merklePath:l});case 16:case"end":return e.stop()}},e,this)})),function(t){return a.apply(this,arguments)})},{key:"recevieInit",value:(o=l()(c.a.mark(function t(e){var r,n,i,o,a,s,u,h,f,l,p,d,g,y,v;return c.a.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(r=e.crossTransferTxId,n=this.chainIdConvertor,i=this.aelfInstance,o=i.sendInstance,a=i.tokenContractSend,i.tokenContractReceive&&a){t.next=5;break}throw Error(JSON.stringify({error:1,message:"Please call tokenCrossChain.init to get tokenContractReceive & tokenContractSend at first.",canReceive:!1}));case 5:return t.next=7,o.chain.getChainStatus();case 7:return s=t.sent,u=s.LastIrreversibleBlockHeight,t.next=11,this.getCrossTransferRawTx({aelfInstance:o,aelfInstanceTokenContract:a,transactionId:r});case 11:return h=t.sent,f=h.crossTransferTxInfo,l=h.crossTransferRawTx,p=f.BlockNumber,d=n.base58ToChainId(this.chainIdSendBase58),g=n.base58ToChainId(this.chainIdReceiveBase58),y=d===this.mainChainId,v=g===this.mainChainId,t.abrupt("return",{lastIrreversibleBlockHeight:u,crossTransferTxInfo:f,crossTransferRawTx:l,crossTransferTxBlockHeight:p,chainIdSend:d,chainIdReceive:g,isFromMainChain:y,isToMainChain:v});case 20:case"end":return t.stop()}},t,this)})),function(t){return o.apply(this,arguments)})},{key:"isChainReadyToReceive",value:(n=l()(c.a.mark(function t(e){var r,n,i,o,a,s,u,h,f,l,p,d,g,y,v,w,m,C,b,I,T,x,A,P,k,E,R;return c.a.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return r=e.crossTransferTxId,n=this.aelfInstance,i=n.sendInstance,o=n.receiveInstance,a=n.crossChainContractSend,s=n.crossChainContractReceive,t.next=4,this.recevieInit({crossTransferTxId:r});case 4:if(u=t.sent,h=u.lastIrreversibleBlockHeight,f=u.crossTransferTxInfo,l=u.crossTransferRawTx,p=u.crossTransferTxBlockHeight,d=u.chainIdSend,g=u.isFromMainChain,y=u.isToMainChain,!(h<p)){t.next=14;break}throw Error(JSON.stringify({error:2,message:"Please waiting until the lastIrreversibleBlockHeight[".concat(h,"]\n >= 'the height[").concat(p,"] of transaction of tokenCrossChainInstance.send()'\n "),canReceive:!0}));case 14:if(f.Status&&"MINED"===f.Status){t.next=16;break}throw Error(JSON.stringify({error:3,message:"The transaction ".concat(r," of CrossChainTransfer\n is ").concat(f.Status,"."),canReceive:!0}));case 16:return t.next=18,this.getMerklePath({sendInstance:i,crossChainContractSend:a,crossTransferTxId:r,crossTransferTxBlockHeight:p,isFromMainChain:g});case 18:if(v=t.sent,w=v.boundParentChainHeight,m=v.merklePath,C=p,!g){t.next=32;break}return t.next=25,s.GetParentChainHeight.call();case 25:if(b=t.sent,I=b.value,!((I=parseInt(I,10))>=0&&I<=p)){t.next=30;break}throw Error(JSON.stringify({error:1,message:"the parent chain block at height of ".concat(p)+"is not recorded, please waiting.",canReceive:!0}));case 30:t.next=61;break;case 32:if(!y){t.next=53;break}return C=w,t.next=36,s.GetSideChainHeight.call({value:d});case 36:if(T=t.sent,!((x=T.value)<p)){t.next=40;break}throw Error(JSON.stringify({error:1,message:"The side chains are not ready to receive tx.\n The height of the side chain recorded in main chain is ".concat(x,".\n sideChainHeightInMainChain need >= ").concat(p,"."),canReceive:!0}));case 40:return t.next=42,a.GetParentChainHeight.call();case 42:return A=t.sent,P=A.value,t.next=46,o.chain.getBlockHeight();case 46:if(k=t.sent,P=parseInt(P,10),k=parseInt(k,10),!(P>k)){t.next=51;break}throw Error(JSON.stringify({error:1,message:"The main chains are not ready to receive tx.\n The boundParentChainHeight of crossChainTransfer is ".concat(w,"\n The parentChainHeight of the chain which receives the tx is ").concat(P,"."),canReceive:!0}));case 51:t.next=61;break;case 53:return t.next=55,s.GetParentChainHeight.call();case 55:if(E=t.sent,R=E.value,R=parseInt(R,10),!(w>R)){t.next=60;break}throw Error(JSON.stringify({error:1,message:"The side chains are not ready to receive tx.\n The boundParentChainHeight of crossChainTransfer is ".concat(w,"\n The parentChainHeight of the chain which receives the tx is ").concat(R,"."),canReceive:!0}));case 60:C=w;case 61:return t.abrupt("return",{isReady:!0,crossTransferRawTx:l,chainIdSend:d,merklePath:m,crossTransferTxParentBlockHeight:C});case 62:case"end":return t.stop()}},t,this)})),function(t){return n.apply(this,arguments)})},{key:"receive",value:(r=l()(c.a.mark(function e(r){var n,i,o,a,s,u,h,f;return c.a.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return n=r.crossTransferTxId,e.next=3,this.isChainReadyToReceive({crossTransferTxId:n});case 3:return i=e.sent,o=i.crossTransferRawTx,a=i.chainIdSend,s=i.merklePath,u=i.crossTransferTxParentBlockHeight,h=this.aelfInstance.tokenContractReceive,e.next=11,h.CrossChainReceiveToken({fromChainId:a,parentChainHeight:u,transferTransactionBytes:t.from(o,"hex"),merklePath:s});case 11:return f=e.sent,e.abrupt("return",f);case 13:case"end":return e.stop()}},e,this)})),function(t){return r.apply(this,arguments)})}]),e}()}).call(this,r(7).Buffer)},function(t,e){t.exports=function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}},function(t,e){function r(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}t.exports=function(t,e,n){return e&&r(t.prototype,e),n&&r(t,n),t}},function(t,e,r){"use strict";(function(t){r.d(e,"b",function(){return s});var n=r(0),i=r.n(n),o=r(1),a=r.n(o);function s(t){return c.apply(this,arguments)}function c(){return(c=a()(i.a.mark(function t(e){var r,n,o,a,s,c,u,h,f,l,p,d,g,y,v,w,m,C,b,I,T,x,A,P,k,E,R,B;return i.a.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(r=e.contractAddresses,n=e.chainIds,o=e.sendInstance,a=e.receiveInstance,s=e.wallet,c=e.sha256,u=e.tokenContractName,h=e.crossChainContractName,!r||!n){t.next=9;break}if(f=r.tokenContractAddressSend,l=r.crossChainContractAddressSend,p=r.tokenContractAddressReceive,d=r.crossChainContractAddressReceive,g=n.chainIdSend,y=n.chainIdReceive,v={tokenContractAddressSend:f,crossChainContractAddressSend:l,tokenContractAddressReceive:p,crossChainContractAddressReceive:d,chainIdSend:g,chainIdReceive:y},w=!0,Object.keys(v).forEach(function(t){v[t]||(w=!1)}),!w){t.next=9;break}return t.abrupt("return",v);case 9:return t.next=11,o.chain.getChainStatus();case 11:return m=t.sent,C=m.GenesisContractAddress,b=m.ChainId,t.next=16,a.chain.getChainStatus();case 16:return I=t.sent,T=I.GenesisContractAddress,x=I.ChainId,t.next=21,o.chain.contractAt(C,s);case 21:return A=t.sent,t.next=24,a.chain.contractAt(T,s);case 24:return P=t.sent,t.next=27,A.GetContractAddressByName.call(c(u));case 27:return k=t.sent,t.next=30,A.GetContractAddressByName.call(c(h));case 30:return E=t.sent,t.next=33,P.GetContractAddressByName.call(c(u));case 33:return R=t.sent,t.next=36,P.GetContractAddressByName.call(c(h));case 36:return B=t.sent,t.abrupt("return",{tokenContractAddressSend:k,crossChainContractAddressSend:E,tokenContractAddressReceive:R,crossChainContractAddressReceive:B,chainIdSend:b,chainIdReceive:x});case 38:case"end":return t.stop()}},t)}))).apply(this,arguments)}}).call(this,r(7).Buffer)},function(t,e,r){var n=r(14),i=r(15),o=r(16);t.exports=function(t){return n(t)||i(t)||o()}},function(t,e,r){"use strict";(function(t){
/*!

@@ -8,0 +8,0 @@ * The buffer module from node.js, for the browser.

@@ -12,7 +12,6 @@ const Wallet = AElf.wallet;

const wallet = Wallet.getWalletByPrivateKey(defaultPrivateKey);
// const sendInstance = new AElf(new AElf.providers.HttpProvider('http://13.231.179.27:8000'));
// const receiveInstance = new AElf(new AElf.providers.HttpProvider('http://52.68.97.242:8000'));
const receiveInstance = new AElf(new AElf.providers.HttpProvider('http://13.231.179.27:8000'));
const sendInstance = new AElf(new AElf.providers.HttpProvider('http://52.68.97.242:8000'));
// Public test net
const receiveInstance = new AElf(new AElf.providers.HttpProvider('http://3.25.10.185:8000'));
const sendInstance = new AElf(new AElf.providers.HttpProvider('http://13.211.28.67:8000'));

@@ -57,23 +56,42 @@ const {

wallet,
mainChainId: 9992731,
issueChainId: 9992731
});
await crossChainInstance.init();
await crossChainInstance.init({
contractAddresses: {
tokenContractAddressSend: '7RzVGiuVWkvL4VfVHdZfQF2Tri3sgLe9U991bohHFfSRZXuGX',
crossChainContractAddressSend: '2snHc8AMh9QMbCAa7XXmdZZVM5EBZUUPDdLjemwUJkBnL6k8z9',
tokenContractAddressReceive: 'JRmBduh4nXWi1aXgdUsj5gJrzeZb2LxmrAbf7W99faZSvoAaE',
crossChainContractAddressReceive: '2SQ9LeGZYSWmfJcYuQkDQxgd3HzwjamAaaL4Tge2eFSXw2cseq'
},
chainIds: {
chainIdSend: 'tDVV',
chainIdReceive: 'AELF'
}
});
const {
crossTransferTxId
} = await crossChainInstance.send({
to: receiveAddress,
symbol: 'ELF',
amount: 1,
memo: 'to be or not to be.'
const result = await crossChainInstance.isChainReadyToReceive({
crossTransferTxId: '4a4fdc083729b1482c837e580b2f956fd2cc80e69d667c49ee63a0277efc0e2d'
});
console.log('crossTransferTxId: ', crossTransferTxId);
console.log('result: ', result);
const receiveInfo = await crossChainInstance.receive({
// crossTransferTxId: 'cad78d4697f23ec34d03956ab17c0c8443d97277f7590d2b178d714d4a9682d3'
crossTransferTxId
// crossTransferTxId: 'ac9011e4e0944cba37f7859b201dee2bc804291c43004ca47bd05cf424bd27f4'
});
return receiveInfo;
// const {
// crossTransferTxId
// } = await crossChainInstance.send({
// to: receiveAddress,
// symbol: 'ELF',
// amount: 1,
// memo: 'to be or not to be.'
// });
//
// console.log('crossTransferTxId: ', crossTransferTxId);
//
// const receiveInfo = await crossChainInstance.receive({
// // crossTransferTxId: 'cad78d4697f23ec34d03956ab17c0c8443d97277f7590d2b178d714d4a9682d3'
// crossTransferTxId
// // crossTransferTxId: 'ac9011e4e0944cba37f7859b201dee2bc804291c43004ca47bd05cf424bd27f4'
// });
//
// return receiveInfo;
}

@@ -85,2 +103,2 @@

console.log('init error: ', error);
});
});
{
"name": "aelf-sdk-cross-chain",
"version": "1.0.12",
"version": "1.0.13",
"description": "sdk for cross chain",

@@ -5,0 +5,0 @@ "main": "dist/aelf-cross-chain.cjs.js",

@@ -377,2 +377,3 @@ /**

sendInstance,
receiveInstance,
// tokenContractReceive,

@@ -397,118 +398,117 @@ crossChainContractSend,

// console.log('lastIrreversibleBlockHeight: ', lastIrreversibleBlockHeight, crossTransferTxRefBlockHeight);
if (lastIrreversibleBlockHeight >= crossTransferTxBlockHeight) {
if (crossTransferTxInfo.Status && crossTransferTxInfo.Status === 'MINED') {
const {
boundParentChainHeight,
merklePath
} = await this.getMerklePath({
sendInstance,
crossChainContractSend,
crossTransferTxId,
crossTransferTxBlockHeight,
isFromMainChain
});
console.log('boundParentChainHeight: ', boundParentChainHeight, isFromMainChain, isToMainChain);
if (lastIrreversibleBlockHeight < crossTransferTxBlockHeight) {
throw Error(JSON.stringify({
error: 2,
message: `Please waiting until the lastIrreversibleBlockHeight[${lastIrreversibleBlockHeight}]
>= 'the height[${crossTransferTxBlockHeight}] of transaction of tokenCrossChainInstance.send()'
`,
canReceive: true
}));
}
let crossTransferTxParentBlockHeight = crossTransferTxBlockHeight;
if (!crossTransferTxInfo.Status || crossTransferTxInfo.Status !== 'MINED') {
throw Error(JSON.stringify({
error: 3,
message: `The transaction ${crossTransferTxId} of CrossChainTransfer
is ${crossTransferTxInfo.Status}.`,
canReceive: true
}));
}
if (isFromMainChain) {
// main chain to side chain
let {
value: parentChainHeight
} = await crossChainContractReceive.GetParentChainHeight.call();
parentChainHeight = parseInt(parentChainHeight, 10);
const {
boundParentChainHeight,
merklePath
} = await this.getMerklePath({
sendInstance,
crossChainContractSend,
crossTransferTxId,
crossTransferTxBlockHeight,
isFromMainChain
});
console.log('boundParentChainHeight: ', boundParentChainHeight, isFromMainChain, isToMainChain);
// console.log('parentChainHeight: ', parentChainHeight);
// If the crossChainContractReceive belongs to mainChain, we will get {value: '-1'};
// If the crossChainContractReceive belongs to sideChain.
if (parentChainHeight >= 0 && (parentChainHeight < crossTransferTxBlockHeight)) {
throw Error(JSON.stringify({
error: 1,
message: `the parent chain block at height of ${crossTransferTxBlockHeight}`
+ 'is not recorded, please waiting.',
canReceive: true
}));
}
} else if (isToMainChain) {
// side chain to main chain
crossTransferTxParentBlockHeight = boundParentChainHeight;
let crossTransferTxParentBlockHeight = crossTransferTxBlockHeight;
const {
value: sideChainHeightInMainChain
} = await crossChainContractReceive.GetSideChainHeight.call({
value: chainIdSend
});
if (isFromMainChain) {
// main chain to side chain
let {
value: parentChainHeight
} = await crossChainContractReceive.GetParentChainHeight.call();
parentChainHeight = parseInt(parentChainHeight, 10);
// await = receiveInstance.GetChainStatus.call();
// console.log('parentChainHeight: ', parentChainHeight);
// If the crossChainContractReceive belongs to mainChain, we will get {value: '-1'};
// If the crossChainContractReceive belongs to sideChain.
if (parentChainHeight >= 0 && (parentChainHeight <= crossTransferTxBlockHeight)) {
throw Error(JSON.stringify({
error: 1,
message: `the parent chain block at height of ${crossTransferTxBlockHeight}`
+ 'is not recorded, please waiting.',
canReceive: true
}));
}
} else if (isToMainChain) {
// side chain to main chain
crossTransferTxParentBlockHeight = boundParentChainHeight;
// let {
// value: sendChainParentChainHeight
// } = await crossChainContractSend.GetParentChainHeight.call();
// sendChainParentChainHeight = parseInt(sendChainParentChainHeight, 10);
const {
value: sideChainHeightInMainChain
} = await crossChainContractReceive.GetSideChainHeight.call({
value: chainIdSend
});
// console.log('??????---------', crossTransferTxParentBlockHeight, sendChainParentChainHeight);
if (sideChainHeightInMainChain < crossTransferTxBlockHeight) {
throw Error(JSON.stringify({
error: 1,
message: `The side chains are not ready to receive tx.
The height of the side chain recorded in main chain is ${sideChainHeightInMainChain}.
sideChainHeightInMainChain need >= ${crossTransferTxBlockHeight}.`,
canReceive: true
}));
}
// if (sendChainParentChainHeight < crossTransferTxParentBlockHeight) {
// console.log('??????---------', crossTransferTxParentBlockHeight, sendChainParentChainHeight);
// // throw Error(JSON.stringify({
// // error: 1,
// // message: `The side chains are not ready to receive tx.
// // The crossTransferTxParentBlockHeight is ${crossTransferTxParentBlockHeight}.
// // The block height of parent in side chain is ${sendChainParentChainHeight}.`,
// // canReceive: true
// // }));
// }
let {
value: receiveChainParentChainHeight
} = await crossChainContractSend.GetParentChainHeight.call();
let mainChainBlockHeight = await receiveInstance.chain.getBlockHeight();
if (sideChainHeightInMainChain < crossTransferTxBlockHeight) {
throw Error(JSON.stringify({
error: 1,
message: `The side chains are not ready to receive tx.
The height of the side chain recorded in main chain is ${sideChainHeightInMainChain}.
sideChainHeightInMainChain need >= ${crossTransferTxBlockHeight}.`,
canReceive: true
}));
}
} else {
// side chain to side chain
let {
value: receiveChainParentChainHeight
} = await crossChainContractReceive.GetParentChainHeight.call();
receiveChainParentChainHeight = parseInt(receiveChainParentChainHeight, 10);
receiveChainParentChainHeight = parseInt(receiveChainParentChainHeight, 10);
mainChainBlockHeight = parseInt(mainChainBlockHeight, 10);
// When we call this.getMerklePath
if (boundParentChainHeight > receiveChainParentChainHeight) {
throw Error(JSON.stringify({
error: 1,
message: `The side chains are not ready to receive tx.
The boundParentChainHeight of crossChainTransfer is ${boundParentChainHeight}
The parentChainHeight of the chain which receives the tx is ${receiveChainParentChainHeight}.`,
canReceive: true
}));
}
crossTransferTxParentBlockHeight = boundParentChainHeight;
}
if (receiveChainParentChainHeight > mainChainBlockHeight) {
throw Error(JSON.stringify({
error: 1,
message: `The main chains are not ready to receive tx.
The boundParentChainHeight of crossChainTransfer is ${boundParentChainHeight}
The parentChainHeight of the chain which receives the tx is ${receiveChainParentChainHeight}.`,
canReceive: true
}));
}
} else {
// side chain to side chain
let {
value: receiveChainParentChainHeight
} = await crossChainContractReceive.GetParentChainHeight.call();
receiveChainParentChainHeight = parseInt(receiveChainParentChainHeight, 10);
return {
isReady: true,
crossTransferRawTx,
chainIdSend,
merklePath,
crossTransferTxParentBlockHeight
};
// When we call this.getMerklePath
if (boundParentChainHeight > receiveChainParentChainHeight) {
throw Error(JSON.stringify({
error: 1,
message: `The side chains are not ready to receive tx.
The boundParentChainHeight of crossChainTransfer is ${boundParentChainHeight}
The parentChainHeight of the chain which receives the tx is ${receiveChainParentChainHeight}.`,
canReceive: true
}));
}
throw Error(JSON.stringify({
error: 3,
message: `The transaction ${crossTransferTxId} of CrossChainTransfer
is ${crossTransferTxInfo.Status}.`,
canReceive: true
}));
} else {
throw Error(JSON.stringify({
error: 2,
message: `Please waiting until the lastIrreversibleBlockHeight[${lastIrreversibleBlockHeight}]
>= 'the height[${crossTransferTxBlockHeight}] of transaction of tokenCrossChainInstance.send()'
`,
canReceive: true
}));
crossTransferTxParentBlockHeight = boundParentChainHeight;
}
return {
isReady: true,
crossTransferRawTx,
chainIdSend,
merklePath,
crossTransferTxParentBlockHeight
};
}

@@ -515,0 +515,0 @@

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc