token.g.dart 3.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. // Generated code, do not modify. Run `build_runner build` to re-generate!
  2. // @dart=2.12
  3. import 'package:web3dart/web3dart.dart' as _i1;
  4. final _contractAbi = _i1.ContractAbi.fromJson(
  5. '[{"inputs":[],"payable":false,"stateMutability":"nonpayable","type":"constructor","signature":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"name":"_from","type":"address"},{"indexed":true,"name":"_to","type":"address"},{"indexed":false,"name":"_value","type":"uint256"}],"name":"Transfer","type":"event","signature":"0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef"},{"constant":false,"inputs":[{"name":"receiver","type":"address"},{"name":"amount","type":"uint256"}],"name":"sendCoin","outputs":[{"name":"sufficient","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function","signature":"0x90b98a11"},{"constant":true,"inputs":[{"name":"addr","type":"address"}],"name":"getBalanceInEth","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function","signature":"0x7bd703e8"},{"constant":true,"inputs":[{"name":"addr","type":"address"}],"name":"getBalance","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function","signature":"0xf8b2cb4f"}]',
  6. 'Token');
  7. class Token extends _i1.GeneratedContract {
  8. Token(
  9. {required _i1.EthereumAddress address,
  10. required _i1.Web3Client client,
  11. int? chainId})
  12. : super(_i1.DeployedContract(_contractAbi, address), client, chainId);
  13. /// The optional [transaction] parameter can be used to override parameters
  14. /// like the gas price, nonce and max gas. The `data` and `to` fields will be
  15. /// set by the contract.
  16. Future<String> sendCoin(_i1.EthereumAddress receiver, BigInt amount,
  17. {required _i1.Credentials credentials,
  18. _i1.Transaction? transaction}) async {
  19. final function = self.abi.functions[1];
  20. assert(checkSignature(function, '90b98a11'));
  21. final params = [receiver, amount];
  22. return write(credentials, transaction, function, params);
  23. }
  24. /// The optional [atBlock] parameter can be used to view historical data. When
  25. /// set, the function will be evaluated in the specified block. By default, the
  26. /// latest on-chain block will be used.
  27. Future<BigInt> getBalanceInEth(_i1.EthereumAddress addr,
  28. {_i1.BlockNum? atBlock}) async {
  29. final function = self.abi.functions[2];
  30. assert(checkSignature(function, '7bd703e8'));
  31. final params = [addr];
  32. final response = await read(function, params, atBlock);
  33. return (response[0] as BigInt);
  34. }
  35. /// The optional [atBlock] parameter can be used to view historical data. When
  36. /// set, the function will be evaluated in the specified block. By default, the
  37. /// latest on-chain block will be used.
  38. Future<BigInt> getBalance(_i1.EthereumAddress addr,
  39. {_i1.BlockNum? atBlock}) async {
  40. final function = self.abi.functions[3];
  41. assert(checkSignature(function, 'f8b2cb4f'));
  42. final params = [addr];
  43. final response = await read(function, params, atBlock);
  44. return (response[0] as BigInt);
  45. }
  46. /// Returns a live stream of all Transfer events emitted by this contract.
  47. Stream<Transfer> transferEvents(
  48. {_i1.BlockNum? fromBlock, _i1.BlockNum? toBlock}) {
  49. final event = self.event('Transfer');
  50. final filter = _i1.FilterOptions.events(
  51. contract: self, event: event, fromBlock: fromBlock, toBlock: toBlock);
  52. return client.events(filter).map((_i1.FilterEvent result) {
  53. final decoded = event.decodeResults(result.topics!, result.data!);
  54. return Transfer(decoded);
  55. });
  56. }
  57. }
  58. class Transfer {
  59. Transfer(List<dynamic> response)
  60. : from = (response[0] as _i1.EthereumAddress),
  61. to = (response[1] as _i1.EthereumAddress),
  62. value = (response[2] as BigInt);
  63. final _i1.EthereumAddress from;
  64. final _i1.EthereumAddress to;
  65. final BigInt value;
  66. }