From a94ada8b3eef24f32e14ddac100fdb5f8f2f1a32 Mon Sep 17 00:00:00 2001 From: Steven Luscher Date: Tue, 6 Sep 2022 22:37:27 -0700 Subject: [PATCH] fix: recursively size variable size structs in your buffer layouts (#27624) --- web3.js/src/layout.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/web3.js/src/layout.ts b/web3.js/src/layout.ts index 8c35d589a4..c4d161e04d 100644 --- a/web3.js/src/layout.ts +++ b/web3.js/src/layout.ts @@ -152,6 +152,9 @@ export function getAlloc(type: any, fields: any): number { if (Array.isArray(field)) { return field.length * getItemAlloc(item.elementLayout); } + } else if ('fields' in item) { + // This is a `Structure` whose size needs to be recursively measured. + return getAlloc({layout: item}, fields[item.property]); } // Couldn't determine allocated size of layout return 0;