UNPKG

witnet-solidity-bridge

Version:

Witnet Solidity Bridge contracts for EVM-compatible chains

843 lines 885 kB
{ "contractName": "Bech32", "abi": [], "metadata": "{\"compiler\":{\"version\":\"0.8.30+commit.73712a01\"},\"language\":\"Solidity\",\"output\":{\"abi\":[],\"devdoc\":{\"details\":\"Collection of functions related to the Bech32 address generation\",\"kind\":\"dev\",\"methods\":{},\"version\":1},\"userdoc\":{\"kind\":\"user\",\"methods\":{},\"version\":1}},\"settings\":{\"compilationTarget\":{\"project:/contracts/libs/Bech32.sol\":\"Bech32\"},\"evmVersion\":\"prague\",\"libraries\":{},\"metadata\":{\"bytecodeHash\":\"ipfs\"},\"optimizer\":{\"enabled\":true,\"runs\":200},\"remappings\":[]},\"sources\":{\"project:/contracts/libs/Bech32.sol\":{\"keccak256\":\"0x14618323a0efe7586c20906a2e9cee7ad63baa976ff231c57f7f2d7d3707fb8b\",\"license\":\"MIT\",\"urls\":[\"bzz-raw://a19f05fe84047a7a6d3d6fc39972b432e6e536aa70472386a9d7a6d9aab64a64\",\"dweb:/ipfs/QmcHwUY66yjiotRH4Q3kbRvSzcHyLQ1yHL3KbtQKiMhtZE\"]}},\"version\":1}", "bytecode": "0x60556032600b8282823980515f1a607314602657634e487b7160e01b5f525f60045260245ffd5b305f52607381538281f3fe730000000000000000000000000000000000000000301460806040525f5ffdfea26469706673582212201c2b58c277b06128a10efc19ef226cfe7c83a376981c7b84802e13cdd622881864736f6c634300081e0033", "deployedBytecode": "0x730000000000000000000000000000000000000000301460806040525f5ffdfea26469706673582212201c2b58c277b06128a10efc19ef226cfe7c83a376981c7b84802e13cdd622881864736f6c634300081e0033", "immutableReferences": {}, "generatedSources": [], "deployedGeneratedSources": [], "sourceMap": "211:13199:110:-:0;;;;;;;;;;;;;;;-1:-1:-1;;;211:13199:110;;;;;;;;;;;;;;;;;", "deployedSourceMap": "211:13199:110:-:0;;;;;;;;", "source": "// SPDX-License-Identifier: MIT\r\n// Stratonet Contracts (last updated v1.0.0) (utils/Bech32.sol)\r\n\r\npragma solidity ^0.8.0;\r\n\r\n/**\r\n * @dev Collection of functions related to the Bech32 address generation\r\n */\r\nlibrary Bech32 {\r\n bytes constant ALPHABET = \"qpzry9x8gf2tvdw0s3jn54khce6mua7l\";\r\n bytes constant ALPHABET_REV = hex\"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0fff0a1115141a1e0705ffffffffffffff1dff180d19090817ff12161f1b13ff010003100b1c0c0e060402ffffffffffff1dff180d19090817ff12161f1b13ff010003100b1c0c0e060402ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff\";\r\n bytes constant ALPHABET_REV_LOWER_ONLY = hex\"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0fff0a1115141a1e0705ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1dff180d19090817ff12161f1b13ff010003100b1c0c0e060402ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff\";\r\n\r\n // 0f <= 0: 48 | 30\r\n // 0a <= 2: 50 | 32\r\n // 11 <= 3: 51 | 33\r\n // 15 <= 4: 52 | 34\r\n // 14 <= 5: 53 | 35\r\n // 1a <= 6: 54 | 36\r\n // 1e <= 7: 55 | 37\r\n // 07 <= 8: 56 | 38\r\n // 05 <= 9: 57 | 39\r\n \r\n // 1d <= a: 97, 65 | 61, 41\r\n // 18 <= c: 99, 67 | 63, 43\r\n // 0d <= d: 100, 68 | 64, 44\r\n // 19 <= e: 101, 69 | 65, 45\r\n // 09 <= f: 102, 70 | 66, 46\r\n // 08 <= g: 103, 71 | 67, 47\r\n // 17 <= h: 104, 72 | 68, 48\r\n // 12 <= j: 106, 74 | 6A, 4A\r\n // 16 <= k: 107, 75 | 6B, 4B\r\n // 1f <= l: 108, 76 | 6C, 4C\r\n // 1b <= m: 109, 77 | 6D, 4D\r\n // 13 <= n: 110, 78 | 6E, 4E\r\n \r\n // 01 <= p: 112, 80 | 70, 50\r\n // 00 <= q: 113, 81 | 71, 51\r\n // 03 <= r: 114, 82 | 72, 52\r\n // 10 <= s: 115, 83 | 73, 53\r\n // 0b <= t: 116, 84 | 74, 54\r\n // 1c <= u: 117, 85 | 75, 55\r\n // 0c <= v: 118, 86 | 76, 56\r\n // 0e <= w: 119, 87 | 77, 57\r\n // 06 <= x: 120, 88 | 78, 58\r\n // 04 <= y: 121, 89 | 79, 59\r\n // 02 <= z: 122, 90 | 7A, 5A\r\n \r\n uint32 constant ENC_BECH32 = 1;\r\n uint32 constant ENC_BECH32M = 0x2bc830a3;\r\n\r\n\r\n function toBech32(\r\n address addr,\r\n string memory prefix\r\n ) internal pure returns (string memory) {\r\n return toBech32(abi.encodePacked(addr), prefix);\r\n }\r\n\r\n function toBech32(\r\n bytes memory data,\r\n string memory prefix\r\n ) internal pure returns (string memory) {\r\n bytes memory hrp = abi.encodePacked(prefix);\r\n bytes memory input = convertBits(data, 8, 5, true);\r\n return encode(hrp, input, ENC_BECH32);\r\n }\r\n\r\n function toBech32(\r\n address addr,\r\n string memory prefix,\r\n uint8 version\r\n ) internal pure returns (string memory) {\r\n return toBech32(abi.encodePacked(addr), prefix, version);\r\n }\r\n\r\n function toBech32(\r\n bytes memory data,\r\n string memory prefix,\r\n uint8 version\r\n ) internal pure returns (string memory) {\r\n bytes memory hrp = abi.encodePacked(prefix);\r\n bytes memory input = convertBits(data, 8, 5, true);\r\n uint32 enc = ENC_BECH32;\r\n if (version > 0) {\r\n enc = ENC_BECH32M;\r\n }\r\n bytes memory inputWithV = abi.encodePacked(bytes1(version), input);\r\n return encode(hrp, inputWithV, enc);\r\n }\r\n\r\n function fromBech32(\r\n string memory bechAddr\r\n ) internal pure returns (address) {\r\n (, uint8[] memory data) = decode(\r\n abi.encodePacked(bechAddr),\r\n ENC_BECH32\r\n );\r\n bytes memory input = convertBits(data, 5, 8, false);\r\n return getAddressFromBytes(input);\r\n }\r\n\r\n function fromBech32(\r\n string memory bechAddr,\r\n string memory prefix\r\n ) internal pure returns (address) {\r\n (bytes memory dHrp, uint8[] memory data) = decode(\r\n abi.encodePacked(bechAddr),\r\n ENC_BECH32\r\n );\r\n _requireHrpMatch(abi.encodePacked(prefix), dHrp);\r\n bytes memory input = convertBits(data, 5, 8, false);\r\n return getAddressFromBytes(input);\r\n }\r\n\r\n function fromBech32WithVersion(\r\n string memory bechAddr,\r\n string memory prefix,\r\n uint32 enc\r\n ) internal pure returns (uint8, bytes memory) {\r\n (bytes memory dHrp, uint8[] memory data) = decode(\r\n abi.encodePacked(bechAddr),\r\n enc\r\n );\r\n _requireHrpMatch(abi.encodePacked(prefix), dHrp);\r\n require(!(data.length < 1 || data[0] > 16), \"Bech32: wrong version\");\r\n uint8[] memory dataNoV = new uint8[](data.length - 1);\r\n for (uint8 i = 1; i < data.length; ++i) {\r\n dataNoV[i - 1] = data[i];\r\n }\r\n bytes memory input = convertBits(dataNoV, 5, 8, false);\r\n require(\r\n input.length >= 2 && input.length <= 40,\r\n \"Bech32: wrong bits length\"\r\n );\r\n require(\r\n !(data[0] == 0 && input.length != 20 && input.length != 32),\r\n \"Bech32: wrong bits length for version\"\r\n );\r\n return (uint8(data[0]), input);\r\n }\r\n\r\n function _requireHrpMatch(\r\n bytes memory hrp1,\r\n bytes memory hrp2\r\n ) internal pure {\r\n require(keccak256(hrp1) == keccak256(hrp2), \"Bech32: hrp mismatch\");\r\n }\r\n\r\n function getAddressFromBytes(\r\n bytes memory data\r\n ) internal pure returns (address) {\r\n require(data.length == 20, \"Bech32: invalid data length\");\r\n\r\n address addr;\r\n assembly {\r\n addr := mload(add(data, 20))\r\n }\r\n return addr;\r\n }\r\n\r\n function encode(\r\n bytes memory hrp,\r\n bytes memory input,\r\n uint32 enc\r\n ) internal pure returns (string memory) {\r\n unchecked {\r\n uint8[] memory checksum = createChecksum(hrp, input, enc);\r\n bytes memory result = new bytes(hrp.length + input.length + checksum.length + 1);\r\n for (uint i; i < hrp.length; ++ i) {\r\n result[i] = hrp[i];\r\n }\r\n result[hrp.length] = bytes1(\"1\");\r\n uint offset = hrp.length + 1;\r\n for (uint i; i < input.length; ++ i) {\r\n uint8 _data = uint8(input[i]);\r\n if (_data < ALPHABET.length) {\r\n result[i + offset] = ALPHABET[_data];\r\n }\r\n }\r\n offset += input.length;\r\n for (uint i; i < checksum.length; ++ i) {\r\n uint8 _data = uint8(checksum[i]);\r\n if (_data < ALPHABET.length) {\r\n result[i + offset] = ALPHABET[_data];\r\n }\r\n }\r\n return string(result);\r\n }\r\n }\r\n\r\n function decode(bytes memory bechStr, uint32 enc) \r\n internal pure \r\n returns (bytes memory hrp, uint8[] memory data)\r\n {\r\n unchecked {\r\n uint pos;\r\n require(\r\n bechStr.length <= 90, \r\n \"Bech32: invalid string length\"\r\n );\r\n for (uint p = 0; p < bechStr.length; ++ p) {\r\n uint8 charAt = uint8(bechStr[p]);\r\n require(\r\n charAt >= 33 \r\n && charAt <= 126, \r\n \"Bech32: wrong char\"\r\n );\r\n if (charAt == uint8(bytes1(\"1\"))) {\r\n require(\r\n pos == 0 \r\n && p >= 1 \r\n && p + 7 <= bechStr.length, \r\n \"Bech32: wrong pos of 1\"\r\n );\r\n pos = p;\r\n }\r\n }\r\n hrp = new bytes(pos);\r\n for (uint i; i < pos; ++ i) {\r\n hrp[i] = bechStr[i]; \r\n }\r\n data = new uint8[](bechStr.length - pos - 1);\r\n for (uint i; i < data.length; ++ i) {\r\n bytes1 charAt = ALPHABET_REV_LOWER_ONLY[uint8(bechStr[i + pos + 1])];\r\n require(charAt != 0xff, \"Bech32: byte not in alphabet\");\r\n data[i] = uint8(charAt);\r\n }\r\n require(\r\n verifyChecksum(hrp, data, enc), \r\n \"Bech32: wrong checksum\"\r\n );\r\n uint dataLength = data.length - 6;\r\n assembly {\r\n mstore(data, dataLength)\r\n }\r\n }\r\n }\r\n\r\n function hrpExpand(\r\n bytes memory hrp\r\n ) internal pure returns (uint8[] memory ret) {\r\n unchecked {\r\n ret = new uint8[](hrp.length + hrp.length + 1);\r\n for (uint p; p < hrp.length; ++ p) {\r\n ret[p] = uint8(hrp[p]) >> 5;\r\n ret[p + hrp.length + 1] = uint8(hrp[p]) & 31;\r\n }\r\n }\r\n }\r\n\r\n function polymod(uint32[] memory values) internal pure returns (uint32) {\r\n uint32 chk = 1;\r\n uint32[5] memory GEN = [\r\n 0x3b6a57b2,\r\n 0x26508e6d,\r\n 0x1ea119fa,\r\n 0x3d4233dd,\r\n 0x2a1462b3\r\n ];\r\n\r\n unchecked {\r\n for (uint32 i = 0; i < values.length; ++i) {\r\n uint32 top = chk >> 25;\r\n chk = (uint32(chk & 0x1ffffff) << 5) ^ uint32(values[i]);\r\n for (uint32 j = 0; j < 5; ++j) {\r\n if (((top >> j) & 1) == 1) {\r\n chk ^= GEN[j];\r\n }\r\n }\r\n }\r\n }\r\n\r\n return chk;\r\n }\r\n\r\n function createChecksum(\r\n bytes memory hrp,\r\n bytes memory data,\r\n uint32 enc\r\n ) internal pure returns (uint8[] memory res) {\r\n unchecked {\r\n uint8[] memory values = hrpExpand(hrp);\r\n uint32[] memory comb = new uint32[](values.length + data.length + 6);\r\n\r\n for (uint i; i < values.length + data.length; ++ i) {\r\n if (i < values.length) {\r\n comb[i] = uint32(values[i]);\r\n } else {\r\n comb[i] = uint32(uint8(data[i - values.length]));\r\n }\r\n }\r\n \r\n res = new uint8[](6);\r\n uint32 mod = polymod(comb) ^ enc;\r\n for (uint p = 0; p < 6; ++ p) {\r\n res[p] = uint8((mod >> (5 * (5 - p))) & 31);\r\n }\r\n }\r\n }\r\n\r\n function verifyChecksum(\r\n bytes memory hrp,\r\n uint8[] memory data,\r\n uint32 enc\r\n ) internal pure returns (bool) {\r\n unchecked {\r\n uint8[] memory ehrp = hrpExpand(hrp);\r\n uint32[] memory cData = new uint32[](ehrp.length + data.length);\r\n for (uint i; i < ehrp.length; ++ i) {\r\n cData[i] = uint32(ehrp[i]);\r\n }\r\n for (uint i; i < data.length; ++ i) {\r\n cData[i + ehrp.length] = uint32(data[i]);\r\n }\r\n return polymod(cData) == enc;\r\n }\r\n }\r\n\r\n function convertBits(\r\n bytes memory data,\r\n uint frombits,\r\n uint tobits,\r\n bool pad\r\n ) internal pure returns (bytes memory) {\r\n uint8[] memory dataBits = new uint8[](data.length);\r\n\r\n for (uint32 p = 0; p < dataBits.length; ++p) {\r\n dataBits[p] = uint8(data[p]);\r\n }\r\n\r\n return _convertBits(dataBits, frombits, tobits, pad);\r\n }\r\n\r\n function convertBits(\r\n uint8[] memory data,\r\n uint frombits,\r\n uint tobits,\r\n bool pad\r\n ) internal pure returns (bytes memory) {\r\n return _convertBits(data, frombits, tobits, pad);\r\n }\r\n\r\n function _convertBits(\r\n uint8[] memory dataBits,\r\n uint frombits,\r\n uint tobits,\r\n bool pad\r\n ) internal pure returns (bytes memory ret) {\r\n uint acc = 0;\r\n uint bits = 0;\r\n\r\n uint maxv = (1 << tobits) - 1;\r\n\r\n unchecked {\r\n for (uint p; p < dataBits.length; ++p) {\r\n uint8 value = dataBits[p];\r\n require(\r\n value >= 0 && (value >> frombits) == 0,\r\n \"Bech32: value must be non-negative and fit in frombits\"\r\n );\r\n\r\n acc = (acc << frombits) | value;\r\n bits += frombits;\r\n\r\n while (bits >= tobits) {\r\n bits -= tobits;\r\n ret = abi.encodePacked(\r\n ret,\r\n bytes1(uint8((acc >> bits) & maxv))\r\n );\r\n }\r\n }\r\n }\r\n\r\n if (pad) {\r\n if (bits > 0) {\r\n ret = abi.encodePacked(\r\n ret,\r\n bytes1(uint8((acc << (tobits - bits)) & maxv))\r\n );\r\n }\r\n } else {\r\n require(\r\n bits < frombits || ((acc << (tobits - bits)) & maxv) == 0,\r\n \"Bech32: invalid padding or value size\"\r\n );\r\n }\r\n }\r\n}", "sourcePath": "C:\\Users\\guill\\github\\guidiaz\\witnet-solidity-bridge\\contracts\\libs\\Bech32.sol", "ast": { "absolutePath": "project:/contracts/libs/Bech32.sol", "exportedSymbols": { "Bech32": [ 31372 ] }, "id": 31373, "license": "MIT", "nodeType": "SourceUnit", "nodes": [ { "id": 29986, "literals": [ "solidity", "^", "0.8", ".0" ], "nodeType": "PragmaDirective", "src": "100:23:110" }, { "abstract": false, "baseContracts": [], "canonicalName": "Bech32", "contractDependencies": [], "contractKind": "library", "documentation": { "id": 29987, "nodeType": "StructuredDocumentation", "src": "127:82:110", "text": " @dev Collection of functions related to the Bech32 address generation" }, "fullyImplemented": true, "id": 31372, "linearizedBaseContracts": [ 31372 ], "name": "Bech32", "nameLocation": "219:6:110", "nodeType": "ContractDefinition", "nodes": [ { "constant": true, "id": 29990, "mutability": "constant", "name": "ALPHABET", "nameLocation": "248:8:110", "nodeType": "VariableDeclaration", "scope": 31372, "src": "233:60:110", "stateVariable": true, "storageLocation": "default", "typeDescriptions": { "typeIdentifier": "t_bytes_memory_ptr", "typeString": "bytes" }, "typeName": { "id": 29988, "name": "bytes", "nodeType": "ElementaryTypeName", "src": "233:5:110", "typeDescriptions": { "typeIdentifier": "t_bytes_storage_ptr", "typeString": "bytes" } }, "value": { "hexValue": "71707a7279397838676632747664773073336a6e35346b686365366d7561376c", "id": 29989, "isConstant": false, "isLValue": false, "isPure": true, "kind": "string", "lValueRequested": false, "nodeType": "Literal", "src": "259:34:110", "typeDescriptions": { "typeIdentifier": "t_stringliteral_fe46e7811aa772220414abf676d1f699331bebeac02e9f688b4e6a861070d4df", "typeString": "literal_string \"qpzry9x8gf2tvdw0s3jn54khce6mua7l\"" }, "value": "qpzry9x8gf2tvdw0s3jn54khce6mua7l" }, "visibility": "internal" }, { "constant": true, "id": 29993, "mutability": "constant", "name": "ALPHABET_REV", "nameLocation": "315:12:110", "nodeType": "VariableDeclaration", "scope": 31372, "src": "300:547:110", "stateVariable": true, "storageLocation": "default", "typeDescriptions": { "typeIdentifier": "t_bytes_memory_ptr", "typeString": "bytes" }, "typeName": { "id": 29991, "name": "bytes", "nodeType": "ElementaryTypeName", "src": "300:5:110", "typeDescriptions": { "typeIdentifier": "t_bytes_storage_ptr", "typeString": "bytes" } }, "value": { "hexValue": "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0fff0a1115141a1e0705ffffffffffffff1dff180d19090817ff12161f1b13ff010003100b1c0c0e060402ffffffffffff1dff180d19090817ff12161f1b13ff010003100b1c0c0e060402ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", "id": 29992, "isConstant": false, "isLValue": false, "isPure": true, "kind": "hexString", "lValueRequested": false, "nodeType": "Literal", "src": "330:517:110", "typeDescriptions": { "typeIdentifier": "t_stringliteral_0cc2f264e88daa0a2d7055222781b00a2c15c4cc02e5bac4341846379adfb56d", "typeString": "literal_string hex\"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0fff0a1115141a1e0705ffffffffffffff1dff180d19090817ff12161f1b13ff010003100b1c0c0e060402ffffffffffff1dff180d19090817ff12161f1b13ff010003100b1c0c0e060402ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff\"" } }, "visibility": "internal" }, { "constant": true, "id": 29996, "mutability": "constant", "name": "ALPHABET_REV_LOWER_ONLY", "nameLocation": "869:23:110", "nodeType": "VariableDeclaration", "scope": 31372, "src": "854:558:110", "stateVariable": true, "storageLocation": "default", "typeDescriptions": { "typeIdentifier": "t_bytes_memory_ptr", "typeString": "bytes" }, "typeName": { "id": 29994, "name": "bytes", "nodeType": "ElementaryTypeName", "src": "854:5:110", "typeDescriptions": { "typeIdentifier": "t_bytes_storage_ptr", "typeString": "bytes" } }, "value": { "hexValue": "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0fff0a1115141a1e0705ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1dff180d19090817ff12161f1b13ff010003100b1c0c0e060402ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", "id": 29995, "isConstant": false, "isLValue": false, "isPure": true, "kind": "hexString", "lValueRequested": false, "nodeType": "Literal", "src": "895:517:110", "typeDescriptions": { "typeIdentifier": "t_stringliteral_c8d3b1ac944044017f62cd6afb4942669ca30804db13dd8406bdeaca3edf27e1", "typeString": "literal_string hex\"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0fff0a1115141a1e0705ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1dff180d19090817ff12161f1b13ff010003100b1c0c0e060402ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff\"" } }, "visibility": "internal" }, { "constant": true, "id": 29999, "mutability": "constant", "name": "ENC_BECH32", "nameLocation": "2507:10:110", "nodeType": "VariableDeclaration", "scope": 31372, "src": "2491:30:110", "stateVariable": true, "storageLocation": "default", "typeDescriptions": { "typeIdentifier": "t_uint32", "typeString": "uint32" }, "typeName": { "id": 29997, "name": "uint32", "nodeType": "ElementaryTypeName", "src": "2491:6:110", "typeDescriptions": { "typeIdentifier": "t_uint32", "typeString": "uint32" } }, "value": { "hexValue": "31", "id": 29998, "isConstant": false, "isLValue": false, "isPure": true, "kind": "number", "lValueRequested": false, "nodeType": "Literal", "src": "2520:1:110", "typeDescriptions": { "typeIdentifier": "t_rational_1_by_1", "typeString": "int_const 1" }, "value": "1" }, "visibility": "internal" }, { "constant": true, "id": 30002, "mutability": "constant", "name": "ENC_BECH32M", "nameLocation": "2544:11:110", "nodeType": "VariableDeclaration", "scope": 31372, "src": "2528:40:110", "stateVariable": true, "storageLocation": "default", "typeDescriptions": { "typeIdentifier": "t_uint32", "typeString": "uint32" }, "typeName": { "id": 30000, "name": "uint32", "nodeType": "ElementaryTypeName", "src": "2528:6:110", "typeDescriptions": { "typeIdentifier": "t_uint32", "typeString": "uint32" } }, "value": { "hexValue": "30783262633833306133", "id": 30001, "isConstant": false, "isLValue": false, "isPure": true, "kind": "number", "lValueRequested": false, "nodeType": "Literal", "src": "2558:10:110", "typeDescriptions": { "typeIdentifier": "t_rational_734539939_by_1", "typeString": "int_const 734539939" }, "value": "0x2bc830a3" }, "visibility": "internal" }, { "body": { "id": 30019, "nodeType": "Block", "src": "2696:66:110", "statements": [ { "expression": { "arguments": [ { "arguments": [ { "id": 30014, "name": "addr", "nodeType": "Identifier", "overloadedDeclarations": [], "referencedDeclaration": 30004, "src": "2740:4:110", "typeDescriptions": { "typeIdentifier": "t_address", "typeString": "address" } } ], "expression": { "argumentTypes": [ { "typeIdentifier": "t_address", "typeString": "address" } ], "expression": { "id": 30012, "name": "abi", "nodeType": "Identifier", "overloadedDeclarations": [], "referencedDeclaration": 4294967295, "src": "2723:3:110", "typeDescriptions": { "typeIdentifier": "t_magic_abi", "typeString": "abi" } }, "id": 30013, "isConstant": false, "isLValue": false, "isPure": true, "lValueRequested": false, "memberLocation": "2727:12:110", "memberName": "encodePacked", "nodeType": "MemberAccess", "src": "2723:16:110", "typeDescriptions": { "typeIdentifier": "t_function_abiencodepacked_pure$__$returns$_t_bytes_memory_ptr_$", "typeString": "function () pure returns (bytes memory)" } }, "id": 30015, "isConstant": false, "isLValue": false, "isPure": false, "kind": "functionCall", "lValueRequested": false, "nameLocations": [], "names": [], "nodeType": "FunctionCall", "src": "2723:22:110", "tryCall": false, "typeDescriptions": { "typeIdentifier": "t_bytes_memory_ptr", "typeString": "bytes memory" } }, { "id": 30016, "name": "prefix", "nodeType": "Identifier", "overloadedDeclarations": [], "referencedDeclaration": 30006, "src": "2747:6:110", "typeDescriptions": { "typeIdentifier": "t_string_memory_ptr", "typeString": "string memory" } } ], "expression": { "argumentTypes": [ { "typeIdentifier": "t_bytes_memory_ptr", "typeString": "bytes memory" }, { "typeIdentifier": "t_string_memory_ptr", "typeString": "string memory" } ], "id": 30011, "name": "toBech32", "nodeType": "Identifier", "overloadedDeclarations": [ 30020, 30052, 30073, 30131 ], "referencedDeclaration": 30052, "src": "2714:8:110", "typeDescriptions": { "typeIdentifier": "t_function_internal_pure$_t_bytes_memory_ptr_$_t_string_memory_ptr_$returns$_t_string_memory_ptr_$", "typeString": "function (bytes memory,string memory) pure returns (string memory)" } }, "id": 30017, "isConstant": false, "isLValue": false, "isPure": false, "kind": "functionCall", "lValueRequested": false, "nameLocations": [], "names": [], "nodeType": "FunctionCall", "src": "2714:40:110", "tryCall": false, "typeDescriptions": { "typeIdentifier": "t_string_memory_ptr", "typeString": "string memory" } }, "functionReturnParameters": 30010, "id": 30018, "nodeType": "Return", "src": "2707:47:110" } ] }, "id": 30020, "implemented": true, "kind": "function", "modifiers": [], "name": "toBech32", "nameLocation": "2588:8:110", "nodeType": "FunctionDefinition", "parameters": { "id": 30007, "nodeType": "ParameterList", "parameters": [ { "constant": false, "id": 30004, "mutability": "mutable", "name": "addr", "nameLocation": "2615:4:110", "nodeType": "VariableDeclaration", "scope": 30020, "src": "2607:12:110", "stateVariable": false, "storageLocation": "default", "typeDescriptions": { "typeIdentifier": "t_address", "typeString": "address" }, "typeName": { "id": 30003, "name": "address", "nodeType": "ElementaryTypeName", "src": "2607:7:110", "stateMutability": "nonpayable", "typeDescriptions": { "typeIdentifier": "t_address", "typeString": "address" } }, "visibility": "internal" }, { "constant": false, "id": 30006, "mutability": "mutable", "name": "prefix", "nameLocation": "2644:6:110", "nodeType": "VariableDeclaration", "scope": 30020, "src": "2630:20:110", "stateVariable": false, "storageLocation": "memory", "typeDescriptions": { "typeIdentifier": "t_string_memory_ptr", "typeString": "string" }, "typeName": { "id": 30005, "name": "string", "nodeType": "ElementaryTypeName", "src": "2630:6:110", "typeDescriptions": { "typeIdentifier": "t_string_storage_ptr", "typeString": "string" } }, "visibility": "internal" } ], "src": "2596:61:110" }, "returnParameters": { "id": 30010, "nodeType": "ParameterList", "parameters": [ { "constant": false, "id": 30009, "mutability": "mutable", "name": "", "nameLocation": "-1:-1:-1", "nodeType": "VariableDeclaration", "scope": 30020, "src": "2681:13:110", "stateVariable": false, "storageLocation": "memory", "typeDescriptions": { "typeIdentifier": "t_string_memory_ptr", "typeString": "string" }, "typeName": { "id": 30008, "name": "string", "nodeType": "ElementaryTypeName", "src": "2681:6:110", "typeDescriptions": { "typeIdentifier": "t_string_storage_ptr", "typeString": "string" } }, "visibility": "internal" } ], "src": "2680:15:110" }, "scope": 31372, "src": "2579:183:110", "stateMutability": "pure", "virtual": false, "visibility": "internal" }, { "body": { "id": 30051, "nodeType": "Block", "src": "2892:171:110", "statements": [ { "assignments": [ 30030 ], "declarations": [ { "constant": false, "id": 30030, "mutability": "mutable", "name": "hrp", "nameLocation": "2916:3:110", "nodeType": "VariableDeclaration", "scope": 30051, "src": "2903:16:110", "stateVariable": false, "storageLocation": "memory", "typeDescriptions": { "typeIdentifier": "t_bytes_memory_ptr", "typeString": "bytes" }, "typeName": { "id": 30029, "name": "bytes", "nodeType": "ElementaryTypeName", "src": "2903:5:110", "typeDescriptions": { "typeIdentifier": "t_bytes_storage_ptr", "typeString": "bytes" } }, "visibility": "internal" } ], "id": 30035, "initialValue": { "arguments": [ { "id": 30033, "name": "prefix", "nodeType": "Identifier", "overloadedDeclarations": [], "referencedDeclaration": 30024, "src": "2939:6:110", "typeDescriptions": { "typeIdentifier": "t_string_memory_ptr", "typeString": "string memory" } } ], "expression": { "argumentTypes": [ { "typeIdentifier": "t_string_memory_ptr", "typeString": "string memory" } ], "expression": { "id": 30031, "name": "abi", "nodeType": "Identifier", "overloadedDeclarations": [], "referencedDeclaration": 4294967295, "src": "2922:3:110", "typeDescriptions": { "typeIdentifier": "t_magic_abi", "typeString": "abi" } }, "id": 30032, "isConstant": false, "isLValue": false, "isPure": true, "lValueRequested": false, "memberLocation": "2926:12:110", "memberName": "encodePacked", "nodeType": "MemberAccess", "src": "2922:16:110", "typeDescriptions": { "typeIdentifier": "t_function_abiencodepacked_pure$__$returns$_t_bytes_memory_ptr_$", "typeString": "function () pure returns (bytes memory)" } }, "id": 30034, "isConstant": false, "isLValue": false, "isPure": false, "kind": "functionCall", "lValueRequested": false, "nameLocations": [], "names": [], "nodeType": "FunctionCall", "src": "2922:24:110", "tryCall": false, "typeDescriptions": { "typeIdentifier": "t_bytes_memory_ptr", "typeString": "bytes memory" } }, "nodeType": "VariableDeclarationStatement", "src": "2903:43:110" }, { "assignments": [ 30037 ], "declarations": [ { "constant": false, "id": 30037, "mutability": "mutable", "name": "input", "nameLocation": "2970:5:110", "nodeType": "VariableDeclaration", "scope": 30051, "src": "2957:18:110", "stateVariable": false, "storageLocation": "memory", "typeDescriptions": { "typeIdentifier": "t_bytes_memory_ptr", "typeString": "bytes" }, "typeName": { "id": 30036, "name": "bytes", "nodeType": "ElementaryTypeName", "src": "2957:5:110", "typeDescriptions": { "typeIdentifier": "t_bytes_storage_ptr", "typeString": "bytes" } }, "visibility": "internal" } ], "id": 30044, "initialValue": { "arguments": [ { "id": 30039, "name": "data", "nodeType": "Identifier", "overloadedDeclarations": [], "referencedDeclaration": 30022, "src": "2990:4:110", "typeDescriptions": { "typeIdentifier": "t_bytes_memory_ptr", "typeString": "bytes memory" } }, { "hexValue": "38", "id": 30040, "isConstant": false, "isLValue": false, "isPure": true, "kind": "number", "lValueRequested": false, "nodeType": "Literal", "src": "2996:1:110", "typeDescriptions": { "typeIdentifier": "t_rational_8_by_1", "typeString": "int_const 8" }, "value": "8" }, { "hexValue": "35", "id": 30041, "isConstant": false, "isLValue": false, "isPure": true, "kind": "number", "lValueRequested": false, "nodeType": "Literal", "src": "2999:1:110", "typeDescriptions": { "typeIdentifier": "t_rational_5_by_1", "typeString": "int_const 5" }, "value": "5" }, { "hexValue": "74727565", "id": 30042, "isConstant": false, "isLValue": false, "isPure": true, "kind": "bool", "lValueRequested": false, "nodeType": "Literal", "src": "3002:4:110", "typeDescriptions": { "typeIdentifier": "t_bool", "typeString": "bool" }, "value": "true" } ], "expression": { "argumentTypes": [ { "typeIdentifier": "t_bytes_memory_ptr", "typeString": "bytes memory" }, { "typeIdentifier": "t_rational_8_by_1", "typeString": "int_const 8" }, { "typeIdentifier": "t_rational_5_by_1", "typeString": "int_const 5" }, { "typeIdentifier": "t_bool", "typeString": "bool" } ], "id": 30038, "name": "convertBits", "nodeType": "Identifier", "overloadedDeclarations": [ 31192, 31214 ], "referencedDeclaration": 31192, "src": "2978:11:110", "typeDescriptions": { "typeIdentifier": "t_function_internal_pure$_t_bytes_memory_ptr_$_t_uint256_$_t_uint256_$_t_bool_$returns$_t_bytes_memory_ptr_$", "typeString": "function (bytes memory,uint256,uint256,bool) pure returns (bytes memory)" } }, "id": 30043, "isConstant": false, "isLValue": false, "isPure": false, "kind": "functionCall", "lValueRequested": false, "nameLocations": [], "names": [], "nodeType": "FunctionCall", "src": "2978:29:110", "tryCall": false, "typeDescriptions": { "typeIdentifier": "t_bytes_memory_ptr", "typeString": "bytes memory" } }, "nodeType": "VariableDeclarationStatement", "src": "2957:50:110" }, { "expression": { "arguments": [ { "id": 30046, "name": "hrp", "nodeType": "Identifier", "overloadedDeclarations": [], "referencedDeclaration": 30030, "src": "3032:3:110", "typeDescriptions": { "typeIdentifier": "t_bytes_memory_ptr", "typeString": "bytes memory" } }, { "id": 30047, "name": "input", "nodeType": "Identifier", "overloadedDeclarations": [], "referencedDeclaration": 30037, "src": "3037:5:110", "typeDescriptions": { "typeIdentifier": "t_bytes_memory_ptr", "typeString": "bytes memory" } }, { "id": 30048, "name": "ENC_BECH32", "nodeType": "Identifier", "overloadedDeclarations": [], "referencedDeclaration": 29999, "src": "3044:10:110", "typeDescriptions": { "typeIdentifier": "t_uint32", "typeString": "uint32" } } ], "expression": { "argumentTypes": [ { "typeIdentifier": "t_bytes_memory_ptr", "typeString": "bytes memory" }, { "typeIdentifier": "t_bytes_memory_ptr", "typeString": "bytes memory" }, { "typeIdentifier": "t_uint32", "typeString": "uint32" } ], "id": 30045, "name": "encode", "nodeType": "Identifier", "overloadedDeclarations": [], "referencedDeclaration": 30551, "src": "3025:6:110", "typeDescriptions": { "typeIdentifier": "t_function_internal_pure$_t_bytes_memory_ptr_$_t_bytes_memory_ptr_$_t_uint32_$returns$_t_string_memory_ptr_$", "typeString": "function (bytes memory,bytes memory,uint32) pure returns (string memory)" } }, "id": 30049, "isConstant": false, "isLValue": false, "isPure": false, "kind": "functionCall", "lValueRequested": false, "name