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

storage: move token type translation to go #533

Merged
merged 2 commits into from
Oct 5, 2023
Merged

Conversation

pro-wh
Copy link
Collaborator

@pro-wh pro-wh commented Sep 28, 2023

did we want to move this?

@@ -18,6 +18,7 @@ import (
oasisConfig "github.com/oasisprotocol/oasis-sdk/client-sdk/go/config"
sdkTypes "github.com/oasisprotocol/oasis-sdk/client-sdk/go/types"

"github.com/oasisprotocol/nexus/analyzer/runtime/evm"
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dang ol storage depending on analyzer

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤷 you could move it to common/types.go? Although it looks OK enough to me as-is. The true storage type is int, really ... But it's nice to do the automatic cast into analyzer types, because the compiler will warn us(*) if we change the db input (= analyzer) but not the handling of the db output (= storage/client).

(*) in limited cases, Go's approach to enums is a joke, call me at 1 800 VITRIOL for more pointless Go rants

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah yeah, would make sense to move it to common, now that it shows up in both storage and api

go has a lot of progressive ideas about preventing authors from locking down their own stuff, including via enums

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

moved. also it's now TokenType instead of EVMTokenType

Copy link
Collaborator Author

@pro-wh pro-wh Oct 5, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

correction: doesn't show up in api. just analyzer and storage

func translateTokenType(tokenType evm.EVMTokenType) apiTypes.EvmTokenType {
switch tokenType {
case evm.EVMTokenTypeERC20:
return apiTypes.EvmTokenTypeERC20
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dang ol storage depending on api

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ya ideally it shouldn't, or at least not this directly. Can you define a storage version of EvmTokenType in storage/client/types.go please? You'll see all of those are actually just aliases for API types 🥲 -- but at least it gives us a layer where we could introduce different storage types if needed. In the past, we used to use this more actively when txs were stored in the db not fully parsed.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ugh now I think this is fine. it lets us have the list of enum values in the api spec for the price of one copy of the values

storage/client/client.go Outdated Show resolved Hide resolved
Copy link
Contributor

@mitjat mitjat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hallelujah. Thank you, I've wanted to scratch this itch for a while. Sorry for allowing it to spawn in the first place.

func translateTokenType(tokenType evm.EVMTokenType) apiTypes.EvmTokenType {
switch tokenType {
case evm.EVMTokenTypeERC20:
return apiTypes.EvmTokenTypeERC20
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ya ideally it shouldn't, or at least not this directly. Can you define a storage version of EvmTokenType in storage/client/types.go please? You'll see all of those are actually just aliases for API types 🥲 -- but at least it gives us a layer where we could introduce different storage types if needed. In the past, we used to use this more actively when txs were stored in the db not fully parsed.

@@ -18,6 +18,7 @@ import (
oasisConfig "github.com/oasisprotocol/oasis-sdk/client-sdk/go/config"
sdkTypes "github.com/oasisprotocol/oasis-sdk/client-sdk/go/types"

"github.com/oasisprotocol/nexus/analyzer/runtime/evm"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤷 you could move it to common/types.go? Although it looks OK enough to me as-is. The true storage type is int, really ... But it's nice to do the automatic cast into analyzer types, because the compiler will warn us(*) if we change the db input (= analyzer) but not the handling of the db output (= storage/client).

(*) in limited cases, Go's approach to enums is a joke, call me at 1 800 VITRIOL for more pointless Go rants

@pro-wh pro-wh force-pushed the pro-wh/feature/holders12 branch from 6754434 to e4cb046 Compare September 29, 2023 23:09
@pro-wh pro-wh force-pushed the pro-wh/feature/ttt branch 2 times, most recently from 35d9ba7 to 7c9ac25 Compare October 3, 2023 23:25
@pro-wh pro-wh force-pushed the pro-wh/feature/holders12 branch from e4cb046 to 91cd6aa Compare October 3, 2023 23:25
@pro-wh pro-wh force-pushed the pro-wh/feature/ttt branch from 7c9ac25 to fd03b59 Compare October 3, 2023 23:35
@pro-wh pro-wh force-pushed the pro-wh/feature/holders12 branch from 91cd6aa to a8d53b2 Compare October 3, 2023 23:35
Base automatically changed from pro-wh/feature/holders12 to main October 3, 2023 23:59
@pro-wh pro-wh force-pushed the pro-wh/feature/ttt branch 2 times, most recently from 3d83231 to 981c4f2 Compare October 5, 2023 22:24
@pro-wh pro-wh force-pushed the pro-wh/feature/ttt branch from 981c4f2 to 5b4fb91 Compare October 5, 2023 22:54
@pro-wh pro-wh merged commit 5881904 into main Oct 5, 2023
6 checks passed
@pro-wh pro-wh deleted the pro-wh/feature/ttt branch October 5, 2023 23:12
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 this pull request may close these issues.

2 participants