From 9edc55ab830b75eb4f43c873a0ea458795a1638a Mon Sep 17 00:00:00 2001 From: Dario Date: Tue, 19 Dec 2023 00:35:28 -0300 Subject: [PATCH] upload matching dist with src --- dist/examples/getDeployment.js | 3 +- dist/index.js | 9 +- dist/lib/Abi.js | 5 +- dist/lib/BcSearch.js | 15 +-- dist/lib/Contract.js | 7 +- dist/lib/ContractParser.js | 35 +++---- dist/lib/ContractParser.js.map | 2 +- dist/lib/EventDecoder.js | 21 +++-- dist/lib/EventDecoder.js.map | 2 +- dist/lib/btcUtils.js | 27 +++--- dist/lib/compileJsonAbis.js | 21 +++-- dist/lib/interfacesIds.js | 31 ++++--- dist/lib/nativeContracts/FakeABI.js | 93 ++++++++++--------- dist/lib/nativeContracts/NativeContracts.js | 23 ++--- .../nativeContracts/NativeContractsDecoder.js | 5 +- .../nativeContracts/NativeContractsEvents.js | 27 +++--- dist/lib/nativeContracts/bridgeAbi.js | 11 ++- dist/lib/nod3Connect.js | 13 +-- dist/lib/types.js | 27 +++--- dist/lib/utils.js | 51 +++++----- 20 files changed, 223 insertions(+), 205 deletions(-) diff --git a/dist/examples/getDeployment.js b/dist/examples/getDeployment.js index bd42546..a0a7703 100644 --- a/dist/examples/getDeployment.js +++ b/dist/examples/getDeployment.js @@ -38,4 +38,5 @@ function help(msg) { console.log(`Set environment variable URL to change node url`); console.log(`Example: export URL=http://localhost:4444`); process.exit(0); -} \ No newline at end of file +} +//# sourceMappingURL=getDeployment.js.map \ No newline at end of file diff --git a/dist/index.js b/dist/index.js index a8f377d..012e0b9 100644 --- a/dist/index.js +++ b/dist/index.js @@ -1,15 +1,16 @@ -"use strict";Object.defineProperty(exports, "__esModule", { value: true });Object.defineProperty(exports, "ContractParser", { enumerable: true, get: function () {return _ContractParser.ContractParser;} });Object.defineProperty(exports, "BcSearch", { enumerable: true, get: function () {return _BcSearch.BcSearch;} });Object.defineProperty(exports, "Contract", { enumerable: true, get: function () {return _Contract.default;} });exports.default = exports.abi = void 0;var _ContractParser = require("./lib/ContractParser"); +"use strict";Object.defineProperty(exports, "__esModule", { value: true });Object.defineProperty(exports, "BcSearch", { enumerable: true, get: function () {return _BcSearch.BcSearch;} });Object.defineProperty(exports, "Contract", { enumerable: true, get: function () {return _Contract.default;} });Object.defineProperty(exports, "ContractParser", { enumerable: true, get: function () {return _ContractParser.ContractParser;} });exports.default = exports.abi = void 0;var _ContractParser = require("./lib/ContractParser"); var _BcSearch = require("./lib/BcSearch"); var _Contract = _interopRequireDefault(require("./lib/Contract")); var _bridgeAbi = require("./lib/nativeContracts/bridgeAbi");function _interopRequireDefault(obj) {return obj && obj.__esModule ? obj : { default: obj };} -const abi = { bridge: _bridgeAbi.getBridgeAbi };exports.abi = abi;var _default = +const abi = exports.abi = { bridge: _bridgeAbi.getBridgeAbi };var _default = exports.default = _ContractParser.ContractParser; // HOTFIX: because the dependency @ethersproject/abi:5.7.0 spam the logs with 'duplicate definition' warning, this temporary fix should silence those messages until a newer version of the library fixes the issue -exports.default = _default;const originalConsoleLog = console.log; +const originalConsoleLog = console.log; console.log = function (message) { if (!String(message).includes('duplicate definition')) { originalConsoleLog(message); } -}; \ No newline at end of file +}; +//# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/dist/lib/Abi.js b/dist/lib/Abi.js index 8be5623..6ab57d7 100755 --- a/dist/lib/Abi.js +++ b/dist/lib/Abi.js @@ -1,2 +1,3 @@ -"use strict";Object.defineProperty(exports, "__esModule", { value: true });exports.default = void 0;var _compiled_abi = _interopRequireDefault(require("./compiled_abi.json"));function _interopRequireDefault(obj) {return obj && obj.__esModule ? obj : { default: obj };}var _default = -_compiled_abi.default;exports.default = _default; \ No newline at end of file +"use strict";Object.defineProperty(exports, "__esModule", { value: true });exports.default = void 0;var _compiled_abi = _interopRequireDefault(require("./compiled_abi.json"));function _interopRequireDefault(obj) {return obj && obj.__esModule ? obj : { default: obj };}var _default = exports.default = +_compiled_abi.default; +//# sourceMappingURL=Abi.js.map \ No newline at end of file diff --git a/dist/lib/BcSearch.js b/dist/lib/BcSearch.js index 675b0e5..9430283 100644 --- a/dist/lib/BcSearch.js +++ b/dist/lib/BcSearch.js @@ -2,7 +2,7 @@ var _rskUtils = require("@rsksmart/rsk-utils"); function BcSearch(nod3) { - const getBlock = hashOrNumber => { + const getBlock = (hashOrNumber) => { return nod3.eth.getBlock(hashOrNumber); }; @@ -27,7 +27,7 @@ function BcSearch(nod3) { }; const deploymentBlock = (address, highBlock, lowBlock) => { - return block(blockNumber => isContractAtBlock(address, blockNumber), highBlock, lowBlock); + return block((blockNumber) => isContractAtBlock(address, blockNumber), highBlock, lowBlock); }; const searchReceipt = async (transactions, cb) => { for (let tx of transactions) { @@ -44,11 +44,11 @@ function BcSearch(nod3) { try { blockNumber = blockNumber || (await deploymentBlock(address, highBlock)); block = block || (await nod3.eth.getBlock(blockNumber, true)); - let transactions = block.transactions.filter(tx => !(0, _rskUtils.isAddress)(tx.to)); - let transaction = await searchReceipt(transactions, receipt => receipt.contractAddress === address); + let transactions = block.transactions.filter((tx) => !(0, _rskUtils.isAddress)(tx.to)); + let transaction = await searchReceipt(transactions, (receipt) => receipt.contractAddress === address); if (!transaction) {// internal transactions blockTrace = blockTrace || (await nod3.trace.block(block.hash)); - let internalTx = blockTrace.find(trace => isItxDeployment(address, trace)); + let internalTx = blockTrace.find((trace) => isItxDeployment(address, trace)); if (internalTx) transaction = { internalTx }; } if (transaction) transaction.timestamp = block.timestamp; @@ -59,6 +59,7 @@ function BcSearch(nod3) { }; return Object.freeze({ block, deploymentBlock, deploymentTx, isItxDeployment }); -}var _default = +}var _default = exports.default = -BcSearch;exports.default = _default; \ No newline at end of file +BcSearch; +//# sourceMappingURL=BcSearch.js.map \ No newline at end of file diff --git a/dist/lib/Contract.js b/dist/lib/Contract.js index 5fff330..0cfa450 100755 --- a/dist/lib/Contract.js +++ b/dist/lib/Contract.js @@ -4,11 +4,11 @@ function Contract(abi, { address, nod3 } = {}) { if (!abi || typeof abi !== 'object') throw new Error('Invalid abi'); const contractInterface = new _abi.Interface(abi); - const at = newAddress => { + const at = (newAddress) => { address = newAddress; }; - const setNod3 = nod3Instance => { + const setNod3 = (nod3Instance) => { nod3 = nod3Instance; }; @@ -37,4 +37,5 @@ function Contract(abi, { address, nod3 } = {}) { } }; return Object.freeze({ at, setNod3, encodeCall, decodeCall, call }); -} \ No newline at end of file +} +//# sourceMappingURL=Contract.js.map \ No newline at end of file diff --git a/dist/lib/ContractParser.js b/dist/lib/ContractParser.js index ad41850..b31c937 100755 --- a/dist/lib/ContractParser.js +++ b/dist/lib/ContractParser.js @@ -16,8 +16,8 @@ var _utils = require("./utils");function _interopRequireDefault(obj) {return obj function mapInterfacesToERCs(interfaces) { return Object.keys(interfaces). - filter(k => interfaces[k] === true). - map(t => _types.contractsInterfaces[t] || t); + filter((k) => interfaces[k] === true). + map((t) => _types.contractsInterfaces[t] || t); } function hasMethodSelector(txInputData, selector) { @@ -67,8 +67,8 @@ class ContractParser { getAbiMethods() { let methods = {}; - this.abi.filter(def => def.type === 'function'). - map(m => { + this.abi.filter((def) => def.type === 'function'). + map((m) => { let sig = m[_types.ABI_SIGNATURE] || (0, _utils.abiSignatureData)(m); sig.name = m.name; methods[sig.method] = sig; @@ -77,7 +77,7 @@ class ContractParser { } parseTxLogs(logs, abi) { - return this.decodeLogs(logs, abi).map(event => { + return this.decodeLogs(logs, abi).map((event) => { this.addEventAddresses(event); event.abi = (0, _utils.removeAbiSignatureData)(event.abi); return event; @@ -96,7 +96,7 @@ class ContractParser { if (v.type === 'address[]') { let value = args[i] || []; if (Array.isArray(value)) {// temp fix to undecoded events - value.forEach(v => _addresses.push(v)); + value.forEach((v) => _addresses.push(v)); } else { let i = 0; while (2 + (i + 1) * 40 <= value.length) { @@ -119,7 +119,7 @@ class ContractParser { } const { isNativeContract } = this.nativeContracts; const { nativeContractsEvents } = this; - return logs.map(log => { + return logs.map((log) => { const { address } = log; const decoder = isNativeContract(address) ? nativeContractsEvents.getEventDecoder(log) : eventDecoder; return decoder.decodeLog(log); @@ -146,11 +146,11 @@ class ContractParser { async getTokenData(contract, { methods } = {}) { methods = methods || ['name', 'symbol', 'decimals', 'totalSupply']; let result = await Promise.all( - methods.map((m) => - this.call(m, contract). - then(res => res). - catch(err => this.log.debug(`[${contract.address}] Error executing ${m} Error: ${err}`)))); - + methods.map((m) => + this.call(m, contract). + then((res) => res). + catch((err) => this.log.debug(`[${contract.address}] Error executing ${m} Error: ${err}`))) + ); return result.reduce((v, a, i) => { let name = methods[i]; v[name] = a; @@ -161,7 +161,7 @@ class ContractParser { getMethodsBySelectors(txInputData) { let methods = this.getMethodsSelectors(); return Object.keys(methods). - filter(method => hasMethodSelector(txInputData, methods[method]) === true); + filter((method) => hasMethodSelector(txInputData, methods[method]) === true); } async getContractInfo(txInputData, contract) { @@ -231,7 +231,7 @@ class ContractParser { getInterfacesByMethods(methods, isErc165) { return Object.keys(_interfacesIds.default). - map(i => { + map((i) => { return [i, (0, _rskUtils.includesAll)(methods, _interfacesIds.default[i].methods)]; }). reduce((obj, value) => { @@ -258,7 +258,8 @@ class ContractParser { } catch (err) { return Promise.reject(err); } - }}exports.ContractParser = ContractParser;var _default = - + } +}exports.ContractParser = ContractParser;var _default = exports.default = -ContractParser;exports.default = _default; \ No newline at end of file +ContractParser; +//# sourceMappingURL=ContractParser.js.map \ No newline at end of file diff --git a/dist/lib/ContractParser.js.map b/dist/lib/ContractParser.js.map index 9cf0bb9..6bde39f 100644 --- a/dist/lib/ContractParser.js.map +++ b/dist/lib/ContractParser.js.map @@ -1 +1 @@ -{"version":3,"file":"ContractParser.js","names":["_interfacesIds","_interopRequireDefault","require","_rskUtils","_NativeContractsDecoder","_NativeContracts","_Contract","_EventDecoder","_Abi","_types","_utils","obj","__esModule","default","mapInterfacesToERCs","interfaces","Object","keys","filter","k","map","t","contractsInterfaces","hasMethodSelector","txInputData","selector","includes","ContractParser","constructor","abi","log","initConfig","nod3","txBlockNumber","net","netId","id","undefined","setAbi","defaultABI","console","nativeContracts","NativeContracts","bitcoinNetwork","bitcoinRskNetWorks","nativeContractsEvents","NativeContractsDecoder","setNod3","getNativeContractAddress","name","getMethodsSelectors","selectors","methods","getAbiMethods","m","method","signature","soliditySignature","soliditySelector","def","type","sig","ABI_SIGNATURE","abiSignatureData","parseTxLogs","logs","decodeLogs","event","addEventAddresses","removeAbiSignatureData","args","_addresses","inputs","forEach","v","i","push","value","Array","isArray","length","slice","Set","eventDecoder","EventDecoder","Error","isNativeContract","address","decoder","getEventDecoder","decodeLog","makeContract","Contract","call","contract","params","options","res","err","warn","getTokenData","result","Promise","all","then","catch","debug","reduce","a","getMethodsBySelectors","getContractInfo","getContractImplementedInterfaces","getEIP1967Info","contractAddress","isUpgradeable","impContractAddress","isERC1967","proxyContractBytecode","getContractCodeFromNode","getInterfacesByMethods","isErc165","includesAll","implementsErc165","getInterfacesERC165","storedValue","eth","getStorageAt","getContractCodeAt","ifaces","interfacesIds","supportsInterface","interfaceId","gas","first","ERC165","second","reject","exports","_default"],"sources":["../../src/lib/ContractParser.js"],"sourcesContent":["import interfacesIds from './interfacesIds'\nimport { includesAll } from '@rsksmart/rsk-utils'\nimport NativeContractsDecoder from './nativeContracts/NativeContractsDecoder'\nimport NativeContracts from './nativeContracts/NativeContracts'\nimport Contract from './Contract'\nimport EventDecoder from './EventDecoder'\nimport defaultABI from './Abi'\nimport { ABI_SIGNATURE, bitcoinRskNetWorks, contractsInterfaces } from './types'\nimport {\n setAbi,\n removeAbiSignatureData,\n abiSignatureData,\n soliditySelector,\n soliditySignature\n} from './utils'\n\nfunction mapInterfacesToERCs (interfaces) {\n return Object.keys(interfaces)\n .filter(k => interfaces[k] === true)\n .map(t => contractsInterfaces[t] || t)\n}\n\nfunction hasMethodSelector (txInputData, selector) {\n return selector && txInputData && txInputData.includes(selector)\n}\n\nexport class ContractParser {\n constructor ({ abi, log, initConfig, nod3, txBlockNumber } = {}) {\n initConfig = initConfig || {}\n const { net } = initConfig\n this.netId = (net) ? net.id : undefined\n this.abi = setAbi(abi || defaultABI)\n this.log = log || console\n this.nod3 = nod3\n this.nativeContracts = NativeContracts(initConfig)\n if (this.netId) {\n let bitcoinNetwork = bitcoinRskNetWorks[this.netId]\n this.nativeContractsEvents = NativeContractsDecoder({ bitcoinNetwork, txBlockNumber })\n }\n }\n\n setNod3 (nod3) {\n this.nod3 = nod3\n }\n\n getNativeContractAddress (name) {\n const { nativeContracts } = this\n if (nativeContracts) {\n return nativeContracts.getNativeContractAddress(name)\n }\n }\n\n setAbi (abi) {\n this.abi = setAbi(abi)\n }\n\n getMethodsSelectors () {\n let selectors = {}\n let methods = this.getAbiMethods()\n for (let m in methods) {\n let method = methods[m]\n let signature = method.signature || soliditySignature(m)\n selectors[m] = soliditySelector(signature)\n }\n return selectors\n }\n\n getAbiMethods () {\n let methods = {}\n this.abi.filter(def => def.type === 'function')\n .map(m => {\n let sig = m[ABI_SIGNATURE] || abiSignatureData(m)\n sig.name = m.name\n methods[sig.method] = sig\n })\n return methods\n }\n\n parseTxLogs (logs, abi) {\n return this.decodeLogs(logs, abi).map(event => {\n this.addEventAddresses(event)\n event.abi = removeAbiSignatureData(event.abi)\n return event\n })\n }\n\n addEventAddresses (event) {\n const { abi, args } = event\n let _addresses = event._addresses || []\n if (abi && args) {\n let inputs = abi.inputs || []\n inputs.forEach((v, i) => {\n if (v.type === 'address') {\n _addresses.push(args[i])\n }\n if (v.type === 'address[]') {\n let value = args[i] || []\n if (Array.isArray(value)) { // temp fix to undecoded events\n value.forEach(v => _addresses.push(v))\n } else {\n let i = 0\n while (2 + (i + 1) * 40 <= value.length) {\n _addresses.push('0x' + value.slice(2 + i * 40, 2 + (i + 1) * 40))\n i++\n }\n }\n }\n })\n event._addresses = [...new Set(_addresses)]\n }\n return event\n }\n\n decodeLogs (logs, abi) {\n abi = abi || this.abi\n const eventDecoder = EventDecoder(abi, this.log)\n if (!this.nativeContracts || !this.nativeContractsEvents) {\n throw new Error(`Native contracts decoder is missing, check the value of netId:${this.netId}`)\n }\n const { isNativeContract } = this.nativeContracts\n const { nativeContractsEvents } = this\n return logs.map(log => {\n const { address } = log\n const decoder = (isNativeContract(address)) ? nativeContractsEvents.getEventDecoder(log) : eventDecoder\n return decoder.decodeLog(log)\n })\n }\n\n makeContract (address, abi) {\n abi = abi || this.abi\n let { nod3 } = this\n return Contract(abi, { address, nod3 })\n }\n\n async call (method, contract, params = [], options = {}) {\n try {\n const res = await contract.call(method, params, options)\n return res\n } catch (err) {\n this.log.warn(`Method ${method} call ${err}`)\n return null\n }\n }\n\n async getTokenData (contract, { methods } = {}) {\n methods = methods || ['name', 'symbol', 'decimals', 'totalSupply']\n let result = await Promise.all(\n methods.map(m =>\n this.call(m, contract)\n .then(res => res)\n .catch(err => this.log.debug(`[${contract.address}] Error executing ${m} Error: ${err}`)))\n )\n return result.reduce((v, a, i) => {\n let name = methods[i]\n v[name] = a\n return v\n }, {})\n }\n\n getMethodsBySelectors (txInputData) {\n let methods = this.getMethodsSelectors()\n return Object.keys(methods)\n .filter(method => hasMethodSelector(txInputData, methods[method]) === true)\n }\n\n async getContractInfo (txInputData, contract) {\n let { interfaces, methods } = await this.getContractImplementedInterfaces(txInputData, contract)\n\n interfaces = mapInterfacesToERCs(interfaces)\n return { methods, interfaces }\n }\n\n async getEIP1967Info (contractAddress) {\n const { isUpgradeable, impContractAddress } = await this.isERC1967(contractAddress)\n if (isUpgradeable) {\n // manual check required\n const proxyContractBytecode = await this.getContractCodeFromNode(impContractAddress)\n const methods = this.getMethodsBySelectors(proxyContractBytecode)\n let interfaces = this.getInterfacesByMethods(methods)\n\n interfaces = mapInterfacesToERCs(interfaces)\n return { methods, interfaces: [...interfaces, 'ERC1967'] }\n }\n return {methods: [], interfaces: []}\n }\n\n async getContractImplementedInterfaces (txInputData, contract) {\n let methods = this.getMethodsBySelectors(txInputData)\n let isErc165 = false\n // skip non-erc165 contracts\n if (includesAll(methods, ['supportsInterface(bytes4)'])) {\n isErc165 = await this.implementsErc165(contract)\n }\n let interfaces\n if (isErc165) {\n interfaces = await this.getInterfacesERC165(contract)\n } else {\n interfaces = this.getInterfacesByMethods(methods)\n }\n\n return { methods, interfaces }\n }\n\n async isERC1967 (contractAddress) {\n // check For ERC1967\n // https://eips.ethereum.org/EIPS/eip-1967\n // 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc storage address where the implementation address is stored\n const storedValue = await this.nod3.eth.getStorageAt(contractAddress, '0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc')\n const isUpgradeable = storedValue !== '0x0'\n if (isUpgradeable) {\n const impContractAddress = `0x${storedValue.slice(-40)}` // extract contract address\n return { isUpgradeable, impContractAddress }\n } else {\n return { isUpgradeable, impContractAddress: storedValue }\n }\n }\n\n async getContractCodeFromNode (contractAddress) {\n return this.nod3.eth.getContractCodeAt(contractAddress)\n }\n\n async getInterfacesERC165 (contract) {\n let ifaces = {}\n let keys = Object.keys(interfacesIds)\n for (let i of keys) {\n ifaces[i] = await this.supportsInterface(contract, interfacesIds[i].id)\n }\n return ifaces\n }\n\n getInterfacesByMethods (methods, isErc165) {\n return Object.keys(interfacesIds)\n .map(i => {\n return [i, includesAll(methods, interfacesIds[i].methods)]\n })\n .reduce((obj, value) => {\n obj[value[0]] = value[1]\n return obj\n }, {})\n }\n\n async supportsInterface (contract, interfaceId) {\n // fixed gas to prevent infinite loops\n let options = { gas: '0x7530' }\n let res = await this.call('supportsInterface', contract, [interfaceId], options)\n return res\n }\n\n async implementsErc165 (contract) {\n try {\n let first = await this.supportsInterface(contract, interfacesIds.ERC165.id)\n if (first === true) {\n let second = await this.supportsInterface(contract, '0xffffffff')\n return !(second === true || second === null)\n }\n return false\n } catch (err) {\n return Promise.reject(err)\n }\n }\n}\n\nexport default ContractParser\n"],"mappings":"6HAAA,IAAAA,cAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,SAAA,GAAAD,OAAA;AACA,IAAAE,uBAAA,GAAAH,sBAAA,CAAAC,OAAA;AACA,IAAAG,gBAAA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C,QAAQ,EAAE,CAACqC,WAAW,CAAC,EAAEnC,OAAO,CAAC;IAChF,OAAOC,GAAG;EACZ;;EAEA,MAAMyB,gBAAgBA,CAAE5B,QAAQ,EAAE;IAChC,IAAI;MACF,IAAIuC,KAAK,GAAG,MAAM,IAAI,CAACH,iBAAiB,CAACpC,QAAQ,EAAEmC,sBAAa,CAACK,MAAM,CAAClG,EAAE,CAAC;MAC3E,IAAIiG,KAAK,KAAK,IAAI,EAAE;QAClB,IAAIE,MAAM,GAAG,MAAM,IAAI,CAACL,iBAAiB,CAACpC,QAAQ,EAAE,YAAY,CAAC;QACjE,OAAO,EAAEyC,MAAM,KAAK,IAAI,IAAIA,MAAM,KAAK,IAAI,CAAC;MAC9C;MACA,OAAO,KAAK;IACd,CAAC,CAAC,OAAOrC,GAAG,EAAE;MACZ,OAAOI,OAAO,CAACkC,MAAM,CAACtC,GAAG,CAAC;IAC5B;EACF;AACF,CAACuC,OAAA,CAAA9G,cAAA,GAAAA,cAAA,KAAA+G,QAAA,GAAAD,OAAA,CAAA5H,OAAA;;AAEcc,cAAc"} \ No newline at end of file +{"version":3,"file":"ContractParser.js","names":["_interfacesIds","_interopRequireDefault","require","_rskUtils","_NativeContractsDecoder","_NativeContracts","_Contract","_EventDecoder","_Abi","_types","_utils","obj","__esModule","default","mapInterfacesToERCs","interfaces","Object","keys","filter","k","map","t","contractsInterfaces","hasMethodSelector","txInputData","selector","includes","ContractParser","constructor","abi","log","initConfig","nod3","txBlockNumber","net","netId","id","undefined","setAbi","defaultABI","console","nativeContracts","NativeContracts","bitcoinNetwork","bitcoinRskNetWorks","nativeContractsEvents","NativeContractsDecoder","setNod3","getNativeContractAddress","name","getMethodsSelectors","selectors","methods","getAbiMethods","m","method","signature","soliditySignature","soliditySelector","def","type","sig","ABI_SIGNATURE","abiSignatureData","parseTxLogs","logs","decodeLogs","event","addEventAddresses","removeAbiSignatureData","args","_addresses","inputs","forEach","v","i","push","value","Array","isArray","length","slice","Set","eventDecoder","EventDecoder","Error","isNativeContract","address","decoder","getEventDecoder","decodeLog","makeContract","Contract","call","contract","params","options","res","err","getTokenData","result","Promise","all","then","catch","debug","reduce","a","getMethodsBySelectors","getContractInfo","getContractImplementedInterfaces","getEIP1967Info","contractAddress","isUpgradeable","impContractAddress","isERC1967","proxyContractBytecode","getContractCodeFromNode","getInterfacesByMethods","isErc165","includesAll","implementsErc165","getInterfacesERC165","storedValue","eth","getStorageAt","getContractCodeAt","ifaces","interfacesIds","supportsInterface","interfaceId","gas","first","ERC165","second","reject","exports","_default"],"sources":["../../src/lib/ContractParser.js"],"sourcesContent":["import interfacesIds from './interfacesIds'\nimport { includesAll } from '@rsksmart/rsk-utils'\nimport NativeContractsDecoder from './nativeContracts/NativeContractsDecoder'\nimport NativeContracts from './nativeContracts/NativeContracts'\nimport Contract from './Contract'\nimport EventDecoder from './EventDecoder'\nimport defaultABI from './Abi'\nimport { ABI_SIGNATURE, bitcoinRskNetWorks, contractsInterfaces } from './types'\nimport {\n setAbi,\n removeAbiSignatureData,\n abiSignatureData,\n soliditySelector,\n soliditySignature\n} from './utils'\n\nfunction mapInterfacesToERCs (interfaces) {\n return Object.keys(interfaces)\n .filter(k => interfaces[k] === true)\n .map(t => contractsInterfaces[t] || t)\n}\n\nfunction hasMethodSelector (txInputData, selector) {\n return selector && txInputData && txInputData.includes(selector)\n}\n\nexport class ContractParser {\n constructor ({ abi, log, initConfig, nod3, txBlockNumber } = {}) {\n initConfig = initConfig || {}\n const { net } = initConfig\n this.netId = (net) ? net.id : undefined\n this.abi = setAbi(abi || defaultABI)\n this.log = log || console\n this.nod3 = nod3\n this.nativeContracts = NativeContracts(initConfig)\n if (this.netId) {\n let bitcoinNetwork = bitcoinRskNetWorks[this.netId]\n this.nativeContractsEvents = NativeContractsDecoder({ bitcoinNetwork, txBlockNumber })\n }\n }\n\n setNod3 (nod3) {\n this.nod3 = nod3\n }\n\n getNativeContractAddress (name) {\n const { nativeContracts } = this\n if (nativeContracts) {\n return nativeContracts.getNativeContractAddress(name)\n }\n }\n\n setAbi (abi) {\n this.abi = setAbi(abi)\n }\n\n getMethodsSelectors () {\n let selectors = {}\n let methods = this.getAbiMethods()\n for (let m in methods) {\n let method = methods[m]\n let signature = method.signature || soliditySignature(m)\n selectors[m] = soliditySelector(signature)\n }\n return selectors\n }\n\n getAbiMethods () {\n let methods = {}\n this.abi.filter(def => def.type === 'function')\n .map(m => {\n let sig = m[ABI_SIGNATURE] || abiSignatureData(m)\n sig.name = m.name\n methods[sig.method] = sig\n })\n return methods\n }\n\n parseTxLogs (logs, abi) {\n return this.decodeLogs(logs, abi).map(event => {\n this.addEventAddresses(event)\n event.abi = removeAbiSignatureData(event.abi)\n return event\n })\n }\n\n addEventAddresses (event) {\n const { abi, args } = event\n let _addresses = event._addresses || []\n if (abi && args) {\n let inputs = abi.inputs || []\n inputs.forEach((v, i) => {\n if (v.type === 'address') {\n _addresses.push(args[i])\n }\n if (v.type === 'address[]') {\n let value = args[i] || []\n if (Array.isArray(value)) { // temp fix to undecoded events\n value.forEach(v => _addresses.push(v))\n } else {\n let i = 0\n while (2 + (i + 1) * 40 <= value.length) {\n _addresses.push('0x' + value.slice(2 + i * 40, 2 + (i + 1) * 40))\n i++\n }\n }\n }\n })\n event._addresses = [...new Set(_addresses)]\n }\n return event\n }\n\n decodeLogs (logs, abi) {\n abi = abi || this.abi\n const eventDecoder = EventDecoder(abi, this.log)\n if (!this.nativeContracts || !this.nativeContractsEvents) {\n throw new Error(`Native contracts decoder is missing, check the value of netId:${this.netId}`)\n }\n const { isNativeContract } = this.nativeContracts\n const { nativeContractsEvents } = this\n return logs.map(log => {\n const { address } = log\n const decoder = (isNativeContract(address)) ? nativeContractsEvents.getEventDecoder(log) : eventDecoder\n return decoder.decodeLog(log)\n })\n }\n\n makeContract (address, abi) {\n abi = abi || this.abi\n let { nod3 } = this\n return Contract(abi, { address, nod3 })\n }\n\n async call (method, contract, params = [], options = {}) {\n try {\n const res = await contract.call(method, params, options)\n return res\n } catch (err) {\n // temporary fix to avoid errored contract calls spam logs\n // this.log.warn(`Method ${method} call ${err}`)\n return null\n }\n }\n\n async getTokenData (contract, { methods } = {}) {\n methods = methods || ['name', 'symbol', 'decimals', 'totalSupply']\n let result = await Promise.all(\n methods.map(m =>\n this.call(m, contract)\n .then(res => res)\n .catch(err => this.log.debug(`[${contract.address}] Error executing ${m} Error: ${err}`)))\n )\n return result.reduce((v, a, i) => {\n let name = methods[i]\n v[name] = a\n return v\n }, {})\n }\n\n getMethodsBySelectors (txInputData) {\n let methods = this.getMethodsSelectors()\n return Object.keys(methods)\n .filter(method => hasMethodSelector(txInputData, methods[method]) === true)\n }\n\n async getContractInfo (txInputData, contract) {\n let { interfaces, methods } = await this.getContractImplementedInterfaces(txInputData, contract)\n\n interfaces = mapInterfacesToERCs(interfaces)\n return { methods, interfaces }\n }\n\n async getEIP1967Info (contractAddress) {\n const { isUpgradeable, impContractAddress } = await this.isERC1967(contractAddress)\n if (isUpgradeable) {\n // manual check required\n const proxyContractBytecode = await this.getContractCodeFromNode(impContractAddress)\n const methods = this.getMethodsBySelectors(proxyContractBytecode)\n let interfaces = this.getInterfacesByMethods(methods)\n\n interfaces = mapInterfacesToERCs(interfaces)\n return { methods, interfaces: [...interfaces, 'ERC1967'] }\n }\n return {methods: [], interfaces: []}\n }\n\n async getContractImplementedInterfaces (txInputData, contract) {\n let methods = this.getMethodsBySelectors(txInputData)\n let isErc165 = false\n // skip non-erc165 contracts\n if (includesAll(methods, ['supportsInterface(bytes4)'])) {\n isErc165 = await this.implementsErc165(contract)\n }\n let interfaces\n if (isErc165) {\n interfaces = await this.getInterfacesERC165(contract)\n } else {\n interfaces = this.getInterfacesByMethods(methods)\n }\n\n return { methods, interfaces }\n }\n\n async isERC1967 (contractAddress) {\n // check For ERC1967\n // https://eips.ethereum.org/EIPS/eip-1967\n // 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc storage address where the implementation address is stored\n const storedValue = await this.nod3.eth.getStorageAt(contractAddress, '0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc')\n const isUpgradeable = storedValue !== '0x0'\n if (isUpgradeable) {\n const impContractAddress = `0x${storedValue.slice(-40)}` // extract contract address\n return { isUpgradeable, impContractAddress }\n } else {\n return { isUpgradeable, impContractAddress: storedValue }\n }\n }\n\n async getContractCodeFromNode (contractAddress) {\n return this.nod3.eth.getContractCodeAt(contractAddress)\n }\n\n async getInterfacesERC165 (contract) {\n let ifaces = {}\n let keys = Object.keys(interfacesIds)\n for (let i of keys) {\n ifaces[i] = await this.supportsInterface(contract, interfacesIds[i].id)\n }\n return ifaces\n }\n\n getInterfacesByMethods (methods, isErc165) {\n return Object.keys(interfacesIds)\n .map(i => {\n return [i, includesAll(methods, interfacesIds[i].methods)]\n })\n .reduce((obj, value) => {\n obj[value[0]] = value[1]\n return obj\n }, {})\n }\n\n async supportsInterface (contract, interfaceId) {\n // fixed gas to prevent infinite loops\n let options = { gas: '0x7530' }\n let res = await this.call('supportsInterface', contract, [interfaceId], options)\n return res\n }\n\n async implementsErc165 (contract) {\n try {\n let first = await this.supportsInterface(contract, interfacesIds.ERC165.id)\n if (first === true) {\n let second = await this.supportsInterface(contract, '0xffffffff')\n return !(second === true || second === null)\n }\n return false\n } catch (err) {\n return Promise.reject(err)\n }\n }\n}\n\nexport default ContractParser\n"],"mappings":"6HAAA,IAAAA,cAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,SAAA,GAAAD,OAAA;AACA,IAAAE,uBAAA,GAAAH,sBAAA,CAAAC,OAAA;AACA,IAAAG,gBAAA,GAAAJ,sBAAA,CAAAC,OAAA;AACA,IAAAI,SAAA,GAAAL,sBAAA,CAAAC,OAAA;AACA,IAAAK,aAAA,GAAAN,sBAAA,CAAAC,OAAA;AACA,IAAAM,IAAA,GAAAP,sBAAA,CAAAC,OAAA;AACA,IAAAO,MAAA,GAAAP,OAAA;AACA,IAAAQ,MAAA,GAAAR,OAAA,YAMgB,S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AAG,MAAM,IAAI,CAACL,iBAAiB,CAACnC,QAAQ,EAAE,YAAY,CAAC;QACjE,OAAO,EAAEwC,MAAM,KAAK,IAAI,IAAIA,MAAM,KAAK,IAAI,CAAC;MAC9C;MACA,OAAO,KAAK;IACd,CAAC,CAAC,OAAOpC,GAAG,EAAE;MACZ,OAAOG,OAAO,CAACkC,MAAM,CAACrC,GAAG,CAAC;IAC5B;EACF;AACF,CAACsC,OAAA,CAAA7G,cAAA,GAAAA,cAAA,KAAA8G,QAAA,GAAAD,OAAA,CAAA3H,OAAA;;AAEcc,cAAc"} \ No newline at end of file diff --git a/dist/lib/EventDecoder.js b/dist/lib/EventDecoder.js index 4293ecc..e12b45a 100755 --- a/dist/lib/EventDecoder.js +++ b/dist/lib/EventDecoder.js @@ -5,10 +5,10 @@ var _abi = require("@ethersproject/abi"); function EventDecoder(abi, logger) { const contractInterface = new _abi.Interface((0, _utils.addSignatureDataToAbi)(abi)); - const getEventAbi = topics => { + const getEventAbi = (topics) => { topics = [...topics]; const sigHash = (0, _rskUtils.remove0x)(topics.shift()); - let events = abi.filter(i => { + let events = abi.filter((i) => { let { indexed, signature } = (0, _utils.getSignatureDataFromAbi)(i); return signature === sigHash && indexed === topics.length; }); @@ -29,7 +29,7 @@ function EventDecoder(abi, logger) { const encodeElement = (type, decoded) => { if (Array.isArray(decoded)) { - decoded = decoded.map(d => formatElement(type, d)); + decoded = decoded.map((d) => formatElement(type, d)); if (decoded.length === 1) decoded = decoded.join(); } else { decoded = formatElement(type, decoded); @@ -37,7 +37,7 @@ function EventDecoder(abi, logger) { return decoded; }; - const decodeLog = log => { + const decodeLog = (log) => { try { const { eventFragment, name, args, topic } = contractInterface.parseLog(log); @@ -47,8 +47,8 @@ function EventDecoder(abi, logger) { for (const i in eventFragment.inputs) { parsedArgs.push( - encodeElement(eventFragment.inputs[i].type, args[i])); - + encodeElement(eventFragment.inputs[i].type, args[i]) + ); } return Object.assign({}, log, { @@ -56,8 +56,8 @@ function EventDecoder(abi, logger) { event: name, address, args: parsedArgs, - abi: JSON.parse(eventFragment.format('json')) }); - + abi: JSON.parse(eventFragment.format('json')) + }); } catch (e) { // temporary fix to avoid ethers "no matching event" error spam if (!e.message.includes('no matching event')) { @@ -68,6 +68,7 @@ function EventDecoder(abi, logger) { }; return Object.freeze({ decodeLog, getEventAbi }); -}var _default = +}var _default = exports.default = -EventDecoder;exports.default = _default; \ No newline at end of file +EventDecoder; +//# sourceMappingURL=EventDecoder.js.map \ No newline at end of file diff --git a/dist/lib/EventDecoder.js.map b/dist/lib/EventDecoder.js.map index 8b3e596..968b9ef 100644 --- a/dist/lib/EventDecoder.js.map +++ b/dist/lib/EventDecoder.js.map @@ -1 +1 @@ -{"version":3,"file":"EventDecoder.js","names":["_utils","require","_rskUtils","_abi","EventDecoder","abi","logger","contractInterface","Interface","addSignatureDataToAbi","getEventAbi","topics","sigHash","remove0x","shift","events","filter","i","indexed","signature","getSignatureDataFromAbi","length","Error","eventABI","formatElement","type","decoded","_isIndexed","hash","_isBigNumber","toHexString","res","add0x","Buffer","isBuffer","bufferToHex","toString","toLowerCase","encodeElement","Array","isArray","map","d","join","decodeLog","log","eventFragment","name","args","topic","parseLog","address","parsedArgs","inputs","push","Object","assign","event","JSON","parse","format","e","error","freeze","_default","exports","default"],"sources":["../../src/lib/EventDecoder.js"],"sourcesContent":["import { addSignatureDataToAbi, getSignatureDataFromAbi } from './utils'\nimport { remove0x, add0x, bufferToHex } from '@rsksmart/rsk-utils'\nimport { Interface } from '@ethersproject/abi'\n\nfunction EventDecoder (abi, logger) {\n const contractInterface = new Interface(addSignatureDataToAbi(abi))\n\n const getEventAbi = topics => {\n topics = [...topics]\n const sigHash = remove0x(topics.shift())\n let events = abi.filter(i => {\n let { indexed, signature } = getSignatureDataFromAbi(i)\n return signature === sigHash && indexed === topics.length\n })\n if (events.length > 1) throw new Error('Duplicate events in ABI')\n const eventABI = events[0]\n return { eventABI, topics }\n }\n\n const formatElement = (type, decoded) => {\n if (decoded._isIndexed) return { _isIndexed: true, hash: decoded.hash }\n if (decoded._isBigNumber) {\n return decoded.toHexString()\n }\n const res = add0x(Buffer.isBuffer(decoded) ? bufferToHex(decoded) : decoded.toString(16))\n if (type === 'address' || type === 'address[]') return res.toLowerCase()\n return res\n }\n\n const encodeElement = (type, decoded) => {\n if (Array.isArray(decoded)) {\n decoded = decoded.map(d => formatElement(type, d))\n if (decoded.length === 1) decoded = decoded.join()\n } else {\n decoded = formatElement(type, decoded)\n }\n return decoded\n }\n\n const decodeLog = log => {\n try {\n const { eventFragment, name, args, topic } = contractInterface.parseLog(log)\n\n const { address } = log\n\n const parsedArgs = []\n\n for (const i in eventFragment.inputs) {\n parsedArgs.push(\n encodeElement(eventFragment.inputs[i].type, args[i])\n )\n }\n\n return Object.assign({}, log, {\n signature: remove0x(topic),\n event: name,\n address,\n args: parsedArgs,\n abi: JSON.parse(eventFragment.format('json'))\n })\n } catch (e) {\n logger.error(e)\n return log\n }\n }\n\n return Object.freeze({ decodeLog, getEventAbi })\n}\n\nexport default EventDecoder\n"],"mappings":"oGAAA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,SAAA,GAAAD,OAAA;AACA,IAAAE,IAAA,GAAAF,OAAA;;AAEA,SAASG,YAAYA,CAAEC,GAAG,EAAEC,MAAM,EAAE;EAClC,MAAMC,iBAAiB,GAAG,IAAIC,cAAS,CAAC,IAAAC,4BAAqB,EAACJ,GAAG,CAAC,CAAC;;EAEnE,MAAMK,WAAW,GAAGA,CAAAC,MAAM,KAAI;IAC5BA,MAAM,GAAG,CAAC,GAAGA,MAAM,CAAC;IACpB,MAAMC,OAAO,GAAG,IAAAC,kBAAQ,EAACF,MAAM,CAACG,KAAK,CAAC,CAAC,CAAC;IACxC,IAAIC,MAAM,GAAGV,GAAG,CAACW,MAAM,CAAC,CAAAC,CAAC,KAAI;MAC3B,IAAI,EAAEC,OAAO,EAAEC,SAAS,CAAC,CAAC,GAAG,IAAAC,8BAAuB,EAACH,CAAC,CA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CAACC,IAAI,EAAEC,OAAO,CAAC;IACxC;IACA,OAAOA,OAAO;EAChB,CAAC;;EAED,MAAMkB,SAAS,GAAGA,CAAAC,GAAG,KAAI;IACvB,IAAI;MACF,MAAM,EAAEC,aAAa,EAAEC,IAAI,EAAEC,IAAI,EAAEC,KAAK,CAAC,CAAC,GAAG1C,iBAAiB,CAAC2C,QAAQ,CAACL,GAAG,CAAC;;MAE5E,MAAM,EAAEM,OAAO,CAAC,CAAC,GAAGN,GAAG;;MAEvB,MAAMO,UAAU,GAAG,EAAE;;MAErB,KAAK,MAAMnC,CAAC,IAAI6B,aAAa,CAACO,MAAM,EAAE;QACpCD,UAAU,CAACE,IAAI;UACbhB,aAAa,CAACQ,aAAa,CAACO,MAAM,CAACpC,CAAC,CAAC,CAACQ,IAAI,EAAEuB,IAAI,CAAC/B,CAAC,CAAC;QACrD,CAAC;MACH;;MAEA,OAAOsC,MAAM,CAACC,MAAM,CAAC,CAAC,CAAC,EAAEX,GAAG,EAAE;QAC5B1B,SAAS,EAAE,IAAAN,kBAAQ,EAACoC,KAAK,CAAC;QAC1BQ,KAAK,EAAEV,IAAI;QACXI,OAAO;QACPH,IAAI,EAAEI,UAAU;QAChB/C,GAAG,EAAEqD,IAAI,CAACC,KAAK,CAACb,aAAa,CAACc,MAAM,CAAC,MAAM,CAAC;MAC9C,CAAC,CAAC;IACJ,CAAC,CAAC,OAAOC,CAAC,EAAE;MACVvD,MAAM,CAACwD,KAAK,CAACD,CAAC,CAAC;MACf,OAAOhB,GAAG;IACZ;EACF,CAAC;;EAED,OAAOU,MAAM,CAACQ,MAAM,CAAC,EAAEnB,SAAS,EAAElC,WAAW,CAAC,CAAC,CAAC;AAClD,CAAC,IAAAsD,QAAA,GAAAC,OAAA,CAAAC,OAAA;;AAEc9D,YAAY"} \ No newline at end of file +{"version":3,"file":"EventDecoder.js","names":["_utils","require","_rskUtils","_abi","EventDecoder","abi","logger","contractInterface","Interface","addSignatureDataToAbi","getEventAbi","topics","sigHash","remove0x","shift","events","filter","i","indexed","signature","getSignatureDataFromAbi","length","Error","eventABI","formatElement","type","decoded","_isIndexed","hash","_isBigNumber","toHexString","res","add0x","Buffer","isBuffer","bufferToHex","toString","toLowerCase","encodeElement","Array","isArray","map","d","join","decodeLog","log","eventFragment","name","args","topic","parseLog","address","parsedArgs","inputs","push","Object","assign","event","JSON","parse","format","e","message","includes","error","freeze","_default","exports","default"],"sources":["../../src/lib/EventDecoder.js"],"sourcesContent":["import { addSignatureDataToAbi, getSignatureDataFromAbi } from './utils'\nimport { remove0x, add0x, bufferToHex } from '@rsksmart/rsk-utils'\nimport { Interface } from '@ethersproject/abi'\n\nfunction EventDecoder (abi, logger) {\n const contractInterface = new Interface(addSignatureDataToAbi(abi))\n\n const getEventAbi = topics => {\n topics = [...topics]\n const sigHash = remove0x(topics.shift())\n let events = abi.filter(i => {\n let { indexed, signature } = getSignatureDataFromAbi(i)\n return signature === sigHash && indexed === topics.length\n })\n if (events.length > 1) throw new Error('Duplicate events in ABI')\n const eventABI = events[0]\n return { eventABI, topics }\n }\n\n const formatElement = (type, decoded) => {\n if (decoded._isIndexed) return { _isIndexed: true, hash: decoded.hash }\n if (decoded._isBigNumber) {\n return decoded.toHexString()\n }\n const res = add0x(Buffer.isBuffer(decoded) ? bufferToHex(decoded) : decoded.toString(16))\n if (type === 'address' || type === 'address[]') return res.toLowerCase()\n return res\n }\n\n const encodeElement = (type, decoded) => {\n if (Array.isArray(decoded)) {\n decoded = decoded.map(d => formatElement(type, d))\n if (decoded.length === 1) decoded = decoded.join()\n } else {\n decoded = formatElement(type, decoded)\n }\n return decoded\n }\n\n const decodeLog = log => {\n try {\n const { eventFragment, name, args, topic } = contractInterface.parseLog(log)\n\n const { address } = log\n\n const parsedArgs = []\n\n for (const i in eventFragment.inputs) {\n parsedArgs.push(\n encodeElement(eventFragment.inputs[i].type, args[i])\n )\n }\n\n return Object.assign({}, log, {\n signature: remove0x(topic),\n event: name,\n address,\n args: parsedArgs,\n abi: JSON.parse(eventFragment.format('json'))\n })\n } catch (e) {\n // temporary fix to avoid ethers \"no matching event\" error spam\n if (!e.message.includes('no matching event')) {\n logger.error(e)\n }\n return log\n }\n }\n\n return Object.freeze({ decodeLog, getEventAbi })\n}\n\nexport default EventDecoder\n"],"mappings":"oGAAA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,SAAA,GAAAD,OAAA;AACA,IAAAE,IAAA,GAAAF,OAAA;;AAEA,SAASG,YAAYA,CAAEC,GAAG,EAAEC,MAAM,EAAE;EAClC,MAAMC,iBAAiB,GAAG,IAAIC,cAAS,CAAC,IAAAC,4BAAqB,EAACJ,GAAG,CAAC,CAAC;;EAEnE,MAAMK,WAAW,GAAGA,CAAAC,MAAM,KAAI;IAC5BA,MAAM,GAAG,CAAC,GAAGA,MAAM,CAAC;IACpB,MAAMC,OAAO,GAAG,IAAAC,kBAAQ,EAACF,MAAM,CAACG,KAAK,CAAC,CAAC,CAAC;IACxC,IAAIC,MAAM,GAAGV,GAAG,CAACW,MAAM,CAAC,CAAAC,CAAC,KAAI;MAC3B,IAAI,EAAEC,OAAO,EAAEC,SAAS,CAAC,CAAC,GAAG,IAAAC,8BAAuB,EAACH,CAAC,CAAC;MACvD,OAAOE,SAAS,KAAKP,OAAO,IAAIM,OAAO,KAAKP,MAAM,CAACU,MAAM;IAC3D,CAAC,CAAC;IACF,IAAIN,MAAM,CAACM,MAAM,GAAG,CAAC,EAAE,MAAM,IAAIC,KAAK,CAAC,yBAAyB,CAAC;IACjE,MAAMC,QAAQ,GAAGR,MAAM,CAAC,CAAC,CAAC;IAC1B,OAAO,EAAEQ,QAAQ,EAAEZ,MAAM,CAAC,CAAC;EAC7B,CAAC;;EAED,MAAMa,aAAa,GAAGA,CAACC,IAAI,EAAEC,OAAO,KAAK;IACvC,IAAIA,OAAO,CAACC,UAAU,EAAE,OAAO,EAAEA,UAAU,EAAE,IAAI,EAAEC,IAAI,EAAEF,OAAO,CAACE,IAAI,CAAC,CAAC;IACv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CAACQ,IAAI,EAAEuB,IAAI,CAAC/B,CAAC,CAAC;QACrD,CAAC;MACH;;MAEA,OAAOsC,MAAM,CAACC,MAAM,CAAC,CAAC,CAAC,EAAEX,GAAG,EAAE;QAC5B1B,SAAS,EAAE,IAAAN,kBAAQ,EAACoC,KAAK,CAAC;QAC1BQ,KAAK,EAAEV,IAAI;QACXI,OAAO;QACPH,IAAI,EAAEI,UAAU;QAChB/C,GAAG,EAAEqD,IAAI,CAACC,KAAK,CAACb,aAAa,CAACc,MAAM,CAAC,MAAM,CAAC;MAC9C,CAAC,CAAC;IACJ,CAAC,CAAC,OAAOC,CAAC,EAAE;MACV;MACA,IAAI,CAACA,CAAC,CAACC,OAAO,CAACC,QAAQ,CAAC,mBAAmB,CAAC,EAAE;QAC5CzD,MAAM,CAAC0D,KAAK,CAACH,CAAC,CAAC;MACjB;MACA,OAAOhB,GAAG;IACZ;EACF,CAAC;;EAED,OAAOU,MAAM,CAACU,MAAM,CAAC,EAAErB,SAAS,EAAElC,WAAW,CAAC,CAAC,CAAC;AAClD,CAAC,IAAAwD,QAAA,GAAAC,OAAA,CAAAC,OAAA;;AAEchE,YAAY"} \ No newline at end of file diff --git a/dist/lib/btcUtils.js b/dist/lib/btcUtils.js index bcc18f7..3d3eb99 100755 --- a/dist/lib/btcUtils.js +++ b/dist/lib/btcUtils.js @@ -1,23 +1,23 @@ -"use strict";Object.defineProperty(exports, "__esModule", { value: true });exports.rskAddressFromBtcPublicKey = exports.compressPublic = exports.decompressPublic = exports.parsePublic = exports.pubToAddress = exports.h160toAddress = exports.h160 = exports.sha256 = void 0;var _crypto = _interopRequireDefault(require("crypto")); +"use strict";Object.defineProperty(exports, "__esModule", { value: true });exports.sha256 = exports.rskAddressFromBtcPublicKey = exports.pubToAddress = exports.parsePublic = exports.h160toAddress = exports.h160 = exports.decompressPublic = exports.compressPublic = void 0;var _crypto = _interopRequireDefault(require("crypto")); var bs58 = _interopRequireWildcard(require("bs58")); var _rskUtils = require("@rsksmart/rsk-utils"); -var _secp256k = _interopRequireDefault(require("secp256k1"));function _getRequireWildcardCache() {if (typeof WeakMap !== "function") return null;var cache = new WeakMap();_getRequireWildcardCache = function () {return cache;};return cache;}function _interopRequireWildcard(obj) {if (obj && obj.__esModule) {return obj;}if (obj === null || typeof obj !== "object" && typeof obj !== "function") {return { default: obj };}var cache = _getRequireWildcardCache();if (cache && cache.has(obj)) {return cache.get(obj);}var newObj = {};var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;for (var key in obj) {if (Object.prototype.hasOwnProperty.call(obj, key)) {var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;if (desc && (desc.get || desc.set)) {Object.defineProperty(newObj, key, desc);} else {newObj[key] = obj[key];}}}newObj.default = obj;if (cache) {cache.set(obj, newObj);}return newObj;}function _interopRequireDefault(obj) {return obj && obj.__esModule ? obj : { default: obj };} +var _secp256k = _interopRequireDefault(require("secp256k1"));function _getRequireWildcardCache(e) {if ("function" != typeof WeakMap) return null;var r = new WeakMap(),t = new WeakMap();return (_getRequireWildcardCache = function (e) {return e ? t : r;})(e);}function _interopRequireWildcard(e, r) {if (!r && e && e.__esModule) return e;if (null === e || "object" != typeof e && "function" != typeof e) return { default: e };var t = _getRequireWildcardCache(r);if (t && t.has(e)) return t.get(e);var n = { __proto__: null },a = Object.defineProperty && Object.getOwnPropertyDescriptor;for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) {var i = a ? Object.getOwnPropertyDescriptor(e, u) : null;i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u];}return n.default = e, t && t.set(e, n), n;}function _interopRequireDefault(obj) {return obj && obj.__esModule ? obj : { default: obj };} const PREFIXES = { mainnet: { pubKeyHash: '00', - scriptHash: '05' }, - + scriptHash: '05' + }, testnet: { pubKeyHash: '6F', - scriptHash: 'C4' }, - + scriptHash: 'C4' + }, regtest: { pubKeyHash: '00', - scriptHash: '00' } }; - - -const getNetPrefix = netName => { + scriptHash: '00' + } +}; +const getNetPrefix = (netName) => { let prefixes = PREFIXES[netName]; if (!prefixes) throw new Error(`Unknown network ${netName}`); return prefixes; @@ -48,8 +48,9 @@ const parsePublic = (pub, compressed) => { return _secp256k.default.publicKeyConvert(pub, compressed); };exports.parsePublic = parsePublic; -const decompressPublic = compressed => parsePublic(compressed, false).toString('hex');exports.decompressPublic = decompressPublic; +const decompressPublic = (compressed) => parsePublic(compressed, false).toString('hex');exports.decompressPublic = decompressPublic; -const compressPublic = pub => parsePublic(pub, true).toString('hex');exports.compressPublic = compressPublic; +const compressPublic = (pub) => parsePublic(pub, true).toString('hex');exports.compressPublic = compressPublic; -const rskAddressFromBtcPublicKey = cpk => (0, _rskUtils.add0x)((0, _rskUtils.keccak256)(parsePublic(cpk, false).slice(1)).slice(-40));exports.rskAddressFromBtcPublicKey = rskAddressFromBtcPublicKey; \ No newline at end of file +const rskAddressFromBtcPublicKey = (cpk) => (0, _rskUtils.add0x)((0, _rskUtils.keccak256)(parsePublic(cpk, false).slice(1)).slice(-40));exports.rskAddressFromBtcPublicKey = rskAddressFromBtcPublicKey; +//# sourceMappingURL=btcUtils.js.map \ No newline at end of file diff --git a/dist/lib/compileJsonAbis.js b/dist/lib/compileJsonAbis.js index f0ceb8e..37f76c1 100755 --- a/dist/lib/compileJsonAbis.js +++ b/dist/lib/compileJsonAbis.js @@ -12,7 +12,7 @@ const jsonPath = `${__dirname}/jsonAbis`; const ozPath = _path.default.resolve('node_modules/openzeppelin-solidity/build/contracts'); const destinationFile = `${__dirname}/compiled_abi.json`; -compileAbi([jsonPath, ozPath]).then(abi => { +compileAbi([jsonPath, ozPath]).then((abi) => { writeFile(destinationFile, JSON.stringify(abi, null, 2)). then(() => { console.log(`New ABI saved on ${destinationFile}`); @@ -25,11 +25,11 @@ async function compileAbi(dirs) { let jsonFiles = []; for (let dir of dirs) { let files = await readDir(dir); - files = files.filter(file => _path.default.extname(file) === '.json'); + files = files.filter((file) => _path.default.extname(file) === '.json'); if (!files || !files.length) throw new Error(`No json files in dir ${dir}`); - jsonFiles = jsonFiles.concat(files.map(file => `${dir}/${file}`)); + jsonFiles = jsonFiles.concat(files.map((file) => `${dir}/${file}`)); } - let abi = await Promise.all(jsonFiles.map(file => readJson(`${file}`).then(content => { + let abi = await Promise.all(jsonFiles.map((file) => readJson(`${file}`).then((content) => { return Array.isArray(content) ? content : content.abi; }))); if (!abi) throw new Error(`Invalid abi `); @@ -55,15 +55,15 @@ async function readJson(file) { function processAbi(abi) { // remove fallbacks - abi = abi.filter(a => a.type !== 'fallback'); + abi = abi.filter((a) => a.type !== 'fallback'); // remove duplicates - abi = [...new Set(abi.map(a => JSON.stringify(a)))].map(a => JSON.parse(a)); + abi = [...new Set(abi.map((a) => JSON.stringify(a)))].map((a) => JSON.parse(a)); // add signatures abi = (0, _utils.addSignatureDataToAbi)(abi); // detect 4 bytes collisions - let signatures = abi.map(a => a[_types.ABI_SIGNATURE].signature).filter(v => v); + let signatures = abi.map((a) => a[_types.ABI_SIGNATURE].signature).filter((v) => v); signatures = [...new Set(signatures)]; - let fourBytes = signatures.map(s => s.slice(0, 8)); + let fourBytes = signatures.map((s) => s.slice(0, 8)); if (fourBytes.length !== [...new Set(fourBytes)].length) { console.log(fourBytes.filter((v, i) => fourBytes.indexOf(v) !== i)); throw new Error('4bytes collision'); @@ -73,7 +73,8 @@ function processAbi(abi) { return abi; } -process.on('unhandledRejection', err => { +process.on('unhandledRejection', (err) => { console.error(err); process.exit(9); -}); \ No newline at end of file +}); +//# sourceMappingURL=compileJsonAbis.js.map \ No newline at end of file diff --git a/dist/lib/interfacesIds.js b/dist/lib/interfacesIds.js index 970a4d0..4e279ba 100755 --- a/dist/lib/interfacesIds.js +++ b/dist/lib/interfacesIds.js @@ -1,4 +1,4 @@ -"use strict";Object.defineProperty(exports, "__esModule", { value: true });exports.default = exports.interfacesIds = void 0;var _utils = require("./utils"); +"use strict";Object.defineProperty(exports, "__esModule", { value: true });exports.interfacesIds = exports.default = void 0;var _utils = require("./utils"); const erc20methods = [ 'totalSupply()', @@ -10,10 +10,10 @@ const erc20methods = [ const erc677Methods = erc20methods.concat([ -'transferAndCall(address,uint256,bytes)']); +'transferAndCall(address,uint256,bytes)'] +); - -const interfacesIds = { +const interfacesIds = exports.interfacesIds = { ERC20: makeInterface(erc20methods), ERC677: makeInterface(erc677Methods), ERC165: makeInterface(['supportsInterface(bytes4)']), @@ -26,26 +26,27 @@ const interfacesIds = { 'isApprovedForAll(address,address)', 'transferFrom(address,address,uint256)', 'safeTransferFrom(address,address,uint256)', - 'safeTransferFrom(address,address,uint256,bytes)']), - + 'safeTransferFrom(address,address,uint256,bytes)'] + ), ERC721Enumerable: makeInterface([ 'totalSupply()', 'tokenOfOwnerByIndex(address,uint256)', - 'tokenByIndex(uint256)']), - + 'tokenByIndex(uint256)'] + ), ERC721Metadata: makeInterface([ 'name()', 'symbol()', - 'tokenURI(uint256)']), - + 'tokenURI(uint256)'] + ), ERC721Exists: makeInterface([ - 'exists(uint256)']) };exports.interfacesIds = interfacesIds; - - + 'exists(uint256)'] + ) +}; function makeInterface(methods) { let id = (0, _utils.erc165IdFromMethods)(methods); return { methods, id }; -}var _default = +}var _default = exports.default = -interfacesIds;exports.default = _default; \ No newline at end of file +interfacesIds; +//# sourceMappingURL=interfacesIds.js.map \ No newline at end of file diff --git a/dist/lib/nativeContracts/FakeABI.js b/dist/lib/nativeContracts/FakeABI.js index 4e1439c..1d93829 100644 --- a/dist/lib/nativeContracts/FakeABI.js +++ b/dist/lib/nativeContracts/FakeABI.js @@ -1,26 +1,26 @@ "use strict";Object.defineProperty(exports, "__esModule", { value: true });exports.default = FakeABI; var _rskUtils = require("@rsksmart/rsk-utils"); var _utils = require("../utils"); -var btcUtils = _interopRequireWildcard(require("../btcUtils"));function _getRequireWildcardCache() {if (typeof WeakMap !== "function") return null;var cache = new WeakMap();_getRequireWildcardCache = function () {return cache;};return cache;}function _interopRequireWildcard(obj) {if (obj && obj.__esModule) {return obj;}if (obj === null || typeof obj !== "object" && typeof obj !== "function") {return { default: obj };}var cache = _getRequireWildcardCache();if (cache && cache.has(obj)) {return cache.get(obj);}var newObj = {};var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;for (var key in obj) {if (Object.prototype.hasOwnProperty.call(obj, key)) {var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;if (desc && (desc.get || desc.set)) {Object.defineProperty(newObj, key, desc);} else {newObj[key] = obj[key];}}}newObj.default = obj;if (cache) {cache.set(obj, newObj);}return newObj;} +var btcUtils = _interopRequireWildcard(require("../btcUtils"));function _getRequireWildcardCache(e) {if ("function" != typeof WeakMap) return null;var r = new WeakMap(),t = new WeakMap();return (_getRequireWildcardCache = function (e) {return e ? t : r;})(e);}function _interopRequireWildcard(e, r) {if (!r && e && e.__esModule) return e;if (null === e || "object" != typeof e && "function" != typeof e) return { default: e };var t = _getRequireWildcardCache(r);if (t && t.has(e)) return t.get(e);var n = { __proto__: null },a = Object.defineProperty && Object.getOwnPropertyDescriptor;for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) {var i = a ? Object.getOwnPropertyDescriptor(e, u) : null;i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u];}return n.default = e, t && t.set(e, n), n;} function FakeABI(network) { - const decodeBtcTxHash = data => { + const decodeBtcTxHash = (data) => { if ((0, _rskUtils.remove0x)(data).length === 128) { let buffer = Buffer.from((0, _rskUtils.remove0x)(data), 'hex'); data = (0, _rskUtils.add0x)(buffer.toString('ascii')); } return data; }; - const decodeArray = data => data.map(d => Array.isArray(d) ? decodeArray(d) : (0, _rskUtils.add0x)(d.toString('hex'))); + const decodeArray = (data) => data.map((d) => Array.isArray(d) ? decodeArray(d) : (0, _rskUtils.add0x)(d.toString('hex'))); - const decodeFederationData = data => { + const decodeFederationData = (data) => { let [a160, keys] = data; let address = btcUtils.h160toAddress(a160, { prefixKey: 'scriptHash', network }).toString('hex'); - keys = keys.map(d => btcUtils.rskAddressFromBtcPublicKey(d.toString('hex'))); + keys = keys.map((d) => btcUtils.rskAddressFromBtcPublicKey(d.toString('hex'))); return [address, keys]; }; - const commitFederationDecoder = data => { + const commitFederationDecoder = (data) => { const decoded = _rskUtils.rlp.decode(data); let [oldData, newData, block] = decoded; let [oldFederationAddress, oldFederationMembers] = decodeFederationData(oldData); @@ -35,102 +35,103 @@ function FakeABI(network) { { indexed: true, name: 'to', - type: 'address' }, - + type: 'address' + }, { indexed: false, name: 'blockHash', - type: 'string' }, - + type: 'string' + }, { indexed: false, name: 'value', - type: 'uint256' }], - + type: 'uint256' + }], name: 'mining_fee_topic', - type: 'event' }, - + type: 'event' + }, { // Bridge events inputs: [ { indexed: false, name: 'btcTxHash', - type: 'string' }, - + type: 'string' + }, { indexed: false, name: 'btcTx', // raw tx? - type: 'string' }], - + type: 'string' + }], name: 'release_btc_topic', - type: 'event' }, - + type: 'event' + }, { inputs: [ { indexed: false, name: 'sender', - type: 'address' }], - + type: 'address' + }], name: 'update_collections_topic', - type: 'event' }, - + type: 'event' + }, { inputs: [ { indexed: false, name: 'btcTxHash', type: 'string', - _filter: decodeBtcTxHash }, - + _filter: decodeBtcTxHash + }, { indexed: false, name: 'federatorPublicKey', - type: 'string' }, - + type: 'string' + }, { indexed: false, name: 'rskTxHash', - type: 'string' }], - + type: 'string' + }], name: 'add_signature_topic', - type: 'event' }, - + type: 'event' + }, { inputs: [ { indexed: false, name: 'oldFederationAddress', - type: 'string' }, - + type: 'string' + }, { indexed: false, name: 'oldFederationMembers', - type: 'address[]' }, - + type: 'address[]' + }, { indexed: false, name: 'newFederationAddress', - type: 'string' }, - + type: 'string' + }, { indexed: false, name: 'newFederationMembers', - type: 'address[]' }, - + type: 'address[]' + }, { indexed: false, name: 'activationBlockNumber', - type: 'string' }], - + type: 'string' + }], name: 'commit_federation_topic', type: 'event', - _decoder: commitFederationDecoder }])); - - -} \ No newline at end of file + _decoder: commitFederationDecoder + }] + )); +} +//# sourceMappingURL=FakeABI.js.map \ No newline at end of file diff --git a/dist/lib/nativeContracts/NativeContracts.js b/dist/lib/nativeContracts/NativeContracts.js index d6d7c6f..7f27c7f 100644 --- a/dist/lib/nativeContracts/NativeContracts.js +++ b/dist/lib/nativeContracts/NativeContracts.js @@ -1,12 +1,12 @@ -"use strict";Object.defineProperty(exports, "__esModule", { value: true });exports.NativeContracts = NativeContracts;exports.default = exports.parseNativeContracts = exports.defaultNativeContracts = void 0; +"use strict";Object.defineProperty(exports, "__esModule", { value: true });exports.NativeContracts = NativeContracts;exports.parseNativeContracts = exports.defaultNativeContracts = exports.default = void 0; var _rskUtils = require("@rsksmart/rsk-utils"); -const defaultNativeContracts = { +const defaultNativeContracts = exports.defaultNativeContracts = { bridge: '0x0000000000000000000000000000000001000006', - remasc: '0x0000000000000000000000000000000001000008' };exports.defaultNativeContracts = defaultNativeContracts; + remasc: '0x0000000000000000000000000000000001000008' +}; - -const parseNativeContracts = nativeContracts => { +const parseNativeContracts = (nativeContracts) => { if (typeof nativeContracts !== 'object') throw new TypeError(`nativeContracts must be an object`); if (Object.keys(nativeContracts) < 1) throw new Error(`Empty native contracts list`); for (let name in nativeContracts) { @@ -21,19 +21,20 @@ function NativeContracts({ nativeContracts } = {}) { nativeContracts = parseNativeContracts(nativeContracts || defaultNativeContracts); const names = Object.keys(nativeContracts); - const getNativeContractAddress = contractName => { + const getNativeContractAddress = (contractName) => { return nativeContracts[contractName]; }; - const getNativeContractName = address => { + const getNativeContractName = (address) => { address = address.toLowerCase(); - return names.find(name => nativeContracts[name] === address); + return names.find((name) => nativeContracts[name] === address); }; - const isNativeContract = address => !!getNativeContractName(address); + const isNativeContract = (address) => !!getNativeContractName(address); const list = () => nativeContracts; return Object.freeze({ getNativeContractAddress, getNativeContractName, isNativeContract, list }); -}var _default = +}var _default = exports.default = -NativeContracts;exports.default = _default; \ No newline at end of file +NativeContracts; +//# sourceMappingURL=NativeContracts.js.map \ No newline at end of file diff --git a/dist/lib/nativeContracts/NativeContractsDecoder.js b/dist/lib/nativeContracts/NativeContractsDecoder.js index d9bdff8..13385b1 100644 --- a/dist/lib/nativeContracts/NativeContractsDecoder.js +++ b/dist/lib/nativeContracts/NativeContractsDecoder.js @@ -8,9 +8,10 @@ function NativeContractsEventDecoder({ bitcoinNetwork, txBlockNumber }) { const ABI = (0, _utils.addSignatureDataToAbi)((0, _bridgeAbi.getBridgeAbi)({ txBlockNumber, bitcoinNetwork })); const solidityDecoder = (0, _EventDecoder.default)(ABI); - const getEventDecoder = log => { + const getEventDecoder = (log) => { const { eventABI } = solidityDecoder.getEventAbi([...log.topics]); return eventABI ? solidityDecoder : nativeDecoder; }; return Object.freeze({ getEventDecoder }); -} \ No newline at end of file +} +//# sourceMappingURL=NativeContractsDecoder.js.map \ No newline at end of file diff --git a/dist/lib/nativeContracts/NativeContractsEvents.js b/dist/lib/nativeContracts/NativeContractsEvents.js index fefee03..4d842f9 100755 --- a/dist/lib/nativeContracts/NativeContractsEvents.js +++ b/dist/lib/nativeContracts/NativeContractsEvents.js @@ -4,27 +4,27 @@ var _FakeABI = _interopRequireDefault(require("./FakeABI"));function _interopReq function NativeContractsEvents({ bitcoinNetwork } = {}) { const network = bitcoinNetwork || 'testnet'; const fakeAbi = (0, _FakeABI.default)(network); - const decodeAddress = address => { + const decodeAddress = (address) => { address = Buffer.from((0, _rskUtils.remove0x)(address), 'hex'); return (0, _rskUtils.add0x)(address.toString('hex').slice(-40)); }; - const decodeEventName = name => { + const decodeEventName = (name) => { return Buffer.from((0, _rskUtils.remove0x)(name), 'hex').toString('ascii').replace(/\0/g, ''); }; - const removeEmptyStartBytes = d => { + const removeEmptyStartBytes = (d) => { d = !Buffer.isBuffer(d) ? Buffer.from(d, 'hex') : d; - return d.slice(d.findIndex(x => x > 0)); + return d.slice(d.findIndex((x) => x > 0)); }; - const decodeData = data => { + const decodeData = (data) => { let decoded = _rskUtils.rlp.decode(data); if (!Array.isArray(decoded)) decoded = [decoded]; - return decoded.map(d => (0, _rskUtils.add0x)(removeEmptyStartBytes(d).toString('hex'))); + return decoded.map((d) => (0, _rskUtils.add0x)(removeEmptyStartBytes(d).toString('hex'))); }; - const getEventAbi = eventName => fakeAbi.find(a => a.name === eventName && a.type === 'event'); + const getEventAbi = (eventName) => fakeAbi.find((a) => a.name === eventName && a.type === 'event'); const decodeByType = (type, value) => { if (type === 'address') return decodeAddress(value); @@ -39,7 +39,7 @@ function NativeContractsEvents({ bitcoinNetwork } = {}) { return decodeByType(type, value); }; - const removeCustomProperties = obj => { + const removeCustomProperties = (obj) => { const res = Object.assign({}, obj); for (let p in res) { if (p[0] === '_') delete res[p]; @@ -47,14 +47,14 @@ function NativeContractsEvents({ bitcoinNetwork } = {}) { return res; }; - const cleanAbi = abi => { + const cleanAbi = (abi) => { abi = removeCustomProperties(abi); let { inputs } = abi; - if (Array.isArray(inputs)) abi.inputs = inputs.map(input => removeCustomProperties(input)); + if (Array.isArray(inputs)) abi.inputs = inputs.map((input) => removeCustomProperties(input)); return abi; }; - const decodeLog = log => { + const decodeLog = (log) => { let topics = [...log.topics]; let event = decodeEventName(topics.shift()); let abi = getEventAbi(event); @@ -78,6 +78,7 @@ function NativeContractsEvents({ bitcoinNetwork } = {}) { return log; }; return Object.freeze({ decodeLog, abi: fakeAbi }); -}var _default = +}var _default = exports.default = -NativeContractsEvents;exports.default = _default; \ No newline at end of file +NativeContractsEvents; +//# sourceMappingURL=NativeContractsEvents.js.map \ No newline at end of file diff --git a/dist/lib/nativeContracts/bridgeAbi.js b/dist/lib/nativeContracts/bridgeAbi.js index dea334b..318fb54 100644 --- a/dist/lib/nativeContracts/bridgeAbi.js +++ b/dist/lib/nativeContracts/bridgeAbi.js @@ -1,11 +1,11 @@ -"use strict";Object.defineProperty(exports, "__esModule", { value: true });exports.getBridgeAbi = getBridgeAbi;exports.RELEASES = void 0;var _bridgeOrchid = _interopRequireDefault(require("./bridge-orchid.json")); +"use strict";Object.defineProperty(exports, "__esModule", { value: true });exports.RELEASES = void 0;exports.getBridgeAbi = getBridgeAbi;var _bridgeOrchid = _interopRequireDefault(require("./bridge-orchid.json")); var _bridgeWasabi = _interopRequireDefault(require("./bridge-wasabi.json")); var _bridgePapyrus = _interopRequireDefault(require("./bridge-papyrus.json")); var _bridgeIris = _interopRequireDefault(require("./bridge-iris.json")); var _bridgeFingerroot = _interopRequireDefault(require("./bridge-fingerroot.json")); var _bridgeHop = _interopRequireDefault(require("./bridge-hop.json"));function _interopRequireDefault(obj) {return obj && obj.__esModule ? obj : { default: obj };} -const RELEASES = { +const RELEASES = exports.RELEASES = { mainnet: [ { height: 0, abi: _bridgeOrchid.default }, { height: 1591000, abi: _bridgeWasabi.default }, @@ -19,9 +19,9 @@ const RELEASES = { { height: 863000, abi: _bridgePapyrus.default }, { height: 2060500, abi: _bridgeIris.default }, { height: 3103000, abi: _bridgeHop.default }, - { height: 4015800, abi: _bridgeFingerroot.default }] };exports.RELEASES = RELEASES; - + { height: 4015800, abi: _bridgeFingerroot.default }] +}; function findmatchingAbi(txHeight, abisWithHeight) { const lastIndex = abisWithHeight.length - 1; @@ -44,4 +44,5 @@ function getBridgeAbi({ txBlockNumber, bitcoinNetwork }) { } return findmatchingAbi(txBlockNumber, RELEASES[bitcoinNetwork]); -} \ No newline at end of file +} +//# sourceMappingURL=bridgeAbi.js.map \ No newline at end of file diff --git a/dist/lib/nod3Connect.js b/dist/lib/nod3Connect.js index 31fb4e3..71b112b 100755 --- a/dist/lib/nod3Connect.js +++ b/dist/lib/nod3Connect.js @@ -1,10 +1,11 @@ -"use strict";Object.defineProperty(exports, "__esModule", { value: true });exports.default = exports.nod3Connect = void 0;var _nod = _interopRequireDefault(require("@rsksmart/nod3"));function _interopRequireDefault(obj) {return obj && obj.__esModule ? obj : { default: obj };} +"use strict";Object.defineProperty(exports, "__esModule", { value: true });exports.nod3Connect = exports.default = void 0;var _nod = _interopRequireDefault(require("@rsksmart/nod3"));function _interopRequireDefault(obj) {return obj && obj.__esModule ? obj : { default: obj };} -const nod3Connect = url => { +const nod3Connect = (url) => { url = url || process.env['RSK_NODE_URL'] || 'http://localhost:4444'; return new _nod.default( - new _nod.default.providers.HttpProvider(url)); + new _nod.default.providers.HttpProvider(url) + ); +};exports.nod3Connect = nod3Connect;var _default = exports.default = -};exports.nod3Connect = nod3Connect;var _default = - -nod3Connect();exports.default = _default; \ No newline at end of file +nod3Connect(); +//# sourceMappingURL=nod3Connect.js.map \ No newline at end of file diff --git a/dist/lib/types.js b/dist/lib/types.js index a53b168..4b3983e 100755 --- a/dist/lib/types.js +++ b/dist/lib/types.js @@ -1,29 +1,30 @@ -"use strict";Object.defineProperty(exports, "__esModule", { value: true });exports.tokensInterfaces = exports.contractsInterfaces = exports.bitcoinRskNetWorks = exports.bitcoinNetworks = exports.INTERFACE_ID_BYTES = exports.ABI_SIGNATURE = void 0;const ABI_SIGNATURE = '__signatureData';exports.ABI_SIGNATURE = ABI_SIGNATURE; +"use strict";Object.defineProperty(exports, "__esModule", { value: true });exports.tokensInterfaces = exports.contractsInterfaces = exports.bitcoinRskNetWorks = exports.bitcoinNetworks = exports.INTERFACE_ID_BYTES = exports.ABI_SIGNATURE = void 0;const ABI_SIGNATURE = exports.ABI_SIGNATURE = '__signatureData'; -const INTERFACE_ID_BYTES = 4;exports.INTERFACE_ID_BYTES = INTERFACE_ID_BYTES; +const INTERFACE_ID_BYTES = exports.INTERFACE_ID_BYTES = 4; -const bitcoinNetworks = { +const bitcoinNetworks = exports.bitcoinNetworks = { TESTNET: 'testnet', MAINNET: 'mainnet', - REGTEST: 'regtest' };exports.bitcoinNetworks = bitcoinNetworks; + REGTEST: 'regtest' +}; - -const bitcoinRskNetWorks = { +const bitcoinRskNetWorks = exports.bitcoinRskNetWorks = { 31: bitcoinNetworks.TESTNET, 30: bitcoinNetworks.MAINNET, - 33: bitcoinNetworks.REGTEST };exports.bitcoinRskNetWorks = bitcoinRskNetWorks; - + 33: bitcoinNetworks.REGTEST +}; -const contractsInterfaces = { +const contractsInterfaces = exports.contractsInterfaces = { ERC20: 'ERC20', ERC677: 'ERC677', ERC165: 'ERC165', - ERC721: 'ERC721' };exports.contractsInterfaces = contractsInterfaces; - + ERC721: 'ERC721' +}; const ci = contractsInterfaces; -const tokensInterfaces = [ +const tokensInterfaces = exports.tokensInterfaces = [ ci.ERC20, ci.ERC677, -ci.ERC721];exports.tokensInterfaces = tokensInterfaces; \ No newline at end of file +ci.ERC721]; +//# sourceMappingURL=types.js.map \ No newline at end of file diff --git a/dist/lib/utils.js b/dist/lib/utils.js index f850881..c07b330 100755 --- a/dist/lib/utils.js +++ b/dist/lib/utils.js @@ -1,38 +1,38 @@ -"use strict";Object.defineProperty(exports, "__esModule", { value: true });exports.filterEvents = filterEvents;exports.binarySearchNumber = binarySearchNumber;exports.getSignatureDataFromAbi = exports.erc165IdFromMethods = exports.erc165Id = exports.addSignatureDataToAbi = exports.abiSignatureData = exports.getInputsIndexes = exports.removeAbiSignatureData = exports.solidityName = exports.soliditySelector = exports.soliditySignature = exports.abiMethods = exports.abiEvents = exports.setAbi = void 0;var _rskUtils = require("@rsksmart/rsk-utils"); +"use strict";Object.defineProperty(exports, "__esModule", { value: true });exports.addSignatureDataToAbi = exports.abiSignatureData = exports.abiMethods = exports.abiEvents = void 0;exports.binarySearchNumber = binarySearchNumber;exports.erc165IdFromMethods = exports.erc165Id = void 0;exports.filterEvents = filterEvents;exports.soliditySignature = exports.soliditySelector = exports.solidityName = exports.setAbi = exports.removeAbiSignatureData = exports.getSignatureDataFromAbi = exports.getInputsIndexes = void 0;var _rskUtils = require("@rsksmart/rsk-utils"); var _types = require("./types"); -const setAbi = abi => addSignatureDataToAbi(abi, true);exports.setAbi = setAbi; +const setAbi = (abi) => addSignatureDataToAbi(abi, true);exports.setAbi = setAbi; -const abiEvents = abi => abi.filter(v => v.type === 'event');exports.abiEvents = abiEvents; +const abiEvents = (abi) => abi.filter((v) => v.type === 'event');exports.abiEvents = abiEvents; -const abiMethods = abi => abi.filter(v => v.type === 'function');exports.abiMethods = abiMethods; +const abiMethods = (abi) => abi.filter((v) => v.type === 'function');exports.abiMethods = abiMethods; -const soliditySignature = name => (0, _rskUtils.keccak256)(name);exports.soliditySignature = soliditySignature; +const soliditySignature = (name) => (0, _rskUtils.keccak256)(name);exports.soliditySignature = soliditySignature; -const soliditySelector = signature => signature.slice(0, 8);exports.soliditySelector = soliditySelector; +const soliditySelector = (signature) => signature.slice(0, 8);exports.soliditySelector = soliditySelector; -const solidityName = abi => { +const solidityName = (abi) => { let { name, inputs } = abi; - inputs = inputs ? inputs.map(i => i.type) : []; + inputs = inputs ? inputs.map((i) => i.type) : []; return name ? `${name}(${inputs.join(',')})` : null; };exports.solidityName = solidityName; -const removeAbiSignatureData = abi => { +const removeAbiSignatureData = (abi) => { abi = Object.assign({}, abi); if (undefined !== abi[_types.ABI_SIGNATURE]) delete abi[_types.ABI_SIGNATURE]; return abi; };exports.removeAbiSignatureData = removeAbiSignatureData; -const getInputsIndexes = abi => { +const getInputsIndexes = (abi) => { let { inputs } = abi; - return inputs && abi.type === 'event' ? inputs.map(i => i.indexed) : []; + return inputs && abi.type === 'event' ? inputs.map((i) => i.indexed) : []; };exports.getInputsIndexes = getInputsIndexes; -const abiSignatureData = abi => { +const abiSignatureData = (abi) => { let method = solidityName(abi); let signature = method ? soliditySignature(method) : null; let index = getInputsIndexes(abi); - let indexed = index ? index.filter(i => i === true).length : 0; + let indexed = index ? index.filter((i) => i === true).length : 0; let eventSignature = null; if (method && abi.type === 'event') { eventSignature = soliditySignature(`${method}${Buffer.from(index).toString('hex')}`); @@ -49,8 +49,8 @@ const addSignatureDataToAbi = (abi, skip) => { return abi; };exports.addSignatureDataToAbi = addSignatureDataToAbi; -const erc165Id = selectors => { - let id = selectors.map(s => Buffer.from(s, 'hex')). +const erc165Id = (selectors) => { + let id = selectors.map((s) => Buffer.from(s, 'hex')). reduce((a, bytes) => { for (let i = 0; i < _types.INTERFACE_ID_BYTES; i++) { a[i] = a[i] ^ bytes[i]; @@ -60,29 +60,29 @@ const erc165Id = selectors => { return (0, _rskUtils.add0x)(id.toString('hex')); };exports.erc165Id = erc165Id; -const erc165IdFromMethods = methods => { - return erc165Id(methods.map(m => soliditySelector(soliditySignature(m)))); +const erc165IdFromMethods = (methods) => { + return erc165Id(methods.map((m) => soliditySelector(soliditySignature(m)))); };exports.erc165IdFromMethods = erc165IdFromMethods; -const getSignatureDataFromAbi = abi => { +const getSignatureDataFromAbi = (abi) => { return abi[_types.ABI_SIGNATURE]; };exports.getSignatureDataFromAbi = getSignatureDataFromAbi; function filterEvents(abi) { const type = 'event'; // get events from ABI - let events = abi.filter(a => a.type === type); + let events = abi.filter((a) => a.type === type); // remove events from ABI - abi = abi.filter(a => a.type !== type); - let keys = [...new Set(events.map(e => e[_types.ABI_SIGNATURE].eventSignature))]; - events = keys.map(k => events.find(e => e[_types.ABI_SIGNATURE].eventSignature === k)); + abi = abi.filter((a) => a.type !== type); + let keys = [...new Set(events.map((e) => e[_types.ABI_SIGNATURE].eventSignature))]; + events = keys.map((k) => events.find((e) => e[_types.ABI_SIGNATURE].eventSignature === k)); abi = abi.concat(events); return abi; } function filterArr(a) { if (!Array.isArray(a)) return a; - return a.find(x => filterArr(x)); + return a.find((x) => filterArr(x)); } async function binarySearchNumber(searchCb, high, low) { @@ -90,7 +90,7 @@ async function binarySearchNumber(searchCb, high, low) { high = parseInt(high || 0); low = parseInt(low || 0); if (typeof searchCb !== 'function') throw new Error('SeachCb must be a function'); - let [l, h] = await Promise.all([low, high].map(b => searchCb(b))); + let [l, h] = await Promise.all([low, high].map((b) => searchCb(b))); if (l !== h) { if (high === low + 1) { return high; @@ -105,4 +105,5 @@ async function binarySearchNumber(searchCb, high, low) { } catch (err) { return Promise.reject(err); } -} \ No newline at end of file +} +//# sourceMappingURL=utils.js.map \ No newline at end of file