diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..02aab33 --- /dev/null +++ b/.gitignore @@ -0,0 +1,31 @@ +# Miscellaneous +*.class +*.log +*.pyc +*.swp +.DS_Store +.atom/ +.buildlog/ +.history +.svn/ + +# IntelliJ related +*.iml +*.ipr +*.iws +.idea/ +**/.env +.env + +# The .vscode folder contains launch configuration and tasks you configure in +# VS Code which you may wish to be included in version control, so this line +# is commented out by default. +#.vscode/ + +# Flutter/Dart/Pub related +# Libraries should not include pubspec.lock, per https://dart.dev/guides/libraries/private-files#pubspeclock. +/pubspec.lock +**/doc/api/ +.dart_tool/ +.packages +build/ diff --git a/.metadata b/.metadata new file mode 100644 index 0000000..0daf357 --- /dev/null +++ b/.metadata @@ -0,0 +1,10 @@ +# This file tracks properties of this Flutter project. +# Used by Flutter tool to assess capabilities and perform upgrades etc. +# +# This file should be version controlled and should not be manually edited. + +version: + revision: 262b70ece1aebf84f132c51ec4cf90be605ce61b + channel: beta + +project_type: package diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..6c51f3c --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1 @@ +## 1.0.0 diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..cb10848 --- /dev/null +++ b/LICENSE @@ -0,0 +1,7 @@ +Copyright 2022 Chiziaruhoma Ogbonda + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..0905684 --- /dev/null +++ b/README.md @@ -0,0 +1,65 @@ +# ⚡️ ENS Dart + +A dart library that wraps the Ethereum Name Service. + +The Ethereum Name Service is analogous to the Domain Name Service. It enables users and developers to use human-friendly names in place of error-prone hexadecimal addresses, content hashes, and more. + +- Interop with `web3dart` package +- Get ENS name from ETH address +- Get address from ENS name +- Get contentHash +- Get textRecord +- Call functions on ENS smart contracts and listen for contract events + +## Usage + +### Get ENS name and address + +ENS Dart provides an interface to look up an address from a name, the reverse, and more. + +```dart +Future main() async { + env.load('../.env'); + final infuraKey = env.env['INFURA_KEY']; + + final rpcUrl = 'https://mainnet.infura.io/v3/$infuraKey'; + final wsUrl = 'wss://mainnet.infura.io/ws/v3/$infuraKey'; + + final client = Web3Client(rpcUrl, Client(), socketConnector: () { + return IOWebSocketChannel.connect(wsUrl).cast(); + }); + + /// ENS client + final ens = Ens(client: client); + + /// Get name from address + final name = await ens + .withAddress('0x1a5cdcFBA600e0c669795e0B65c344D5A37a4d5A') + .getName(); + + /// Get address from name + final addr = await ens.withName('brantly.eth').getAddress(); + + /// Get text record + final textRecord = await ens.getTextRecord(); + + print('name: $name'); // addr: 0x324f9307b6d26881822c7c8692eeac39791a9756 + print('addr: $addr'); // name: sea.eth + print( + 'textRecord: $textRecord'); /* EnsTextRecord { + email: me@brantly.xyz, + url: http://brantly.xyz/, + avatar: eip155:1/erc721:0xb7F7F6C52F2e2fdb1963Eab30438024864c313F6/2430, + description: "If anyone would come after me, let him deny himself and take up his cross daily and follow me. For whoever would save his life will lose it, but whoever loses his life for my sake will save it. For what does it profit a man if he gains the whole world and loses or forfeits himself?" - Jesus, Luke 9.23-25, + notice: Not for sale, + keywords: , + com.discord: brantly.eth#9803, + com.github: brantlymillegan, + com.reddit: brantlymillegan, + com.twitter: brantlymillegan, + org.telegram: brantlymillegan, + eth.ens.delegate: https://discuss.ens.domains/t/ens-dao-delegate-applications/815/697?u=brantlymillegan + } +} + +``` diff --git a/analysis_options.yaml b/analysis_options.yaml new file mode 100644 index 0000000..a5744c1 --- /dev/null +++ b/analysis_options.yaml @@ -0,0 +1,4 @@ +include: package:flutter_lints/flutter.yaml + +# Additional information about this file can be found at +# https://dart.dev/guides/language/analysis-options diff --git a/example/main.dart b/example/main.dart new file mode 100644 index 0000000..13bf825 --- /dev/null +++ b/example/main.dart @@ -0,0 +1,48 @@ +import 'package:ens_dart/ens_dart.dart'; +import 'package:dotenv/dotenv.dart' as env; + +import 'package:http/http.dart'; +import 'package:web3dart/web3dart.dart'; +import 'package:web_socket_channel/io.dart'; + +Future main() async { + env.load('../.env'); + final infuraKey = env.env['INFURA_KEY']; + + final rpcUrl = 'https://mainnet.infura.io/v3/$infuraKey'; + final wsUrl = 'wss://mainnet.infura.io/ws/v3/$infuraKey'; + + final client = Web3Client(rpcUrl, Client(), socketConnector: () { + return IOWebSocketChannel.connect(wsUrl).cast(); + }); + + final ens = Ens(client: client); + + // ENS supports reverse resolution to allow applications to display + // ENS names in place of hexadecimal addresses. + final name = await ens + .withAddress('0x1a5cdcFBA600e0c669795e0B65c344D5A37a4d5A') + .getName(); + + final addr = await ens.withName('brantly.eth').getAddress(); + final content = await ens.getTextRecord(); + + print('name: $name'); // addr: 0x324f9307b6d26881822c7c8692eeac39791a9756 + print('addr: $addr'); // name: sea.eth + + print( + 'content: $content'); /* EnsTextRecord { + email: me@brantly.xyz, + url: http://brantly.xyz/, + avatar: eip155:1/erc721:0xb7F7F6C52F2e2fdb1963Eab30438024864c313F6/2430, + description: "If anyone would come after me, let him deny himself and take up his cross daily and follow me. For whoever would save his life will lose it, but whoever loses his life for my sake will save it. For what does it profit a man if he gains the whole world and loses or forfeits himself?" - Jesus, Luke 9.23-25, + notice: Not for sale, + keywords: , + com.discord: brantly.eth#9803, + com.github: brantlymillegan, + com.reddit: brantlymillegan, + com.twitter: brantlymillegan, + org.telegram: brantlymillegan, + eth.ens.delegate: https://discuss.ens.domains/t/ens-dao-delegate-applications/815/697?u=brantlymillegan + } */ +} diff --git a/lib/ens_dart.dart b/lib/ens_dart.dart new file mode 100644 index 0000000..dffeb1b --- /dev/null +++ b/lib/ens_dart.dart @@ -0,0 +1 @@ +export 'src/ens_dart.dart'; \ No newline at end of file diff --git a/lib/src/const/const.dart b/lib/src/const/const.dart new file mode 100644 index 0000000..b0cda4c --- /dev/null +++ b/lib/src/const/const.dart @@ -0,0 +1,14 @@ +// ignore_for_file: non_constant_identifier_names + +import 'package:web3dart/web3dart.dart'; + +final ENS = + EthereumAddress.fromHex('0xC18360217D8F7Ab5e7c516566761Ea12Ce7F9D72'); +final ENS_FALLBACK_REGISTRY = + EthereumAddress.fromHex('0x00000000000c2e074ec69a0dfb2997ba6c7d2e1e'); +final ENS_RESOLVER = + EthereumAddress.fromHex('0x4976fb03c32e5b8cfe2b6ccb31c09ba78ebaba41'); +final ENS_REVERSE_RESOLVER = + EthereumAddress.fromHex('0xa2c122be93b0074270ebee7f6b7292c7deb45047'); +final ENS_REVERSE_REGISTRAR = + EthereumAddress.fromHex('0x084b1c3c81545d370f3634392de611caabff8148'); diff --git a/lib/src/contracts/contracts.dart b/lib/src/contracts/contracts.dart new file mode 100644 index 0000000..1f365ec --- /dev/null +++ b/lib/src/contracts/contracts.dart @@ -0,0 +1,9 @@ +export 'ens.g.dart'; +export 'ens_root.g.dart'; +export 'ens_token.g.dart' hide Transfer; +export 'ens_service.g.dart' hide Transfer, NewTTL, NewResolver, NewOwner; +export 'ens_resolver.g.dart'; +export 'ens_reverse_registrar.g.dart'; +export 'ens_reverse_resolver.g.dart'; +export 'ens_registry_fallback.g.dart' + hide ApprovalForAll, NewTTL, Transfer, NewResolver, NewOwner; diff --git a/lib/src/contracts/ens.g.dart b/lib/src/contracts/ens.g.dart new file mode 100644 index 0000000..6c31838 --- /dev/null +++ b/lib/src/contracts/ens.g.dart @@ -0,0 +1,278 @@ +// Generated code, do not modify. Run `build_runner build` to re-generate! +// @dart=2.12 +import 'package:web3dart/web3dart.dart' as _i1; +import 'dart:typed_data' as _i2; + +final _contractAbi = _i1.ContractAbi.fromJson( + '[{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"operator","type":"address"},{"indexed":false,"internalType":"bool","name":"approved","type":"bool"}],"name":"ApprovalForAll","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"node","type":"bytes32"},{"indexed":true,"internalType":"bytes32","name":"label","type":"bytes32"},{"indexed":false,"internalType":"address","name":"owner","type":"address"}],"name":"NewOwner","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"node","type":"bytes32"},{"indexed":false,"internalType":"address","name":"resolver","type":"address"}],"name":"NewResolver","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"node","type":"bytes32"},{"indexed":false,"internalType":"uint64","name":"ttl","type":"uint64"}],"name":"NewTTL","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"node","type":"bytes32"},{"indexed":false,"internalType":"address","name":"owner","type":"address"}],"name":"Transfer","type":"event"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"operator","type":"address"}],"name":"isApprovedForAll","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"node","type":"bytes32"}],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"node","type":"bytes32"}],"name":"recordExists","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"node","type":"bytes32"}],"name":"resolver","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"operator","type":"address"},{"internalType":"bool","name":"approved","type":"bool"}],"name":"setApprovalForAll","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"node","type":"bytes32"},{"internalType":"address","name":"owner","type":"address"}],"name":"setOwner","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"node","type":"bytes32"},{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"resolver","type":"address"},{"internalType":"uint64","name":"ttl","type":"uint64"}],"name":"setRecord","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"node","type":"bytes32"},{"internalType":"address","name":"resolver","type":"address"}],"name":"setResolver","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"node","type":"bytes32"},{"internalType":"bytes32","name":"label","type":"bytes32"},{"internalType":"address","name":"owner","type":"address"}],"name":"setSubnodeOwner","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"node","type":"bytes32"},{"internalType":"bytes32","name":"label","type":"bytes32"},{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"resolver","type":"address"},{"internalType":"uint64","name":"ttl","type":"uint64"}],"name":"setSubnodeRecord","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"node","type":"bytes32"},{"internalType":"uint64","name":"ttl","type":"uint64"}],"name":"setTTL","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"node","type":"bytes32"}],"name":"ttl","outputs":[{"internalType":"uint64","name":"","type":"uint64"}],"stateMutability":"view","type":"function"}]', + 'EnsContract'); + +class EnsContract extends _i1.GeneratedContract { + EnsContract( + {required _i1.EthereumAddress address, + required _i1.Web3Client client, + int? chainId}) + : super(_i1.DeployedContract(_contractAbi, address), client, chainId); + + /// The optional [atBlock] parameter can be used to view historical data. When + /// set, the function will be evaluated in the specified block. By default, the + /// latest on-chain block will be used. + Future isApprovedForAll( + _i1.EthereumAddress owner, _i1.EthereumAddress operator, + {_i1.BlockNum? atBlock}) async { + final function = self.abi.functions[0]; + assert(checkSignature(function, 'e985e9c5')); + final params = [owner, operator]; + final response = await read(function, params, atBlock); + return (response[0] as bool); + } + + /// The optional [atBlock] parameter can be used to view historical data. When + /// set, the function will be evaluated in the specified block. By default, the + /// latest on-chain block will be used. + Future<_i1.EthereumAddress> owner(_i2.Uint8List node, + {_i1.BlockNum? atBlock}) async { + final function = self.abi.functions[1]; + assert(checkSignature(function, '02571be3')); + final params = [node]; + final response = await read(function, params, atBlock); + return (response[0] as _i1.EthereumAddress); + } + + /// The optional [atBlock] parameter can be used to view historical data. When + /// set, the function will be evaluated in the specified block. By default, the + /// latest on-chain block will be used. + Future recordExists(_i2.Uint8List node, {_i1.BlockNum? atBlock}) async { + final function = self.abi.functions[2]; + assert(checkSignature(function, 'f79fe538')); + final params = [node]; + final response = await read(function, params, atBlock); + return (response[0] as bool); + } + + /// The optional [atBlock] parameter can be used to view historical data. When + /// set, the function will be evaluated in the specified block. By default, the + /// latest on-chain block will be used. + Future<_i1.EthereumAddress> resolver(_i2.Uint8List node, + {_i1.BlockNum? atBlock}) async { + final function = self.abi.functions[3]; + assert(checkSignature(function, '0178b8bf')); + final params = [node]; + final response = await read(function, params, atBlock); + return (response[0] as _i1.EthereumAddress); + } + + /// The optional [transaction] parameter can be used to override parameters + /// like the gas price, nonce and max gas. The `data` and `to` fields will be + /// set by the contract. + Future setApprovalForAll(_i1.EthereumAddress operator, bool approved, + {required _i1.Credentials credentials, + _i1.Transaction? transaction}) async { + final function = self.abi.functions[4]; + assert(checkSignature(function, 'a22cb465')); + final params = [operator, approved]; + return write(credentials, transaction, function, params); + } + + /// The optional [transaction] parameter can be used to override parameters + /// like the gas price, nonce and max gas. The `data` and `to` fields will be + /// set by the contract. + Future setOwner(_i2.Uint8List node, _i1.EthereumAddress owner, + {required _i1.Credentials credentials, + _i1.Transaction? transaction}) async { + final function = self.abi.functions[5]; + assert(checkSignature(function, '5b0fc9c3')); + final params = [node, owner]; + return write(credentials, transaction, function, params); + } + + /// The optional [transaction] parameter can be used to override parameters + /// like the gas price, nonce and max gas. The `data` and `to` fields will be + /// set by the contract. + Future setRecord(_i2.Uint8List node, _i1.EthereumAddress owner, + _i1.EthereumAddress resolver, BigInt ttl, + {required _i1.Credentials credentials, + _i1.Transaction? transaction}) async { + final function = self.abi.functions[6]; + assert(checkSignature(function, 'cf408823')); + final params = [node, owner, resolver, ttl]; + return write(credentials, transaction, function, params); + } + + /// The optional [transaction] parameter can be used to override parameters + /// like the gas price, nonce and max gas. The `data` and `to` fields will be + /// set by the contract. + Future setResolver(_i2.Uint8List node, _i1.EthereumAddress resolver, + {required _i1.Credentials credentials, + _i1.Transaction? transaction}) async { + final function = self.abi.functions[7]; + assert(checkSignature(function, '1896f70a')); + final params = [node, resolver]; + return write(credentials, transaction, function, params); + } + + /// The optional [transaction] parameter can be used to override parameters + /// like the gas price, nonce and max gas. The `data` and `to` fields will be + /// set by the contract. + Future setSubnodeOwner( + _i2.Uint8List node, _i2.Uint8List label, _i1.EthereumAddress owner, + {required _i1.Credentials credentials, + _i1.Transaction? transaction}) async { + final function = self.abi.functions[8]; + assert(checkSignature(function, '06ab5923')); + final params = [node, label, owner]; + return write(credentials, transaction, function, params); + } + + /// The optional [transaction] parameter can be used to override parameters + /// like the gas price, nonce and max gas. The `data` and `to` fields will be + /// set by the contract. + Future setSubnodeRecord(_i2.Uint8List node, _i2.Uint8List label, + _i1.EthereumAddress owner, _i1.EthereumAddress resolver, BigInt ttl, + {required _i1.Credentials credentials, + _i1.Transaction? transaction}) async { + final function = self.abi.functions[9]; + assert(checkSignature(function, '5ef2c7f0')); + final params = [node, label, owner, resolver, ttl]; + return write(credentials, transaction, function, params); + } + + /// The optional [transaction] parameter can be used to override parameters + /// like the gas price, nonce and max gas. The `data` and `to` fields will be + /// set by the contract. + Future setTTL(_i2.Uint8List node, BigInt ttl, + {required _i1.Credentials credentials, + _i1.Transaction? transaction}) async { + final function = self.abi.functions[10]; + assert(checkSignature(function, '14ab9038')); + final params = [node, ttl]; + return write(credentials, transaction, function, params); + } + + /// The optional [atBlock] parameter can be used to view historical data. When + /// set, the function will be evaluated in the specified block. By default, the + /// latest on-chain block will be used. + Future ttl(_i2.Uint8List node, {_i1.BlockNum? atBlock}) async { + final function = self.abi.functions[11]; + assert(checkSignature(function, '16a25cbd')); + final params = [node]; + final response = await read(function, params, atBlock); + return (response[0] as BigInt); + } + + /// Returns a live stream of all ApprovalForAll events emitted by this contract. + Stream approvalForAllEvents( + {_i1.BlockNum? fromBlock, _i1.BlockNum? toBlock}) { + final event = self.event('ApprovalForAll'); + final filter = _i1.FilterOptions.events( + contract: self, event: event, fromBlock: fromBlock, toBlock: toBlock); + return client.events(filter).map((_i1.FilterEvent result) { + final decoded = event.decodeResults(result.topics!, result.data!); + return ApprovalForAll(decoded); + }); + } + + /// Returns a live stream of all NewOwner events emitted by this contract. + Stream newOwnerEvents( + {_i1.BlockNum? fromBlock, _i1.BlockNum? toBlock}) { + final event = self.event('NewOwner'); + final filter = _i1.FilterOptions.events( + contract: self, event: event, fromBlock: fromBlock, toBlock: toBlock); + return client.events(filter).map((_i1.FilterEvent result) { + final decoded = event.decodeResults(result.topics!, result.data!); + return NewOwner(decoded); + }); + } + + /// Returns a live stream of all NewResolver events emitted by this contract. + Stream newResolverEvents( + {_i1.BlockNum? fromBlock, _i1.BlockNum? toBlock}) { + final event = self.event('NewResolver'); + final filter = _i1.FilterOptions.events( + contract: self, event: event, fromBlock: fromBlock, toBlock: toBlock); + return client.events(filter).map((_i1.FilterEvent result) { + final decoded = event.decodeResults(result.topics!, result.data!); + return NewResolver(decoded); + }); + } + + /// Returns a live stream of all NewTTL events emitted by this contract. + Stream newTTLEvents( + {_i1.BlockNum? fromBlock, _i1.BlockNum? toBlock}) { + final event = self.event('NewTTL'); + final filter = _i1.FilterOptions.events( + contract: self, event: event, fromBlock: fromBlock, toBlock: toBlock); + return client.events(filter).map((_i1.FilterEvent result) { + final decoded = event.decodeResults(result.topics!, result.data!); + return NewTTL(decoded); + }); + } + + /// Returns a live stream of all Transfer events emitted by this contract. + Stream transferEvents( + {_i1.BlockNum? fromBlock, _i1.BlockNum? toBlock}) { + final event = self.event('Transfer'); + final filter = _i1.FilterOptions.events( + contract: self, event: event, fromBlock: fromBlock, toBlock: toBlock); + return client.events(filter).map((_i1.FilterEvent result) { + final decoded = event.decodeResults(result.topics!, result.data!); + return Transfer(decoded); + }); + } +} + +class ApprovalForAll { + ApprovalForAll(List response) + : owner = (response[0] as _i1.EthereumAddress), + operator = (response[1] as _i1.EthereumAddress), + approved = (response[2] as bool); + + final _i1.EthereumAddress owner; + + final _i1.EthereumAddress operator; + + final bool approved; +} + +class NewOwner { + NewOwner(List response) + : node = (response[0] as _i2.Uint8List), + label = (response[1] as _i2.Uint8List), + owner = (response[2] as _i1.EthereumAddress); + + final _i2.Uint8List node; + + final _i2.Uint8List label; + + final _i1.EthereumAddress owner; +} + +class NewResolver { + NewResolver(List response) + : node = (response[0] as _i2.Uint8List), + resolver = (response[1] as _i1.EthereumAddress); + + final _i2.Uint8List node; + + final _i1.EthereumAddress resolver; +} + +class NewTTL { + NewTTL(List response) + : node = (response[0] as _i2.Uint8List), + ttl = (response[1] as BigInt); + + final _i2.Uint8List node; + + final BigInt ttl; +} + +class Transfer { + Transfer(List response) + : node = (response[0] as _i2.Uint8List), + owner = (response[1] as _i1.EthereumAddress); + + final _i2.Uint8List node; + + final _i1.EthereumAddress owner; +} diff --git a/lib/src/contracts/ens_registry_fallback.g.dart b/lib/src/contracts/ens_registry_fallback.g.dart new file mode 100644 index 0000000..a8a4813 --- /dev/null +++ b/lib/src/contracts/ens_registry_fallback.g.dart @@ -0,0 +1,289 @@ +// Generated code, do not modify. Run `build_runner build` to re-generate! +// @dart=2.12 +import 'package:web3dart/web3dart.dart' as _i1; +import 'dart:typed_data' as _i2; + +final _contractAbi = _i1.ContractAbi.fromJson( + '[{"inputs":[{"internalType":"contract ENS","name":"_old","type":"address"}],"payable":false,"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"operator","type":"address"},{"indexed":false,"internalType":"bool","name":"approved","type":"bool"}],"name":"ApprovalForAll","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"node","type":"bytes32"},{"indexed":true,"internalType":"bytes32","name":"label","type":"bytes32"},{"indexed":false,"internalType":"address","name":"owner","type":"address"}],"name":"NewOwner","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"node","type":"bytes32"},{"indexed":false,"internalType":"address","name":"resolver","type":"address"}],"name":"NewResolver","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"node","type":"bytes32"},{"indexed":false,"internalType":"uint64","name":"ttl","type":"uint64"}],"name":"NewTTL","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"node","type":"bytes32"},{"indexed":false,"internalType":"address","name":"owner","type":"address"}],"name":"Transfer","type":"event"},{"constant":true,"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"operator","type":"address"}],"name":"isApprovedForAll","outputs":[{"internalType":"bool","name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"old","outputs":[{"internalType":"contract ENS","name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"internalType":"bytes32","name":"node","type":"bytes32"}],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"internalType":"bytes32","name":"node","type":"bytes32"}],"name":"recordExists","outputs":[{"internalType":"bool","name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"internalType":"bytes32","name":"node","type":"bytes32"}],"name":"resolver","outputs":[{"internalType":"address","name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"operator","type":"address"},{"internalType":"bool","name":"approved","type":"bool"}],"name":"setApprovalForAll","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"bytes32","name":"node","type":"bytes32"},{"internalType":"address","name":"owner","type":"address"}],"name":"setOwner","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"bytes32","name":"node","type":"bytes32"},{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"resolver","type":"address"},{"internalType":"uint64","name":"ttl","type":"uint64"}],"name":"setRecord","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"bytes32","name":"node","type":"bytes32"},{"internalType":"address","name":"resolver","type":"address"}],"name":"setResolver","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"bytes32","name":"node","type":"bytes32"},{"internalType":"bytes32","name":"label","type":"bytes32"},{"internalType":"address","name":"owner","type":"address"}],"name":"setSubnodeOwner","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"bytes32","name":"node","type":"bytes32"},{"internalType":"bytes32","name":"label","type":"bytes32"},{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"resolver","type":"address"},{"internalType":"uint64","name":"ttl","type":"uint64"}],"name":"setSubnodeRecord","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"bytes32","name":"node","type":"bytes32"},{"internalType":"uint64","name":"ttl","type":"uint64"}],"name":"setTTL","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"internalType":"bytes32","name":"node","type":"bytes32"}],"name":"ttl","outputs":[{"internalType":"uint64","name":"","type":"uint64"}],"payable":false,"stateMutability":"view","type":"function"}]', + 'EnsRegistryFallback'); + +class EnsRegistryFallback extends _i1.GeneratedContract { + EnsRegistryFallback({ + required _i1.EthereumAddress address, + required _i1.Web3Client client, + int? chainId, + }) : super(_i1.DeployedContract(_contractAbi, address), client, chainId); + + /// The optional [atBlock] parameter can be used to view historical data. When + /// set, the function will be evaluated in the specified block. By default, the + /// latest on-chain block will be used. + Future isApprovedForAll( + _i1.EthereumAddress owner, _i1.EthereumAddress operator, + {_i1.BlockNum? atBlock}) async { + final function = self.abi.functions[1]; + assert(checkSignature(function, 'e985e9c5')); + final params = [owner, operator]; + final response = await read(function, params, atBlock); + return (response[0] as bool); + } + + /// The optional [atBlock] parameter can be used to view historical data. When + /// set, the function will be evaluated in the specified block. By default, the + /// latest on-chain block will be used. + Future<_i1.EthereumAddress> old({_i1.BlockNum? atBlock}) async { + final function = self.abi.functions[2]; + assert(checkSignature(function, 'b83f8663')); + final params = []; + final response = await read(function, params, atBlock); + return (response[0] as _i1.EthereumAddress); + } + + /// The optional [atBlock] parameter can be used to view historical data. When + /// set, the function will be evaluated in the specified block. By default, the + /// latest on-chain block will be used. + Future<_i1.EthereumAddress> owner(_i2.Uint8List node, + {_i1.BlockNum? atBlock}) async { + final function = self.abi.functions[3]; + assert(checkSignature(function, '02571be3')); + final params = [node]; + final response = await read(function, params, atBlock); + return (response[0] as _i1.EthereumAddress); + } + + /// The optional [atBlock] parameter can be used to view historical data. When + /// set, the function will be evaluated in the specified block. By default, the + /// latest on-chain block will be used. + Future recordExists(_i2.Uint8List node, {_i1.BlockNum? atBlock}) async { + final function = self.abi.functions[4]; + assert(checkSignature(function, 'f79fe538')); + final params = [node]; + final response = await read(function, params, atBlock); + return (response[0] as bool); + } + + /// The optional [atBlock] parameter can be used to view historical data. When + /// set, the function will be evaluated in the specified block. By default, the + /// latest on-chain block will be used. + Future<_i1.EthereumAddress> resolver(_i2.Uint8List node, + {_i1.BlockNum? atBlock}) async { + final function = self.abi.functions[5]; + assert(checkSignature(function, '0178b8bf')); + final params = [node]; + final response = await read(function, params, atBlock); + return (response[0] as _i1.EthereumAddress); + } + + /// The optional [transaction] parameter can be used to override parameters + /// like the gas price, nonce and max gas. The `data` and `to` fields will be + /// set by the contract. + Future setApprovalForAll(_i1.EthereumAddress operator, bool approved, + {required _i1.Credentials credentials, + _i1.Transaction? transaction}) async { + final function = self.abi.functions[6]; + assert(checkSignature(function, 'a22cb465')); + final params = [operator, approved]; + return write(credentials, transaction, function, params); + } + + /// The optional [transaction] parameter can be used to override parameters + /// like the gas price, nonce and max gas. The `data` and `to` fields will be + /// set by the contract. + Future setOwner(_i2.Uint8List node, _i1.EthereumAddress owner, + {required _i1.Credentials credentials, + _i1.Transaction? transaction}) async { + final function = self.abi.functions[7]; + assert(checkSignature(function, '5b0fc9c3')); + final params = [node, owner]; + return write(credentials, transaction, function, params); + } + + /// The optional [transaction] parameter can be used to override parameters + /// like the gas price, nonce and max gas. The `data` and `to` fields will be + /// set by the contract. + Future setRecord(_i2.Uint8List node, _i1.EthereumAddress owner, + _i1.EthereumAddress resolver, BigInt ttl, + {required _i1.Credentials credentials, + _i1.Transaction? transaction}) async { + final function = self.abi.functions[8]; + assert(checkSignature(function, 'cf408823')); + final params = [node, owner, resolver, ttl]; + return write(credentials, transaction, function, params); + } + + /// The optional [transaction] parameter can be used to override parameters + /// like the gas price, nonce and max gas. The `data` and `to` fields will be + /// set by the contract. + Future setResolver(_i2.Uint8List node, _i1.EthereumAddress resolver, + {required _i1.Credentials credentials, + _i1.Transaction? transaction}) async { + final function = self.abi.functions[9]; + assert(checkSignature(function, '1896f70a')); + final params = [node, resolver]; + return write(credentials, transaction, function, params); + } + + /// The optional [transaction] parameter can be used to override parameters + /// like the gas price, nonce and max gas. The `data` and `to` fields will be + /// set by the contract. + Future setSubnodeOwner( + _i2.Uint8List node, _i2.Uint8List label, _i1.EthereumAddress owner, + {required _i1.Credentials credentials, + _i1.Transaction? transaction}) async { + final function = self.abi.functions[10]; + assert(checkSignature(function, '06ab5923')); + final params = [node, label, owner]; + return write(credentials, transaction, function, params); + } + + /// The optional [transaction] parameter can be used to override parameters + /// like the gas price, nonce and max gas. The `data` and `to` fields will be + /// set by the contract. + Future setSubnodeRecord(_i2.Uint8List node, _i2.Uint8List label, + _i1.EthereumAddress owner, _i1.EthereumAddress resolver, BigInt ttl, + {required _i1.Credentials credentials, + _i1.Transaction? transaction}) async { + final function = self.abi.functions[11]; + assert(checkSignature(function, '5ef2c7f0')); + final params = [node, label, owner, resolver, ttl]; + return write(credentials, transaction, function, params); + } + + /// The optional [transaction] parameter can be used to override parameters + /// like the gas price, nonce and max gas. The `data` and `to` fields will be + /// set by the contract. + Future setTTL(_i2.Uint8List node, BigInt ttl, + {required _i1.Credentials credentials, + _i1.Transaction? transaction}) async { + final function = self.abi.functions[12]; + assert(checkSignature(function, '14ab9038')); + final params = [node, ttl]; + return write(credentials, transaction, function, params); + } + + /// The optional [atBlock] parameter can be used to view historical data. When + /// set, the function will be evaluated in the specified block. By default, the + /// latest on-chain block will be used. + Future ttl(_i2.Uint8List node, {_i1.BlockNum? atBlock}) async { + final function = self.abi.functions[13]; + assert(checkSignature(function, '16a25cbd')); + final params = [node]; + final response = await read(function, params, atBlock); + return (response[0] as BigInt); + } + + /// Returns a live stream of all ApprovalForAll events emitted by this contract. + Stream approvalForAllEvents( + {_i1.BlockNum? fromBlock, _i1.BlockNum? toBlock}) { + final event = self.event('ApprovalForAll'); + final filter = _i1.FilterOptions.events( + contract: self, event: event, fromBlock: fromBlock, toBlock: toBlock); + return client.events(filter).map((_i1.FilterEvent result) { + final decoded = event.decodeResults(result.topics!, result.data!); + return ApprovalForAll(decoded); + }); + } + + /// Returns a live stream of all NewOwner events emitted by this contract. + Stream newOwnerEvents( + {_i1.BlockNum? fromBlock, _i1.BlockNum? toBlock}) { + final event = self.event('NewOwner'); + final filter = _i1.FilterOptions.events( + contract: self, event: event, fromBlock: fromBlock, toBlock: toBlock); + return client.events(filter).map((_i1.FilterEvent result) { + final decoded = event.decodeResults(result.topics!, result.data!); + return NewOwner(decoded); + }); + } + + /// Returns a live stream of all NewResolver events emitted by this contract. + Stream newResolverEvents( + {_i1.BlockNum? fromBlock, _i1.BlockNum? toBlock}) { + final event = self.event('NewResolver'); + final filter = _i1.FilterOptions.events( + contract: self, event: event, fromBlock: fromBlock, toBlock: toBlock); + return client.events(filter).map((_i1.FilterEvent result) { + final decoded = event.decodeResults(result.topics!, result.data!); + return NewResolver(decoded); + }); + } + + /// Returns a live stream of all NewTTL events emitted by this contract. + Stream newTTLEvents( + {_i1.BlockNum? fromBlock, _i1.BlockNum? toBlock}) { + final event = self.event('NewTTL'); + final filter = _i1.FilterOptions.events( + contract: self, event: event, fromBlock: fromBlock, toBlock: toBlock); + return client.events(filter).map((_i1.FilterEvent result) { + final decoded = event.decodeResults(result.topics!, result.data!); + return NewTTL(decoded); + }); + } + + /// Returns a live stream of all Transfer events emitted by this contract. + Stream transferEvents( + {_i1.BlockNum? fromBlock, _i1.BlockNum? toBlock}) { + final event = self.event('Transfer'); + final filter = _i1.FilterOptions.events( + contract: self, event: event, fromBlock: fromBlock, toBlock: toBlock); + return client.events(filter).map((_i1.FilterEvent result) { + final decoded = event.decodeResults(result.topics!, result.data!); + return Transfer(decoded); + }); + } +} + +class ApprovalForAll { + ApprovalForAll(List response) + : owner = (response[0] as _i1.EthereumAddress), + operator = (response[1] as _i1.EthereumAddress), + approved = (response[2] as bool); + + final _i1.EthereumAddress owner; + + final _i1.EthereumAddress operator; + + final bool approved; +} + +class NewOwner { + NewOwner(List response) + : node = (response[0] as _i2.Uint8List), + label = (response[1] as _i2.Uint8List), + owner = (response[2] as _i1.EthereumAddress); + + final _i2.Uint8List node; + + final _i2.Uint8List label; + + final _i1.EthereumAddress owner; +} + +class NewResolver { + NewResolver(List response) + : node = (response[0] as _i2.Uint8List), + resolver = (response[1] as _i1.EthereumAddress); + + final _i2.Uint8List node; + + final _i1.EthereumAddress resolver; +} + +class NewTTL { + NewTTL(List response) + : node = (response[0] as _i2.Uint8List), + ttl = (response[1] as BigInt); + + final _i2.Uint8List node; + + final BigInt ttl; +} + +class Transfer { + Transfer(List response) + : node = (response[0] as _i2.Uint8List), + owner = (response[1] as _i1.EthereumAddress); + + final _i2.Uint8List node; + + final _i1.EthereumAddress owner; +} diff --git a/lib/src/contracts/ens_resolver.g.dart b/lib/src/contracts/ens_resolver.g.dart new file mode 100644 index 0000000..21a2a8c --- /dev/null +++ b/lib/src/contracts/ens_resolver.g.dart @@ -0,0 +1,641 @@ +// Generated code, do not modify. Run `build_runner build` to re-generate! +// @dart=2.12 +import 'package:ens_dart/src/ens_dart.dart'; +import 'package:web3dart/web3dart.dart' as _i1; +import 'dart:typed_data' as _i2; + +final _contractAbi = _i1.ContractAbi.fromJson( + '[{"inputs":[{"internalType":"contract ENS","name":"_ens","type":"address"}],"payable":false,"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"node","type":"bytes32"},{"indexed":true,"internalType":"uint256","name":"contentType","type":"uint256"}],"name":"ABIChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"node","type":"bytes32"},{"indexed":false,"internalType":"address","name":"a","type":"address"}],"name":"AddrChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"node","type":"bytes32"},{"indexed":false,"internalType":"uint256","name":"coinType","type":"uint256"},{"indexed":false,"internalType":"bytes","name":"newAddress","type":"bytes"}],"name":"AddressChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"node","type":"bytes32"},{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"target","type":"address"},{"indexed":false,"internalType":"bool","name":"isAuthorised","type":"bool"}],"name":"AuthorisationChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"node","type":"bytes32"},{"indexed":false,"internalType":"bytes","name":"hash","type":"bytes"}],"name":"ContenthashChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"node","type":"bytes32"},{"indexed":false,"internalType":"bytes","name":"name","type":"bytes"},{"indexed":false,"internalType":"uint16","name":"resource","type":"uint16"},{"indexed":false,"internalType":"bytes","name":"record","type":"bytes"}],"name":"DNSRecordChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"node","type":"bytes32"},{"indexed":false,"internalType":"bytes","name":"name","type":"bytes"},{"indexed":false,"internalType":"uint16","name":"resource","type":"uint16"}],"name":"DNSRecordDeleted","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"node","type":"bytes32"}],"name":"DNSZoneCleared","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"node","type":"bytes32"},{"indexed":true,"internalType":"bytes4","name":"interfaceID","type":"bytes4"},{"indexed":false,"internalType":"address","name":"implementer","type":"address"}],"name":"InterfaceChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"node","type":"bytes32"},{"indexed":false,"internalType":"string","name":"name","type":"string"}],"name":"NameChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"node","type":"bytes32"},{"indexed":false,"internalType":"bytes32","name":"x","type":"bytes32"},{"indexed":false,"internalType":"bytes32","name":"y","type":"bytes32"}],"name":"PubkeyChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"node","type":"bytes32"},{"indexed":true,"internalType":"string","name":"indexedKey","type":"string"},{"indexed":false,"internalType":"string","name":"key","type":"string"}],"name":"TextChanged","type":"event"},{"constant":true,"inputs":[{"internalType":"bytes32","name":"node","type":"bytes32"},{"internalType":"uint256","name":"contentTypes","type":"uint256"}],"name":"ABI","outputs":[{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"bytes","name":"","type":"bytes"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"internalType":"bytes32","name":"node","type":"bytes32"}],"name":"addr","outputs":[{"internalType":"address payable","name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"internalType":"bytes32","name":"node","type":"bytes32"},{"internalType":"uint256","name":"coinType","type":"uint256"}],"name":"addr","outputs":[{"internalType":"bytes","name":"","type":"bytes"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"internalType":"bytes32","name":"","type":"bytes32"},{"internalType":"address","name":"","type":"address"},{"internalType":"address","name":"","type":"address"}],"name":"authorisations","outputs":[{"internalType":"bool","name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"internalType":"bytes32","name":"node","type":"bytes32"}],"name":"clearDNSZone","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"internalType":"bytes32","name":"node","type":"bytes32"}],"name":"contenthash","outputs":[{"internalType":"bytes","name":"","type":"bytes"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"internalType":"bytes32","name":"node","type":"bytes32"},{"internalType":"bytes32","name":"name","type":"bytes32"},{"internalType":"uint16","name":"resource","type":"uint16"}],"name":"dnsRecord","outputs":[{"internalType":"bytes","name":"","type":"bytes"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"internalType":"bytes32","name":"node","type":"bytes32"},{"internalType":"bytes32","name":"name","type":"bytes32"}],"name":"hasDNSRecords","outputs":[{"internalType":"bool","name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"internalType":"bytes32","name":"node","type":"bytes32"},{"internalType":"bytes4","name":"interfaceID","type":"bytes4"}],"name":"interfaceImplementer","outputs":[{"internalType":"address","name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"internalType":"bytes32","name":"node","type":"bytes32"}],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"internalType":"bytes32","name":"node","type":"bytes32"}],"name":"pubkey","outputs":[{"internalType":"bytes32","name":"x","type":"bytes32"},{"internalType":"bytes32","name":"y","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"internalType":"bytes32","name":"node","type":"bytes32"},{"internalType":"uint256","name":"contentType","type":"uint256"},{"internalType":"bytes","name":"data","type":"bytes"}],"name":"setABI","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"bytes32","name":"node","type":"bytes32"},{"internalType":"uint256","name":"coinType","type":"uint256"},{"internalType":"bytes","name":"a","type":"bytes"}],"name":"setAddr","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"bytes32","name":"node","type":"bytes32"},{"internalType":"address","name":"a","type":"address"}],"name":"setAddr","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"bytes32","name":"node","type":"bytes32"},{"internalType":"address","name":"target","type":"address"},{"internalType":"bool","name":"isAuthorised","type":"bool"}],"name":"setAuthorisation","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"bytes32","name":"node","type":"bytes32"},{"internalType":"bytes","name":"hash","type":"bytes"}],"name":"setContenthash","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"bytes32","name":"node","type":"bytes32"},{"internalType":"bytes","name":"data","type":"bytes"}],"name":"setDNSRecords","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"bytes32","name":"node","type":"bytes32"},{"internalType":"bytes4","name":"interfaceID","type":"bytes4"},{"internalType":"address","name":"implementer","type":"address"}],"name":"setInterface","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"bytes32","name":"node","type":"bytes32"},{"internalType":"string","name":"name","type":"string"}],"name":"setName","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"bytes32","name":"node","type":"bytes32"},{"internalType":"bytes32","name":"x","type":"bytes32"},{"internalType":"bytes32","name":"y","type":"bytes32"}],"name":"setPubkey","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"bytes32","name":"node","type":"bytes32"},{"internalType":"string","name":"key","type":"string"},{"internalType":"string","name":"value","type":"string"}],"name":"setText","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"internalType":"bytes4","name":"interfaceID","type":"bytes4"}],"name":"supportsInterface","outputs":[{"internalType":"bool","name":"","type":"bool"}],"payable":false,"stateMutability":"pure","type":"function"},{"constant":true,"inputs":[{"internalType":"bytes32","name":"node","type":"bytes32"},{"internalType":"string","name":"key","type":"string"}],"name":"text","outputs":[{"internalType":"string","name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"}]', + 'Ens'); + +class Ens extends _i1.GeneratedContract { + Ens( + {_i1.EthereumAddress? address, + required _i1.Web3Client client, + int? chainId}) + : super( + _i1.DeployedContract( + _contractAbi, + address ?? ENS_RESOLVER, + ), + client, + chainId, + ); + + String? _ensName; + String? get ensName => _ensName; + Ens withName(String? _name) { + _ensName = _name; + return this; + } + + EnsTextRecord? _textRecord; + EnsTextRecord? get textRecord => _textRecord; + void setEnsTextRecord(EnsTextRecord? _) { + _textRecord = _; + } + + Ens reverseEns(_i1.EthereumAddress addr) => Ens( + address: addr, + client: client, + ); + + _i1.EthereumAddress? _ensAddress; + _i1.EthereumAddress? get ensAddress => _ensAddress; + Ens withAddress(Object? _) { + if (_.runtimeType == _i1.EthereumAddress) { + _ensAddress = _ as _i1.EthereumAddress; + } else { + _ensAddress = _i1.EthereumAddress.fromHex('${_ ?? ''}'); + } + return this; + } + + /// The optional [atBlock] parameter can be used to view historical data. When + /// set, the function will be evaluated in the specified block. By default, the + /// latest on-chain block will be used. + Future abi(_i2.Uint8List node, BigInt contentTypes, + {_i1.BlockNum? atBlock}) async { + final function = self.abi.functions[1]; + assert(checkSignature(function, '2203ab56')); + final params = [node, contentTypes]; + final response = await read(function, params, atBlock); + return ABI(response); + } + + /// The optional [atBlock] parameter can be used to view historical data. When + /// set, the function will be evaluated in the specified block. By default, the + /// latest on-chain block will be used. + Future<_i1.EthereumAddress> addr(_i2.Uint8List node, + {_i1.BlockNum? atBlock}) async { + final function = self.abi.functions[2]; + assert(checkSignature(function, '3b3b57de')); + final params = [node]; + final response = await read(function, params, atBlock); + return (response[0] as _i1.EthereumAddress); + } + + /// The optional [atBlock] parameter can be used to view historical data. When + /// set, the function will be evaluated in the specified block. By default, the + /// latest on-chain block will be used. + Future<_i2.Uint8List> addr$2(_i2.Uint8List node, BigInt coinType, + {_i1.BlockNum? atBlock}) async { + final function = self.abi.functions[3]; + assert(checkSignature(function, 'f1cb7e06')); + final params = [node, coinType]; + final response = await read(function, params, atBlock); + return (response[0] as _i2.Uint8List); + } + + /// The optional [atBlock] parameter can be used to view historical data. When + /// set, the function will be evaluated in the specified block. By default, the + /// latest on-chain block will be used. + Future authorisations(_i2.Uint8List $param5, + _i1.EthereumAddress $param6, _i1.EthereumAddress $param7, + {_i1.BlockNum? atBlock}) async { + final function = self.abi.functions[4]; + assert(checkSignature(function, 'f86bc879')); + final params = [$param5, $param6, $param7]; + final response = await read(function, params, atBlock); + return (response[0] as bool); + } + + /// The optional [transaction] parameter can be used to override parameters + /// like the gas price, nonce and max gas. The `data` and `to` fields will be + /// set by the contract. + Future clearDNSZone(_i2.Uint8List node, + {required _i1.Credentials credentials, + _i1.Transaction? transaction}) async { + final function = self.abi.functions[5]; + assert(checkSignature(function, 'ad5780af')); + final params = [node]; + return write(credentials, transaction, function, params); + } + + /// The optional [atBlock] parameter can be used to view historical data. When + /// set, the function will be evaluated in the specified block. By default, the + /// latest on-chain block will be used. + Future<_i2.Uint8List> contenthash(_i2.Uint8List node, + {_i1.BlockNum? atBlock}) async { + final function = self.abi.functions[6]; + assert(checkSignature(function, 'bc1c58d1')); + final params = [node]; + final response = await read(function, params, atBlock); + return (response[0] as _i2.Uint8List); + } + + /// The optional [atBlock] parameter can be used to view historical data. When + /// set, the function will be evaluated in the specified block. By default, the + /// latest on-chain block will be used. + Future<_i2.Uint8List> dnsRecord( + _i2.Uint8List node, _i2.Uint8List name, BigInt resource, + {_i1.BlockNum? atBlock}) async { + final function = self.abi.functions[7]; + assert(checkSignature(function, 'a8fa5682')); + final params = [node, name, resource]; + final response = await read(function, params, atBlock); + return (response[0] as _i2.Uint8List); + } + + /// The optional [atBlock] parameter can be used to view historical data. When + /// set, the function will be evaluated in the specified block. By default, the + /// latest on-chain block will be used. + Future hasDNSRecords(_i2.Uint8List node, _i2.Uint8List name, + {_i1.BlockNum? atBlock}) async { + final function = self.abi.functions[8]; + assert(checkSignature(function, '4cbf6ba4')); + final params = [node, name]; + final response = await read(function, params, atBlock); + return (response[0] as bool); + } + + /// The optional [atBlock] parameter can be used to view historical data. When + /// set, the function will be evaluated in the specified block. By default, the + /// latest on-chain block will be used. + Future<_i1.EthereumAddress> interfaceImplementer( + _i2.Uint8List node, _i2.Uint8List interfaceID, + {_i1.BlockNum? atBlock}) async { + final function = self.abi.functions[9]; + assert(checkSignature(function, '124a319c')); + final params = [node, interfaceID]; + final response = await read(function, params, atBlock); + return (response[0] as _i1.EthereumAddress); + } + + /// The optional [atBlock] parameter can be used to view historical data. When + /// set, the function will be evaluated in the specified block. By default, the + /// latest on-chain block will be used. + Future name(_i2.Uint8List node, {_i1.BlockNum? atBlock}) async { + final function = self.abi.functions[10]; + assert(checkSignature(function, '691f3431')); + final params = [node]; + final response = await read(function, params, atBlock); + return (response[0] as String); + } + + /// The optional [atBlock] parameter can be used to view historical data. When + /// set, the function will be evaluated in the specified block. By default, the + /// latest on-chain block will be used. + Future pubkey(_i2.Uint8List node, {_i1.BlockNum? atBlock}) async { + final function = self.abi.functions[11]; + assert(checkSignature(function, 'c8690233')); + final params = [node]; + final response = await read(function, params, atBlock); + return Pubkey(response); + } + + /// The optional [transaction] parameter can be used to override parameters + /// like the gas price, nonce and max gas. The `data` and `to` fields will be + /// set by the contract. + Future setABI( + _i2.Uint8List node, BigInt contentType, _i2.Uint8List data, + {required _i1.Credentials credentials, + _i1.Transaction? transaction}) async { + final function = self.abi.functions[12]; + assert(checkSignature(function, '623195b0')); + final params = [node, contentType, data]; + return write(credentials, transaction, function, params); + } + + /// The optional [transaction] parameter can be used to override parameters + /// like the gas price, nonce and max gas. The `data` and `to` fields will be + /// set by the contract. + Future setAddr(_i2.Uint8List node, BigInt coinType, _i2.Uint8List a, + {required _i1.Credentials credentials, + _i1.Transaction? transaction}) async { + final function = self.abi.functions[13]; + assert(checkSignature(function, '8b95dd71')); + final params = [node, coinType, a]; + return write(credentials, transaction, function, params); + } + + /// The optional [transaction] parameter can be used to override parameters + /// like the gas price, nonce and max gas. The `data` and `to` fields will be + /// set by the contract. + Future setAddr$2(_i2.Uint8List node, _i1.EthereumAddress a, + {required _i1.Credentials credentials, + _i1.Transaction? transaction}) async { + final function = self.abi.functions[14]; + assert(checkSignature(function, 'd5fa2b00')); + final params = [node, a]; + return write(credentials, transaction, function, params); + } + + /// The optional [transaction] parameter can be used to override parameters + /// like the gas price, nonce and max gas. The `data` and `to` fields will be + /// set by the contract. + Future setAuthorisation( + _i2.Uint8List node, _i1.EthereumAddress target, bool isAuthorised, + {required _i1.Credentials credentials, + _i1.Transaction? transaction}) async { + final function = self.abi.functions[15]; + assert(checkSignature(function, '3e9ce794')); + final params = [node, target, isAuthorised]; + return write(credentials, transaction, function, params); + } + + /// The optional [transaction] parameter can be used to override parameters + /// like the gas price, nonce and max gas. The `data` and `to` fields will be + /// set by the contract. + Future setContenthash(_i2.Uint8List node, _i2.Uint8List hash, + {required _i1.Credentials credentials, + _i1.Transaction? transaction}) async { + final function = self.abi.functions[16]; + assert(checkSignature(function, '304e6ade')); + final params = [node, hash]; + return write(credentials, transaction, function, params); + } + + /// The optional [transaction] parameter can be used to override parameters + /// like the gas price, nonce and max gas. The `data` and `to` fields will be + /// set by the contract. + Future setDNSRecords(_i2.Uint8List node, _i2.Uint8List data, + {required _i1.Credentials credentials, + _i1.Transaction? transaction}) async { + final function = self.abi.functions[17]; + assert(checkSignature(function, '0af179d7')); + final params = [node, data]; + return write(credentials, transaction, function, params); + } + + /// The optional [transaction] parameter can be used to override parameters + /// like the gas price, nonce and max gas. The `data` and `to` fields will be + /// set by the contract. + Future setInterface(_i2.Uint8List node, _i2.Uint8List interfaceID, + _i1.EthereumAddress implementer, + {required _i1.Credentials credentials, + _i1.Transaction? transaction}) async { + final function = self.abi.functions[18]; + assert(checkSignature(function, 'e59d895d')); + final params = [node, interfaceID, implementer]; + return write(credentials, transaction, function, params); + } + + /// The optional [transaction] parameter can be used to override parameters + /// like the gas price, nonce and max gas. The `data` and `to` fields will be + /// set by the contract. + Future setName(_i2.Uint8List node, String name, + {required _i1.Credentials credentials, + _i1.Transaction? transaction}) async { + final function = self.abi.functions[19]; + assert(checkSignature(function, '77372213')); + final params = [node, name]; + return write(credentials, transaction, function, params); + } + + /// The optional [transaction] parameter can be used to override parameters + /// like the gas price, nonce and max gas. The `data` and `to` fields will be + /// set by the contract. + Future setPubkey(_i2.Uint8List node, _i2.Uint8List x, _i2.Uint8List y, + {required _i1.Credentials credentials, + _i1.Transaction? transaction}) async { + final function = self.abi.functions[20]; + assert(checkSignature(function, '29cd62ea')); + final params = [node, x, y]; + return write(credentials, transaction, function, params); + } + + /// The optional [transaction] parameter can be used to override parameters + /// like the gas price, nonce and max gas. The `data` and `to` fields will be + /// set by the contract. + Future setText(_i2.Uint8List node, String key, String value, + {required _i1.Credentials credentials, + _i1.Transaction? transaction}) async { + final function = self.abi.functions[21]; + assert(checkSignature(function, '10f13a8c')); + final params = [node, key, value]; + return write(credentials, transaction, function, params); + } + + /// The optional [atBlock] parameter can be used to view historical data. When + /// set, the function will be evaluated in the specified block. By default, the + /// latest on-chain block will be used. + Future supportsInterface(_i2.Uint8List interfaceID, + {_i1.BlockNum? atBlock}) async { + final function = self.abi.functions[22]; + assert(checkSignature(function, '01ffc9a7')); + final params = [interfaceID]; + final response = await read(function, params, atBlock); + return (response[0] as bool); + } + + /// The optional [atBlock] parameter can be used to view historical data. When + /// set, the function will be evaluated in the specified block. By default, the + /// latest on-chain block will be used. + Future text(_i2.Uint8List node, String key, + {_i1.BlockNum? atBlock}) async { + final function = self.abi.functions[23]; + assert(checkSignature(function, '59d1d43c')); + final params = [node, key]; + final response = await read(function, params, atBlock); + return (response[0] as String); + } + + /// Returns a live stream of all ABIChanged events emitted by this contract. + Stream aBIChangedEvents( + {_i1.BlockNum? fromBlock, _i1.BlockNum? toBlock}) { + final event = self.event('ABIChanged'); + final filter = _i1.FilterOptions.events( + contract: self, event: event, fromBlock: fromBlock, toBlock: toBlock); + return client.events(filter).map((_i1.FilterEvent result) { + final decoded = event.decodeResults(result.topics!, result.data!); + return ABIChanged(decoded); + }); + } + + /// Returns a live stream of all AddrChanged events emitted by this contract. + Stream addrChangedEvents( + {_i1.BlockNum? fromBlock, _i1.BlockNum? toBlock}) { + final event = self.event('AddrChanged'); + final filter = _i1.FilterOptions.events( + contract: self, event: event, fromBlock: fromBlock, toBlock: toBlock); + return client.events(filter).map((_i1.FilterEvent result) { + final decoded = event.decodeResults(result.topics!, result.data!); + return AddrChanged(decoded); + }); + } + + /// Returns a live stream of all AddressChanged events emitted by this contract. + Stream addressChangedEvents( + {_i1.BlockNum? fromBlock, _i1.BlockNum? toBlock}) { + final event = self.event('AddressChanged'); + final filter = _i1.FilterOptions.events( + contract: self, event: event, fromBlock: fromBlock, toBlock: toBlock); + return client.events(filter).map((_i1.FilterEvent result) { + final decoded = event.decodeResults(result.topics!, result.data!); + return AddressChanged(decoded); + }); + } + + /// Returns a live stream of all AuthorisationChanged events emitted by this contract. + Stream authorisationChangedEvents( + {_i1.BlockNum? fromBlock, _i1.BlockNum? toBlock}) { + final event = self.event('AuthorisationChanged'); + final filter = _i1.FilterOptions.events( + contract: self, event: event, fromBlock: fromBlock, toBlock: toBlock); + return client.events(filter).map((_i1.FilterEvent result) { + final decoded = event.decodeResults(result.topics!, result.data!); + return AuthorisationChanged(decoded); + }); + } + + /// Returns a live stream of all ContenthashChanged events emitted by this contract. + Stream contenthashChangedEvents( + {_i1.BlockNum? fromBlock, _i1.BlockNum? toBlock}) { + final event = self.event('ContenthashChanged'); + final filter = _i1.FilterOptions.events( + contract: self, event: event, fromBlock: fromBlock, toBlock: toBlock); + return client.events(filter).map((_i1.FilterEvent result) { + final decoded = event.decodeResults(result.topics!, result.data!); + return ContenthashChanged(decoded); + }); + } + + /// Returns a live stream of all DNSRecordChanged events emitted by this contract. + Stream dNSRecordChangedEvents( + {_i1.BlockNum? fromBlock, _i1.BlockNum? toBlock}) { + final event = self.event('DNSRecordChanged'); + final filter = _i1.FilterOptions.events( + contract: self, event: event, fromBlock: fromBlock, toBlock: toBlock); + return client.events(filter).map((_i1.FilterEvent result) { + final decoded = event.decodeResults(result.topics!, result.data!); + return DNSRecordChanged(decoded); + }); + } + + /// Returns a live stream of all DNSRecordDeleted events emitted by this contract. + Stream dNSRecordDeletedEvents( + {_i1.BlockNum? fromBlock, _i1.BlockNum? toBlock}) { + final event = self.event('DNSRecordDeleted'); + final filter = _i1.FilterOptions.events( + contract: self, event: event, fromBlock: fromBlock, toBlock: toBlock); + return client.events(filter).map((_i1.FilterEvent result) { + final decoded = event.decodeResults(result.topics!, result.data!); + return DNSRecordDeleted(decoded); + }); + } + + /// Returns a live stream of all DNSZoneCleared events emitted by this contract. + Stream dNSZoneClearedEvents( + {_i1.BlockNum? fromBlock, _i1.BlockNum? toBlock}) { + final event = self.event('DNSZoneCleared'); + final filter = _i1.FilterOptions.events( + contract: self, event: event, fromBlock: fromBlock, toBlock: toBlock); + return client.events(filter).map((_i1.FilterEvent result) { + final decoded = event.decodeResults(result.topics!, result.data!); + return DNSZoneCleared(decoded); + }); + } + + /// Returns a live stream of all InterfaceChanged events emitted by this contract. + Stream interfaceChangedEvents( + {_i1.BlockNum? fromBlock, _i1.BlockNum? toBlock}) { + final event = self.event('InterfaceChanged'); + final filter = _i1.FilterOptions.events( + contract: self, event: event, fromBlock: fromBlock, toBlock: toBlock); + return client.events(filter).map((_i1.FilterEvent result) { + final decoded = event.decodeResults(result.topics!, result.data!); + return InterfaceChanged(decoded); + }); + } + + /// Returns a live stream of all NameChanged events emitted by this contract. + Stream nameChangedEvents( + {_i1.BlockNum? fromBlock, _i1.BlockNum? toBlock}) { + final event = self.event('NameChanged'); + final filter = _i1.FilterOptions.events( + contract: self, event: event, fromBlock: fromBlock, toBlock: toBlock); + return client.events(filter).map((_i1.FilterEvent result) { + final decoded = event.decodeResults(result.topics!, result.data!); + return NameChanged(decoded); + }); + } + + /// Returns a live stream of all PubkeyChanged events emitted by this contract. + Stream pubkeyChangedEvents( + {_i1.BlockNum? fromBlock, _i1.BlockNum? toBlock}) { + final event = self.event('PubkeyChanged'); + final filter = _i1.FilterOptions.events( + contract: self, event: event, fromBlock: fromBlock, toBlock: toBlock); + return client.events(filter).map((_i1.FilterEvent result) { + final decoded = event.decodeResults(result.topics!, result.data!); + return PubkeyChanged(decoded); + }); + } + + /// Returns a live stream of all TextChanged events emitted by this contract. + Stream textChangedEvents( + {_i1.BlockNum? fromBlock, _i1.BlockNum? toBlock}) { + final event = self.event('TextChanged'); + final filter = _i1.FilterOptions.events( + contract: self, event: event, fromBlock: fromBlock, toBlock: toBlock); + return client.events(filter).map((_i1.FilterEvent result) { + final decoded = event.decodeResults(result.topics!, result.data!); + return TextChanged(decoded); + }); + } +} + +class ABI { + ABI(List response) + : var1 = (response[0] as BigInt), + var2 = (response[1] as _i2.Uint8List); + + final BigInt var1; + + final _i2.Uint8List var2; +} + +class Pubkey { + Pubkey(List response) + : x = (response[0] as _i2.Uint8List), + y = (response[1] as _i2.Uint8List); + + final _i2.Uint8List x; + + final _i2.Uint8List y; +} + +class ABIChanged { + ABIChanged(List response) + : node = (response[0] as _i2.Uint8List), + contentType = (response[1] as BigInt); + + final _i2.Uint8List node; + + final BigInt contentType; +} + +class AddrChanged { + AddrChanged(List response) + : node = (response[0] as _i2.Uint8List), + a = (response[1] as _i1.EthereumAddress); + + final _i2.Uint8List node; + + final _i1.EthereumAddress a; +} + +class AddressChanged { + AddressChanged(List response) + : node = (response[0] as _i2.Uint8List), + coinType = (response[1] as BigInt), + newAddress = (response[2] as _i2.Uint8List); + + final _i2.Uint8List node; + + final BigInt coinType; + + final _i2.Uint8List newAddress; +} + +class AuthorisationChanged { + AuthorisationChanged(List response) + : node = (response[0] as _i2.Uint8List), + owner = (response[1] as _i1.EthereumAddress), + target = (response[2] as _i1.EthereumAddress), + isAuthorised = (response[3] as bool); + + final _i2.Uint8List node; + + final _i1.EthereumAddress owner; + + final _i1.EthereumAddress target; + + final bool isAuthorised; +} + +class ContenthashChanged { + ContenthashChanged(List response) + : node = (response[0] as _i2.Uint8List), + hash = (response[1] as _i2.Uint8List); + + final _i2.Uint8List node; + + final _i2.Uint8List hash; +} + +class DNSRecordChanged { + DNSRecordChanged(List response) + : node = (response[0] as _i2.Uint8List), + name = (response[1] as _i2.Uint8List), + resource = (response[2] as BigInt), + record = (response[3] as _i2.Uint8List); + + final _i2.Uint8List node; + + final _i2.Uint8List name; + + final BigInt resource; + + final _i2.Uint8List record; +} + +class DNSRecordDeleted { + DNSRecordDeleted(List response) + : node = (response[0] as _i2.Uint8List), + name = (response[1] as _i2.Uint8List), + resource = (response[2] as BigInt); + + final _i2.Uint8List node; + + final _i2.Uint8List name; + + final BigInt resource; +} + +class DNSZoneCleared { + DNSZoneCleared(List response) + : node = (response[0] as _i2.Uint8List); + + final _i2.Uint8List node; +} + +class InterfaceChanged { + InterfaceChanged(List response) + : node = (response[0] as _i2.Uint8List), + interfaceID = (response[1] as _i2.Uint8List), + implementer = (response[2] as _i1.EthereumAddress); + + final _i2.Uint8List node; + + final _i2.Uint8List interfaceID; + + final _i1.EthereumAddress implementer; +} + +class NameChanged { + NameChanged(List response) + : node = (response[0] as _i2.Uint8List), + name = (response[1] as String); + + final _i2.Uint8List node; + + final String name; +} + +class PubkeyChanged { + PubkeyChanged(List response) + : node = (response[0] as _i2.Uint8List), + x = (response[1] as _i2.Uint8List), + y = (response[2] as _i2.Uint8List); + + final _i2.Uint8List node; + + final _i2.Uint8List x; + + final _i2.Uint8List y; +} + +class TextChanged { + TextChanged(List response) + : node = (response[0] as _i2.Uint8List), + indexedKey = (response[1] as String), + key = (response[2] as String); + + final _i2.Uint8List node; + + final String indexedKey; + + final String key; +} diff --git a/lib/src/contracts/ens_reverse_registrar.g.dart b/lib/src/contracts/ens_reverse_registrar.g.dart new file mode 100644 index 0000000..8feb272 --- /dev/null +++ b/lib/src/contracts/ens_reverse_registrar.g.dart @@ -0,0 +1,99 @@ +// Generated code, do not modify. Run `build_runner build` to re-generate! +// @dart=2.12 +import 'package:ens_dart/src/const/const.dart'; +import 'package:web3dart/web3dart.dart' as _i1; +import 'dart:typed_data' as _i2; + +final _contractAbi = _i1.ContractAbi.fromJson( + '[{"inputs":[{"internalType":"contract ENS","name":"ensAddr","type":"address"},{"internalType":"contract Resolver","name":"resolverAddr","type":"address"}],"payable":false,"stateMutability":"nonpayable","type":"constructor"},{"constant":true,"inputs":[],"name":"ADDR_REVERSE_NODE","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"owner","type":"address"}],"name":"claim","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"resolver","type":"address"}],"name":"claimWithResolver","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"defaultResolver","outputs":[{"internalType":"contract Resolver","name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"ens","outputs":[{"internalType":"contract ENS","name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"internalType":"address","name":"addr","type":"address"}],"name":"node","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"payable":false,"stateMutability":"pure","type":"function"},{"constant":false,"inputs":[{"internalType":"string","name":"name","type":"string"}],"name":"setName","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"payable":false,"stateMutability":"nonpayable","type":"function"}]', + 'EnsReverseRegistrar'); + +class EnsReverseRegistrar extends _i1.GeneratedContract { + EnsReverseRegistrar( + {_i1.EthereumAddress? address, + required _i1.Web3Client client, + int? chainId}) + : super(_i1.DeployedContract(_contractAbi, address ?? ENS_REVERSE_REGISTRAR), client, chainId); + + /// The optional [atBlock] parameter can be used to view historical data. When + /// set, the function will be evaluated in the specified block. By default, the + /// latest on-chain block will be used. + Future<_i2.Uint8List> aDDRkREVERSEkNODE({_i1.BlockNum? atBlock}) async { + final function = self.abi.functions[1]; + assert(checkSignature(function, '7cf8a2eb')); + final params = []; + final response = await read(function, params, atBlock); + return (response[0] as _i2.Uint8List); + } + + /// The optional [transaction] parameter can be used to override parameters + /// like the gas price, nonce and max gas. The `data` and `to` fields will be + /// set by the contract. + Future claim(_i1.EthereumAddress owner, + {required _i1.Credentials credentials, + _i1.Transaction? transaction}) async { + final function = self.abi.functions[2]; + assert(checkSignature(function, '1e83409a')); + final params = [owner]; + return write(credentials, transaction, function, params); + } + + /// The optional [transaction] parameter can be used to override parameters + /// like the gas price, nonce and max gas. The `data` and `to` fields will be + /// set by the contract. + Future claimWithResolver( + _i1.EthereumAddress owner, _i1.EthereumAddress resolver, + {required _i1.Credentials credentials, + _i1.Transaction? transaction}) async { + final function = self.abi.functions[3]; + assert(checkSignature(function, '0f5a5466')); + final params = [owner, resolver]; + return write(credentials, transaction, function, params); + } + + /// The optional [atBlock] parameter can be used to view historical data. When + /// set, the function will be evaluated in the specified block. By default, the + /// latest on-chain block will be used. + Future<_i1.EthereumAddress> defaultResolver({_i1.BlockNum? atBlock}) async { + final function = self.abi.functions[4]; + assert(checkSignature(function, '828eab0e')); + final params = []; + final response = await read(function, params, atBlock); + return (response[0] as _i1.EthereumAddress); + } + + /// The optional [atBlock] parameter can be used to view historical data. When + /// set, the function will be evaluated in the specified block. By default, the + /// latest on-chain block will be used. + Future<_i1.EthereumAddress> ens({_i1.BlockNum? atBlock}) async { + final function = self.abi.functions[5]; + assert(checkSignature(function, '3f15457f')); + final params = []; + final response = await read(function, params, atBlock); + return (response[0] as _i1.EthereumAddress); + } + + /// The optional [atBlock] parameter can be used to view historical data. When + /// set, the function will be evaluated in the specified block. By default, the + /// latest on-chain block will be used. + Future<_i2.Uint8List> node(_i1.EthereumAddress addr, + {_i1.BlockNum? atBlock}) async { + final function = self.abi.functions[6]; + assert(checkSignature(function, 'bffbe61c')); + final params = [addr]; + final response = await read(function, params, atBlock); + return (response[0] as _i2.Uint8List); + } + + /// The optional [transaction] parameter can be used to override parameters + /// like the gas price, nonce and max gas. The `data` and `to` fields will be + /// set by the contract. + Future setName(String name, + {required _i1.Credentials credentials, + _i1.Transaction? transaction}) async { + final function = self.abi.functions[7]; + assert(checkSignature(function, 'c47f0027')); + final params = [name]; + return write(credentials, transaction, function, params); + } +} diff --git a/lib/src/contracts/ens_reverse_resolver.g.dart b/lib/src/contracts/ens_reverse_resolver.g.dart new file mode 100644 index 0000000..12f40b4 --- /dev/null +++ b/lib/src/contracts/ens_reverse_resolver.g.dart @@ -0,0 +1,58 @@ +// Generated code, do not modify. Run `build_runner build` to re-generate! +// @dart=2.12 +import 'package:ens_dart/src/const/const.dart'; +import 'package:web3dart/web3dart.dart' as _i1; +import 'dart:typed_data' as _i2; + +final _contractAbi = _i1.ContractAbi.fromJson( + '[{"inputs":[{"internalType":"contract ENS","name":"ensAddr","type":"address"}],"payable":false,"stateMutability":"nonpayable","type":"constructor"},{"constant":true,"inputs":[],"name":"ens","outputs":[{"internalType":"contract ENS","name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"internalType":"bytes32","name":"node","type":"bytes32"},{"internalType":"string","name":"_name","type":"string"}],"name":"setName","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"}]', + 'EnsReverseResolver'); + +class EnsReverseResolver extends _i1.GeneratedContract { + EnsReverseResolver({ + _i1.EthereumAddress? address, + required _i1.Web3Client client, + int? chainId, + }) : super( + _i1.DeployedContract( + _contractAbi, + address ?? ENS_REVERSE_RESOLVER, + ), + client, + chainId, + ); + + /// The optional [atBlock] parameter can be used to view historical data. When + /// set, the function will be evaluated in the specified block. By default, the + /// latest on-chain block will be used. + Future<_i1.EthereumAddress> ens({_i1.BlockNum? atBlock}) async { + final function = self.abi.functions[1]; + assert(checkSignature(function, '3f15457f')); + final params = []; + final response = await read(function, params, atBlock); + return (response[0] as _i1.EthereumAddress); + } + + /// The optional [atBlock] parameter can be used to view historical data. When + /// set, the function will be evaluated in the specified block. By default, the + /// latest on-chain block will be used. + Future name(_i2.Uint8List $param0, {_i1.BlockNum? atBlock}) async { + final function = self.abi.functions[2]; + assert(checkSignature(function, '691f3431')); + final params = [$param0]; + final response = await read(function, params, atBlock); + return (response[0] as String); + } + + /// The optional [transaction] parameter can be used to override parameters + /// like the gas price, nonce and max gas. The `data` and `to` fields will be + /// set by the contract. + Future setName(_i2.Uint8List node, String _name, + {required _i1.Credentials credentials, + _i1.Transaction? transaction}) async { + final function = self.abi.functions[3]; + assert(checkSignature(function, '77372213')); + final params = [node, _name]; + return write(credentials, transaction, function, params); + } +} diff --git a/lib/src/contracts/ens_root.g.dart b/lib/src/contracts/ens_root.g.dart new file mode 100644 index 0000000..493c1e7 --- /dev/null +++ b/lib/src/contracts/ens_root.g.dart @@ -0,0 +1,168 @@ +// Generated code, do not modify. Run `build_runner build` to re-generate! +// @dart=2.12 +import 'package:web3dart/web3dart.dart' as _i1; +import 'dart:typed_data' as _i2; + +final _contractAbi = _i1.ContractAbi.fromJson( + '[{"inputs":[{"internalType":"contract ENS","name":"_ens","type":"address"}],"payable":false,"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"label","type":"bytes32"}],"name":"TLDLocked","type":"event"},{"constant":true,"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"controllers","outputs":[{"internalType":"bool","name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"ens","outputs":[{"internalType":"contract ENS","name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"internalType":"address","name":"addr","type":"address"}],"name":"isOwner","outputs":[{"internalType":"bool","name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"internalType":"bytes32","name":"label","type":"bytes32"}],"name":"lock","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"name":"locked","outputs":[{"internalType":"bool","name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"controller","type":"address"},{"internalType":"bool","name":"enabled","type":"bool"}],"name":"setController","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"resolver","type":"address"}],"name":"setResolver","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"bytes32","name":"label","type":"bytes32"},{"internalType":"address","name":"owner","type":"address"}],"name":"setSubnodeOwner","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"internalType":"bytes4","name":"interfaceID","type":"bytes4"}],"name":"supportsInterface","outputs":[{"internalType":"bool","name":"","type":"bool"}],"payable":false,"stateMutability":"pure","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"}]', + 'ENSRoot'); + +class ENSRoot extends _i1.GeneratedContract { + ENSRoot({required _i1.Web3Client client, int? chainId}) + : super( + _i1.DeployedContract( + _contractAbi, + _i1.EthereumAddress.fromHex( + '0xaB528d626EC275E3faD363fF1393A41F581c5897', + ), + ), + client, + chainId); + + /// The optional [atBlock] parameter can be used to view historical data. When + /// set, the function will be evaluated in the specified block. By default, the + /// latest on-chain block will be used. + Future controllers(_i1.EthereumAddress $param0, + {_i1.BlockNum? atBlock}) async { + final function = self.abi.functions[1]; + assert(checkSignature(function, 'da8c229e')); + final params = [$param0]; + final response = await read(function, params, atBlock); + return (response[0] as bool); + } + + /// The optional [atBlock] parameter can be used to view historical data. When + /// set, the function will be evaluated in the specified block. By default, the + /// latest on-chain block will be used. + Future<_i1.EthereumAddress> ens({_i1.BlockNum? atBlock}) async { + final function = self.abi.functions[2]; + assert(checkSignature(function, '3f15457f')); + final params = []; + final response = await read(function, params, atBlock); + return (response[0] as _i1.EthereumAddress); + } + + /// The optional [atBlock] parameter can be used to view historical data. When + /// set, the function will be evaluated in the specified block. By default, the + /// latest on-chain block will be used. + Future isOwner(_i1.EthereumAddress addr, + {_i1.BlockNum? atBlock}) async { + final function = self.abi.functions[3]; + assert(checkSignature(function, '2f54bf6e')); + final params = [addr]; + final response = await read(function, params, atBlock); + return (response[0] as bool); + } + + /// The optional [transaction] parameter can be used to override parameters + /// like the gas price, nonce and max gas. The `data` and `to` fields will be + /// set by the contract. + Future lock(_i2.Uint8List label, + {required _i1.Credentials credentials, + _i1.Transaction? transaction}) async { + final function = self.abi.functions[4]; + assert(checkSignature(function, '01670ba9')); + final params = [label]; + return write(credentials, transaction, function, params); + } + + /// The optional [atBlock] parameter can be used to view historical data. When + /// set, the function will be evaluated in the specified block. By default, the + /// latest on-chain block will be used. + Future locked(_i2.Uint8List $param3, {_i1.BlockNum? atBlock}) async { + final function = self.abi.functions[5]; + assert(checkSignature(function, 'cbe9e764')); + final params = [$param3]; + final response = await read(function, params, atBlock); + return (response[0] as bool); + } + + /// The optional [atBlock] parameter can be used to view historical data. When + /// set, the function will be evaluated in the specified block. By default, the + /// latest on-chain block will be used. + Future<_i1.EthereumAddress> owner({_i1.BlockNum? atBlock}) async { + final function = self.abi.functions[6]; + assert(checkSignature(function, '8da5cb5b')); + final params = []; + final response = await read(function, params, atBlock); + return (response[0] as _i1.EthereumAddress); + } + + /// The optional [transaction] parameter can be used to override parameters + /// like the gas price, nonce and max gas. The `data` and `to` fields will be + /// set by the contract. + Future setController(_i1.EthereumAddress controller, bool enabled, + {required _i1.Credentials credentials, + _i1.Transaction? transaction}) async { + final function = self.abi.functions[7]; + assert(checkSignature(function, 'e0dba60f')); + final params = [controller, enabled]; + return write(credentials, transaction, function, params); + } + + /// The optional [transaction] parameter can be used to override parameters + /// like the gas price, nonce and max gas. The `data` and `to` fields will be + /// set by the contract. + Future setResolver(_i1.EthereumAddress resolver, + {required _i1.Credentials credentials, + _i1.Transaction? transaction}) async { + final function = self.abi.functions[8]; + assert(checkSignature(function, '4e543b26')); + final params = [resolver]; + return write(credentials, transaction, function, params); + } + + /// The optional [transaction] parameter can be used to override parameters + /// like the gas price, nonce and max gas. The `data` and `to` fields will be + /// set by the contract. + Future setSubnodeOwner(_i2.Uint8List label, _i1.EthereumAddress owner, + {required _i1.Credentials credentials, + _i1.Transaction? transaction}) async { + final function = self.abi.functions[9]; + assert(checkSignature(function, '8cb8ecec')); + final params = [label, owner]; + return write(credentials, transaction, function, params); + } + + /// The optional [atBlock] parameter can be used to view historical data. When + /// set, the function will be evaluated in the specified block. By default, the + /// latest on-chain block will be used. + Future supportsInterface(_i2.Uint8List interfaceID, + {_i1.BlockNum? atBlock}) async { + final function = self.abi.functions[10]; + assert(checkSignature(function, '01ffc9a7')); + final params = [interfaceID]; + final response = await read(function, params, atBlock); + return (response[0] as bool); + } + + /// The optional [transaction] parameter can be used to override parameters + /// like the gas price, nonce and max gas. The `data` and `to` fields will be + /// set by the contract. + Future transferOwnership(_i1.EthereumAddress newOwner, + {required _i1.Credentials credentials, + _i1.Transaction? transaction}) async { + final function = self.abi.functions[11]; + assert(checkSignature(function, 'f2fde38b')); + final params = [newOwner]; + return write(credentials, transaction, function, params); + } + + /// Returns a live stream of all TLDLocked events emitted by this contract. + Stream tLDLockedEvents( + {_i1.BlockNum? fromBlock, _i1.BlockNum? toBlock}) { + final event = self.event('TLDLocked'); + final filter = _i1.FilterOptions.events( + contract: self, event: event, fromBlock: fromBlock, toBlock: toBlock); + return client.events(filter).map((_i1.FilterEvent result) { + final decoded = event.decodeResults(result.topics!, result.data!); + return TLDLocked(decoded); + }); + } +} + +class TLDLocked { + TLDLocked(List response) : label = (response[0] as _i2.Uint8List); + + final _i2.Uint8List label; +} diff --git a/lib/src/contracts/ens_service.g.dart b/lib/src/contracts/ens_service.g.dart new file mode 100644 index 0000000..6fa33fa --- /dev/null +++ b/lib/src/contracts/ens_service.g.dart @@ -0,0 +1,192 @@ +// Generated code, do not modify. Run `build_runner build` to re-generate! +// @dart=2.12 +import 'package:web3dart/web3dart.dart' as _i1; +import 'dart:typed_data' as _i2; + +final _contractAbi = _i1.ContractAbi.fromJson( + '[{"constant":true,"inputs":[{"name":"node","type":"bytes32"}],"name":"resolver","outputs":[{"name":"","type":"address"}],"payable":false,"type":"function"},{"constant":true,"inputs":[{"name":"node","type":"bytes32"}],"name":"owner","outputs":[{"name":"","type":"address"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"node","type":"bytes32"},{"name":"label","type":"bytes32"},{"name":"owner","type":"address"}],"name":"setSubnodeOwner","outputs":[],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"node","type":"bytes32"},{"name":"ttl","type":"uint64"}],"name":"setTTL","outputs":[],"payable":false,"type":"function"},{"constant":true,"inputs":[{"name":"node","type":"bytes32"}],"name":"ttl","outputs":[{"name":"","type":"uint64"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"node","type":"bytes32"},{"name":"resolver","type":"address"}],"name":"setResolver","outputs":[],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"node","type":"bytes32"},{"name":"owner","type":"address"}],"name":"setOwner","outputs":[],"payable":false,"type":"function"},{"anonymous":false,"inputs":[{"indexed":true,"name":"node","type":"bytes32"},{"indexed":false,"name":"owner","type":"address"}],"name":"Transfer","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"node","type":"bytes32"},{"indexed":true,"name":"label","type":"bytes32"},{"indexed":false,"name":"owner","type":"address"}],"name":"NewOwner","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"node","type":"bytes32"},{"indexed":false,"name":"resolver","type":"address"}],"name":"NewResolver","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"node","type":"bytes32"},{"indexed":false,"name":"ttl","type":"uint64"}],"name":"NewTTL","type":"event"}]', + 'EnsService'); + +class EnsService extends _i1.GeneratedContract { + EnsService( + {required _i1.EthereumAddress address, + required _i1.Web3Client client, + int? chainId}) + : super(_i1.DeployedContract(_contractAbi, address), client, chainId); + + /// The optional [transaction] parameter can be used to override parameters + /// like the gas price, nonce and max gas. The `data` and `to` fields will be + /// set by the contract. + Future resolver(_i2.Uint8List node, + {required _i1.Credentials credentials, + _i1.Transaction? transaction}) async { + final function = self.abi.functions[0]; + assert(checkSignature(function, '0178b8bf')); + final params = [node]; + return write(credentials, transaction, function, params); + } + + /// The optional [transaction] parameter can be used to override parameters + /// like the gas price, nonce and max gas. The `data` and `to` fields will be + /// set by the contract. + Future owner(_i2.Uint8List node, + {required _i1.Credentials credentials, + _i1.Transaction? transaction}) async { + final function = self.abi.functions[1]; + assert(checkSignature(function, '02571be3')); + final params = [node]; + return write(credentials, transaction, function, params); + } + + /// The optional [transaction] parameter can be used to override parameters + /// like the gas price, nonce and max gas. The `data` and `to` fields will be + /// set by the contract. + Future setSubnodeOwner( + _i2.Uint8List node, _i2.Uint8List label, _i1.EthereumAddress owner, + {required _i1.Credentials credentials, + _i1.Transaction? transaction}) async { + final function = self.abi.functions[2]; + assert(checkSignature(function, '06ab5923')); + final params = [node, label, owner]; + return write(credentials, transaction, function, params); + } + + /// The optional [transaction] parameter can be used to override parameters + /// like the gas price, nonce and max gas. The `data` and `to` fields will be + /// set by the contract. + Future setTTL(_i2.Uint8List node, BigInt ttl, + {required _i1.Credentials credentials, + _i1.Transaction? transaction}) async { + final function = self.abi.functions[3]; + assert(checkSignature(function, '14ab9038')); + final params = [node, ttl]; + return write(credentials, transaction, function, params); + } + + /// The optional [transaction] parameter can be used to override parameters + /// like the gas price, nonce and max gas. The `data` and `to` fields will be + /// set by the contract. + Future ttl(_i2.Uint8List node, + {required _i1.Credentials credentials, + _i1.Transaction? transaction}) async { + final function = self.abi.functions[4]; + assert(checkSignature(function, '16a25cbd')); + final params = [node]; + return write(credentials, transaction, function, params); + } + + /// The optional [transaction] parameter can be used to override parameters + /// like the gas price, nonce and max gas. The `data` and `to` fields will be + /// set by the contract. + Future setResolver(_i2.Uint8List node, _i1.EthereumAddress resolver, + {required _i1.Credentials credentials, + _i1.Transaction? transaction}) async { + final function = self.abi.functions[5]; + assert(checkSignature(function, '1896f70a')); + final params = [node, resolver]; + return write(credentials, transaction, function, params); + } + + /// The optional [transaction] parameter can be used to override parameters + /// like the gas price, nonce and max gas. The `data` and `to` fields will be + /// set by the contract. + Future setOwner(_i2.Uint8List node, _i1.EthereumAddress owner, + {required _i1.Credentials credentials, + _i1.Transaction? transaction}) async { + final function = self.abi.functions[6]; + assert(checkSignature(function, '5b0fc9c3')); + final params = [node, owner]; + return write(credentials, transaction, function, params); + } + + /// Returns a live stream of all Transfer events emitted by this contract. + Stream transferEvents( + {_i1.BlockNum? fromBlock, _i1.BlockNum? toBlock}) { + final event = self.event('Transfer'); + final filter = _i1.FilterOptions.events( + contract: self, event: event, fromBlock: fromBlock, toBlock: toBlock); + return client.events(filter).map((_i1.FilterEvent result) { + final decoded = event.decodeResults(result.topics!, result.data!); + return Transfer(decoded); + }); + } + + /// Returns a live stream of all NewOwner events emitted by this contract. + Stream newOwnerEvents( + {_i1.BlockNum? fromBlock, _i1.BlockNum? toBlock}) { + final event = self.event('NewOwner'); + final filter = _i1.FilterOptions.events( + contract: self, event: event, fromBlock: fromBlock, toBlock: toBlock); + return client.events(filter).map((_i1.FilterEvent result) { + final decoded = event.decodeResults(result.topics!, result.data!); + return NewOwner(decoded); + }); + } + + /// Returns a live stream of all NewResolver events emitted by this contract. + Stream newResolverEvents( + {_i1.BlockNum? fromBlock, _i1.BlockNum? toBlock}) { + final event = self.event('NewResolver'); + final filter = _i1.FilterOptions.events( + contract: self, event: event, fromBlock: fromBlock, toBlock: toBlock); + return client.events(filter).map((_i1.FilterEvent result) { + final decoded = event.decodeResults(result.topics!, result.data!); + return NewResolver(decoded); + }); + } + + /// Returns a live stream of all NewTTL events emitted by this contract. + Stream newTTLEvents( + {_i1.BlockNum? fromBlock, _i1.BlockNum? toBlock}) { + final event = self.event('NewTTL'); + final filter = _i1.FilterOptions.events( + contract: self, event: event, fromBlock: fromBlock, toBlock: toBlock); + return client.events(filter).map((_i1.FilterEvent result) { + final decoded = event.decodeResults(result.topics!, result.data!); + return NewTTL(decoded); + }); + } +} + +class Transfer { + Transfer(List response) + : node = (response[0] as _i2.Uint8List), + owner = (response[1] as _i1.EthereumAddress); + + final _i2.Uint8List node; + + final _i1.EthereumAddress owner; +} + +class NewOwner { + NewOwner(List response) + : node = (response[0] as _i2.Uint8List), + label = (response[1] as _i2.Uint8List), + owner = (response[2] as _i1.EthereumAddress); + + final _i2.Uint8List node; + + final _i2.Uint8List label; + + final _i1.EthereumAddress owner; +} + +class NewResolver { + NewResolver(List response) + : node = (response[0] as _i2.Uint8List), + resolver = (response[1] as _i1.EthereumAddress); + + final _i2.Uint8List node; + + final _i1.EthereumAddress resolver; +} + +class NewTTL { + NewTTL(List response) + : node = (response[0] as _i2.Uint8List), + ttl = (response[1] as BigInt); + + final _i2.Uint8List node; + + final BigInt ttl; +} diff --git a/lib/src/contracts/ens_token.g.dart b/lib/src/contracts/ens_token.g.dart new file mode 100644 index 0000000..e3104d9 --- /dev/null +++ b/lib/src/contracts/ens_token.g.dart @@ -0,0 +1,593 @@ +// Generated code, do not modify. Run `build_runner build` to re-generate! +// @dart=2.12 +import 'package:web3dart/web3dart.dart' as _i1; +import 'dart:typed_data' as _i2; + +final _contractAbi = _i1.ContractAbi.fromJson( + '[{"inputs":[{"internalType":"uint256","name":"freeSupply","type":"uint256"},{"internalType":"uint256","name":"airdropSupply","type":"uint256"},{"internalType":"uint256","name":"_claimPeriodEnds","type":"uint256"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"spender","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"claimant","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"Claim","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"delegator","type":"address"},{"indexed":true,"internalType":"address","name":"fromDelegate","type":"address"},{"indexed":true,"internalType":"address","name":"toDelegate","type":"address"}],"name":"DelegateChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"delegate","type":"address"},{"indexed":false,"internalType":"uint256","name":"previousBalance","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"newBalance","type":"uint256"}],"name":"DelegateVotesChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"bytes32","name":"merkleRoot","type":"bytes32"}],"name":"MerkleRootChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Transfer","type":"event"},{"inputs":[],"name":"DOMAIN_SEPARATOR","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"spender","type":"address"}],"name":"allowance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"approve","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"},{"internalType":"uint32","name":"pos","type":"uint32"}],"name":"checkpoints","outputs":[{"components":[{"internalType":"uint32","name":"fromBlock","type":"uint32"},{"internalType":"uint224","name":"votes","type":"uint224"}],"internalType":"struct ERC20Votes.Checkpoint","name":"","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"claimPeriodEnds","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"address","name":"delegate","type":"address"},{"internalType":"bytes32[]","name":"merkleProof","type":"bytes32[]"}],"name":"claimTokens","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"decimals","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"subtractedValue","type":"uint256"}],"name":"decreaseAllowance","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"delegatee","type":"address"}],"name":"delegate","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"delegatee","type":"address"},{"internalType":"uint256","name":"nonce","type":"uint256"},{"internalType":"uint256","name":"expiry","type":"uint256"},{"internalType":"uint8","name":"v","type":"uint8"},{"internalType":"bytes32","name":"r","type":"bytes32"},{"internalType":"bytes32","name":"s","type":"bytes32"}],"name":"delegateBySig","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"delegates","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"blockNumber","type":"uint256"}],"name":"getPastTotalSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"},{"internalType":"uint256","name":"blockNumber","type":"uint256"}],"name":"getPastVotes","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"getVotes","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"addedValue","type":"uint256"}],"name":"increaseAllowance","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"index","type":"uint256"}],"name":"isClaimed","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"merkleRoot","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"minimumMintInterval","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"dest","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"mint","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"mintCap","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"nextMint","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"}],"name":"nonces","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"numCheckpoints","outputs":[{"internalType":"uint32","name":"","type":"uint32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"value","type":"uint256"},{"internalType":"uint256","name":"deadline","type":"uint256"},{"internalType":"uint8","name":"v","type":"uint8"},{"internalType":"bytes32","name":"r","type":"bytes32"},{"internalType":"bytes32","name":"s","type":"bytes32"}],"name":"permit","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"_merkleRoot","type":"bytes32"}],"name":"setMerkleRoot","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"dest","type":"address"}],"name":"sweep","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"symbol","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"recipient","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transfer","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"sender","type":"address"},{"internalType":"address","name":"recipient","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transferFrom","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"}]', + 'EnsToken'); + +class EnsToken extends _i1.GeneratedContract { + EnsToken( + {required _i1.EthereumAddress address, + required _i1.Web3Client client, + int? chainId}) + : super(_i1.DeployedContract(_contractAbi, address), client, chainId); + + /// The optional [atBlock] parameter can be used to view historical data. When + /// set, the function will be evaluated in the specified block. By default, the + /// latest on-chain block will be used. + Future<_i2.Uint8List> dOMAINkSEPARATOR({_i1.BlockNum? atBlock}) async { + final function = self.abi.functions[1]; + assert(checkSignature(function, '3644e515')); + final params = []; + final response = await read(function, params, atBlock); + return (response[0] as _i2.Uint8List); + } + + /// The optional [atBlock] parameter can be used to view historical data. When + /// set, the function will be evaluated in the specified block. By default, the + /// latest on-chain block will be used. + Future allowance( + _i1.EthereumAddress owner, _i1.EthereumAddress spender, + {_i1.BlockNum? atBlock}) async { + final function = self.abi.functions[2]; + assert(checkSignature(function, 'dd62ed3e')); + final params = [owner, spender]; + final response = await read(function, params, atBlock); + return (response[0] as BigInt); + } + + /// The optional [transaction] parameter can be used to override parameters + /// like the gas price, nonce and max gas. The `data` and `to` fields will be + /// set by the contract. + Future approve(_i1.EthereumAddress spender, BigInt amount, + {required _i1.Credentials credentials, + _i1.Transaction? transaction}) async { + final function = self.abi.functions[3]; + assert(checkSignature(function, '095ea7b3')); + final params = [spender, amount]; + return write(credentials, transaction, function, params); + } + + /// The optional [atBlock] parameter can be used to view historical data. When + /// set, the function will be evaluated in the specified block. By default, the + /// latest on-chain block will be used. + Future balanceOf(_i1.EthereumAddress account, + {_i1.BlockNum? atBlock}) async { + final function = self.abi.functions[4]; + assert(checkSignature(function, '70a08231')); + final params = [account]; + final response = await read(function, params, atBlock); + return (response[0] as BigInt); + } + + /// The optional [atBlock] parameter can be used to view historical data. When + /// set, the function will be evaluated in the specified block. By default, the + /// latest on-chain block will be used. + Future checkpoints(_i1.EthereumAddress account, BigInt pos, + {_i1.BlockNum? atBlock}) async { + final function = self.abi.functions[5]; + assert(checkSignature(function, 'f1127ed8')); + final params = [account, pos]; + final response = await read(function, params, atBlock); + return (response[0] as dynamic); + } + + /// The optional [atBlock] parameter can be used to view historical data. When + /// set, the function will be evaluated in the specified block. By default, the + /// latest on-chain block will be used. + Future claimPeriodEnds({_i1.BlockNum? atBlock}) async { + final function = self.abi.functions[6]; + assert(checkSignature(function, '66deac47')); + final params = []; + final response = await read(function, params, atBlock); + return (response[0] as BigInt); + } + + /// The optional [transaction] parameter can be used to override parameters + /// like the gas price, nonce and max gas. The `data` and `to` fields will be + /// set by the contract. + Future claimTokens(BigInt amount, _i1.EthereumAddress delegate, + List<_i2.Uint8List> merkleProof, + {required _i1.Credentials credentials, + _i1.Transaction? transaction}) async { + final function = self.abi.functions[7]; + assert(checkSignature(function, '76122903')); + final params = [amount, delegate, merkleProof]; + return write(credentials, transaction, function, params); + } + + /// The optional [atBlock] parameter can be used to view historical data. When + /// set, the function will be evaluated in the specified block. By default, the + /// latest on-chain block will be used. + Future decimals({_i1.BlockNum? atBlock}) async { + final function = self.abi.functions[8]; + assert(checkSignature(function, '313ce567')); + final params = []; + final response = await read(function, params, atBlock); + return (response[0] as BigInt); + } + + /// The optional [transaction] parameter can be used to override parameters + /// like the gas price, nonce and max gas. The `data` and `to` fields will be + /// set by the contract. + Future decreaseAllowance( + _i1.EthereumAddress spender, BigInt subtractedValue, + {required _i1.Credentials credentials, + _i1.Transaction? transaction}) async { + final function = self.abi.functions[9]; + assert(checkSignature(function, 'a457c2d7')); + final params = [spender, subtractedValue]; + return write(credentials, transaction, function, params); + } + + /// The optional [transaction] parameter can be used to override parameters + /// like the gas price, nonce and max gas. The `data` and `to` fields will be + /// set by the contract. + Future delegate(_i1.EthereumAddress delegatee, + {required _i1.Credentials credentials, + _i1.Transaction? transaction}) async { + final function = self.abi.functions[10]; + assert(checkSignature(function, '5c19a95c')); + final params = [delegatee]; + return write(credentials, transaction, function, params); + } + + /// The optional [transaction] parameter can be used to override parameters + /// like the gas price, nonce and max gas. The `data` and `to` fields will be + /// set by the contract. + Future delegateBySig(_i1.EthereumAddress delegatee, BigInt nonce, + BigInt expiry, BigInt v, _i2.Uint8List r, _i2.Uint8List s, + {required _i1.Credentials credentials, + _i1.Transaction? transaction}) async { + final function = self.abi.functions[11]; + assert(checkSignature(function, 'c3cda520')); + final params = [delegatee, nonce, expiry, v, r, s]; + return write(credentials, transaction, function, params); + } + + /// The optional [atBlock] parameter can be used to view historical data. When + /// set, the function will be evaluated in the specified block. By default, the + /// latest on-chain block will be used. + Future<_i1.EthereumAddress> delegates(_i1.EthereumAddress account, + {_i1.BlockNum? atBlock}) async { + final function = self.abi.functions[12]; + assert(checkSignature(function, '587cde1e')); + final params = [account]; + final response = await read(function, params, atBlock); + return (response[0] as _i1.EthereumAddress); + } + + /// The optional [atBlock] parameter can be used to view historical data. When + /// set, the function will be evaluated in the specified block. By default, the + /// latest on-chain block will be used. + Future getPastTotalSupply(BigInt blockNumber, + {_i1.BlockNum? atBlock}) async { + final function = self.abi.functions[13]; + assert(checkSignature(function, '8e539e8c')); + final params = [blockNumber]; + final response = await read(function, params, atBlock); + return (response[0] as BigInt); + } + + /// The optional [atBlock] parameter can be used to view historical data. When + /// set, the function will be evaluated in the specified block. By default, the + /// latest on-chain block will be used. + Future getPastVotes(_i1.EthereumAddress account, BigInt blockNumber, + {_i1.BlockNum? atBlock}) async { + final function = self.abi.functions[14]; + assert(checkSignature(function, '3a46b1a8')); + final params = [account, blockNumber]; + final response = await read(function, params, atBlock); + return (response[0] as BigInt); + } + + /// The optional [atBlock] parameter can be used to view historical data. When + /// set, the function will be evaluated in the specified block. By default, the + /// latest on-chain block will be used. + Future getVotes(_i1.EthereumAddress account, + {_i1.BlockNum? atBlock}) async { + final function = self.abi.functions[15]; + assert(checkSignature(function, '9ab24eb0')); + final params = [account]; + final response = await read(function, params, atBlock); + return (response[0] as BigInt); + } + + /// The optional [transaction] parameter can be used to override parameters + /// like the gas price, nonce and max gas. The `data` and `to` fields will be + /// set by the contract. + Future increaseAllowance( + _i1.EthereumAddress spender, BigInt addedValue, + {required _i1.Credentials credentials, + _i1.Transaction? transaction}) async { + final function = self.abi.functions[16]; + assert(checkSignature(function, '39509351')); + final params = [spender, addedValue]; + return write(credentials, transaction, function, params); + } + + /// The optional [atBlock] parameter can be used to view historical data. When + /// set, the function will be evaluated in the specified block. By default, the + /// latest on-chain block will be used. + Future isClaimed(BigInt index, {_i1.BlockNum? atBlock}) async { + final function = self.abi.functions[17]; + assert(checkSignature(function, '9e34070f')); + final params = [index]; + final response = await read(function, params, atBlock); + return (response[0] as bool); + } + + /// The optional [atBlock] parameter can be used to view historical data. When + /// set, the function will be evaluated in the specified block. By default, the + /// latest on-chain block will be used. + Future<_i2.Uint8List> merkleRoot({_i1.BlockNum? atBlock}) async { + final function = self.abi.functions[18]; + assert(checkSignature(function, '2eb4a7ab')); + final params = []; + final response = await read(function, params, atBlock); + return (response[0] as _i2.Uint8List); + } + + /// The optional [atBlock] parameter can be used to view historical data. When + /// set, the function will be evaluated in the specified block. By default, the + /// latest on-chain block will be used. + Future minimumMintInterval({_i1.BlockNum? atBlock}) async { + final function = self.abi.functions[19]; + assert(checkSignature(function, '515b612a')); + final params = []; + final response = await read(function, params, atBlock); + return (response[0] as BigInt); + } + + /// The optional [transaction] parameter can be used to override parameters + /// like the gas price, nonce and max gas. The `data` and `to` fields will be + /// set by the contract. + Future mint(_i1.EthereumAddress dest, BigInt amount, + {required _i1.Credentials credentials, + _i1.Transaction? transaction}) async { + final function = self.abi.functions[20]; + assert(checkSignature(function, '40c10f19')); + final params = [dest, amount]; + return write(credentials, transaction, function, params); + } + + /// The optional [atBlock] parameter can be used to view historical data. When + /// set, the function will be evaluated in the specified block. By default, the + /// latest on-chain block will be used. + Future mintCap({_i1.BlockNum? atBlock}) async { + final function = self.abi.functions[21]; + assert(checkSignature(function, '76c71ca1')); + final params = []; + final response = await read(function, params, atBlock); + return (response[0] as BigInt); + } + + /// The optional [atBlock] parameter can be used to view historical data. When + /// set, the function will be evaluated in the specified block. By default, the + /// latest on-chain block will be used. + Future name({_i1.BlockNum? atBlock}) async { + final function = self.abi.functions[22]; + assert(checkSignature(function, '06fdde03')); + final params = []; + final response = await read(function, params, atBlock); + return (response[0] as String); + } + + /// The optional [atBlock] parameter can be used to view historical data. When + /// set, the function will be evaluated in the specified block. By default, the + /// latest on-chain block will be used. + Future nextMint({_i1.BlockNum? atBlock}) async { + final function = self.abi.functions[23]; + assert(checkSignature(function, 'cf665443')); + final params = []; + final response = await read(function, params, atBlock); + return (response[0] as BigInt); + } + + /// The optional [atBlock] parameter can be used to view historical data. When + /// set, the function will be evaluated in the specified block. By default, the + /// latest on-chain block will be used. + Future nonces(_i1.EthereumAddress owner, + {_i1.BlockNum? atBlock}) async { + final function = self.abi.functions[24]; + assert(checkSignature(function, '7ecebe00')); + final params = [owner]; + final response = await read(function, params, atBlock); + return (response[0] as BigInt); + } + + /// The optional [atBlock] parameter can be used to view historical data. When + /// set, the function will be evaluated in the specified block. By default, the + /// latest on-chain block will be used. + Future numCheckpoints(_i1.EthereumAddress account, + {_i1.BlockNum? atBlock}) async { + final function = self.abi.functions[25]; + assert(checkSignature(function, '6fcfff45')); + final params = [account]; + final response = await read(function, params, atBlock); + return (response[0] as BigInt); + } + + /// The optional [atBlock] parameter can be used to view historical data. When + /// set, the function will be evaluated in the specified block. By default, the + /// latest on-chain block will be used. + Future<_i1.EthereumAddress> owner({_i1.BlockNum? atBlock}) async { + final function = self.abi.functions[26]; + assert(checkSignature(function, '8da5cb5b')); + final params = []; + final response = await read(function, params, atBlock); + return (response[0] as _i1.EthereumAddress); + } + + /// The optional [transaction] parameter can be used to override parameters + /// like the gas price, nonce and max gas. The `data` and `to` fields will be + /// set by the contract. + Future permit(_i1.EthereumAddress owner, _i1.EthereumAddress spender, + BigInt value, BigInt deadline, BigInt v, _i2.Uint8List r, _i2.Uint8List s, + {required _i1.Credentials credentials, + _i1.Transaction? transaction}) async { + final function = self.abi.functions[27]; + assert(checkSignature(function, 'd505accf')); + final params = [owner, spender, value, deadline, v, r, s]; + return write(credentials, transaction, function, params); + } + + /// The optional [transaction] parameter can be used to override parameters + /// like the gas price, nonce and max gas. The `data` and `to` fields will be + /// set by the contract. + Future renounceOwnership( + {required _i1.Credentials credentials, + _i1.Transaction? transaction}) async { + final function = self.abi.functions[28]; + assert(checkSignature(function, '715018a6')); + final params = []; + return write(credentials, transaction, function, params); + } + + /// The optional [transaction] parameter can be used to override parameters + /// like the gas price, nonce and max gas. The `data` and `to` fields will be + /// set by the contract. + Future setMerkleRoot(_i2.Uint8List _merkleRoot, + {required _i1.Credentials credentials, + _i1.Transaction? transaction}) async { + final function = self.abi.functions[29]; + assert(checkSignature(function, '7cb64759')); + final params = [_merkleRoot]; + return write(credentials, transaction, function, params); + } + + /// The optional [transaction] parameter can be used to override parameters + /// like the gas price, nonce and max gas. The `data` and `to` fields will be + /// set by the contract. + Future sweep(_i1.EthereumAddress dest, + {required _i1.Credentials credentials, + _i1.Transaction? transaction}) async { + final function = self.abi.functions[30]; + assert(checkSignature(function, '01681a62')); + final params = [dest]; + return write(credentials, transaction, function, params); + } + + /// The optional [atBlock] parameter can be used to view historical data. When + /// set, the function will be evaluated in the specified block. By default, the + /// latest on-chain block will be used. + Future symbol({_i1.BlockNum? atBlock}) async { + final function = self.abi.functions[31]; + assert(checkSignature(function, '95d89b41')); + final params = []; + final response = await read(function, params, atBlock); + return (response[0] as String); + } + + /// The optional [atBlock] parameter can be used to view historical data. When + /// set, the function will be evaluated in the specified block. By default, the + /// latest on-chain block will be used. + Future totalSupply({_i1.BlockNum? atBlock}) async { + final function = self.abi.functions[32]; + assert(checkSignature(function, '18160ddd')); + final params = []; + final response = await read(function, params, atBlock); + return (response[0] as BigInt); + } + + /// The optional [transaction] parameter can be used to override parameters + /// like the gas price, nonce and max gas. The `data` and `to` fields will be + /// set by the contract. + Future transfer(_i1.EthereumAddress recipient, BigInt amount, + {required _i1.Credentials credentials, + _i1.Transaction? transaction}) async { + final function = self.abi.functions[33]; + assert(checkSignature(function, 'a9059cbb')); + final params = [recipient, amount]; + return write(credentials, transaction, function, params); + } + + /// The optional [transaction] parameter can be used to override parameters + /// like the gas price, nonce and max gas. The `data` and `to` fields will be + /// set by the contract. + Future transferFrom( + _i1.EthereumAddress sender, _i1.EthereumAddress recipient, BigInt amount, + {required _i1.Credentials credentials, + _i1.Transaction? transaction}) async { + final function = self.abi.functions[34]; + assert(checkSignature(function, '23b872dd')); + final params = [sender, recipient, amount]; + return write(credentials, transaction, function, params); + } + + /// The optional [transaction] parameter can be used to override parameters + /// like the gas price, nonce and max gas. The `data` and `to` fields will be + /// set by the contract. + Future transferOwnership(_i1.EthereumAddress newOwner, + {required _i1.Credentials credentials, + _i1.Transaction? transaction}) async { + final function = self.abi.functions[35]; + assert(checkSignature(function, 'f2fde38b')); + final params = [newOwner]; + return write(credentials, transaction, function, params); + } + + /// Returns a live stream of all Approval events emitted by this contract. + Stream approvalEvents( + {_i1.BlockNum? fromBlock, _i1.BlockNum? toBlock}) { + final event = self.event('Approval'); + final filter = _i1.FilterOptions.events( + contract: self, event: event, fromBlock: fromBlock, toBlock: toBlock); + return client.events(filter).map((_i1.FilterEvent result) { + final decoded = event.decodeResults(result.topics!, result.data!); + return Approval(decoded); + }); + } + + /// Returns a live stream of all Claim events emitted by this contract. + Stream claimEvents({_i1.BlockNum? fromBlock, _i1.BlockNum? toBlock}) { + final event = self.event('Claim'); + final filter = _i1.FilterOptions.events( + contract: self, event: event, fromBlock: fromBlock, toBlock: toBlock); + return client.events(filter).map((_i1.FilterEvent result) { + final decoded = event.decodeResults(result.topics!, result.data!); + return Claim(decoded); + }); + } + + /// Returns a live stream of all DelegateChanged events emitted by this contract. + Stream delegateChangedEvents( + {_i1.BlockNum? fromBlock, _i1.BlockNum? toBlock}) { + final event = self.event('DelegateChanged'); + final filter = _i1.FilterOptions.events( + contract: self, event: event, fromBlock: fromBlock, toBlock: toBlock); + return client.events(filter).map((_i1.FilterEvent result) { + final decoded = event.decodeResults(result.topics!, result.data!); + return DelegateChanged(decoded); + }); + } + + /// Returns a live stream of all DelegateVotesChanged events emitted by this contract. + Stream delegateVotesChangedEvents( + {_i1.BlockNum? fromBlock, _i1.BlockNum? toBlock}) { + final event = self.event('DelegateVotesChanged'); + final filter = _i1.FilterOptions.events( + contract: self, event: event, fromBlock: fromBlock, toBlock: toBlock); + return client.events(filter).map((_i1.FilterEvent result) { + final decoded = event.decodeResults(result.topics!, result.data!); + return DelegateVotesChanged(decoded); + }); + } + + /// Returns a live stream of all MerkleRootChanged events emitted by this contract. + Stream merkleRootChangedEvents( + {_i1.BlockNum? fromBlock, _i1.BlockNum? toBlock}) { + final event = self.event('MerkleRootChanged'); + final filter = _i1.FilterOptions.events( + contract: self, event: event, fromBlock: fromBlock, toBlock: toBlock); + return client.events(filter).map((_i1.FilterEvent result) { + final decoded = event.decodeResults(result.topics!, result.data!); + return MerkleRootChanged(decoded); + }); + } + + /// Returns a live stream of all OwnershipTransferred events emitted by this contract. + Stream ownershipTransferredEvents( + {_i1.BlockNum? fromBlock, _i1.BlockNum? toBlock}) { + final event = self.event('OwnershipTransferred'); + final filter = _i1.FilterOptions.events( + contract: self, event: event, fromBlock: fromBlock, toBlock: toBlock); + return client.events(filter).map((_i1.FilterEvent result) { + final decoded = event.decodeResults(result.topics!, result.data!); + return OwnershipTransferred(decoded); + }); + } + + /// Returns a live stream of all Transfer events emitted by this contract. + Stream transferEvents( + {_i1.BlockNum? fromBlock, _i1.BlockNum? toBlock}) { + final event = self.event('Transfer'); + final filter = _i1.FilterOptions.events( + contract: self, event: event, fromBlock: fromBlock, toBlock: toBlock); + return client.events(filter).map((_i1.FilterEvent result) { + final decoded = event.decodeResults(result.topics!, result.data!); + return Transfer(decoded); + }); + } +} + +class Approval { + Approval(List response) + : owner = (response[0] as _i1.EthereumAddress), + spender = (response[1] as _i1.EthereumAddress), + value = (response[2] as BigInt); + + final _i1.EthereumAddress owner; + + final _i1.EthereumAddress spender; + + final BigInt value; +} + +class Claim { + Claim(List response) + : claimant = (response[0] as _i1.EthereumAddress), + amount = (response[1] as BigInt); + + final _i1.EthereumAddress claimant; + + final BigInt amount; +} + +class DelegateChanged { + DelegateChanged(List response) + : delegator = (response[0] as _i1.EthereumAddress), + fromDelegate = (response[1] as _i1.EthereumAddress), + toDelegate = (response[2] as _i1.EthereumAddress); + + final _i1.EthereumAddress delegator; + + final _i1.EthereumAddress fromDelegate; + + final _i1.EthereumAddress toDelegate; +} + +class DelegateVotesChanged { + DelegateVotesChanged(List response) + : delegate = (response[0] as _i1.EthereumAddress), + previousBalance = (response[1] as BigInt), + newBalance = (response[2] as BigInt); + + final _i1.EthereumAddress delegate; + + final BigInt previousBalance; + + final BigInt newBalance; +} + +class MerkleRootChanged { + MerkleRootChanged(List response) + : merkleRoot = (response[0] as _i2.Uint8List); + + final _i2.Uint8List merkleRoot; +} + +class OwnershipTransferred { + OwnershipTransferred(List response) + : previousOwner = (response[0] as _i1.EthereumAddress), + newOwner = (response[1] as _i1.EthereumAddress); + + final _i1.EthereumAddress previousOwner; + + final _i1.EthereumAddress newOwner; +} + +class Transfer { + Transfer(List response) + : from = (response[0] as _i1.EthereumAddress), + to = (response[1] as _i1.EthereumAddress), + value = (response[2] as BigInt); + + final _i1.EthereumAddress from; + + final _i1.EthereumAddress to; + + final BigInt value; +} diff --git a/lib/src/ens_dart.dart b/lib/src/ens_dart.dart new file mode 100644 index 0000000..62f6005 --- /dev/null +++ b/lib/src/ens_dart.dart @@ -0,0 +1,5 @@ +export 'contracts/contracts.dart'; +export 'utils.dart'; +export 'ens_resolver.dart'; +export 'models/models.dart'; +export 'const/const.dart'; \ No newline at end of file diff --git a/lib/src/ens_resolver.dart b/lib/src/ens_resolver.dart new file mode 100644 index 0000000..6ab824c --- /dev/null +++ b/lib/src/ens_resolver.dart @@ -0,0 +1,140 @@ +// ignore_for_file: constant_identifier_names + +import 'dart:typed_data'; +import 'package:convert/convert.dart'; + +import 'package:web3dart/crypto.dart'; +import 'package:web3dart/web3dart.dart'; + +import 'ens_dart.dart'; + +enum EnsTextKey { + email, + url, + avatar, + description, + notice, + keywords, + com_discord, + com_github, + com_reddit, + com_twitter, + org_telegram, + eth_ens_delegate +} + +extension EnsResolve on Ens { + /// Name hash for ENS name + Uint8List get nodeHash => hexToBytes(ENSUtils.nameHash(ensName ?? '')); + + /// Reverse node hash for ENS name + Uint8List get reverseNodeHash => hexToBytes( + ENSUtils.reverseNameHash('${ensAddress!.hexNo0x}.addr.reverse')); + + /// Returns the owner/controller for the current ENS name. + Future getAddress() async { + if (ensName == null) { + throw 'ensName needs to be set first with .withName()'; + } + + final _resolvedAddress = await addr(nodeHash); + withAddress(_resolvedAddress); + return _resolvedAddress; + } + + /// Returns the owner/controller for the current ENS name. + Future getCoinAddress(CoinType coinType) async { + if (ensName == null) { + throw 'ensName needs to be set first with .withName()'; + } + + final _resolvedAddress = await addr$2(nodeHash, coinType.coinTypeInt); + return hex.encode(_resolvedAddress); + } + + /// Returns the address for the current ENS name for the coinId provided. + Future setAddress( + EthereumAddress address, + BigInt coinType, { + required Credentials credentials, + Transaction? transaction, + }) async { + if (ensName == null) { + throw 'ensName needs to be set first with .withName()'; + } + + final _resolvedAddress = await setAddr( + nodeHash, + coinType, + address.addressBytes, + credentials: credentials, + transaction: transaction, + ); + return _resolvedAddress; + } + + /// Sets the address for the current ENS name for the coinId provided. + Future getContentHash() async { + return hex.encode(await contenthash(nodeHash)); + } + + /// Returns the text record for a given key for the current ENS name. + Future getTextRecord() async { + var map = {}; + + for (var item in EnsTextKey.values) { + var _name = ENSUtils.describeEnum(item); + final _raw = await text( + nodeHash, + _name.replaceAll('_', '.'), + ); + + map.putIfAbsent(_name, () => _raw); + } + + final _record = EnsTextRecord.fromMap(map); + setEnsTextRecord(_record); + + return _record; + } + + /// Returns a Resolver Object, allowing you to query names from this specific resolver. + /// Most useful when querying a different resolver that is different than is currently recorded on the registry. + /// E.g. migrating to a new resolver + Future getResolverAddress(Uint8List hash) async { + final ensReg = EnsRegistryFallback( + address: ENS_FALLBACK_REGISTRY, + client: client, + ); + return ensReg.resolver(hash); + } + + ///Returns a name, that allows you to make record queries. + Future getName() async { + if (ensAddress == null) { + throw 'ensAddress needs to be set first with .withAddress()'; + } + final resolver = await getResolverAddress(reverseNodeHash); + final name = await reverseEns(resolver).name(reverseNodeHash); + withName(name); + return name; + } + + /// Sets the name for the current Ethereum address + Future setEnsName( + String name, { + required Credentials credentials, + Transaction? transaction, + }) async { + if (ensAddress == null) { + throw 'ensAddress needs to be set first with .withAddress()'; + } + final _resolvedAddress = await setName( + reverseNodeHash, + name, + credentials: credentials, + transaction: transaction, + ); + return _resolvedAddress; + } +} diff --git a/lib/src/models/coin_types.dart b/lib/src/models/coin_types.dart new file mode 100644 index 0000000..f071631 --- /dev/null +++ b/lib/src/models/coin_types.dart @@ -0,0 +1,256 @@ +// ignore_for_file: constant_identifier_names + +import 'package:ens_dart/src/ens_dart.dart'; + +enum CoinType { + BTC, + LTC, + DOGE, + RDD, + DASH, + PPC, + NMC, + VIA, + GRS, + DGB, + MONA, + DCR, + XEM, + AIB, + SYS, + ETH, + ETC, + ICX, + XVG, + STRAT, + ARK, + ATOM, + ZIL, + EGLD, + ZEN, + XMR, + ZEC, + LSK, + STEEM, + FIRO, + RSK, + KMD, + XRP, + BCH, + XLM, + BTM, + OPT, + XDAI, + VET, + BNB, + CLO, + HIVE, + TOMO, + HNT, + RUNE, + BCD, + TT, + FTM, + ONE, + ONT, + XTZ, + ADA, + SC, + QTUM, + GXC, + ELA, + NAS, + HBAR, + IOTA, + HNS, + STX, + GO, + XCH, + NULS, + AVAX, + NRG, + ARDR, + ZEL, + CELO, + WICC, + WAN, + WAVES, + BSC, + MATIC, + ARB1, + BTG, + NANO, + RVN, + POA, + LCC, + EOS, + TRX, + BCN, + FIO, + BSV, + NEO, + NIM, + EWT, + ALGO, + IOST, + DIVI, + IOTX, + BTS, + CKB, + LUNA, + DOT, + VSYS, + ABBC, + NEAR, + ETN, + AION, + KSM, + AE, + KAVA, + FIL, + AR, + CCA, + THETA, + SOL, + XHV, + FLOW, + IRIS, + LRG, + SERO, + BDX, + CCXX, + SRM, + VLX, + BPS, + TFUEL, + GRIN +} + +const _coinMaps = { + 'BTC': 0, + 'LTC': 2, + 'DOGE': 3, + 'RDD': 4, + 'DASH': 5, + 'PPC': 6, + 'NMC': 7, + 'VIA': 14, + 'GRS': 17, + 'DGB': 20, + 'MONA': 22, + 'DCR': 42, + 'XEM': 43, + 'AIB': 55, + 'SYS': 57, + 'ETH': 60, + 'ETC': 61, + 'ICX': 74, + 'XVG': 77, + 'STRAT': 105, + 'ARK': 111, + 'ATOM': 118, + 'ZIL': 119, + 'EGLD': 120, + 'ZEN': 121, + 'XMR': 128, + 'ZEC': 133, + 'LSK': 134, + 'STEEM': 135, + 'FIRO': 136, + 'RSK': 137, + 'KMD': 141, + 'XRP': 144, + 'BCH': 145, + 'XLM': 148, + 'BTM': 153, + 'OPT': 614, + 'XDAI': 700, + 'VET': 703, + 'BNB': 714, + 'CLO': 820, + 'HIVE': 825, + 'TOMO': 889, + 'HNT': 904, + 'RUNE': 931, + 'BCD': 999, + 'TT': 1001, + 'FTM': 1007, + 'ONE': 1023, + 'ONT': 1024, + 'XTZ': 1729, + 'ADA': 1815, + 'SC': 1991, + 'QTUM': 2301, + 'GXC': 2303, + 'ELA': 2305, + 'NAS': 2718, + 'HBAR': 3030, + 'IOTA': 4218, + 'HNS': 5353, + 'STX': 5757, + 'GO': 6060, + 'XCH': 8444, + 'NULS': 8964, + 'AVAX': 9000, + 'NRG': 9797, + 'ARDR': 16754, + 'ZEL': 19167, + 'CELO': 52752, + 'WICC': 99999, + 'WAN': 5718350, + 'WAVES': 5741564, + 'BSC': 56, + 'MATIC': 137, + 'ARB1': 42161, + 'BTG': 156, + 'NANO': 165, + 'RVN': 175, + 'POA': 178, + 'LCC': 192, + 'EOS': 194, + 'TRX': 195, + 'BCN': 204, + 'FIO': 235, + 'BSV': 236, + 'NEO': 239, + 'NIM': 242, + 'EWT': 246, + 'ALGO': 283, + 'IOST': 291, + 'DIVI': 301, + 'IOTX': 304, + 'BTS': 308, + 'CKB': 309, + 'LUNA': 330, + 'DOT': 354, + 'VSYS': 360, + 'ABBC': 367, + 'NEAR': 397, + 'ETN': 415, + 'AION': 425, + 'KSM': 434, + 'AE': 457, + 'KAVA': 459, + 'FIL': 461, + 'AR': 472, + 'CCA': 489, + 'THETA': 500, + 'SOL': 501, + 'XHV': 535, + 'FLOW': 539, + 'IRIS': 566, + 'LRG': 568, + 'SERO': 569, + 'BDX': 570, + 'CCXX': 571, + 'SRM': 573, + 'VLX': 574, + 'BPS': 576, + 'TFUEL': 589, + 'GRIN': 592 +}; + +extension CoinTypeVal on CoinType { + BigInt get coinTypeInt => + BigInt.from(_coinMaps[ENSUtils.describeEnum(this)] as int); +} diff --git a/lib/src/models/ens_text_record.dart b/lib/src/models/ens_text_record.dart new file mode 100644 index 0000000..b7d9c80 --- /dev/null +++ b/lib/src/models/ens_text_record.dart @@ -0,0 +1,153 @@ +import 'dart:convert'; + +class EnsTextRecord { + final String email; + final String url; + final String avatar; + final String description; + final String notice; + final String keywords; + final String discord; + final String github; + final String reddit; + final String twitter; + final String telegram; + final String ensDelegate; + EnsTextRecord({ + required this.email, + required this.url, + required this.avatar, + required this.description, + required this.notice, + required this.keywords, + required this.discord, + required this.github, + required this.reddit, + required this.twitter, + required this.telegram, + required this.ensDelegate, + }); + + EnsTextRecord copyWith({ + String? email, + String? url, + String? avatar, + String? description, + String? notice, + String? keywords, + String? discord, + String? github, + String? reddit, + String? twitter, + String? telegram, + String? ensDelegate, + }) { + return EnsTextRecord( + email: email ?? this.email, + url: url ?? this.url, + avatar: avatar ?? this.avatar, + description: description ?? this.description, + notice: notice ?? this.notice, + keywords: keywords ?? this.keywords, + discord: discord ?? this.discord, + github: github ?? this.github, + reddit: reddit ?? this.reddit, + twitter: twitter ?? this.twitter, + telegram: telegram ?? this.telegram, + ensDelegate: ensDelegate ?? this.ensDelegate, + ); + } + + Map toMap() { + return { + 'email': email, + 'url': url, + 'avatar': avatar, + 'description': description, + 'notice': notice, + 'keywords': keywords, + 'com_discord': discord, + 'com_github': github, + 'com_reddit': reddit, + 'com_twitter': twitter, + 'org_telegram': telegram, + 'eth_ens_delegate': ensDelegate, + }; + } + + factory EnsTextRecord.fromMap(Map map) { + return EnsTextRecord( + email: map['email'] ?? '', + url: map['url'] ?? '', + avatar: map['avatar'] ?? '', + description: map['description'] ?? '', + notice: map['notice'] ?? '', + keywords: map['keywords'] ?? '', + discord: map['com_discord'] ?? '', + github: map['com_github'] ?? '', + reddit: map['com_reddit'] ?? '', + twitter: map['com_twitter'] ?? '', + telegram: map['org_telegram'] ?? '', + ensDelegate: map['eth_ens_delegate'] ?? '', + ); + } + + String toJson() => json.encode(toMap()); + + factory EnsTextRecord.fromJson(String source) => + EnsTextRecord.fromMap(json.decode(source)); + + @override + String toString() { + return ''' + EnsTextRecord { + email: $email, + url: $url, + avatar: $avatar, + description: $description, + notice: $notice, + keywords: $keywords, + com.discord: $discord, + com.github: $github, + com.reddit: $reddit, + com.twitter: $twitter, + org.telegram: $telegram, + eth.ens.delegate: $ensDelegate + }'''; + } + + @override + bool operator ==(Object other) { + if (identical(this, other)) return true; + + return other is EnsTextRecord && + other.email == email && + other.url == url && + other.avatar == avatar && + other.description == description && + other.notice == notice && + other.keywords == keywords && + other.discord == discord && + other.github == github && + other.reddit == reddit && + other.twitter == twitter && + other.telegram == telegram && + other.ensDelegate == ensDelegate; + } + + @override + int get hashCode { + return email.hashCode ^ + url.hashCode ^ + avatar.hashCode ^ + description.hashCode ^ + notice.hashCode ^ + keywords.hashCode ^ + discord.hashCode ^ + github.hashCode ^ + reddit.hashCode ^ + twitter.hashCode ^ + telegram.hashCode ^ + ensDelegate.hashCode; + } +} diff --git a/lib/src/models/models.dart b/lib/src/models/models.dart new file mode 100644 index 0000000..4a40bdd --- /dev/null +++ b/lib/src/models/models.dart @@ -0,0 +1,2 @@ +export 'coin_types.dart'; +export 'ens_text_record.dart'; diff --git a/lib/src/utils.dart b/lib/src/utils.dart new file mode 100644 index 0000000..dd3c5da --- /dev/null +++ b/lib/src/utils.dart @@ -0,0 +1,124 @@ +import 'package:convert/convert.dart'; +import 'package:sha3/sha3.dart'; + +class ENSUtils { + static String nameHash(String? inputName) { + var node = ''; + for (var i = 0; i < 32; i++) { + node += '00'; + } + if (inputName != null) { + if (!inputName.contains('.eth')) { + inputName = '$inputName.eth'; + } + + var labels = inputName.split('.'); + + for (var i = labels.length - 1; i >= 0; i--) { + String labelSha; + if (isEncodedLabelhash(labels[i])) { + labelSha = decodeLabelhash(labels[i]); + } else { + var normalisedLabel = labels[i]; + labelSha = sha3(normalisedLabel); + } + + node = sha3(String.fromCharCodes(hex.decode('$node$labelSha'))); + } + } + + return '0x' + node; + } + + static String reverseNameHash(inputName) { + // Reject empty names: + var node = ''; + for (var i = 0; i < 32; i++) { + node += '00'; + } + + var name = normalize(inputName); + + var labels = name.split('.'); + + for (var i = labels.length - 1; i >= 0; i--) { + var labelSha = sha3(labels[i]); + node = sha3(String.fromCharCodes(hex.decode('$node$labelSha'))); + } + + return '0x' + node; + } + + String encodeLabelhash(hash) { + if (!hash.startsWith('0x')) { + throw 'Expected label hash to start with 0x'; + } + + if (hash.length != 66) { + throw 'Expected label hash to have a length of 66'; + } + + return '[${hash.slice(2)}]'; + } + + static String decodeLabelhash(String hash) { + if (!(hash.startsWith('[') && hash.endsWith(']'))) { + throw 'Expected encoded labelhash to start and end with square brackets'; + } + + if (hash.length != 66) { + throw 'Expected encoded labelhash to have a length of 66'; + } + + return hash.slice(1, -1); + } + + static bool isEncodedLabelhash(hash) { + return hash.startsWith('[') && hash.endsWith(']') && hash.length == 66; + } + + static bool isDecrypted(String name) { + final nameArray = name.split('.'); + final decrypted = nameArray.skip(1).fold(true, ((acc, label) { + if (acc == false) return false; + return isEncodedLabelhash(label) ? false : true; + })); + return decrypted; + } + + static String labelhash(unnormalisedLabelOrLabelhash) { + return isEncodedLabelhash(unnormalisedLabelOrLabelhash) + ? '0x' + decodeLabelhash(unnormalisedLabelOrLabelhash) + : '0x' + sha3(normalize(unnormalisedLabelOrLabelhash)); + } + + static String sha3(String string) { + var hash = + SHA3(256, KECCAK_PADDING, 256).update(string.runes.toList()).digest(); + + return hex.encode(hash); + } + + static String normalize(String name) { + return (name); + } + + static String describeEnum(Object enumEntry) { + final String description = enumEntry.toString(); + final int indexOfDot = description.indexOf('.'); + assert( + indexOfDot != -1 && indexOfDot < description.length - 1, + 'The provided object "$enumEntry" is not an enum.', + ); + return description.substring(indexOfDot + 1); + } +} + +extension Slice on String { + String slice(int start, [int? end]) { + if (end != null && end.isNegative) { + return substring(start, length - end.abs()); + } + return substring(start, end); + } +} diff --git a/pubspec.yaml b/pubspec.yaml new file mode 100644 index 0000000..602757f --- /dev/null +++ b/pubspec.yaml @@ -0,0 +1,28 @@ +name: ens_dart +description: A dart library that wraps the Ethereum Name Service. It enables users and developers to use human-friendly names in place of error-prone hexadecimal addresses, content hashes, and more. +version: 1.0.0 +homepage: + +environment: + sdk: ">=2.12.0 <3.0.0" + +dependencies: + flutter: + sdk: flutter + dotenv: ^3.0.0 + sha3: ^0.2.0 + web3dart: 2.3.3 + #path: ../web3dart + web_socket_channel: ^2.1.0 + fast_base58: ^0.2.1 + +dev_dependencies: + flutter_test: + sdk: flutter + flutter_lints: ^1.0.0 + +# For information on the generic Dart part of this file, see the +# following page: https://dart.dev/tools/pub/pubspec + +# The following section is specific to Flutter. +flutter: diff --git a/test/ens_dart_test.dart b/test/ens_dart_test.dart new file mode 100644 index 0000000..d945ed0 --- /dev/null +++ b/test/ens_dart_test.dart @@ -0,0 +1,58 @@ +import 'package:http/http.dart'; +import 'package:dotenv/dotenv.dart' as env; +import 'package:flutter_test/flutter_test.dart'; + +import 'package:ens_dart/ens_dart.dart'; +import 'package:web3dart/web3dart.dart'; +import 'package:web_socket_channel/io.dart'; + +void main() { + final names = [ + 'chizi', + 'mike', + 'coinbase', + 'sea', + 'law', + ]; + + final addresses = [ + '0x324f9307b6d26881822c7c8692eeac39791a9756', + '0x1a5cdcfba600e0c669795e0b65c344d5a37a4d5a', + '0x81b287c0992b110adeb5903bf7e2d9350c80581a', + '0x2cb86d919332d0369c66a2d5982419266f5e490f', + '0x9c308bd202dddfca28f6cdce8e96b1e209833473', + ]; + group('ENS Tests', () { + env.load(); + + final infuraKey = env.env['INFURA_KEY']; + + final rpcUrl = 'https://mainnet.infura.io/v3/$infuraKey'; + final wsUrl = 'wss://mainnet.infura.io/ws/v3/$infuraKey'; + + final client = Web3Client(rpcUrl, Client(), socketConnector: () { + return IOWebSocketChannel.connect(wsUrl).cast(); + }); + + final ens = Ens(client: client); + + test('.getName() fetches correct name', () async { + for (var i = 0; i < addresses.length; i++) { + final name = await ens.withAddress(EthereumAddress.fromHex(addresses[i])).getName(); + expect(name, '${names[i]}.eth'); + } + }); + test('.getAddress() fetches correct address', () async { + for (var i = 0; i < names.length; i++) { + final addr = await ens.withName('${names[i]}.eth').getAddress(); + expect(addr.hex, addresses[i]); + } + }); + test('.getTextRecord() fetches TextRecord', () async { + for (var i = 0; i < names.length; i++) { + final record = await ens.withName('brantly').getTextRecord(); + expect(record.runtimeType, EnsTextRecord); + } + }); + }); +}