Skip to content
This repository was archived by the owner on Mar 5, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -781,6 +781,10 @@ should use 4.0.1-alpha.0 for testing.

- Corrected the error code for `JSONRPC_ERR_UNAUTHORIZED` to be `4100` (#5462)

#### web3-eth

- Fix `getBlock` returning empty transactions object on `hydrated` true (#5556)

#### web3-eth-contract

- According to the latest change in `web3-eth-abi`, the decoded values of the large numbers, returned from function calls or events, are now available as `BigInt`. (#5435)
Expand Down
4 changes: 4 additions & 0 deletions packages/web3-eth/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Removed

- Moved the errors' classes from `web3-eth/src/errors.ts` to `web3-errors/src/errors/transaction_errors.ts` (#5462)

### Fixed

- Fix `getBlock` returning empty transactions object on `hydrated` true (#5556)
35 changes: 26 additions & 9 deletions packages/web3-utils/src/formatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,23 @@ export type FormatType<T, F extends DataFormat> = number extends Extract<T, Numb
}
: T;

const findSchemaByDataPath = (schema: JsonSchema, dataPath: string[]): JsonSchema | undefined => {
const findSchemaByDataPath = (
schema: JsonSchema,
dataPath: string[],
oneOfPath: [string, number][] = [],
): JsonSchema | undefined => {
let result: JsonSchema = { ...schema } as JsonSchema;
let previousDataPath;

for (const dataPart of dataPath) {
if (result.oneOf && previousDataPath) {
// eslint-disable-next-line no-loop-func
const path = oneOfPath.find((element: [string, number]) => element[0] === result.name);
if (path && path[0] === previousDataPath) {
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access
result = result.oneOf[path[1]];
}
}
if (!result.properties && !result.items) {
return undefined;
}
Expand All @@ -95,6 +108,8 @@ const findSchemaByDataPath = (schema: JsonSchema, dataPath: string[]): JsonSchem
} else if (result.items && Array.isArray(result.items)) {
result = (result.items as JsonSchema[])[parseInt(dataPart, 10)];
}

if (result && dataPart) previousDataPath = dataPart;
}

return result;
Expand Down Expand Up @@ -145,6 +160,7 @@ export const convert = (
schema: JsonSchema,
dataPath: string[],
format: DataFormat,
oneOfPath: [string, number][] = [],
) => {
// If it's a scalar value
if (!isObject(data) && !Array.isArray(data)) {
Expand All @@ -155,7 +171,7 @@ export const convert = (

for (const [key, value] of Object.entries(object)) {
dataPath.push(key);
const schemaProp = findSchemaByDataPath(schema, dataPath);
const schemaProp = findSchemaByDataPath(schema, dataPath, oneOfPath);

// If value is a scaler value
if (isNullish(schemaProp)) {
Expand Down Expand Up @@ -186,19 +202,19 @@ export const convert = (
// over each possible schema and check if they type of the schema
// matches the type of value[0], and if so we use the oneOfSchemaProp
// as the schema for formatting
for (const oneOfSchemaProp of schemaProp.oneOf) {
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call
schemaProp.oneOf.forEach((oneOfSchemaProp: JsonSchema, index: number) => {
if (
!Array.isArray(schemaProp?.items) &&
((typeof value[0] === 'object' &&
((oneOfSchemaProp as JsonSchema)?.items as JsonSchema)?.type ===
'object') ||
(oneOfSchemaProp?.items as JsonSchema)?.type === 'object') ||
(typeof value[0] === 'string' &&
((oneOfSchemaProp as JsonSchema)?.items as JsonSchema)?.type !==
'object'))
(oneOfSchemaProp?.items as JsonSchema)?.type !== 'object'))
) {
_schemaProp = oneOfSchemaProp as JsonSchema;
_schemaProp = oneOfSchemaProp;
oneOfPath.push([key, index]);
}
}
});
}

if (isNullish(_schemaProp?.items)) {
Expand Down Expand Up @@ -235,6 +251,7 @@ export const convert = (
schema,
dataPath,
format,
oneOfPath,
);
}

Expand Down