simolus3 / web3dart

Ethereum library, written in Dart.
MIT License
442 stars 273 forks source link

Code generation not working #162

Closed incrypto32 closed 3 years ago

incrypto32 commented 3 years ago

The code generation is not working Screenshot_2021-06-06_08-27-28

incrypto32 commented 3 years ago

@simolus3 I figured out this occured because i used the json generated by truffle instead of abi json itself.. Is there a way to use that json instead of separating abi from it creating a separate json file

simolus3 commented 3 years ago

I think we should already do that actually:

https://github.com/simolus3/web3dart/blob/74b9e61cdf9221587e1ece7299b46011e0b879d2/lib/src/builder/generator.dart#L31-L36

I tried compiling a new MetaMask project and adding the generated file as .abi.json, it generates the code I'd expect. Which web3dart version are you using?

incrypto32 commented 3 years ago

@simolus3 Iam on the latest version ^2.1.3 And the error that i got is the one that i have posted above.. It worked for me when i copied the abi part to a separate json file. I will get back after testing a bit more

simolus3 commented 3 years ago

Could you run the build with --verbose and post the full stack trace? It would also be helpful to have a general view of the file you're using (you can omit sensitive parts).

incrypto32 commented 3 years ago

@simolus3 Here it is

fflutter pub run build_runner build --verbose
[ +131 ms] executing: uname -m
[  +63 ms] Exit code 0 from: uname -m
[        ] x86_64
[  +11 ms] executing: [/home/incrypto/flutter/] git -c log.showSignature=false log -n 1 --pretty=format:%H
[   +9 ms] Exit code 0 from: git -c log.showSignature=false log -n 1 --pretty=format:%H
[        ] b22742018b3edf16c6cadd7b76d9db5e7f9064b5
[   +1 ms] executing: [/home/incrypto/flutter/] git tag --points-at b22742018b3edf16c6cadd7b76d9db5e7f9064b5
[  +25 ms] Exit code 0 from: git tag --points-at b22742018b3edf16c6cadd7b76d9db5e7f9064b5
[        ] 2.2.0
[  +10 ms] executing: [/home/incrypto/flutter/] git rev-parse --abbrev-ref --symbolic @{u}
[   +9 ms] Exit code 0 from: git rev-parse --abbrev-ref --symbolic @{u}
[        ] origin/stable
[        ] executing: [/home/incrypto/flutter/] git ls-remote --get-url origin
[   +8 ms] Exit code 0 from: git ls-remote --get-url origin
[        ] https://github.com/flutter/flutter.git
[ +150 ms] executing: [/home/incrypto/flutter/] git rev-parse --abbrev-ref HEAD
[   +9 ms] Exit code 0 from: git rev-parse --abbrev-ref HEAD
[        ] stable
[ +110 ms] Artifact Instance of 'AndroidGenSnapshotArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'AndroidInternalBuildArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'IOSEngineArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'FlutterWebSdk' is not required, skipping update.
[   +3 ms] Artifact Instance of 'WindowsEngineArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'MacOSEngineArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'LinuxEngineArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'LinuxFuchsiaSDKArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'MacOSFuchsiaSDKArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'FlutterRunnerSDKArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'FlutterRunnerDebugSymbols' is not required, skipping update.
[  +91 ms] Artifact Instance of 'MaterialFonts' is not required, skipping update.
[        ] Artifact Instance of 'GradleWrapper' is not required, skipping update.
[        ] Artifact Instance of 'AndroidGenSnapshotArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'AndroidInternalBuildArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'IOSEngineArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'FlutterWebSdk' is not required, skipping update.
[        ] Artifact Instance of 'FlutterSdk' is not required, skipping update.
[        ] Artifact Instance of 'WindowsEngineArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'MacOSEngineArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'LinuxEngineArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'LinuxFuchsiaSDKArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'MacOSFuchsiaSDKArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'FlutterRunnerSDKArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'FlutterRunnerDebugSymbols' is not required, skipping update.
[        ] Artifact Instance of 'IosUsbArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'IosUsbArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'IosUsbArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'IosUsbArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'IosUsbArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'FontSubsetArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'PubDependencies' is not required, skipping update.
[  +61 ms] Using /home/incrypto/flutter/.pub-cache for the pub cache.
[        ] executing: /home/incrypto/flutter/bin/cache/dart-sdk/bin/pub run build_runner build --verbose
[INFO] Entrypoint:Generating build script...
[INFO] Entrypoint:Generating build script completed, took 694ms

[INFO] BuildDefinition:Initializing inputs
[INFO] BuildDefinition:Reading cached asset graph...
[INFO] BuildDefinition:Reading cached asset graph completed, took 105ms

[INFO] BuildDefinition:Checking for updates since last build...
[INFO] BuildDefinition:Checking for updates since last build completed, took 1.1s

[INFO] Build:Running build...
[INFO] Build:Running build completed, took 34ms

[INFO] Build:Caching finalized dependency graph...
[INFO] Build:Caching finalized dependency graph completed, took 69ms

[SEVERE] web3dart:abi_generator on lib/abi/TodoList.abi.json (cached):

type 'Null' is not a subtype of type 'Map<dynamic, dynamic>' in type cast
package:web3dart/src/builder/documentation.dart 21:38  Documentation.fromJson
package:web3dart/src/builder/generator.dart 42:53      ContractGenerator.build

[SEVERE] Build:
Failed after 166ms
[+5078 ms] "flutter run" took 5,269ms.
[   +9 ms] pub finished with exit code 1
[   +2 ms] 
           #0      throwToolExit (package:flutter_tools/src/base/common.dart:10:3)
           #1      _DefaultPub.interactively (package:flutter_tools/src/dart/pub.dart:366:7)
           <asynchronous suspension>
           #2      PackagesForwardCommand.runCommand (package:flutter_tools/src/commands/packages.dart:241:5)
           <asynchronous suspension>
           #3      FlutterCommand.run.<anonymous closure> (package:flutter_tools/src/runner/flutter_command.dart:1043:27)
           <asynchronous suspension>
           #4      AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:150:19)
           <asynchronous suspension>
           #5      CommandRunner.runCommand (package:args/command_runner.dart:196:13)
           <asynchronous suspension>
           #6      FlutterCommandRunner.runCommand.<anonymous closure> (package:flutter_tools/src/runner/flutter_command_runner.dart:284:9)
           <asynchronous suspension>
           #7      AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:150:19)
           <asynchronous suspension>
           #8      FlutterCommandRunner.runCommand (package:flutter_tools/src/runner/flutter_command_runner.dart:232:5)
           <asynchronous suspension>
           #9      run.<anonymous closure>.<anonymous closure> (package:flutter_tools/runner.dart:62:9)
           <asynchronous suspension>
           #10     AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:150:19)
           <asynchronous suspension>
           #11     main (package:flutter_tools/executable.dart:91:3)
           <asynchronous suspension>

[ +225 ms] ensureAnalyticsSent: 221ms
[   +5 ms] Running shutdown hooks
[   +1 ms] Shutdown hooks complete
[   +1 ms] exiting with code 1

TodoList.abi.json

{
  "contractName": "TodoList",
  "abi": [
    {
      "inputs": [],
      "stateMutability": "nonpayable",
      "type": "constructor"
    },
    {
      "anonymous": false,
      "inputs": [
        {
          "indexed": false,
          "internalType": "uint256",
          "name": "id",
          "type": "uint256"
        },
        {
          "indexed": false,
          "internalType": "bool",
          "name": "completed",
          "type": "bool"
        }
      ],
      "name": "TaskCompleted",
      "type": "event"
    },
    {
      "anonymous": false,
      "inputs": [
        {
          "indexed": false,
          "internalType": "uint256",
          "name": "id",
          "type": "uint256"
        },
        {
          "indexed": false,
          "internalType": "string",
          "name": "content",
          "type": "string"
        },
        {
          "indexed": false,
          "internalType": "bool",
          "name": "completed",
          "type": "bool"
        }
      ],
      "name": "TaskCreated",
      "type": "event"
    },
    {
      "inputs": [],
      "name": "taskCount",
      "outputs": [
        {
          "internalType": "uint256",
          "name": "",
          "type": "uint256"
        }
      ],
      "stateMutability": "view",
      "type": "function",
      "constant": true
    },
    {
      "inputs": [
        {
          "internalType": "uint256",
          "name": "",
          "type": "uint256"
        }
      ],
      "name": "tasks",
      "outputs": [
        {
          "internalType": "uint256",
          "name": "id",
          "type": "uint256"
        },
        {
          "internalType": "string",
          "name": "content",
          "type": "string"
        },
        {
          "internalType": "bool",
          "name": "completed",
          "type": "bool"
        }
      ],
      "stateMutability": "view",
      "type": "function",
      "constant": true
    },
    {
      "inputs": [
        {
          "internalType": "string",
          "name": "_content",
          "type": "string"
        }
      ],
      "name": "createTask",
      "outputs": [],
      "stateMutability": "nonpayable",
      "type": "function"
    },
    {
      "inputs": [
        {
          "internalType": "uint256",
          "name": "_id",
          "type": "uint256"
        }
      ],
      "name": "toggleCompleted",
      "outputs": [],
      "stateMutability": "nonpayable",
      "type": "function"
    }
  ],
  "metadata": "{\"compiler\":{\"version\":\"0.8.4+commit.c7e474f2\"},\"language\":\"Solidity\",\"output\":{\"abi\":[{\"inputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"constructor\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"id\",\"type\":\"uint256\"},{\"indexed\":false,\"internalType\":\"bool\",\"name\":\"completed\",\"type\":\"bool\"}],\"name\":\"TaskCompleted\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"id\",\"type\":\"uint256\"},{\"indexed\":false,\"internalType\":\"string\",\"name\":\"content\",\"type\":\"string\"},{\"indexed\":false,\"internalType\":\"bool\",\"name\":\"completed\",\"type\":\"bool\"}],\"name\":\"TaskCreated\",\"type\":\"event\"},{\"inputs\":[{\"internalType\":\"string\",\"name\":\"_content\",\"type\":\"string\"}],\"name\":\"createTask\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"taskCount\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"name\":\"tasks\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"id\",\"type\":\"uint256\"},{\"internalType\":\"string\",\"name\":\"content\",\"type\":\"string\"},{\"internalType\":\"bool\",\"name\":\"completed\",\"type\":\"bool\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"_id\",\"type\":\"uint256\"}],\"name\":\"toggleCompleted\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"}],\"devdoc\":{\"kind\":\"dev\",\"methods\":{},\"version\":1},\"userdoc\":{\"kind\":\"user\",\"methods\":{},\"version\":1}},\"settings\":{\"compilationTarget\":{\"/home/incrypto/dev/blockchain/blockchain_todo_flutter/smart_contracts/contracts/TodoList.sol\":\"TodoList\"},\"evmVersion\":\"istanbul\",\"libraries\":{},\"metadata\":{\"bytecodeHash\":\"ipfs\"},\"optimizer\":{\"enabled\":true,\"runs\":200},\"remappings\":[]},\"sources\":{\"/home/incrypto/dev/blockchain/blockchain_todo_flutter/smart_contracts/contracts/TodoList.sol\":{\"keccak256\":\"0xaa5051e25a25c85b26bbf26ba8d3781965a292cadf52c2b2b4ef0e36390c4865\",\"license\":\"MIT\",\"urls\":[\"bzz-raw://b90e66b61a13cbe8c4cf4668bf7cb929812402dddd1ccb0244971cea24fd3478\",\"dweb:/ipfs/Qmdf2xa9vfJn66g5MrDnFWBfzFPEd9CgzzaMH8oQR35sgL\"]}},\"version\":1}",
..
...
...
}

Please ignore the dots at the end of json i just out some dots to avoid copy pasting the complete 5000 lines

simolus3 commented 3 years ago

If I remove the dots I can generate the source with the current web3dart version. Looking into it some more, it looks like web3dart struggles with the documentation. Can you post the devdoc key in your generated abi json?

incrypto32 commented 3 years ago

@simolus3 sorry for being late got caught up. By dev doc key do you mean this?

  "devdoc": {
    "kind": "dev",
    "methods": {},
    "version": 1
  },
simolus3 commented 3 years ago

Yes exactly, I see the issue now. web3dart is expecting there to be an events key in devdoc. This should be fixed now, I'll release an update later.

simolus3 commented 3 years ago

I've just published 2.1.4 which should fix this problem!