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/examples/getDeployment.js.map b/dist/examples/getDeployment.js.map new file mode 100644 index 0000000..edf4f53 --- /dev/null +++ b/dist/examples/getDeployment.js.map @@ -0,0 +1 @@ +{"version":3,"file":"getDeployment.js","names":["_index","require","_nod3Connect","_rskUtils","url","process","env","address","argv","highBlock","help","isAddress","nod3","nod3Connect","console","log","search","code","eth","getCode","parseInt","Error","bcsearch","BcSearch","res","deploymentTx","toLowerCase","err","error","exit","msg"],"sources":["../../src/examples/getDeployment.js"],"sourcesContent":["import { BcSearch } from '../index'\nimport { nod3Connect } from '../lib/nod3Connect'\nimport { isAddress } from '@rsksmart/rsk-utils'\n\nconst url = process.env['URL'] || 'http://localhost:4444'\nconst address = process.argv[2]\nconst highBlock = process.argv[3]\n\nif (!address) help()\nif (!isAddress(address)) help(`Invalid address \"${address}\"`)\n\nconst nod3 = nod3Connect(url)\n\nconsole.log(`Searching in node: ${url}`)\nsearch(address, highBlock)\n\nasync function search (address, highBlock) {\n try {\n highBlock = highBlock || 'latest'\n const code = await nod3.eth.getCode(address, highBlock)\n if (!parseInt(code)) {\n throw new Error(`The address ${address} has no code at block ${highBlock}`)\n }\n const bcsearch = BcSearch(nod3)\n let res = await bcsearch.deploymentTx(address.toLowerCase(), { highBlock })\n console.log(res)\n } catch (err) {\n console.error(err)\n process.exit(9)\n }\n}\n\nfunction help (msg) {\n if (msg) console.log(`${msg}`)\n console.log('Usage:')\n console.log(`node ${process.argv[1]} address [highestBlock]`)\n console.log()\n console.log(`Set environment variable URL to change node url`)\n console.log(`Example: export URL=http://localhost:4444`)\n process.exit(0)\n}\n"],"m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,CAACc,KAAK,CAACD,GAAG,CAAC;IAClBtB,OAAO,CAACwB,IAAI,CAAC,CAAC,CAAC;EACjB;AACF;;AAEA,SAASnB,IAAIA,CAAEoB,GAAG,EAAE;EAClB,IAAIA,GAAG,EAAEhB,OAAO,CAACC,GAAG,CAAE,GAAEe,GAAI,EAAC,CAAC;EAC9BhB,OAAO,CAACC,GAAG,CAAC,QAAQ,CAAC;EACrBD,OAAO,CAACC,GAAG,CAAE,QAAOV,OAAO,CAACG,IAAI,CAAC,CAAC,CAAE,yBAAwB,CAAC;EAC7DM,OAAO,CAACC,GAAG,CAAC,CAAC;EACbD,OAAO,CAACC,GAAG,CAAE,iDAAgD,CAAC;EAC9DD,OAAO,CAACC,GAAG,CAAE,2CAA0C,CAAC;EACxDV,OAAO,CAACwB,IAAI,CAAC,CAAC,CAAC;AACjB"} \ No newline at end of file diff --git a/dist/index.js b/dist/index.js index ae2682b..012e0b9 100644 --- a/dist/index.js +++ b/dist/index.js @@ -1,7 +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;exports.default = _default; \ No newline at end of file +_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 +const originalConsoleLog = console.log; +console.log = function (message) { + if (!String(message).includes('duplicate definition')) { + originalConsoleLog(message); + } +}; +//# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/dist/index.js.map b/dist/index.js.map new file mode 100644 index 0000000..c5ff85a --- /dev/null +++ b/dist/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","names":["_ContractParser","require","_BcSearch","_Contract","_interopRequireDefault","_bridgeAbi","obj","__esModule","default","abi","exports","bridge","getBridgeAbi","_default","ContractParser","originalConsoleLog","console","log","message","String","includes"],"sources":["../src/index.js"],"sourcesContent":["import { ContractParser } from './lib/ContractParser'\nimport { BcSearch } from './lib/BcSearch'\nimport Contract from './lib/Contract'\nimport { getBridgeAbi } from './lib/nativeContracts/bridgeAbi'\nconst abi = { bridge: getBridgeAbi }\nexport { ContractParser, BcSearch, Contract, abi }\nexport default ContractParser\n\n// 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\nconst originalConsoleLog = console.log\nconsole.log = function (message) {\n if (!String(message).includes('duplicate definition')) {\n originalConsoleLog(message)\n }\n}\n"],"mappings":"mdAAA,IAAAA,eAAA,GAAAC,OAAA;AACA,IAAAC,SAAA,GAAAD,OAAA;AACA,IAAAE,SAAA,GAAAC,sBAAA,CAAAH,OAAA;AACA,IAAAI,UAAA,GAAAJ,OAAA,oCAA8D,SAAAG,uBAAAE,GAAA,UAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AAC9D,MAAMG,GAAG,GAAAC,OAAA,CAAAD,GAAA,GAAG,EAAEE,MAAM,EAAEC,uBAAY,CAAC,CAAC,KAAAC,QAAA,GAAAH,OAAA,CAAAF,OAAA;;AAErBM,8BAAc;;AAE7B;AACA,MAAMC,kBAAkB,GAAGC,OAAO,CAACC,GAAG;AACtCD,OAAO,CAACC,GAAG,GAAG,UAAUC,OAAO,EAAE;EAC/B,IAAI,CAACC,MAAM,CAACD,OAAO,CAAC,CAACE,QAAQ,CAAC,sBAAsB,CAAC,EAAE;IACrDL,kBAAkB,CAACG,OAAO,CAAC;EAC7B;AACF,CAAC"} \ 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/Abi.js.map b/dist/lib/Abi.js.map new file mode 100644 index 0000000..b8fa3ab --- /dev/null +++ b/dist/lib/Abi.js.map @@ -0,0 +1 @@ +{"version":3,"file":"Abi.js","names":["_compiled_abi","_interopRequireDefault","require","obj","__esModule","default","_default","exports","abi"],"sources":["../../src/lib/Abi.js"],"sourcesContent":["import abi from './compiled_abi.json'\nexport default abi\n"],"mappings":"oGAAA,IAAAA,aAAA,GAAAC,sBAAA,CAAAC,OAAA,yBAAqC,SAAAD,uBAAAE,GAAA,UAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA,QAAAG,QAAA,GAAAC,OAAA,CAAAF,OAAA;AACtBG,qBAAG"} \ 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/BcSearch.js.map b/dist/lib/BcSearch.js.map new file mode 100644 index 0000000..e33e690 --- /dev/null +++ b/dist/lib/BcSearch.js.map @@ -0,0 +1 @@ +{"version":3,"file":"BcSearch.js","names":["_utils","require","_rskUtils","BcSearch","nod3","getBlock","hashOrNumber","eth","block","searchCb","highBlock","lowBlock","number","binarySearchNumber","err","Promise","reject","isContractAtBlock","address","blockNumber","code","getCode","parseInt","isNaN","deploymentBlock","searchReceipt","transactions","cb","tx","receipt","getTransactionReceipt","hash","isItxDeployment","itx","result","type","contractAddress","undefined","deploymentTx","blockTrace","filter","isAddress","to","transaction","trace","internalTx","find","timestamp","Object","freeze","_default","exports","default"],"sources":["../../src/lib/BcSearch.js"],"sourcesContent":["import { binarySearchNumber } from './utils'\nimport { isAddress } from '@rsksmart/rsk-utils'\n\nexport function BcSearch (nod3) {\n const getBlock = (hashOrNumber) => {\n return nod3.eth.getBlock(hashOrNumber)\n }\n\n const block = async (searchCb, highBlock, lowBlock) => {\n try {\n if (!highBlock) {\n let block = await getBlock('latest')\n let { number } = block\n highBlock = number\n }\n lowBlock = lowBlock || 1\n return binarySearchNumber(searchCb, highBlock, lowBlock)\n } catch (err) {\n return Promise.reject(err)\n }\n }\n\n const isContractAtBlock = async (address, blockNumber) => {\n let code = await nod3.eth.getCode(address, blockNumber)\n code = parseInt(code)\n return !isNaN(code) && code > 0\n }\n\n const deploymentBlock = (address, highBlock, lowBlock) => {\n return block(blockNumber => isContractAtBlock(address, blockNumber), highBlock, lowBlock)\n }\n const searchReceipt = async (transactions, cb) => {\n for (let tx of transactions) {\n let receipt = await nod3.eth.getTransactionReceipt(tx.hash)\n if (cb(receipt)) return { tx, receipt }\n }\n }\n const isItxDeployment = (address, itx) => {\n let { result, type } = itx\n let contractAddress = (result) ? result.address : undefined\n return type === 'create' && contractAddress === address\n }\n const deploymentTx = async (address, { blockNumber, blockTrace, block, highBlock } = {}) => {\n try {\n blockNumber = blockNumber || await deploymentBlock(address, highBlock)\n block = block || await nod3.eth.getBlock(blockNumber, true)\n let transactions = block.transactions.filter(tx => !isAddress(tx.to))\n let transaction = await searchReceipt(transactions, receipt => receipt.contractAddress === address)\n if (!transaction) { // internal transactions\n blockTrace = blockTrace || await nod3.trace.block(block.hash)\n let internalTx = blockTrace.find(trace => isItxDeployment(address, trace))\n if (internalTx) transaction = { internalTx }\n }\n if (transaction) transaction.timestamp = block.timestamp\n return transaction\n } catch (err) {\n return Promise.reject(err)\n }\n }\n\n return Object.freeze({ block, deploymentBlock, deploymentTx, isItxDeployment })\n}\n\nexport default BcSearch\n"],"mappings":"gIAAA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,SAAA,GAAAD,OAAA;;AAEO,SAASE,QAAQA,CAAEC,IAAI,EAAE;EAC9B,MAAMC,QAAQ,GAAGA,CAACC,YAAY,KAAK;IACjC,OAAOF,IAAI,CAACG,GAAG,CAACF,QAAQ,CAACC,YAAY,CAAC;EACxC,CAAC;;EAED,MAAME,KAAK,GAAG,MAAAA,CAAOC,QAAQ,EAAEC,SAAS,EAAEC,QAAQ,KAAK;IACrD,IAAI;MACF,IAAI,CAACD,SAAS,EAAE;QACd,IAAIF,KAAK,GAAG,MAAMH,QAAQ,CAAC,QAAQ,CAAC;QACpC,IAAI,EAAEO,MAAM,CAAC,CAAC,GAAGJ,KAAK;QACtBE,SAAS,GAAGE,MAAM;MACpB;MACAD,QAAQ,GAAGA,QAAQ,IAAI,CAAC;MACxB,OAAO,IAAAE,yBAAkB,EAACJ,QAAQ,EAAEC,SAAS,EAAEC,QAAQ,CAAC;IAC1D,CAAC,CAAC,OAAOG,GAAG,EAAE;MACZ,OAAOC,OAAO,CAACC,MAAM,CAACF,GAAG,CAAC;IAC5B;EACF,CAAC;;EAED,MAAMG,iBAAiB,GAAG,MAAAA,CAAOC,OAAO,EAAEC,WAAW,KAAK;IACxD,IAAIC,IAAI,GAAG,MAAMhB,IAAI,CAACG,GAAG,CAACc,OAAO,CAACH,OAAO,EAAEC,WAAW,CAAC;IACvDC,IAAI,GAAG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IAAIO,YAAY,GAAGlB,KAAK,CAACkB,YAAY,CAACc,MAAM,CAAC,CAAAZ,EAAE,KAAI,CAAC,IAAAa,mBAAS,EAACb,EAAE,CAACc,EAAE,CAAC,CAAC;MACrE,IAAIC,WAAW,GAAG,MAAMlB,aAAa,CAACC,YAAY,EAAE,CAAAG,OAAO,KAAIA,OAAO,CAACO,eAAe,KAAKlB,OAAO,CAAC;MACnG,IAAI,CAACyB,WAAW,EAAE,CAAE;QAClBJ,UAAU,GAAGA,UAAU,KAAI,MAAMnC,IAAI,CAACwC,KAAK,CAACpC,KAAK,CAACA,KAAK,CAACuB,IAAI,CAAC;QAC7D,IAAIc,UAAU,GAAGN,UAAU,CAACO,IAAI,CAAC,CAAAF,KAAK,KAAIZ,eAAe,CAACd,OAAO,EAAE0B,KAAK,CAAC,CAAC;QAC1E,IAAIC,UAAU,EAAEF,WAAW,GAAG,EAAEE,UAAU,CAAC,CAAC;MAC9C;MACA,IAAIF,WAAW,EAAEA,WAAW,CAACI,SAAS,GAAGvC,KAAK,CAACuC,SAAS;MACxD,OAAOJ,WAAW;IACpB,CAAC,CAAC,OAAO7B,GAAG,EAAE;MACZ,OAAOC,OAAO,CAACC,MAAM,CAACF,GAAG,CAAC;IAC5B;EACF,CAAC;;EAED,OAAOkC,MAAM,CAACC,MAAM,CAAC,EAAEzC,KAAK,EAAEgB,eAAe,EAAEc,YAAY,EAAEN,eAAe,CAAC,CAAC,CAAC;AACjF,CAAC,IAAAkB,QAAA,GAAAC,OAAA,CAAAC,OAAA;;AAEcjD,QAAQ"} \ 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/Contract.js.map b/dist/lib/Contract.js.map new file mode 100644 index 0000000..565c0a6 --- /dev/null +++ b/dist/lib/Contract.js.map @@ -0,0 +1 @@ +{"version":3,"file":"Contract.js","names":["_abi","require","Contract","abi","address","nod3","Error","contractInterface","Interface","at","newAddress","setNod3","nod3Instance","encodeCall","methodName","params","encodeFunctionData","decodeCall","data","outputs","getFunction","decoded","decodeFunctionResult","Array","isArray","length","call","txData","to","tx","Object","assign","result","eth","err","Promise","reject","freeze"],"sources":["../../src/lib/Contract.js"],"sourcesContent":["import { Interface } from '@ethersproject/abi'\n\nexport default function Contract (abi, { address, nod3 } = {}) {\n if (!abi || typeof abi !== 'object') throw new Error('Invalid abi')\n const contractInterface = new Interface(abi)\n\n const at = newAddress => {\n address = newAddress\n }\n\n const setNod3 = nod3Instance => {\n nod3 = nod3Instance\n }\n\n // const isEvent = name => abiFind('event', name)\n\n const encodeCall = (methodName, params = []) => contractInterface.encodeFunctionData(methodName, params)\n\n const decodeCall = (methodName, data) => {\n const { outputs } = contractInterface.getFunction(methodName)\n const decoded = contractInterface.decodeFunctionResult(methodName, data)\n return (Array.isArray(decoded) && outputs && outputs.length < 2) ? decoded[0] : decoded\n }\n\n const call = async (methodName, params = [], txData = {}) => {\n try {\n if (!nod3) throw new Error(`Set nod3 instance before call`)\n if (!address) throw new Error(`The contract address is not defined`)\n if (!Array.isArray(params)) throw new Error(`Params must be an array`)\n const data = encodeCall(methodName, params)\n const to = address\n const tx = Object.assign(txData, { to, data })\n const result = await nod3.eth.call(tx)\n return decodeCall(methodName, result)\n } catch (err) {\n return Promise.reject(err)\n }\n }\n return Object.freeze({ at, setNod3, encodeCall, decodeCall, call })\n}\n"],"mappings":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qCAAoC,CAAC;MACpE,IAAI,CAACiB,KAAK,CAACC,OAAO,CAACT,MAAM,CAAC,EAAE,MAAM,IAAIT,KAAK,CAAE,yBAAwB,CAAC;MACtE,MAAMY,IAAI,GAAGL,UAAU,CAACC,UAAU,EAAEC,MAAM,CAAC;MAC3C,MAAMa,EAAE,GAAGxB,OAAO;MAClB,MAAMyB,EAAE,GAAGC,MAAM,CAACC,MAAM,CAACJ,MAAM,EAAE,EAAEC,EAAE,EAAEV,IAAI,CAAC,CAAC,CAAC;MAC9C,MAAMc,MAAM,GAAG,MAAM3B,IAAI,CAAC4B,GAAG,CAACP,IAAI,CAACG,EAAE,CAAC;MACtC,OAAOZ,UAAU,CAACH,UAAU,EAAEkB,MAAM,CAAC;IACvC,CAAC,CAAC,OAAOE,GAAG,EAAE;MACZ,OAAOC,OAAO,CAACC,MAAM,CAACF,GAAG,CAAC;IAC5B;EACF,CAAC;EACD,OAAOJ,MAAM,CAACO,MAAM,CAAC,EAAE5B,EAAE,EAAEE,OAAO,EAAEE,UAAU,EAAEI,UAAU,EAAES,IAAI,CAAC,CAAC,CAAC;AACrE"} \ No newline at end of file diff --git a/dist/lib/ContractParser.js b/dist/lib/ContractParser.js index 8af52b4..b8f4547 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); @@ -145,11 +145,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; @@ -160,7 +160,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) { @@ -230,7 +230,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) => { @@ -257,7 +257,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 new file mode 100644 index 0000000..9cf0bb9 --- /dev/null +++ b/dist/lib/ContractParser.js.map @@ -0,0 +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,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,SAAAD,uBAAAU,GAAA,UAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;;;;;;;;AAEhB,SAASG,mBAAmBA,CAAEC,UAAU,EAAE;EACxC,OAAOC,MAAM,CAACC,IAAI,CAACF,UAAU,CAAC;EAC3BG,MAAM,CAAC,CAAAC,CAAC,KAAIJ,UAAU,CAACI,CAAC,CAAC,KAAK,IAAI,CAAC;EACnCC,GAAG,CAAC,CAAAC,CAAC,KAAIC,0BAAmB,CAACD,CAAC,CAAC,IAAIA,CAAC,CAAC;AAC1C;;AAEA,SAASE,iBAAiBA,CAAEC,WAAW,EAAEC,QAAQ,EAAE;EACjD,OAAOA,QAAQ,IAAID,WAAW,IAAIA,WAAW,CAACE,QAAQ,CAACD,QAAQ,CAAC;AAClE;;AAEO,MAAME,cAAc,CAA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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) { logger.error(e); return log; @@ -65,6 +65,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 new file mode 100644 index 0000000..8b3e596 --- /dev/null +++ b/dist/lib/EventDecoder.js.map @@ -0,0 +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,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;IACvE,IAAIF,OAAO,CAACG,YAAY,EA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AC/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 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/btcUtils.js.map b/dist/lib/btcUtils.js.map new file mode 100644 index 0000000..8ec8567 --- /dev/null +++ b/dist/lib/btcUtils.js.map @@ -0,0 +1 @@ +{"version":3,"file":"btcUtils.js","names":["_crypto","_interopRequireDefault","require","bs58","_interopRequireWildcard","_rskUtils","_secp256k","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","default","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","prototype","hasOwnProperty","call","i","set","obj","PREFIXES","mainnet","pubKeyHash","scriptHash","testnet","regtest","getNetPrefix","netName","prefixes","Error","createHash","val","from","to","crypto","update","digest","sha256","remove0x","exports","h160","h160toAddress","hash160","network","prefixKey","prefix","Buffer","isBuffer","toString","check","slice","encode","pubToAddress","pub","parsePublic","compressed","secp256k1","publicKeyConvert","decompressPublic","compressPublic","rskAddressFromBtcPublicKey","cpk","add0x","keccak256"],"sources":["../../src/lib/btcUtils.js"],"sourcesContent":["import crypto from 'crypto'\nimport * as bs58 from 'bs58'\nimport { remove0x, add0x, keccak256 } from '@rsksmart/rsk-utils'\nimport secp256k1 from 'secp256k1'\n\nconst PREFIXES = {\n mainnet: {\n pubKeyHash: '00',\n scriptHash: '05'\n },\n testnet: {\n pubKeyHash: '6F',\n scriptHash: 'C4'\n },\n regtest: {\n pubKeyHash: '00',\n scriptHash: '00'\n }\n}\nconst getNetPrefix = netName => {\n let prefixes = PREFIXES[netName]\n if (!prefixes) throw new Error(`Unknown network ${netName}`)\n return prefixes\n}\n\nconst createHash = (a, val, from = 'hex', to = 'hex') => crypto.createHash(a).update(val, from).digest(to)\n\nexport const sha256 = (val, from, to) => createHash('sha256', remove0x(val), from, to)\n\nexport const h160 = (val, from, to) => createHash('ripemd160', remove0x(val), from, to)\n\nexport const h160toAddress = (hash160, { network, prefixKey }) => {\n network = network || 'mainnet'\n prefixKey = prefixKey || 'pubKeyHash'\n const prefix = getNetPrefix(network)[prefixKey]\n hash160 = (Buffer.isBuffer(hash160)) ? hash160.toString('hex') : remove0x(hash160)\n hash160 = `${prefix}${hash160}`\n let check = sha256(sha256(hash160)).slice(0, 8)\n return bs58.encode(Buffer.from(`${hash160}${check}`, 'hex'))\n}\n\nexport const pubToAddress = (pub, network) => {\n return h160toAddress(h160(sha256(remove0x(pub))), { network })\n}\n\nexport const parsePublic = (pub, compressed) => {\n pub = (!Buffer.isBuffer(pub)) ? Buffer.from(remove0x(pub), 'hex') : pub\n return secp256k1.publicKeyConvert(pub, compressed)\n}\n\nexport const decompressPublic = compressed => parsePublic(compressed, false).toString('hex')\n\nexport const compressPublic = pub => parsePublic(pub, true).toString('hex')\n\nexport const rskAddressFromBtcPublicKey = cpk => add0x(keccak256(parsePublic(cpk, false).slice(1)).slice(-40))\n"],"mappings":"gRAAA,IAAAA,OAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,IAAA,GAAAC,uBAAA,CAAAF,OAAA;AACA,IAAAG,SAAA,GAAAH,OAAA;AACA,IAAAI,SAA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,WAAW,CAACC,UAAU,EAAE,KAAK,CAAC,CAACP,QAAQ,CAAC,KAAK,CAAC,CAAAT,OAAA,CAAAmB,gBAAA,GAAAA,gBAAA;;AAErF,MAAMC,cAAc,GAAGA,CAAAN,GAAG,KAAIC,WAAW,CAACD,GAAG,EAAE,IAAI,CAAC,CAACL,QAAQ,CAAC,KAAK,CAAC,CAAAT,OAAA,CAAAoB,cAAA,GAAAA,cAAA;;AAEpE,MAAMC,0BAA0B,GAAGA,CAAAC,GAAG,KAAI,IAAAC,eAAK,EAAC,IAAAC,mBAAS,EAACT,WAAW,CAACO,GAAG,EAAE,KAAK,CAAC,CAACX,KAAK,CAAC,CAAC,CAAC,CAAC,CAACA,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAAX,OAAA,CAAAqB,0BAAA,GAAAA,0BAAA"} \ 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/compileJsonAbis.js.map b/dist/lib/compileJsonAbis.js.map new file mode 100644 index 0000000..91c2d7a --- /dev/null +++ b/dist/lib/compileJsonAbis.js.map @@ -0,0 +1 @@ +{"version":3,"file":"compileJsonAbis.js","names":["_fs","_interopRequireDefault","require","_util","_path","_types","_utils","obj","__esModule","default","readDir","util","promisify","fs","readdir","readFile","writeFile","jsonPath","__dirname","ozPath","path","resolve","destinationFile","compileAbi","then","abi","JSON","stringify","console","log","process","exit","dirs","jsonFiles","dir","files","filter","file","extname","length","Error","concat","map","Promise","all","readJson","content","Array","isArray","reduce","a","v","i","array","processAbi","err","json","parse","reject","type","Set","addSignatureDataToAbi","signatures","ABI_SIGNATURE","signature","fourBytes","s","slice","indexOf","filterEvents","on","error"],"sources":["../../src/lib/compileJsonAbis.js"],"sourcesContent":["import fs from 'fs'\nimport util from 'util'\nimport path from 'path'\nimport { ABI_SIGNATURE } from './types'\nimport { addSignatureDataToAbi, filterEvents } from './utils'\n\nconst readDir = util.promisify(fs.readdir)\nconst readFile = util.promisify(fs.readFile)\nconst writeFile = util.promisify(fs.writeFile)\n\nconst jsonPath = `${__dirname}/jsonAbis`\nconst ozPath = path.resolve('node_modules/openzeppelin-solidity/build/contracts')\nconst destinationFile = `${__dirname}/compiled_abi.json`\n\ncompileAbi([jsonPath, ozPath]).then(abi => {\n writeFile(destinationFile, JSON.stringify(abi, null, 2))\n .then(() => {\n console.log(`New ABI saved on ${destinationFile}`)\n process.exit(0)\n })\n})\n\nasync function compileAbi (dirs) {\n try {\n let jsonFiles = []\n for (let dir of dirs) {\n let files = await readDir(dir)\n files = files.filter(file => path.extname(file) === '.json')\n if (!files || !files.length) throw new Error(`No json files in dir ${dir}`)\n jsonFiles = jsonFiles.concat(files.map(file => `${dir}/${file}`))\n }\n let abi = await Promise.all(jsonFiles.map(file => readJson(`${file}`).then(content => {\n return (Array.isArray(content)) ? content : content.abi\n })))\n if (!abi) throw new Error(`Invalid abi `)\n abi = abi.reduce((a, v, i, array) => v.concat(a))\n abi = processAbi(abi)\n return abi\n } catch (err) {\n console.log('Compile Error', err)\n process.exit(9)\n }\n}\n\nasync function readJson (file) {\n console.log(`Reading file ${file}`)\n try {\n let json = await readFile(file, 'utf-8')\n return JSON.parse(json)\n } catch (err) {\n console.log(file, err)\n return Promise.reject(err)\n }\n}\n\nexport function processAbi (abi) {\n // remove fallbacks\n abi = abi.filter(a => a.type !== 'fallback')\n // remove duplicates\n abi = [...new Set(abi.map(a => JSON.stringify(a)))].map(a => JSON.parse(a))\n // add signatures\n abi = addSignatureDataToAbi(abi)\n // detect 4 bytes collisions\n let signatures = (abi.map(a => a[ABI_SIGNATURE].signature)).filter(v => v)\n signatures = [...new Set(signatures)]\n let fourBytes = signatures.map(s => s.slice(0, 8))\n if (fourBytes.length !== [...new Set(fourBytes)].length) {\n console.log(fourBytes.filter((v, i) => fourBytes.indexOf(v) !== i))\n throw new Error('4bytes collision')\n }\n // filter events\n abi = filterEvents(abi)\n return abi\n}\n\nprocess.on('unhandledRejection', err => {\n console.error(err)\n process.exit(9)\n})\n"],"mappings":"2GAAA,IAAAA,GAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,KAAA,GAAAF,sBAAA,CAAAC,OAAA;AACA,IAAAE,KAAA,GAAAH,sBAAA,CAAAC,OAAA;AACA,IAAAG,MAAA,GAAAH,OAAA;AACA,IAAAI,MAAA,GAAAJ,OAAA,YAA6D,SAAAD,uBAAAM,GAAA,UAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;;AAE7D,MAAMG,OAAO,GAAGC,aAAI,CAACC,SAAS,CAACC,WAAE,CAACC,OAAO,CAAC;AAC1C,MAAMC,QAAQ,GAAGJ,aAAI,CAACC,SAAS,CAACC,WAAE,CAACE,QAAQ,CAAC;AAC5C,MAAMC,SAAS,GAAGL,aAAI,CAACC,SAAS,CAACC,WAAE,CAACG,SAAS,CAAC;;AAE9C,MAAMC,QAAQ,GAAI,GAAEC,SAAU,WAAU;AACxC,MAAMC,MAAM,GAAGC,aAAI,CAACC,OAAO,CAAC,oDAAoD,CAAC;AACjF,MAAMC,eAAe,GAAI,GAAEJ,SAAU,oBAAmB;;AAExDK,UAAU,CAAC,CAACN,QAAQ,EAAEE,MAAM,CAAC,CAAC,CAACK,IAAI,CAAC,CAAAC,GAAG,KAAI;EACzCT,SAAS,CAACM,eAAe,EAAEI,IAAI,CAACC,SAAS,CAACF,GAAG,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;EACrDD,IAAI,CAAC,MAAM;IACVI,OAAO,CAACC,GAAG,CAAE,oBAAmBP,eAAgB,EAAC,CAAC;IAClDQ,OAAO,CAACC,I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IG,SAAS,GAAGH,UAAU,CAACpB,GAAG,CAAC,CAAAwB,CAAC,KAAIA,CAAC,CAACC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;EAClD,IAAIF,SAAS,CAAC1B,MAAM,KAAK,CAAC,GAAG,IAAIqB,GAAG,CAACK,SAAS,CAAC,CAAC,CAAC1B,MAAM,EAAE;IACvDX,OAAO,CAACC,GAAG,CAACoC,SAAS,CAAC7B,MAAM,CAAC,CAACe,CAAC,EAAEC,CAAC,KAAKa,SAAS,CAACG,OAAO,CAACjB,CAAC,CAAC,KAAKC,CAAC,CAAC,CAAC;IACnE,MAAM,IAAIZ,KAAK,CAAC,kBAAkB,CAAC;EACrC;EACA;EACAf,GAAG,GAAG,IAAA4C,mBAAY,EAAC5C,GAAG,CAAC;EACvB,OAAOA,GAAG;AACZ;;AAEAK,OAAO,CAACwC,EAAE,CAAC,oBAAoB,EAAE,CAAAf,GAAG,KAAI;EACtC3B,OAAO,CAAC2C,KAAK,CAAChB,GAAG,CAAC;EAClBzB,OAAO,CAACC,IAAI,CAAC,CAAC,CAAC;AACjB,CAAC,CAAC"} \ 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/interfacesIds.js.map b/dist/lib/interfacesIds.js.map new file mode 100644 index 0000000..21ee7a1 --- /dev/null +++ b/dist/lib/interfacesIds.js.map @@ -0,0 +1 @@ +{"version":3,"file":"interfacesIds.js","names":["_utils","require","erc20methods","erc677Methods","concat","interfacesIds","exports","ERC20","makeInterface","ERC677","ERC165","ERC721","ERC721Enumerable","ERC721Metadata","ERC721Exists","methods","id","erc165IdFromMethods","_default","default"],"sources":["../../src/lib/interfacesIds.js"],"sourcesContent":["import { erc165IdFromMethods } from './utils'\n\nconst erc20methods = [\n 'totalSupply()',\n 'balanceOf(address)',\n 'allowance(address,address)',\n 'transfer(address,uint256)',\n 'approve(address,uint256)',\n 'transferFrom(address,address,uint256)'\n]\n\nconst erc677Methods = erc20methods.concat([\n 'transferAndCall(address,uint256,bytes)'\n])\n\nexport const interfacesIds = {\n ERC20: makeInterface(erc20methods),\n ERC677: makeInterface(erc677Methods),\n ERC165: makeInterface(['supportsInterface(bytes4)']),\n ERC721: makeInterface([\n 'balanceOf(address)',\n 'ownerOf(uint256)',\n 'approve(address,uint256)',\n 'getApproved(uint256)',\n 'setApprovalForAll(address,bool)',\n 'isApprovedForAll(address,address)',\n 'transferFrom(address,address,uint256)',\n 'safeTransferFrom(address,address,uint256)',\n 'safeTransferFrom(address,address,uint256,bytes)'\n ]),\n ERC721Enumerable: makeInterface([\n 'totalSupply()',\n 'tokenOfOwnerByIndex(address,uint256)',\n 'tokenByIndex(uint256)'\n ]),\n ERC721Metadata: makeInterface([\n 'name()',\n 'symbol()',\n 'tokenURI(uint256)'\n ]),\n ERC721Exists: makeInterface([\n 'exists(uint256)'\n ])\n}\n\nfunction makeInterface (methods) {\n let id = erc165IdFromMethods(methods)\n return { methods, id }\n}\n\nexport default interfacesIds\n"],"mappings":"4HAAA,IAAAA,MAAA,GAAAC,OAAA;;AAEA,MAAMC,YAAY,GAAG;AACnB,eAAe;AACf,oBAAoB;AACpB,4BAA4B;AAC5B,2BAA2B;AAC3B,0BAA0B;AAC1B,uCAAuC,CACxC;;;AAED,MAAMC,aAAa,GAAGD,YAAY,CAACE,MAAM,CAAC;AACxC,wCAAwC;AACzC,CAAC;;AAEK,MAAMC,aAAa,GAAAC,OAAA,CAAAD,aAAA,GAAG;EAC3BE,KAAK,EAAEC,aAAa,CAACN,YAAY,CAAC;EAClCO,MAAM,EAAED,aAAa,CAACL,aAAa,CAAC;EACpCO,MAAM,EAAEF,aAAa,CAAC,CAAC,2BAA2B,CAAC,CAAC;EACpDG,MAAM,EAAEH,aAAa,CAAC;EACpB,oBAAoB;EACpB,kBAAkB;EAClB,0BAA0B;EAC1B,sBAAsB;EACtB,iCAAiC;EACjC,mCAAmC;EACnC,uCAAuC;EACvC,2CAA2C;EAC3C,iDAAiD;EAClD,CAAC;EACFI,gBAAgB,EAAEJ,aAAa,CAAC;EAC9B,eAAe;EACf,sCAAsC;EACtC,uBAAuB;EACxB,CAAC;EACFK,cAAc,EAAEL,aAAa,CAAC;EAC5B,QAAQ;EACR,UAAU;EACV,mBAAmB;EACpB,CAAC;EACFM,YAAY,EAAEN,aAAa,CAAC;EAC1B,iBAAiB;EAClB;AACH,CAAC;;AAED,SAASA,aAAaA,CAAEO,OAAO,EAAE;EAC/B,IAAIC,EAAE,GAAG,IAAAC,0BAAmB,EAACF,OAAO,CAAC;EACrC,OAAO,EAAEA,OAAO,EAAEC,EAAE,CAAC,CAAC;AACxB,CAAC,IAAAE,QAAA,GAAAZ,OAAA,CAAAa,OAAA;;AAEcd,aAAa"} \ 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/FakeABI.js.map b/dist/lib/nativeContracts/FakeABI.js.map new file mode 100644 index 0000000..7d8de7c --- /dev/null +++ b/dist/lib/nativeContracts/FakeABI.js.map @@ -0,0 +1 @@ +{"version":3,"file":"FakeABI.js","names":["_rskUtils","require","_utils","btcUtils","_interopRequireWildcard","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","default","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","prototype","hasOwnProperty","call","i","set","FakeABI","network","decodeBtcTxHash","data","remove0x","length","buffer","Buffer","from","add0x","toString","decodeArray","map","d","Array","isArray","decodeFederationData","a160","keys","address","h160toAddress","prefixKey","rskAddressFromBtcPublicKey","commitFederationDecoder","decoded","rlp","decode","oldData","newData","block","oldFederationAddress","oldFederationMembers","newFederationAddress","newFederationMembers","freeze","addSignatureDataToAbi","anonymous","inputs","indexed","name","type","_filter","_decoder"],"sources":["../../../src/lib/nativeContracts/FakeABI.js"],"sourcesContent":["\nimport { remove0x, add0x, rlp } from '@rsksmart/rsk-utils'\nimport { addSignatureDataToAbi } from '../utils'\nimport * as btcUtils from '../btcUtils'\n\nexport default function FakeABI (network) {\n const decodeBtcTxHash = data => {\n if (remove0x(data).length === 128) {\n let buffer = Buffer.from(remove0x(data), 'hex')\n data = add0x(buffer.toString('ascii'))\n }\n return data\n }\n const decodeArray = data => data.map(d => Array.isArray(d) ? decodeArray(d) : add0x(d.toString('hex')))\n\n const decodeFederationData = data => {\n let [a160, keys] = data\n let address = btcUtils.h160toAddress(a160, { prefixKey: 'scriptHash', network }).toString('hex')\n keys = keys.map(d => btcUtils.rskAddressFromBtcPublicKey(d.toString('hex')))\n return [address, keys]\n }\n\n const commitFederationDecoder = data => {\n const decoded = rlp.decode(data)\n let [oldData, newData, block] = decoded\n let [oldFederationAddress, oldFederationMembers] = decodeFederationData(oldData)\n let [newFederationAddress, newFederationMembers] = decodeFederationData(newData)\n block = block.toString('ascii')\n return [oldFederationAddress, oldFederationMembers, newFederationAddress, newFederationMembers, block]\n }\n return Object.freeze(addSignatureDataToAbi([\n { // Remasc events\n anonymous: false,\n inputs: [\n {\n indexed: true,\n name: 'to',\n type: 'address'\n },\n {\n indexed: false,\n name: 'blockHash',\n type: 'string'\n },\n {\n indexed: false,\n name: 'value',\n type: 'uint256'\n }\n ],\n name: 'mining_fee_topic',\n type: 'event'\n },\n { // Bridge events\n inputs: [\n {\n indexed: false,\n name: 'btcTxHash',\n type: 'string'\n },\n {\n indexed: false,\n name: 'btcTx', // raw tx?\n type: 'string'\n }\n ],\n name: 'release_btc_topic',\n type: 'event'\n },\n {\n inputs: [\n {\n indexed: false,\n name: 'sender',\n type: 'address'\n }\n ],\n name: 'update_collections_topic',\n type: 'event'\n },\n {\n inputs: [\n {\n indexed: false,\n name: 'btcTxHash',\n type: 'string',\n _filter: decodeBtcTxHash\n },\n {\n indexed: false,\n name: 'federatorPublicKey',\n type: 'string'\n },\n {\n indexed: false,\n name: 'rskTxHash',\n type: 'string'\n }\n ],\n name: 'add_signature_topic',\n type: 'event'\n },\n {\n inputs: [\n {\n indexed: false,\n name: 'oldFederationAddress',\n type: 'string'\n },\n {\n indexed: false,\n name: 'oldFederationMembers',\n type: 'address[]'\n },\n {\n indexed: false,\n name: 'newFederationAddress',\n type: 'string'\n },\n {\n indexed: false,\n name: 'newFederationMembers',\n type: 'address[]'\n },\n {\n indexed: false,\n name: 'activationBlockNumber',\n type: 'string'\n }\n ],\n name: 'commit_federation_topic',\n type: 'event',\n _decoder: commitFederationDecoder\n }\n ]))\n}\n"],"mappings":";AACA,IAAAA,SAAA,GAAAC,OAAA;AACA,IAAAC,MAAA,GAAAD,OAAA;AACA,IAAAE,QAAA,GAAAC,uBAAA,CAAAH,OAAA,iBAAuC,SAAAI,yBAAAC,CAAA,4BAAAC,OAAA,kBAAAC,CAAA,OAAAD,OAAA,GAAAE,CAAA,OAAAF,OAAA,WAAAF,wBAAA,YAAAA,CAAAC,CAAA,UAAAA,CAAA,GAAAG,CAAA,GAAAD,CAAA,IAAAF,CAAA,YAAAF,wBAAAE,CAAA,EAAAE,CAAA,QAAAA,CAAA,IAAAF,CAAA,IAAAA,CAAA,CAAAI,UAAA,SAAAJ,CAAA,cAAAA,CAAA,uBAAAA,CAAA,yBAAAA,CAAA,WAAAK,OAAA,EAAAL,CAAA,OAAAG,CAAA,GAAAJ,wBAAA,CAAAG,CAAA,MAAAC,CAAA,IAAAA,CAAA,CAAAG,GAAA,CAAAN,CAAA,UAAAG,CAAA,CAAAI,GAAA,CAAAP,CAAA,MAAAQ,CAAA,KAAAC,SAAA,SAAAC,CAAA,GAAAC,MAAA,CAAAC,cAAA,IAAAD,MAAA,CAAAE,wBAAA,UAAAC,CAAA,IAAAd,CAAA,oBAAAc,CAAA,IAAAH,MAAA,CAAAI,SAAA,CAAAC,cAAA,C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AAE;IACR,CAAC,CACF;;IACDD,IAAI,EAAE,yBAAyB;IAC/BC,IAAI,EAAE,OAAO;IACbE,QAAQ,EAAEnB;EACZ,CAAC;EACF,CAAC,CAAC;AACL"} \ 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/NativeContracts.js.map b/dist/lib/nativeContracts/NativeContracts.js.map new file mode 100644 index 0000000..0853d12 --- /dev/null +++ b/dist/lib/nativeContracts/NativeContracts.js.map @@ -0,0 +1 @@ +{"version":3,"file":"NativeContracts.js","names":["_rskUtils","require","defaultNativeContracts","exports","bridge","remasc","parseNativeContracts","nativeContracts","TypeError","Object","keys","Error","name","address","isAddress","toLowerCase","NativeContracts","names","getNativeContractAddress","contractName","getNativeContractName","find","isNativeContract","list","freeze","_default","default"],"sources":["../../../src/lib/nativeContracts/NativeContracts.js"],"sourcesContent":["\nimport { isAddress } from '@rsksmart/rsk-utils'\n\nexport const defaultNativeContracts = {\n bridge: '0x0000000000000000000000000000000001000006',\n remasc: '0x0000000000000000000000000000000001000008'\n}\n\nexport const parseNativeContracts = nativeContracts => {\n if (typeof nativeContracts !== 'object') throw new TypeError(`nativeContracts must be an object`)\n if (Object.keys(nativeContracts) < 1) throw new Error(`Empty native contracts list`)\n for (let name in nativeContracts) {\n let address = nativeContracts[name]\n if (!isAddress(address)) throw new Error(`Address of ${name} is not an address`)\n nativeContracts[name] = address.toLowerCase()\n }\n return nativeContracts\n}\n\nexport function NativeContracts ({ nativeContracts } = {}) {\n nativeContracts = parseNativeContracts(nativeContracts || defaultNativeContracts)\n const names = Object.keys(nativeContracts)\n\n const getNativeContractAddress = contractName => {\n return nativeContracts[contractName]\n }\n const getNativeContractName = address => {\n address = address.toLowerCase()\n return names.find(name => nativeContracts[name] === address)\n }\n\n const isNativeContract = address => !!getNativeContractName(address)\n\n const list = () => nativeContracts\n\n return Object.freeze({ getNativeContractAddress, getNativeContractName, isNativeContract, list })\n}\n\nexport default NativeContracts\n"],"mappings":";AACA,IAAAA,SAAA,GAAAC,OAAA;;AAEO,MAAMC,sBAAsB,GAAAC,OAAA,CAAAD,sBAA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O,qBAAqB,CAACP,OAAO,CAAC;;EAEpE,MAAMU,IAAI,GAAGA,CAAA,KAAMhB,eAAe;;EAElC,OAAOE,MAAM,CAACe,MAAM,CAAC,EAAEN,wBAAwB,EAAEE,qBAAqB,EAAEE,gBAAgB,EAAEC,IAAI,CAAC,CAAC,CAAC;AACnG,CAAC,IAAAE,QAAA,GAAAtB,OAAA,CAAAuB,OAAA;;AAEcV,eAAe"} \ 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/NativeContractsDecoder.js.map b/dist/lib/nativeContracts/NativeContractsDecoder.js.map new file mode 100644 index 0000000..90690b6 --- /dev/null +++ b/dist/lib/nativeContracts/NativeContractsDecoder.js.map @@ -0,0 +1 @@ +{"version":3,"file":"NativeContractsDecoder.js","names":["_NativeContractsEvents","_interopRequireDefault","require","_EventDecoder","_bridgeAbi","_utils","obj","__esModule","default","NativeContractsEventDecoder","bitcoinNetwork","txBlockNumber","nativeDecoder","NativeContractsEvents","ABI","addSignatureDataToAbi","getBridgeAbi","solidityDecoder","EventDecoder","getEventDecoder","log","eventABI","getEventAbi","topics","Object","freeze"],"sources":["../../../src/lib/nativeContracts/NativeContractsDecoder.js"],"sourcesContent":["import NativeContractsEvents from './NativeContractsEvents'\nimport EventDecoder from '../EventDecoder'\nimport { getBridgeAbi } from './bridgeAbi'\nimport { addSignatureDataToAbi } from '../utils'\n\nexport default function NativeContractsEventDecoder ({ bitcoinNetwork, txBlockNumber }) {\n const nativeDecoder = NativeContractsEvents({ bitcoinNetwork })\n const ABI = addSignatureDataToAbi(getBridgeAbi({ txBlockNumber, bitcoinNetwork }))\n const solidityDecoder = EventDecoder(ABI)\n\n const getEventDecoder = log => {\n const { eventABI } = solidityDecoder.getEventAbi([...log.topics])\n return (eventABI) ? solidityDecoder : nativeDecoder\n }\n return Object.freeze({ getEventDecoder })\n}\n"],"mappings":"yHAAA,IAAAA,sBAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,aAAA,GAAAF,sBAAA,CAAAC,OAAA;AACA,IAAAE,UAAA,GAAAF,OAAA;AACA,IAAAG,MAAA,GAAAH,OAAA,aAAgD,SAAAD,uBAAAK,GAAA,UAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;;AAEjC,SAASG,2BAA2BA,CAAE,EAAEC,cAAc,EAAEC,aAAa,CAAC,CAAC,EAAE;EACtF,MAAMC,aAAa,GAAG,IAAAC,8BAAqB,EAAC,EAAEH,cAAc,CAAC,CAAC,CAAC;EAC/D,MAAMI,GAAG,GAAG,IAAAC,4BAAqB,EAAC,IAAAC,uBAAY,EAAC,EAAEL,aAAa,EAAED,cAAc,CAAC,CAAC,CAAC,CAAC;EAClF,MAAMO,eAAe,GAAG,IAAAC,qBAAY,EAACJ,GAAG,CAAC;;EAEzC,MAAMK,eAAe,GAAGA,CAAAC,GAAG,KAAI;IAC7B,MAAM,EAAEC,QAAQ,CAAC,CAAC,GAAGJ,eAAe,CAACK,WAAW,CAAC,CAAC,GAAGF,GAAG,CAACG,MAAM,CAAC,CAAC;IACjE,OAAQF,QAAQ,GAAIJ,eAAe,GAAGL,aAAa;EACrD,CAAC;EACD,OAAOY,MAAM,CAACC,MAAM,CAAC,EAAEN,eAAe,CAAC,CAAC,CAAC;AAC3C"} \ 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/NativeContractsEvents.js.map b/dist/lib/nativeContracts/NativeContractsEvents.js.map new file mode 100644 index 0000000..4b8cbb7 --- /dev/null +++ b/dist/lib/nativeContracts/NativeContractsEvents.js.map @@ -0,0 +1 @@ +{"version":3,"file":"NativeContractsEvents.js","names":["_rskUtils","require","_utils","_FakeABI","_interopRequireDefault","obj","__esModule","default","NativeContractsEvents","bitcoinNetwork","network","fakeAbi","FakeAbi","decodeAddress","address","Buffer","from","remove0x","add0x","toString","slice","decodeEventName","name","replace","removeEmptyStartBytes","d","isBuffer","findIndex","x","decodeData","data","decoded","rlp","decode","Array","isArray","map","getEventAbi","eventName","find","a","type","decodeByType","value","decodeInput","input","_filter","removeCustomProperties","res","Object","assign","p","cleanAbi","abi","inputs","decodeLog","log","topics","event","shift","signature","getSignatureDataFromAbi","args","decoder","_decoder","dataDecoded","i","indexed","length","push","freeze","_default","exports"],"sources":["../../../src/lib/nativeContracts/NativeContractsEvents.js"],"sourcesContent":["import { remove0x, add0x, rlp } from '@rsksmart/rsk-utils'\nimport { getSignatureDataFromAbi } from '../utils'\nimport FakeAbi from './FakeABI'\nexport function NativeContractsEvents ({ bitcoinNetwork } = {}) {\n const network = bitcoinNetwork || 'testnet'\n const fakeAbi = FakeAbi(network)\n const decodeAddress = address => {\n address = Buffer.from(remove0x(address), 'hex')\n return add0x(address.toString('hex').slice(-40))\n }\n\n const decodeEventName = name => {\n return Buffer.from(remove0x(name), 'hex').toString('ascii').replace(/\\0/g, '')\n }\n\n const removeEmptyStartBytes = d => {\n d = (!Buffer.isBuffer(d)) ? Buffer.from(d, 'hex') : d\n return d.slice(d.findIndex(x => x > 0))\n }\n\n const decodeData = data => {\n let decoded = rlp.decode(data)\n if (!Array.isArray(decoded)) decoded = [decoded]\n return decoded.map(d => add0x(removeEmptyStartBytes(d).toString('hex')))\n }\n\n const getEventAbi = eventName => fakeAbi.find(a => a.name === eventName && a.type === 'event')\n\n const decodeByType = (type, value) => {\n if (type === 'address') return decodeAddress(value)\n return value\n }\n\n const decodeInput = (input, value) => {\n let { type, _filter } = input\n if (_filter && typeof _filter === 'function') {\n value = _filter(value)\n }\n return decodeByType(type, value)\n }\n\n const removeCustomProperties = obj => {\n const res = Object.assign({}, obj)\n for (let p in res) {\n if (p[0] === '_') delete res[p]\n }\n return res\n }\n\n const cleanAbi = abi => {\n abi = removeCustomProperties(abi)\n let { inputs } = abi\n if (Array.isArray(inputs)) abi.inputs = inputs.map(input => removeCustomProperties(input))\n return abi\n }\n\n const decodeLog = log => {\n let topics = [...log.topics]\n let event = decodeEventName(topics.shift())\n let abi = getEventAbi(event)\n if (event && abi) {\n const { signature } = getSignatureDataFromAbi(abi)\n log.event = event\n log.signature = signature\n log.abi = cleanAbi(abi)\n log.args = []\n const decoder = abi._decoder || decodeData\n let dataDecoded = decoder(log.data)\n if (!Array.isArray(dataDecoded)) dataDecoded = [dataDecoded]\n for (let i in abi.inputs) {\n let input = abi.inputs[i]\n let { indexed } = input\n let value = (indexed === true) ? topics[i] : dataDecoded[i - topics.length]\n let decoded = decodeInput(input, value)\n if (decoded) log.args.push(decoded)\n }\n }\n return log\n }\n return Object.freeze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,KAAK,GAAGQ,GAAG,CAACC,MAAM,CAACY,CAAC,CAAC;QACzB,IAAI,EAAEC,OAAO,CAAC,CAAC,GAAGtB,KAAK;QACvB,IAAIF,KAAK,GAAIwB,OAAO,KAAK,IAAI,GAAIV,MAAM,CAACS,CAAC,CAAC,GAAGD,WAAW,CAACC,CAAC,GAAGT,MAAM,CAACW,MAAM,CAAC;QAC3E,IAAIrC,OAAO,GAAGa,WAAW,CAACC,KAAK,EAAEF,KAAK,CAAC;QACvC,IAAIZ,OAAO,EAAEyB,GAAG,CAACM,IAAI,CAACO,IAAI,CAACtC,OAAO,CAAC;MACrC;IACF;IACA,OAAOyB,GAAG;EACZ,CAAC;EACD,OAAOP,MAAM,CAACqB,MAAM,CAAC,EAAEf,SAAS,EAAEF,GAAG,EAAE1C,OAAO,CAAC,CAAC,CAAC;AACnD,CAAC,IAAA4D,QAAA,GAAAC,OAAA,CAAAjE,OAAA;;AAEcC,qBAAqB"} \ 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/nativeContracts/bridgeAbi.js.map b/dist/lib/nativeContracts/bridgeAbi.js.map new file mode 100644 index 0000000..b4d8c81 --- /dev/null +++ b/dist/lib/nativeContracts/bridgeAbi.js.map @@ -0,0 +1 @@ +{"version":3,"file":"bridgeAbi.js","names":["_bridgeOrchid","_interopRequireDefault","require","_bridgeWasabi","_bridgePapyrus","_bridgeIris","_bridgeFingerroot","_bridgeHop","obj","__esModule","default","RELEASES","exports","mainnet","height","abi","orchid","wasabi","papyrus","iris","hop","fingerroot","testnet","findmatchingAbi","txHeight","abisWithHeight","lastIndex","length","undefined","i","previous","getBridgeAbi","txBlockNumber","bitcoinNetwork","includes","Error"],"sources":["../../../src/lib/nativeContracts/bridgeAbi.js"],"sourcesContent":["import orchid from './bridge-orchid.json'\nimport wasabi from './bridge-wasabi.json'\nimport papyrus from './bridge-papyrus.json'\nimport iris from './bridge-iris.json'\nimport fingerroot from './bridge-fingerroot.json'\nimport hop from './bridge-hop.json'\n\nexport const RELEASES = {\n mainnet: [\n { height: 0, abi: orchid },\n { height: 1591000, abi: wasabi },\n { height: 2392700, abi: papyrus },\n { height: 3614800, abi: iris },\n { height: 4598500, abi: hop },\n { height: 5468000, abi: fingerroot }\n ],\n testnet: [\n { height: 0, abi: wasabi },\n { height: 863000, abi: papyrus },\n { height: 2060500, abi: iris },\n { height: 3103000, abi: hop },\n { height: 4015800, abi: fingerroot }\n ]\n}\n\nfunction findmatchingAbi (txHeight, abisWithHeight) {\n const lastIndex = abisWithHeight.length - 1\n\n if (txHeight >= abisWithHeight[lastIndex].height || txHeight === undefined) {\n return abisWithHeight[lastIndex].abi\n }\n\n for (let i = 1; i <= lastIndex; i++) {\n const previous = abisWithHeight[i - 1]\n if (txHeight >= previous.height && txHeight < abisWithHeight[i].height) {\n return previous.abi\n }\n }\n}\n\nexport function getBridgeAbi ({ txBlockNumber, bitcoinNetwork }) {\n if (!['testnet', 'mainnet'].includes(bitcoinNetwork)) {\n throw new Error('Invalid bitcoin network')\n }\n\n return findmatchingAbi(txBlockNumber, RELEASES[bitcoinNetwork])\n}\n"],"mappings":"yIAAA,IAAAA,aAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,aAAA,GAAAF,sBAAA,CAAAC,OAAA;AACA,IAAAE,cAAA,GAAAH,sBAAA,CAAAC,OAAA;AACA,IAAAG,WAAA,GAAAJ,sBAAA,CAAAC,OAAA;AACA,IAAAI,iBAAA,GAAAL,sBAAA,CAAAC,OAAA;AACA,IAAAK,UAAA,GAAAN,sBAAA,CAAAC,OAAA,uBAAmC,SAAAD,uBAAAO,GAAA,UAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;;AAE5B,MAAMG,QAAQ,GAAAC,OAAA,CAAAD,QAAA,GAAG;EACtBE,OAAO,EAAE;EACP,EAAEC,MAAM,EAAE,CAAC,EAAEC,GAAG,EAAEC,qBAAM,CAAC,CAAC;EAC1B,EAAEF,MAAM,EAAE,OAAO,EAAEC,GAAG,EAAEE,qBAAM,CAAC,CAAC;EAChC,EAAEH,MAAM,EAAE,OAAO,EA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;AAEO,SAASgB,YAAYA,CAAE,EAAEC,aAAa,EAAEC,cAAc,CAAC,CAAC,EAAE;EAC/D,IAAI,CAAC,CAAC,SAAS,EAAE,SAAS,CAAC,CAACC,QAAQ,CAACD,cAAc,CAAC,EAAE;IACpD,MAAM,IAAIE,KAAK,CAAC,yBAAyB,CAAC;EAC5C;;EAEA,OAAOZ,eAAe,CAACS,aAAa,EAAErB,QAAQ,CAACsB,cAAc,CAAC,CAAC;AACjE"} \ 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/nod3Connect.js.map b/dist/lib/nod3Connect.js.map new file mode 100644 index 0000000..d7c8fb2 --- /dev/null +++ b/dist/lib/nod3Connect.js.map @@ -0,0 +1 @@ +{"version":3,"file":"nod3Connect.js","names":["_nod","_interopRequireDefault","require","obj","__esModule","default","nod3Connect","url","process","env","Nod3","providers","HttpProvider","exports","_default"],"sources":["../../src/lib/nod3Connect.js"],"sourcesContent":["import Nod3 from '@rsksmart/nod3'\n\nexport const nod3Connect = (url) => {\n url = url || process.env['RSK_NODE_URL'] || 'http://localhost:4444'\n return new Nod3(\n new Nod3.providers.HttpProvider(url)\n )\n}\n\nexport default nod3Connect()\n"],"mappings":"0HAAA,IAAAA,IAAA,GAAAC,sBAAA,CAAAC,OAAA,oBAAiC,SAAAD,uBAAAE,GAAA,UAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;;AAE1B,MAAMG,WAAW,GAAGA,CAACC,GAAG,KAAK;EAClCA,GAAG,GAAGA,GAAG,IAAIC,OAAO,CAACC,GAAG,CAAC,cAAc,CAAC,IAAI,uBAAuB;EACnE,OAAO,IAAIC,YAAI;IACb,IAAIA,YAAI,CAACC,SAAS,CAACC,YAAY,CAACL,GAAG;EACrC,CAAC;AACH,CAAC,CAAAM,OAAA,CAAAP,WAAA,GAAAA,WAAA,KAAAQ,QAAA,GAAAD,OAAA,CAAAR,OAAA;;AAEcC,WAAW,CAAC,CAAC"} \ 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/types.js.map b/dist/lib/types.js.map new file mode 100644 index 0000000..78b42a6 --- /dev/null +++ b/dist/lib/types.js.map @@ -0,0 +1 @@ +{"version":3,"file":"types.js","names":["ABI_SIGNATURE","exports","INTERFACE_ID_BYTES","bitcoinNetworks","TESTNET","MAINNET","REGTEST","bitcoinRskNetWorks","contractsInterfaces","ERC20","ERC677","ERC165","ERC721","ci","tokensInterfaces"],"sources":["../../src/lib/types.js"],"sourcesContent":["export const ABI_SIGNATURE = '__signatureData'\n\nexport const INTERFACE_ID_BYTES = 4\n\nexport const bitcoinNetworks = {\n TESTNET: 'testnet',\n MAINNET: 'mainnet',\n REGTEST: 'regtest'\n}\n\nexport const bitcoinRskNetWorks = {\n 31: bitcoinNetworks.TESTNET,\n 30: bitcoinNetworks.MAINNET,\n 33: bitcoinNetworks.REGTEST\n}\n\nexport const contractsInterfaces = {\n ERC20: 'ERC20',\n ERC677: 'ERC677',\n ERC165: 'ERC165',\n ERC721: 'ERC721'\n}\n\nconst ci = contractsInterfaces\n\nexport const tokensInterfaces = [\n ci.ERC20,\n ci.ERC677,\n ci.ERC721\n]\n"],"mappings":"uPAAO,MAAMA,aAAa,GAAAC,OAAA,CAAAD,aAAA,GAAG,iBAAiB;;AAEvC,MAAME,kBAAkB,GAAAD,OAAA,CAAAC,kBAAA,GAAG,CAAC;;AAE5B,MAAMC,eAAe,GAAAF,OAAA,CAAAE,eAAA,GAAG;EAC7BC,OAAO,EAAE,SAAS;EAClBC,OAAO,EAAE,SAAS;EAClBC,OAAO,EAAE;AACX,CAAC;;AAEM,MAAMC,kBAAkB,GAAAN,OAAA,CAAAM,kBAAA,GAAG;EAChC,EAAE,EAAEJ,eAAe,CAACC,OAAO;EAC3B,EAAE,EAAED,eAAe,CAACE,OAAO;EAC3B,EAAE,EAAEF,eAAe,CAACG;AACtB,CAAC;;AAEM,MAAME,mBAAmB,GAAAP,OAAA,CAAAO,mBAAA,GAAG;EACjCC,KAAK,EAAE,OAAO;EACdC,MAAM,EAAE,QAAQ;EAChBC,MAAM,EAAE,QAAQ;EAChBC,MAAM,EAAE;AACV,CAAC;;AAED,MAAMC,EAAE,GAAGL,mBAAmB;;AAEvB,MAAMM,gBAAgB,GAAAb,OAAA,CAAAa,gBAAA,GAAG;AAC9BD,EAAE,CAACJ,KAAK;AACRI,EAAE,CAACH,MAAM;AACTG,EAAE,CAACD,MAAM,CACV"} \ 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 diff --git a/dist/lib/utils.js.map b/dist/lib/utils.js.map new file mode 100644 index 0000000..c710fd0 --- /dev/null +++ b/dist/lib/utils.js.map @@ -0,0 +1 @@ +{"version":3,"file":"utils.js","names":["_rskUtils","require","_types","setAbi","abi","addSignatureDataToAbi","exports","abiEvents","filter","v","type","abiMethods","soliditySignature","name","keccak256","soliditySelector","signature","slice","solidityName","inputs","map","i","join","removeAbiSignatureData","Object","assign","undefined","ABI_SIGNATURE","getInputsIndexes","indexed","abiSignatureData","method","index","length","eventSignature","Buffer","from","toString","skip","value","erc165Id","selectors","id","s","reduce","a","bytes","INTERFACE_ID_BYTES","alloc","add0x","erc165IdFromMethods","methods","m","getSignatureDataFromAbi","filterEvents","events","keys","Set","e","k","find","concat","filterArr","Array","isArray","x","binarySearchNumber","searchCb","high","low","parseInt","Error","l","h","Promise","all","b","mid","Math","floor","res","err","reject"],"sources":["../../src/lib/utils.js"],"sourcesContent":["import { keccak256, add0x } from '@rsksmart/rsk-utils'\nimport { ABI_SIGNATURE, INTERFACE_ID_BYTES } from './types'\n\nexport const setAbi = abi => addSignatureDataToAbi(abi, true)\n\nexport const abiEvents = abi => abi.filter(v => v.type === 'event')\n\nexport const abiMethods = abi => abi.filter(v => v.type === 'function')\n\nexport const soliditySignature = name => keccak256(name)\n\nexport const soliditySelector = signature => signature.slice(0, 8)\n\nexport const solidityName = abi => {\n let { name, inputs } = abi\n inputs = (inputs) ? inputs.map(i => i.type) : []\n return (name) ? `${name}(${inputs.join(',')})` : null\n}\n\nexport const removeAbiSignatureData = (abi) => {\n abi = Object.assign({}, abi)\n if (undefined !== abi[ABI_SIGNATURE]) delete abi[ABI_SIGNATURE]\n return abi\n}\n\nexport const getInputsIndexes = abi => {\n let { inputs } = abi\n return (inputs && abi.type === 'event') ? inputs.map(i => i.indexed) : []\n}\n\nexport const abiSignatureData = abi => {\n let method = solidityName(abi)\n let signature = (method) ? soliditySignature(method) : null\n let index = getInputsIndexes(abi)\n let indexed = (index) ? index.filter(i => i === true).length : 0\n let eventSignature = null\n if ((method && abi.type === 'event')) {\n eventSignature = soliditySignature(`${method}${Buffer.from(index).toString('hex')}`)\n }\n return { method, signature, index, indexed, eventSignature }\n}\n\nexport const addSignatureDataToAbi = (abi, skip) => {\n abi.map((value, i) => {\n if (!value[ABI_SIGNATURE] || !skip) {\n value[ABI_SIGNATURE] = abiSignatureData(value)\n }\n })\n return abi\n}\n\nexport const erc165Id = selectors => {\n let id = selectors.map(s => Buffer.from(s, 'hex'))\n .reduce((a, bytes) => {\n for (let i = 0; i < INTERFACE_ID_BYTES; i++) {\n a[i] = a[i] ^ bytes[i]\n }\n return a\n }, Buffer.alloc(INTERFACE_ID_BYTES))\n return add0x(id.toString('hex'))\n}\n\nexport const erc165IdFromMethods = methods => {\n return erc165Id(methods.map(m => soliditySelector(soliditySignature(m))))\n}\n\nexport const getSignatureDataFromAbi = abi => {\n return abi[ABI_SIGNATURE]\n}\n\nexport function filterEvents (abi) {\n const type = 'event'\n // get events from ABI\n let events = abi.filter(a => a.type === type)\n // remove events from ABI\n abi = abi.filter(a => a.type !== type)\n let keys = [...new Set(events.map(e => e[ABI_SIGNATURE].eventSignature))]\n events = keys.map(k => events.find(e => e[ABI_SIGNATURE].eventSignature === k))\n abi = abi.concat(events)\n return abi\n}\n\nfunction filterArr (a) {\n if (!Array.isArray(a)) return a\n return a.find(x => filterArr(x))\n}\n\nexport async function binarySearchNumber (searchCb, high, low) {\n try {\n high = parseInt(high || 0)\n low = parseInt(low || 0)\n if (typeof searchCb !== 'function') throw new Error('SeachCb must be a function')\n let [l, h] = await Promise.all([low, high].map(b => searchCb(b)))\n if (l !== h) {\n if (high === low + 1) {\n return high\n } else {\n let mid = Math.floor(high / 2 + low / 2)\n let res = await Promise.all([\n binarySearchNumber(searchCb, high, mid),\n binarySearchNumber(searchCb, mid, low)])\n return filterArr(res)\n }\n }\n } catch (err) {\n return Promise.reject(err)\n }\n}\n"],"mappings":"sgBAAA,IAAAA,SAAA,GAAAC,OAAA;AACA,IAAAC,MAAA,GAAAD,OAAA;;AAEO,MAAME,MAAM,GAAGA,CAAAC,GAAG,KAAIC,qBAAqB,CAACD,GAAG,EAAE,IAAI,CAAC,CAAAE,OAAA,CAAAH,MAAA,GAAAA,MAAA;;AAEtD,MAAMI,SAAS,GAAGA,CAAAH,GAAG,KAAIA,GAAG,CAACI,MAAM,CAAC,CAAAC,CAAC,KAAIA,CAAC,CAACC,IAAI,KAAK,OAAO,CAAC,CAAAJ,OAAA,CAAAC,SAAA,GAAAA,SAAA;;AAE5D,MAAMI,UAAU,GAAGA,CAAAP,GAAG,KAAIA,GAAG,CAACI,MAAM,CAAC,CAAAC,CAAC,KAAIA,CAAC,CAACC,IAAI,KAAK,UAAU,CAAC,CAAAJ,OAAA,CAAAK,UAAA,GAAAA,UAAA;;AAEhE,MAAMC,iBAAiB,GAAGA,CAAAC,IAAI,KAAI,IAAAC,mBAAS,EAACD,IAAI,CAAC,CAAAP,OAAA,CAAAM,iBAAA,GAAAA,iBAAA;;AAEjD,MAAMG,gBAAgB,GAAGA,CAAAC,SAAS,KAA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AAC;QAC1BT,kBAAkB,CAACC,QAAQ,EAAEC,IAAI,EAAES,GAAG,CAAC;QACvCX,kBAAkB,CAACC,QAAQ,EAAEU,GAAG,EAAER,GAAG,CAAC,CAAC,CAAC;QAC1C,OAAOP,SAAS,CAACkB,GAAG,CAAC;MACvB;IACF;EACF,CAAC,CAAC,OAAOC,GAAG,EAAE;IACZ,OAAOP,OAAO,CAACQ,MAAM,CAACD,GAAG,CAAC;EAC5B;AACF"} \ No newline at end of file diff --git a/src/index.js b/src/index.js index 46dcf2a..c91b88f 100644 --- a/src/index.js +++ b/src/index.js @@ -5,3 +5,11 @@ import { getBridgeAbi } from './lib/nativeContracts/bridgeAbi' const abi = { bridge: getBridgeAbi } export { ContractParser, BcSearch, Contract, abi } export default 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 +const originalConsoleLog = console.log +console.log = function (message) { + if (!String(message).includes('duplicate definition')) { + originalConsoleLog(message) + } +}