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 all 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)
7 changes: 6 additions & 1 deletion packages/web3-eth/test/integration/rpc.block.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ You should have received a copy of the GNU Lesser General Public License
along with web3.js. If not, see <http://www.gnu.org/licenses/>.
*/
import { FMT_BYTES, FMT_NUMBER } from 'web3-utils';
import { TransactionInfo, TransactionReceipt } from 'web3-types';
import { TransactionInfo, TransactionReceipt, Transaction } from 'web3-types';
// eslint-disable-next-line import/no-extraneous-dependencies
import { Contract } from 'web3-eth-contract';
// eslint-disable-next-line import/no-extraneous-dependencies
Expand Down Expand Up @@ -155,6 +155,11 @@ describe('rpc with block', () => {
b.totalDifficulty = '0x0';
}
expect(validator.validateJSONSchema(blockSchema, b)).toBeUndefined();

if (hydrated && b.transactions?.length > 0) {
// eslint-disable-next-line jest/no-conditional-expect
expect(b.transactions).toBeInstanceOf(Array<Transaction>);
}
});

it.each(
Expand Down
37 changes: 28 additions & 9 deletions packages/web3-utils/src/formatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,25 @@ 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: string | undefined;

for (const dataPart of dataPath) {
if (result.oneOf && previousDataPath) {
const path = oneOfPath.find(function (element: [string, number]) {
return (this as unknown as string) === element[0];
}, previousDataPath ?? '');

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 +110,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 +162,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 +173,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 +204,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 +253,7 @@ export const convert = (
schema,
dataPath,
format,
oneOfPath,
);
}

Expand Down