Closed khssnv closed 3 months ago
Actually, this is intented behavior. Polkadot.js encodes those addresses under the hood, but our sdk don't. You can use https://github.com/subsquid/squid-sdk/tree/master/substrate/ss58 to get the address in ss58 format
Indeed. The fact that the address is a variant of an enum does not affect the value returned from the SDK storage getter.
What about BoundedVec
? Hex-string with a SCALE encoded value does not contain the length and it is not available from the SDK typegen. In my case on chain the length is a paramter type used for a stored struct. Is it intended to keep track of updates for the length manually?
A code snippet for someone who have the same problem with ASCII decoding from BoundedVec
.
import { TypeRegistry, VecFixed } from '@polkadot/types'
const scaleEncodedAsciiString = '0x33382e3234322e3233362e323436' // SCALE encoded ASCII numbers for string "38.242.236.246"
const boundedVecCapacity = 255
const vecFixedAsciiString = new VecFixed(new TypeRegistry(), 'u8', boundedVecCapacity, scaleEncodedAsciiString)
const endOfAsciiString= vecFixedAsciiString.toU8a().indexOf(0)
const decodedValue = String.fromCharCode(...vecFixedAsciiString.toU8a().slice(0, endOfAsciiString))
console.log(`Decoded ${decodedValue.length} characters: "${decodedValue}".`)
Bounded vector is encoded exactly like a regular vector and exported to the metadata exactly like a regular vector. Hence, the SDK can't distinguish between the two and does not need to.
The SDK functions return primitive types like booleans and numbers decoded from SCALE and it made me to expect the vector to come decoded too. Alright, thanks! Please close the issue.
Describe the bug
Decoding of
BoundedVec<u8, _>
and decoding of an enum withAccountId32
type variant return a part of the SCALE-encoded value instead of the properly decoded SS58-string for the address and decoded ASCII string for the vec of u8. For instance for aBoundedVec<u8, 255>
containing ASCII-encoded string38.242.236.247
it returns0x3137382e3235312e3232382e323336
. At the same time at https://polkadot.js.org/apps/#/chainstate all values correctly decoded and displayed as expected.To Reproduce
Setup the project.
Launch processor.
See badly decoded values in logs.
Expected behavior
For the log lines above expected values are:
6T74euR2ZZ8rDwAs1CdqoWDkVnXw2MmAP6eHsXxCrzkCKdfm
instead of0x9ef98ad9c3626ba725e78d76cfcfc4b4d07e84f0388465bc7eb992e3e117234a
,38.242.236.247
instead of0x33382e3234322e3233362e323437
storage-1.devnet.cere.network
instead of0x73746f726167652d312e6465766e65742e636572652e6e6574776f726b
A full SCALE-encoded value is
0x9ef98ad9c3626ba725e78d76cfcfc4b4d07e84f0388465bc7eb992e3e117234ac2c72f9ce9f1ca879c6a098e2cf729a538b0d341933d949cea755abffee4780a017f82864e4f097e63d04cc279e4d8d2eb45a42ffa3833382e3234322e3233362e3234377473746f726167652d312e6465766e65742e636572652e6e6574776f726b01901f82236e2302
Screenshots
Correctly decoded values displayed at https://polkadot.js.org/apps/#/chainstate. Fields
pubKey
,host
, anddomain
are shown as expected.Environment (please complete the following information):
"@subsquid/substrate-processor": "8.3.0"
,"@subsquid/substrate-typegen": "8.1.0"
,"@subsquid/substrate-metadata-explorer": "3.2.0"
16
10.8
Linux x1 6.5.0-1027-oem #28-Ubuntu SMP PREEMPT_DYNAMIC Thu Jul 25 13:32:46 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux
debug/khssnv-squid-sdk-decoding-bug-report
Applicable to decoding issues:
cere-dev
2,217,350
with hash0x553745d49561192344549449a1662cccc6da5f05f2be718f526ba45d014a1f1a
48400
wss://archive.devnet.cere.network/ws
Additional context
Affected values type definitions:
I would also like to apologize for the flood of issues in recent days 😬. Thank you for swift responses!