new CrossInvoker(config)
Parameters:
| Name | Type | Description |
|---|---|---|
config |
Object | The merged config from user's configuration and sdk configuration.Users' configuration will override the configuration of SDK. |
- Source:
- core/CrossInvoker.js
Members
-
config :Object
-
The merged config from user's configuration and sdk configuration.
{ port: 8545, useLocalNode: false, logPathPrex: '', databasePathPrex: '', loglevel: 'info', network: 'testnet', socketUrl: 'wss://apitest.wanchain.info', ethTokenAddressOnWan: '0x46397994a7e1e926ea0de95557a4806d38f10b0d', wanTokenAddress: 'WAN', ethTokenAddress: 'ETH', ethHtlcAddr: '0x358b18d9dfa4cce042f2926d014643d4b3742b31', wanHtlcAddr: '0xfbaffb655906424d501144eefe35e28753dea037', HtlcETHAbi: ethHtlcAddrE20: '0x4a8f5dd531e4cd1993b79b23dbda21faacb9c731', wanHtlcAddrE20: '0xfc0eba261b49763decb6c911146e3cf524fa7ebc', ethAbiE20: wanAbiE20: orgEthAbiE20: orgWanAbiE20: ethHtlcAddrBtc: '0xcdc96fea7e2a6ce584df5dc22d9211e53a5b18b2', wanHtlcAddrBtc: '0x5d1dd99ebaa6ee3289d9cd3369948e4ce96736c3', wanAbiBtc: inStgLockEvent: 'ETH2WETHLock(address,address,bytes32,uint256)', outStgLockEvent: 'WETH2ETHLock(address,address,bytes32,uint256)', inStgLockEventE20: 'InboundLockLogger(address,address,bytes32,uint256,address)', outStgLockEventE20: 'OutboundLockLogger(address,address,bytes32,uint256,address)', dataName: 'testnet', rpcIpcPath: '/home/jacob/.wanchain/gwan.ipc', keyStorePath: '/home/jacob/.wanchain/testnet/keystore/', ethkeyStorePath: '/home/jacob/.ethereum/testnet/keystore/', databasePath: '/home/jacob/LocalDb', crossDbname: 'wanchainDb', crossCollection: 'crossTrans', crossCollectionBtc: 'crossTransBtc', normalCollection: 'normalTrans', wanKeyStorePath: '/home/jacob/.wanchain/testnet/keystore/', ethKeyStorePath: '/home/jacob/.ethereum/testnet/keystore/', btcKeyStorePath: '', confirmBlocks: 2, tryTimes: 3, consoleColor: { COLOR_FgRed: '\u001b[31m', COLOR_FgYellow: '\u001b[33m', COLOR_FgGreen: '\u001b[32m' }, ccLog: 'logs/crossChainLog.log', ccErr: 'logs/crossChainErr.log', mrLog: 'logs/ccMonitorLog.log', mrErr: 'logs/ccMonitorErr.log', mrLogNormal: 'logs/ccMonitorLogN.log', mrErrNormal: 'logs/ccMonitorErrN.log', logfileName: 'logs/crossChainLog.log', errfileName: 'logs/crossChainErr.log', logfileNameMR: 'logs/ccMonitorLog.log', errfileNameMR: 'logs/ccMonitorErr.log', logfileNameMRN: 'logs/ccMonitorLogN.log', errfileNameMRN: 'logs/ccMonitorErrN.log' }Type:
- Object
- Source:
- core/CrossInvoker.js
-
tokenInfoMap :Map.<string, Map.<string, Object>>
-
All coin and token's info. including wan coin on WAN chain.
{ 'ETH' => Map { 'ETH' => { tokenSymbol: 'ETH', tokenStand: 'ETH', tokenType: 'ETH', buddy: '0x46397994a7e1e926ea0de95557a4806d38f10b0d', storemenGroup: [Array], token2WanRatio: 0, tokenDecimals: 18 }, '0x54950025d1854808b09277fe082b54682b11a50b' => { tokenSymbol: 'MKR', tokenStand: 'E20', tokenType: 'ETH', buddy: '0x29204554d51b6d8e7b477fe0fa4769b47f2a00ef', storemenGroup: [Array], token2WanRatio: '6000000', tokenDecimals: '18' }, '0xdbf193627ee704d38495c2f5eb3afc3512eafa4c' => { tokenSymbol: 'DAI', tokenStand: 'E20', tokenType: 'ETH', buddy: '0xcc0ac621653faae13dae742ebb34f6e459218ff6', storemenGroup: [Array], token2WanRatio: '5000', tokenDecimals: '18' }, '0x00f58d6d585f84b2d7267940cede30ce2fe6eae8' => { tokenSymbol: 'ZRX', tokenStand: 'E20', tokenType: 'ETH', buddy: '0xe7d648256543d2467ca722b7560a92c1dcb654bb', storemenGroup: [Array], token2WanRatio: '3000', tokenDecimals: '18' }, '0x87271f3df675f13e8ceffa6e426d18a787267e9e' => { tokenSymbol: 'WCT', tokenStand: 'E20', tokenType: 'ETH', buddy: '0xe9585620239e4eca4f906cb0382ae9eb57d3ba3b', storemenGroup: [Array], token2WanRatio: '10000', tokenDecimals: '13' } }, 'BTC' => Map { '0xcdc96fea7e2a6ce584df5dc22d9211e53a5b18b2' => { tokenSymbol: 'BTC', tokenStand: 'BTC', tokenType: 'BTC', buddy: '0xcdc96fea7e2a6ce584df5dc22d9211e53a5b18b2', storemenGroup: [], token2WanRatio: 0, tokenDecimals: 18 } }, 'WAN' => Map { 'WAN' => { tokenSymbol: 'WAN', tokenStand: 'WAN', tokenType: 'WAN', buddy: 'WAN', storemenGroup: [Array], token2WanRatio: 0, tokenDecimals: 18 } } }Type:
- Map.<string, Map.<string, Object>>
- Source:
- core/CrossInvoker.js
-
inboundInfoMap :Map.<string, Map.<string, Object>>
-
Source chain's information including both coin info. and configuration of cross chain.
Map { 'ETH' => Map { 'ETH' => { tokenSymbol: 'ETH', tokenStand: 'ETH', useLocalNode: false, tokenDecimals: 18, srcSCAddr: '0x358b18d9dfa4cce042f2926d014643d4b3742b31', srcSCAddrKey: 'ETH', midSCAddr: '0x358b18d9dfa4cce042f2926d014643d4b3742b31', dstSCAddr: '0xfbaffb655906424d501144eefe35e28753dea037', dstSCAddrKey: 'WAN', srcAbi: [Array], midSCAbi: [Array], dstAbi: [Array], srcKeystorePath: '/home/jacob/.ethereum/testnet/keystore/', dstKeyStorePath: '/home/jacob/.wanchain/testnet/keystore/', lockClass: 'CrossChainEthLock', redeemClass: 'CrossChainEthRedeem', revokeClass: 'CrossChainEthRevoke', normalTransClass: 'NormalChainEth', approveScFunc: 'approve', lockScFunc: 'eth2wethLock', redeemScFunc: 'eth2wethRefund', revokeScFunc: 'eth2wethRevoke', srcChainType: 'ETH', dstChainType: 'WAN', crossCollection: 'crossTrans', normalCollection: 'normalTrans' }, '0x54950025d1854808b09277fe082b54682b11a50b' => { tokenSymbol: 'MKR', tokenStand: 'E20', useLocalNode: false, tokenDecimals: '18', srcSCAddr: '0x54950025d1854808b09277fe082b54682b11a50b', srcSCAddrKey: '0x54950025d1854808b09277fe082b54682b11a50b', midSCAddr: '0x4a8f5dd531e4cd1993b79b23dbda21faacb9c731', dstSCAddr: '0xfc0eba261b49763decb6c911146e3cf524fa7ebc', dstSCAddrKey: 'WAN', srcAbi: [Array], // token abi midSCAbi: [Array], // HTLCETH abi dstAbi: [Array], // HTLCWAN abi srcKeystorePath: '/home/jacob/.ethereum/testnet/keystore/', dstKeyStorePath: '/home/jacob/.wanchain/testnet/keystore/', approveClass: 'CrossChainE20Approve', lockClass: 'CrossChainE20Lock', redeemClass: 'CrossChainE20Redeem', revokeClass: 'CrossChainE20Revoke', normalTransClass: 'NormalChainE20', approveScFunc: 'approve', transferScFunc: 'transfer', lockScFunc: 'inboundLock', redeemScFunc: 'inboundRedeem', revokeScFunc: 'inboundRevoke', srcChainType: 'ETH', dstChainType: 'WAN', crossCollection: 'crossTrans', normalCollection: 'normalTrans', token2WanRatio: '6000000' }, '0x87271f3df675f13e8ceffa6e426d18a787267e9e' => { tokenSymbol: 'WCT', tokenStand: 'E20', useLocalNode: false, tokenDecimals: '13', srcSCAddr: '0x87271f3df675f13e8ceffa6e426d18a787267e9e', srcSCAddrKey: '0x87271f3df675f13e8ceffa6e426d18a787267e9e', midSCAddr: '0x4a8f5dd531e4cd1993b79b23dbda21faacb9c731', dstSCAddr: '0xfc0eba261b49763decb6c911146e3cf524fa7ebc', dstSCAddrKey: 'WAN', srcAbi: [Array], midSCAbi: [Array], dstAbi: [Array], srcKeystorePath: '/home/jacob/.ethereum/testnet/keystore/', dstKeyStorePath: '/home/jacob/.wanchain/testnet/keystore/', approveClass: 'CrossChainE20Approve', lockClass: 'CrossChainE20Lock', redeemClass: 'CrossChainE20Redeem', revokeClass: 'CrossChainE20Revoke', normalTransClass: 'NormalChainE20', approveScFunc: 'approve', transferScFunc: 'transfer', lockScFunc: 'inboundLock', redeemScFunc: 'inboundRedeem', revokeScFunc: 'inboundRevoke', srcChainType: 'ETH', dstChainType: 'WAN', crossCollection: 'crossTrans', normalCollection: 'normalTrans', token2WanRatio: '10000' } }, 'BTC' => Map { '0xcdc96fea7e2a6ce584df5dc22d9211e53a5b18b2' => { tokenSymbol: 'BTC', tokenStand: 'BTC', useLocalNode: false, tokenDecimals: 18, srcSCAddr: '0xcdc96fea7e2a6ce584df5dc22d9211e53a5b18b2', srcSCAddrKey: '0xcdc96fea7e2a6ce584df5dc22d9211e53a5b18b2', midSCAddr: '0xcdc96fea7e2a6ce584df5dc22d9211e53a5b18b2', dstSCAddr: '0x5d1dd99ebaa6ee3289d9cd3369948e4ce96736c3', dstSCAddrKey: 'WAN', srcAbi: [Array], midSCAbi: [Array], dstAbi: [Array], srcKeystorePath: '', dstKeyStorePath: '/home/jacob/.wanchain/testnet/keystore/', approveClass: 'CrossChainE20Approve', lockClass: 'CrossChainBtcLock', redeemClass: 'CrossChainBtcRedeem', revokeClass: 'CrossChainBtcRevoke', normalTransClass: 'NormalChainBtc', approveScFunc: 'approve', lockScFunc: 'inboundLock', redeemScFunc: 'inboundRedeem', revokeScFunc: 'inboundRevoke', srcChainType: 'BTC', dstChainType: 'WAN', crossCollection: 'crossTransBtc', normalCollection: 'normalTrans' } } }Type:
- Map.<string, Map.<string, Object>>
- Source:
- core/CrossInvoker.js
-
ouboundInfoMap :Map.<string, Map.<string, Object>>
-
Destination chain's information including both coin info. and configuration of cross chain. It is similar to [Destination chains info.]
Type:
- Map.<string, Map.<string, Object>>
- Source:
- core/CrossInvoker.js
Methods
-
<async> init()
-
Init all the configuration used for cross chain. step1: get tokens info. from api server. step2: init all chains info. step3: update token or coin symbol info. and the storemengroup related to this token or coin. step4: init all the token or coin info. in source chains Map step5: init all the token or coin info. in destination chains Map
- Source:
- core/CrossInvoker.js
Returns:
- Type
- Promise.<void>
-
<async> getTokensE20()
-
get ERC20 tokens from API server, the configuration of API server is located in ../../../../conf/config.js
- Source:
- core/CrossInvoker.js
Returns:
- Type
- Promise.<void>
-
initChainsNameMap()
-
Build all the coins and tokens information, this information is two-layer map structure. first layer: key is chains name(such as 'ETH', 'WAN','BTC'), value is all the tokens and coins info. on this chain. second layer: key is the token unique address(currently, system use contract address of the tokens. second layer: value is the info. about the token or coin. Below is an example. [example for chainsName]
- Source:
- core/CrossInvoker.js
Returns:
- Two layers Map including all the tokens and coins chain information.- Type
- Map.<string, MAP.<string, Object>>
-
initChainsSymbol()
-
Build promise array which is used to get the tokens' symbol and tokens' decimal
- Source:
- core/CrossInvoker.js
Returns:
- promise array about getting symbol- Type
- Array
-
initChainsStoremenGroup()
-
Build promise array which is used to get the storemen group information related to the token or coin.
- Source:
- core/CrossInvoker.js
Returns:
- Type
- Array
-
initSrcChainsMap()
-
Init source chains map, this map is also a two layer map data structure. first layer: key is chains name(such as 'ETH', 'WAN','BTC'), value is all the tokens and coins info. on this chain. second layer: key is the token unique address(currently, system use contract address of the tokens. second layer: value is the info. which used to finish cross token or coin from source chain to destination chain. In this map, there is no WAN info., If the source chain in this map, it surely cross source chain to 'WAN' If the destination chain in destination map (ouboundInfoMap), it surely the source chain is 'WAN' Using this machine , system can decide the inbound (to 'WAN' chain)or outbound (from 'WAN')direction easily, and in the next cross chain step system gets rid of inbound or outbound decision, this sharply make service logic more easier. Attention : in inboundInfoMap and in ouboundInfoMap ,there is no info. of 'WAN', because after system know one side non 'WAN' chain, the other side chain is surely 'WAN'. Below is an example. [example for source chains map]
- Source:
- core/CrossInvoker.js
Returns:
- Type
- Map.<string, MAP.<string, Object>>
-
initDstChainsMap()
-
Build destination chains info. It is similar to source chains info. [example for destination chains map]
- Source:
- core/CrossInvoker.js
Returns:
- Type
- Map.<string, MAP.<string, Object>>
-
isInSrcChainsMap(chainName)
-
Check the chainName whether in source chain Map or not , if yes, the cross chain is chainName->'WAN'
Parameters:
Name Type Description chainNameObject chainName ,chainName[0] the contract address of coin or token; chainName[1] the value of toke or coin chain's info. - Source:
- core/CrossInvoker.js
Returns:
true: In source chains map, the destination chain is 'WAN' false: Not in source chains map.- Type
- boolean
-
isInDstChainsMap(chainName)
-
Check the chainName whether in destination chain Map or not , if yes, the cross chain is 'WAN'>chainName
Parameters:
Name Type Description chainNameObject chainName ,chainName[0] the contract address of coin or token; chainName[1] the value of toke or coin chain's info. - Source:
- core/CrossInvoker.js
Returns:
true: In destination chains map, the source chain is 'WAN' false: Not in destination chains map.- Type
- boolean
-
<async> getSrcChainName()
-
Get the source chains info. supported by system.
- Source:
- core/CrossInvoker.js
Returns:
similar to this- Type
- Promise.<(Map|*)>
-
getDstChainName(selectedSrcChainName)
-
Get the destination chains info. after SDK users have selected the source chain.
Parameters:
Name Type Description selectedSrcChainNameObject selectedSrcChainName ,selectedSrcChainName[0] the contract address of coin or token; selectedSrcChainName[1] the value of toke or coin chain's info. - Source:
- core/CrossInvoker.js
Returns:
similar to this- Type
- Map.<string, Map.<string, Object>>
-
<async> freshErc20Symbols()
-
Because during the system running, there is no Erc20 symbols added or deleted. system can process this scenario automatically.
- Source:
- core/CrossInvoker.js
Returns:
- Type
- Promise.<void>
-
getKeyStorePaths(srcChainName, dstChainName)
-
When users provide source chain, and destination chain. System can get the right keystore path for future use in cross chain process.
Parameters:
Name Type Description srcChainNameObject srcChainName ,srcChainName[0] the contract address of coin or token; srcChainName[1] the value of toke or coin chain's info. dstChainNameObject dstChainName ,dstChainName[0] the contract address of coin or token; dstChainName[1] the value of toke or coin chain's info. - Source:
- core/CrossInvoker.js
Returns:
- Type
- Array
-
getKeyByBuddyContractAddr(contractAddr, chainType)
-
Get the buddy contract address, in chain info., there is two contract address. One is contract address on the chain, for example ZRX is ERC20 token,ZRX token has a contract address on ETH chain; The other contract address for token ZRX is the contract address on WAN chain.Here the buddy contract address is the second contract address. System does not support get contract address on ETH by contract address on WAN
Parameters:
Name Type Description contractAddrsting The coin or token's contract address,unique representing a coin or token. chainTypestring enum {'ETH','WAN','BTC'} - Source:
- core/CrossInvoker.js
Returns:
- The buddy address of coin or token's contract address.- Type
- string
-
<async> getStoremanGroupList(srcChainName, dstChainName)
-
Build the right storeman group list by srcChainName and dstChainName. Since each storeman group has two address, one is the address on ETH chain, the other address is on WAN. System can get the right address by below two parameters.
Parameters:
Name Type Description srcChainNameObject srcChainName ,srcChainName[0] the contract address of coin or token; srcChainName[1] the value of toke or coin chain's info. dstChainNameObject dstChainName ,dstChainName[0] the contract address of coin or token; dstChainName[1] the value of toke or coin chain's info. - Source:
- core/CrossInvoker.js
Returns:
- Type
- Promise.<Array>
-
getSrcChainNameByContractAddr(contractAddr, chainType)
-
Get the chain info by contract address, and the chainType. First, system search value in two layer MAP by chainType. Second, system search value in the second layer, and get the right info. of chain
Parameters:
Name Type Description contractAddrstring The contract address chainTypestring enum {'ETH','WAN','BTC'} - Source:
- core/CrossInvoker.js
Returns:
- Item of {CrossInvoke#tokenInfoMap}TokenInfoMap- Type
- Object
-
getCrossInvokerConfig(srcChainName, dstChainName)
-
Get the configuration used during cross chain.
Parameters:
Name Type Description srcChainNameObject srcChainName ,srcChainName[0] the contract address of coin or token; srcChainName[1] the value of toke or coin chain's info. dstChainNameObject dstChainName ,dstChainName[0] the contract address of coin or token; dstChainName[1] the value of toke or coin chain's info. - Source:
- core/CrossInvoker.js
-
getCrossInvokerClass(crossInvokerConfig, action)
-
Get the class, invoke this class's function run, users can finish cross chain.
Parameters:
Name Type Description crossInvokerConfigObject The config used for cross chain.config example actionstring enum {'APPROVE','LOCK','REDEEM','REVOKE'} - Source:
- core/CrossInvoker.js
Returns:
- Class name used for cross chain.- Type
- CrossChain
-
getInvoker(crossInvokerClass, crossInvokerInput, crossInvokerConfig)
-
Get invoker which includes class, input, config ,this invoker used to finish cross chain.
Parameters:
Name Type Description crossInvokerClassstring Class name used for cross chain. crossInvokerInputObject Input of final users.(gas, gasPrice, value and so on) input example crossInvokerConfigThe config used for cross chain.config example - Source:
- core/CrossInvoker.js
Returns:
- Object used to finish cross chain.- Type
- CrossChain
-
<async> invoke(srcChainName, dstChainName, action, input)
-
Users provide source chain info., destination chain info., and the action,input(amount, gas,gas limit..) 1) SDK build the configuration 2) SDK get the invoke class 3) SDK generate invoker 4) SDK call run function of invoker to finish cross chain.
Parameters:
Name Type Description srcChainNameObject srcChainName ,srcChainName[0] the contract address of coin or token; srcChainName[1] the value of toke or coin chain's info. dstChainNameObject dstChainName ,dstChainName[0] the contract address of coin or token; dstChainName[1] the value of toke or coin chain's info. actionstring enum {'APPROVE','LOCK','REDEEM','REVOKE'} inputObject Input of final users.(gas, gasPrice, value and so on) input example - Source:
- core/CrossInvoker.js
Returns:
- Type
- Promise.<*>
-
<async> invokeNormalTrans(srcChainName, input)
-
This function is used to transfer coin or token on the same chain. Source chain name and destination chain name is same. For example: ETH->ETH, ETH(ZRX)->ETH(ZRX),WAN->WAN
Parameters:
Name Type Description srcChainNameObject srcChainName ,srcChainName[0] the contract address of coin or token; srcChainName[1] the value of toke or coin chain's info. inputObject Input of final users.(gas, gasPrice, value and so on) input example - Source:
- core/CrossInvoker.js
Returns:
- Type
- Promise.<*>
-
<async> invokePrivateTrans(action, input)
-
This function is used to send private transactin on WAN.
Parameters:
Name Type Description actionstring enum {'SEND', 'REFUND'} inputObject Input of final users.(gas, gasPrice, value and so on) input example - Source:
- core/CrossInvoker.js
Returns:
- Type
- Promise.<*>
-
<async> PosDelegateIn(input)
-
This function is used to send POS delegate in on WAN.
Parameters:
Name Type Description inputObject Input of final users.(gas, gasPrice, value and so on) - Source:
- core/CrossInvoker.js
Returns:
- Type
- Promise.<*>
-
<async> PosDelegateOut(input)
-
This function is used to send POS delegate out on WAN.
Parameters:
Name Type Description inputObject Input of final users.(gas, gasPrice, value and so on) - Source:
- core/CrossInvoker.js
Returns:
- Type
- Promise.<*>
-
<async> PosMinerRegister(input)
-
This function is used to send POS stake in on WAN.
Parameters:
Name Type Description inputObject Input of final users.(gas, gasPrice, value and so on) - Source:
- core/CrossInvoker.js
Returns:
- Type
- Promise.<*>
-
<async> PosStakeUpdate(input)
-
This function is used to send POS stake update on WAN.
Parameters:
Name Type Description inputObject Input of final users.(gas, gasPrice, value and so on) - Source:
- core/CrossInvoker.js
Returns:
- Type
- Promise.<*>
-
<async> PosStakeUpdateFeeRate(input)
-
This function is used to send POS stake update fee rate on WAN.
Parameters:
Name Type Description inputObject Input of final users.(gas, gasPrice, value and so on) - Source:
- core/CrossInvoker.js
Returns:
- Type
- Promise.<*>
-
<async> PosStakeAppend(input)
-
This function is used to send POS stake Append on WAN.
Parameters:
Name Type Description inputObject Input of final users.(gas, gasPrice, value and so on) - Source:
- core/CrossInvoker.js
Returns:
- Type
- Promise.<*>
-
<async> invokeNormal(srcChainName, dstChainName, input)
-
This function is used to transfer coin or token on the same chain. Source chain name and destination chain name is same. For example: ETH->ETH, ETH(ZRX)->ETH(ZRX),WAN->WAN; WAN(WETH)->WAN(WETH), WAN(WZRX)->WANWZRX),WAN(WBTC)->WAN(WBTC)
Parameters:
Name Type Description srcChainNameObject srcChainName ,srcChainName[0] the contract address of coin or token; srcChainName[1] the value of toke or coin chain's info. dstChainNameObject dstChainName ,dstChainName[0] the contract address of coin or token; dstChainName[1] the value of toke or coin chain's info. inputObject Input of final users.(gas, gasPrice, value and so on) input example - Source:
- core/CrossInvoker.js
Returns:
- Type
- Promise.<*>