Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

missing generics for enum std::option::Option during forc index build #1328

Closed
chlenc opened this issue Sep 4, 2023 · 7 comments
Closed
Assignees

Comments

@chlenc
Copy link

chlenc commented Sep 4, 2023

missing generics for enum std::option::Option during forc index build

Hi guys, I'm trying to use indexer in my swaylend contract on beta4
Swaylend market contract deployed here:0x2679d41c2981bcd6ab69d66f0ae656077efecac2c2dd729f88f5a6457ce1d5f1
Swaylend code is here:
https://github.com/compolabs/sway-lend/blob/beta-4/contracts/market/src/main.sw

The problem

I've created a brand new indexer using forc index new swaylend-indexer --namespace composabilitylabs
Changed a bit src/lib.rs, added abi and changed swaylend_indexer.manifest.yaml`
You can find the swaylend indexer here
https://github.com/compolabs/sway-lend/tree/beta-4/services/swaylend-indexer

But during build, it fails with next error

>>> forc index build                           
▹▹▸▹▹ ⏰ Building...                                                                                                                                           Compiling swaylend_indexer v0.0.0 (/Users/alexey/projects/fuel/sway-lend/services/swaylend-indexer)
error[E0107]: missing generics for enum `std::option::Option`
   --> src/lib.rs:4:1
    |
4   | #[indexer(manifest = "swaylend_indexer.manifest.yaml")]
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected 1 generic argument
    |
note: enum defined here, with 1 generic parameter: `T`
   --> /Users/alexey/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/src/rust/library/core/src/option.rs:563:10
    |
563 | pub enum Option<T> {
    |          ^^^^^^ -
    = note: this error originates in the attribute macro `indexer` (in Nightly builds, run with -Z macro-backtrace for more info)
help: add missing generic argument
    |
4   | #[indexer(manifest = "swaylend_indexer.manifest.yaml")]<T>
    |                                                        +++

For more information about this error, try `rustc --explain E0107`.
error: could not compile `swaylend_indexer` (lib) due to previous error
▪▪▪▪▪ ❌ Build failed.                                                                                                                                      Error: ❌ Failed to build index.

Uploading image.png…

Toolchain

Default host: aarch64-apple-darwin
fuelup home: /Users/alexey/.fuelup

installed toolchains
--------------------
beta-3-aarch64-apple-darwin
beta-4-rc.2-aarch64-apple-darwin
latest-aarch64-apple-darwin (default)
hotfix
my-custom-toolchain

active toolchain
-----------------
latest-aarch64-apple-darwin (default)
  forc : 0.44.1
    - forc-client
      - forc-deploy : 0.44.1
      - forc-run : 0.44.1
    - forc-doc : 0.44.1
    - forc-explore : 0.28.1
    - forc-fmt : 0.44.1
    - forc-index : 0.20.7
    - forc-lsp : 0.44.1
    - forc-tx : 0.44.1
    - forc-wallet : 0.3.0
  fuel-core : 0.20.4
  fuel-core-keygen : Error getting version string
  fuel-indexer : 0.20.7

fuels versions
---------------
forc : 0.45
forc-wallet : 0.45

How to reproduce

fuelup self update     
fuelup install latest            
fuelup default latest

git clone https://github.com/compolabs/sway-lend.git
cd sway-lend
git checkout beta-4
cd services/swaylend-indexer/   
forc index build  
@chlenc
Copy link
Author

chlenc commented Sep 4, 2023

© @lostman
just added the reply here to keep it all together

There’s an enum Option where the inner type is generic T in market-abi.json.
generic T is non-decodable in the indexer, and so should be the Option.
This will have to be fixed somewhere in the code gen.
Meanwhile, you can manually remove those from market-abi.json :

diff --git a/services/swaylend-indexer/market-abi.json b/services/swaylend-indexer/market-abi.json
index 5082b52..9c49464 100644
--- a/services/swaylend-indexer/market-abi.json
+++ b/services/swaylend-indexer/market-abi.json
@@ -112,25 +112,6 @@
       ],
       "typeParameters": null
     },
-    {
-      "typeId": 5,
-      "type": "enum Option",
-      "components": [
-        {
-          "name": "None",
-          "type": 0,
-          "typeArguments": null
-        },
-        {
-          "name": "Some",
-          "type": 6,
-          "typeArguments": null
-        }
-      ],
-      "typeParameters": [
-        6
-      ]
-    },
     {
       "typeId": 6,
       "type": "generic T",
@@ -1578,37 +1559,5 @@
       }
     }
   ],
-  "messagesTypes": [],
-  "configurables": [
-    {
-      "name": "MARKET_CONFIGURATION",
-      "configurableType": {
-        "name": "",
-        "type": 5,
-        "typeArguments": [
-          {
-            "name": "",
-            "type": 14,
-            "typeArguments": []
-          }
-        ]
-      },
-      "offset": 698444
-    },
-    {
-      "name": "DEBUG_STEP",
-      "configurableType": {
-        "name": "",
-        "type": 5,
-        "typeArguments": [
-          {
-            "name": "",
-            "type": 21,
-            "typeArguments": null
-          }
-        ]
-      },
-      "offset": 698692
-    }
-  ]
-}
\ No newline at end of file
+  "messagesTypes": []
+}

Ant then the indexer should compile.

@lostman
Copy link
Contributor

lostman commented Sep 5, 2023

@lostman
Copy link
Contributor

lostman commented Sep 5, 2023

#1331

@ra0x3
Copy link
Contributor

ra0x3 commented Sep 6, 2023

@chlenc

  • After looking over this in more detail, I don't think there's a "workaround" for this (that wouldn't cause you guys to make non-trivial changes to your smart contract)
  • Given this, and the fact that this is a blocker for you guys, I'm gonna include Option support in the Vec support PR here enhancement: add support for sway generics #1332
  • I will update this issue when this is merged (could be merged by Friday)

@chlenc
Copy link
Author

chlenc commented Sep 6, 2023

Thanks a lot ser ❤️

@ra0x3
Copy link
Contributor

ra0x3 commented Sep 11, 2023

@chlenc

  • Just an update here:

@ra0x3
Copy link
Contributor

ra0x3 commented Sep 12, 2023

Closing as complete in #1332

@ra0x3 ra0x3 closed this as completed Sep 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants