Open ckeshava opened 1 day ago
The changes in this pull request focus on enhancing type safety and precision in the handling of numeric values across various interfaces and methods related to the UInt64
type and its interactions within the XRPL. Key modifications include restricting the accepted types in the UInt64.from
method, updating various interfaces to utilize bigint
instead of number
, and refining validation logic to accommodate these changes. Additionally, the test cases have been updated to reflect these new type requirements, ensuring consistent handling of large integer values.
File Path | Change Summary |
---|---|
packages/ripple-binary-codec/src/types/uint-64.ts |
Updated UInt64.from method signature to accept only UInt64 , string , or bigint . Removed handling for number . |
packages/ripple-binary-codec/test/binary-serializer.test.ts |
Updated tests for UInt64 serialization to enforce type checks for string and bigint . Added new tests for undefined fields. |
packages/xrpl/src/models/common/index.ts |
Changed AssetPrice type from number | string to bigint | string . |
packages/xrpl/src/models/ledger/XChainOwnedCreateAccountClaimID.ts |
Changed XChainAccountCreateCount type from number to bigint . |
packages/xrpl/src/models/transactions/XChainAddAccountCreateAttestation.ts |
Updated XChainAccountCreateCount type to bigint | string and adjusted validation logic. |
packages/xrpl/src/models/transactions/XChainAddClaimAttestation.ts |
Changed XChainClaimID type to bigint | string and updated validation logic. |
packages/xrpl/src/models/transactions/XChainClaim.ts |
Updated XChainClaimID type to bigint | string and modified validation logic accordingly. |
packages/xrpl/src/models/transactions/XChainCommit.ts |
Changed XChainClaimID type to bigint | string and updated validation logic. |
packages/xrpl/src/models/transactions/common.ts |
Added isBigInt function for type checking of bigint . |
packages/xrpl/src/models/transactions/oracleSet.ts |
Updated PriceData validation to use isBigInt for AssetPrice . |
packages/xrpl/test/integration/requests/getAggregatePrice.test.ts |
Changed AssetPrice in tests from number to BigInt . |
packages/xrpl/test/integration/transactions/oracleDelete.test.ts |
Updated AssetPrice in tests from number to BigInt . |
packages/xrpl/test/integration/transactions/oracleSet.test.ts |
Changed AssetPrice in tests from number to BigInt . |
packages/xrpl/test/integration/transactions/xchainAddAccountCreateAttestation.test.ts |
Updated XChainAccountCreateCount in tests from number to BigInt . |
packages/xrpl/test/integration/transactions/xchainAddClaimAttestation.test.ts |
Changed XChainClaimID in tests from number to BigInt . |
packages/xrpl/test/integration/transactions/xchainClaim.test.ts |
Updated XChainClaimID in tests from number to BigInt . |
packages/xrpl/test/integration/transactions/xchainCommit.test.ts |
Changed XChainClaimID in tests from number to BigInt . |
packages/xrpl/test/models/oracleSet.test.ts |
Updated AssetPrice in tests from number to BigInt . |
packages/xrpl/tools/generateModels.js |
Updated type mapping for UINT64 from 'number | string' to 'string' and enhanced model generation logic. |
UINT64
types, ensuring that the handling of large integer values aligns with the requirements mentioned in the issue, particularly regarding acceptable forms of BigInt
representation.π° In the meadow where numbers play,
BigInts hop and dance all day.
With types so strict, we leap with cheer,
Precision's here, no need to fear!
Fromnumber
tobigint
, we make the switch,
In our code, we found the perfect pitch! πΌβ¨
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?
High Level Overview of Change
UINT64
type must support values in the range of[0, 18446744073709551615]
, both inclusive. Javascript'snumber
type does not have a compatible range of values, due to double-precision floating point format.If users specify a large input (say
number(18446744073709551615)
, well-beyond the limits ofnumber
type) into aUINT64
type field, thexrpl.js
SDK parses the input as0
. No error is raised byxrpl.js
, although the VSCode editor displays a red-squiggly warning about the loss-of-precision. We can prevent such unexpected surprises by enforcing a stricter typebigint
.This PR specifies the change in
UINT64.from
method. It also updates relevant Transaction fields to usebigint
type, instead ofnumber
type. These transactions pertain to thePriceOracle
and theXChainBridge
amendments.Context of Change
Type of Change
Did you update HISTORY.md?
Test Plan
Existing tests should suffice for validating the serialization/de-serialization of the UINT64 type fields.