-
Notifications
You must be signed in to change notification settings - Fork 138
Unify ScInt
& scValToBigInt
into XdrLargeInt
#809
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
base: master
Are you sure you want to change the base?
Conversation
Size Change: +4.51 kB (+0.13%) Total Size: 3.44 MB
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
LGTM. The only question, does this implementation really requires static methods E.g. constructor(value: number|string|BigInt|xdr.ScVal, type: string?) {
switch(typeof value) {
case 'number': ... break
case 'string': ... break
case 'bigint': ... break
default: //check for ScVal with duck-typing
break
}
} new Int(12, 'i128');
new Int('12', 'u64');
new Int(12n, 'u128');
new Int(scv); The only potential problem might be with ScVal if people use multiple StellarBase libs in a project (for example importing StellarBase and StellarSDK, I faced this problem multiple times with XDR and Transactions). So would be nice to use some basic duck-typing check for ScVal. |
Because a lot of the types in the SDK offer static functions, to aid with discoverability we could keep the |
Would the second argument, the type, be required for non-ScVal inputs? |
Not necessarily. MongoDB driver, for example, automatically determines an appropriate type (int32, int64, etc) from the number. So, if the number can't fit into i32, the automatically assigned type would be i64, and so on. But yeah, I agree that in the context of smart contracts, the type for non-ScVal value should be provided explicitly. |
@orbitlens that's the way that If people don't mind migrating we can do it this way, then also allow |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've reviewed and don't have anything substantive to add. I haven't used the existing method much and the proposed change seems clean 👍
What
XdrLargeInt
has been renamed toInt
ScInt
andscValToBigInt
have been removed to simplify the API surface:Int
also has new methods and features:fromValue(x: number|string|BigInt)
will create anInt
of an appopriate size for the given valuefromScVal(x: xdr.ScVal)
will create anInt
from anScVal
.toU32()
will return anScVal
of the typescvU32
.toI32()
will return anScVal
of the typescvI32
i32
andu32
as the firsttype
parameterWhy
Addresses #722: we want to reduce and unify the API surface of working with big numbers and
ScVal
s into a single object.