From 1fda292742b51890789ec8f004da62012ea9099c Mon Sep 17 00:00:00 2001 From: Jenea Vranceanu Date: Fri, 14 Jun 2024 01:09:34 +0300 Subject: [PATCH 1/9] fix: transaction.data field bytes decoding --- src/components/shared/ContractFunction.vue | 21 +++++++++++++-------- src/helpers/functionUtils.ts | 9 +++++++-- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/src/components/shared/ContractFunction.vue b/src/components/shared/ContractFunction.vue index cb2ccbca..e944b442 100644 --- a/src/components/shared/ContractFunction.vue +++ b/src/components/shared/ContractFunction.vue @@ -166,14 +166,16 @@ function handleCall(e: Event) { } } -const makeBytes32 = (value: string, type: string) => { - if (/^bytes32/.test(type)) { +const makeBytes = (value: string, type: string) => { + if (/^bytes/.test(type)) { + const _bytesCount = type.match(/\d+/) ?? [] + const bytesCount = _bytesCount.length > 0 ? Number(_bytesCount[0]) : 0 if (/^[0-9]+$/.test(value)) { const hex = numberToHex(value) - return padLeft(hex, 64) + return padLeft(hex, bytesCount * 2) } if (/^0x[0-9a-f]*$/i.test(value)) { - return padLeft(value, 64) + return padLeft(value, bytesCount * 2) } if (/^\w*(:.*,.*)?$/.test(value)) { const items = (value || '').split(',') @@ -184,7 +186,7 @@ const makeBytes32 = (value: string, type: string) => { } } } - return value + return value ? value : '0x' } if (props.dataDecoder) { @@ -226,9 +228,9 @@ const output = computed<{ error: undefined | string; value: string }>(() => { const types = reactiveData.items.map(({ type }) => type) const args = reactiveData.items.map(({ value, type, isWei }) => { const makeItem = (value: any) => - /^bytes32/.test(type) - ? (makeBytes32(value, type) ?? '0x') - : makeValue(value, isWei) || '' + /^bytes/.test(type) + ? (makeBytes(value, type) ?? '0x') + : (makeValue(value, isWei) ?? '') if (/\[\]$/.test(type)) { return value.map(makeItem) } @@ -293,6 +295,9 @@ watch( console.error(err) } } + } else if (!value) { + reactiveData.items = [] + reactiveData.call = undefined } } ) diff --git a/src/helpers/functionUtils.ts b/src/helpers/functionUtils.ts index 49f3e6d9..cde58273 100644 --- a/src/helpers/functionUtils.ts +++ b/src/helpers/functionUtils.ts @@ -90,7 +90,9 @@ export const decodeData = async ( signatureCache = await caches.open(SIGNATURE_CACHE) } catch {} const url = getSelectorLookupURL(selector) - const functionSignatureResponse = await signatureCache?.match(url) + // Use a different cache key instead to fix problem with wrong response. + const functionKey = `${url}/decoded` + const functionSignatureResponse = await signatureCache?.match(functionKey) let functionSignatures: string[] = [] if (functionSignatureResponse) { @@ -152,7 +154,10 @@ export const decodeData = async ( call in { setData: true, getData: true }, })), } - await signatureCache?.put(url, new Response(JSON.stringify(item))) + await signatureCache?.put( + functionKey, + new Response(JSON.stringify(item)) + ) return item } } catch (err) { From 06e530713b07bc5b86c1638b9fce0d7f98b7866e Mon Sep 17 00:00:00 2001 From: Jenea Vranceanu Date: Fri, 14 Jun 2024 10:54:10 +0300 Subject: [PATCH 2/9] chore: lint fix --- src/components/endpoints/Assets.vue | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/components/endpoints/Assets.vue b/src/components/endpoints/Assets.vue index b400de23..d7d77aeb 100644 --- a/src/components/endpoints/Assets.vue +++ b/src/components/endpoints/Assets.vue @@ -119,8 +119,9 @@ const create = async () => { tokenIdFormat: tokenIdType.value, } console.log(digitalAssetData) - deployedAsset = - await deployLSP8IdentifiableDigitalAsset(digitalAssetData) + deployedAsset = await deployLSP8IdentifiableDigitalAsset( + digitalAssetData + ) console.log( 'Deployed asset', deployedAsset.LSP8IdentifiableDigitalAsset From 579084cd92dfc2d3865faa0783e2e7cc55edea95 Mon Sep 17 00:00:00 2001 From: Jenea Vranceanu Date: Fri, 14 Jun 2024 11:43:38 +0300 Subject: [PATCH 3/9] fix: lint fix? --- src/components/endpoints/Assets.vue | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/components/endpoints/Assets.vue b/src/components/endpoints/Assets.vue index d7d77aeb..37ce5866 100644 --- a/src/components/endpoints/Assets.vue +++ b/src/components/endpoints/Assets.vue @@ -119,9 +119,8 @@ const create = async () => { tokenIdFormat: tokenIdType.value, } console.log(digitalAssetData) - deployedAsset = await deployLSP8IdentifiableDigitalAsset( - digitalAssetData - ) + deployedAsset = + await deployLSP8IdentifiableDigitalAsset(digitalAssetData) console.log( 'Deployed asset', deployedAsset.LSP8IdentifiableDigitalAsset From 14b1307dd0e1c849807163276952da842a434900 Mon Sep 17 00:00:00 2001 From: Jenea Vranceanu Date: Fri, 14 Jun 2024 11:44:36 +0300 Subject: [PATCH 4/9] fix: lint fix? --- src/components/endpoints/Assets.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/endpoints/Assets.vue b/src/components/endpoints/Assets.vue index 37ce5866..b400de23 100644 --- a/src/components/endpoints/Assets.vue +++ b/src/components/endpoints/Assets.vue @@ -119,7 +119,7 @@ const create = async () => { tokenIdFormat: tokenIdType.value, } console.log(digitalAssetData) - deployedAsset = + deployedAsset = await deployLSP8IdentifiableDigitalAsset(digitalAssetData) console.log( 'Deployed asset', From b9bb5509ee4da25f673dde23a4f537dec5ec123f Mon Sep 17 00:00:00 2001 From: Jenea Vranceanu Date: Mon, 29 Jul 2024 18:48:32 +0300 Subject: [PATCH 5/9] fix: padRight should be used for hex strings representing encoded bytes --- src/components/shared/ContractFunction.vue | 4 ++-- src/components/shared/ParamField.vue | 11 +++++++++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/components/shared/ContractFunction.vue b/src/components/shared/ContractFunction.vue index e944b442..c7fa25df 100644 --- a/src/components/shared/ContractFunction.vue +++ b/src/components/shared/ContractFunction.vue @@ -1,7 +1,7 @@