-
Notifications
You must be signed in to change notification settings - Fork 6
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
Large number handling #84
Comments
Hey @wbt great question! For your example of 2^64, this is larger than the largest allowed
See the docs for more info on storing JSON https://docs.tableland.xyz/sql-specification#e2bee77cd6d04c679c1dbe1b2dd57204 |
Hmm, it looks like I may not have communicated my points very clearly. Hopefully this helps:
|
@wbt thanks again for all of the input here.
Not sure I'm following what you mean on this point. The canvas game is not using this module. Can you provide a link to the place in the code you're referring to?
We are actively working on the docs and I'll mention your idea to the team. |
On this line the type of columns |
I guess I see what you are saying, but its a bit confusing ask this here since it doesn't involve this module. For the specific lines you mention: tokenId is a uint256 as defined by erc721, and the x and y arguments need to be anything that will be able to contain integers from 0 to 512, and uint256 works for that. All of the arguments are going to be converted to strings before being concatenated into the sql statement, so what ever type reduces gas while still working is probably the right choice. Note smaller doesn't necessarily mean cheaper. |
There are three different type systems involved in a DApp using Tableland: Solidity's, Tableland's, and JavaScript's; there's often a fourth related to application logic. When developing a DApp, it's important to make sure these types are mapping onto one another correctly. For example, I have a value which is an The only example I found of using Tableland in a smart contract to see how the Tableland types map onto Solidity was the Canvas Game, which isn't even discoverable on the main branch of the examples repo. That is was what was available to go on, and it led me to an incorrect belief that Tableland's Because a I think the main proposal here is to either use BigNumbers of some sort in SDK read responses, and/or be WAY more obvious and clear in the documentation that Tableland |
@wbt The mapping of the different type systems to each other is certainly a concern for every Dapp, or app, using Javascript and a SQL Database of any kind. In general if the app wants to support Javascript integers above MAX_SAFE_INTEGER storing the data as a string should work. |
Yes, that is generally true, especially since Tableland read operations from the EVM aren't supported (!). |
Thanks for raising this ticket. It has kicked off a good deal of internal discussion (in addition to the discussions here and on Discord). The action item here is to update documentation and recommendations, and make this clearer to those digging into our docs.We will likely pull in some of the content from this discussion here as well. I'm leaving this open to ensure we circle back to make sure the questions have been addressed. cc @dtbuchholz for your docs updates. |
@carsonfarmer We have a decision related to this here: https://www.notion.so/textile/We-need-to-make-some-concrete-decisions-or-guidelines-for-users-when-working-with-large-integers-e91d3f4c202a4e6ab4724f086beac009 |
I'd like to wait to close it until we're satisfied that the docs updates have indeed been made. |
@carsonfarmer lmk if anythings missing https://docs.tableland.xyz/solidity-to-sql-types |
@dtbuchholz this looks good to me. @carsonfarmer should we solicit feedback from users here? |
No I think we can close this and get feedback on an ongoing basis. |
Using the SDK, the results of a SELECT statement includes a
rows
object with an array ofrow
arrays. If one of the selected values was anint
type during table creation, it is present in the appropriate position of eachrow
array as a JavaScript number.This works fine in most cases.
However, my understanding is that the equivalent Solidity type is
uint256
.One common use case would be to have a numeric integer primary key column of type
uint256
and include a reference to this id in a second table as a foreign key reference, even if not explicitly declared.Does Tableland's SDK actually store and return large numbers correctly? I was trying to build a test case to see what would be returned in the
row
value when a value was outside of JavaScript'sinteger
range (specifically, I tried the number 18446744073709551616 (2^64) added into the query string without having to be stored numerically in JavaScript) and it looked like the change wasn't actually applied. Reading the docs, it looks like the typeint64
might be more appropriate thanuint256
as the EVN version of Tableland numbers, but even this has values well outside Javascript's safe range for accurate computation.Other methods of interacting with blockchains tend to use some BigNumber implementation for numeric values input to or output from blockchain functions; this is one that does not. Should it?
The text was updated successfully, but these errors were encountered: