polkadot-js / api

Promise and RxJS APIs around Polkadot and Substrate based chains via RPC calls. It is dynamically generated based on what the Substrate runtime provides in terms of metadata.
Apache License 2.0
1.07k stars 350 forks source link

Scale encoding with polkadot.js createType converts keys to smallcases. #4790

Closed nuel77 closed 2 years ago

nuel77 commented 2 years ago

I have noticed that types created with createType smallcases the key values , is there a way to keep the case information.

for example

const sig= api.create("Multisignature", signature)
consoe.log(sig.toJSON())

will give me

{
  sr25519: '0xd86be68bb3b43b4e67115eb9c64e1c40680d5a139fb2534a128c95ad1a47b93fb214d02a95ac46d38b5cb0a6eb4af4d7e3f6dee473d71fc48a82fcb0db5c6d88'
}

But the rust types have a capital 'S' as in Sr25519, is there a way to keep the case information, apart from creating the json manually?

jacogr commented 2 years ago

The toJSON is meant to be used in the RPC to communicate with Substrate, so it always conforms to the way the JSON RPC is laid out. In all cases, the Substrate has the camelCase serde attribute for JSONRPC formatting, see e.g. https://github.com/paritytech/substrate/blob/fa778cc1187e37bbab132293ddbbb20158139ea5/primitives/runtime/src/generic/block.rs#L40 & https://github.com/paritytech/substrate/blob/fa778cc1187e37bbab132293ddbbb20158139ea5/primitives/runtime/src/generic/block.rs#L86

So in all cases, fields (via toJSON) is always serialized with camelCase. This also applies to all methods exposed by the runtime, e.g. set_code becomes setCode on api.tx.system.*. (In this case it is not due to the JSONRPC formats, but rather since in the JS world, camelCase it more wide-spread)

There is no override flag for this.

polkadot-js-bot commented 2 years ago

This issue has been open for 21 days with no activity and is not labelled as an enhancement. It will be closed in 7 days.

polkadot-js-bot commented 2 years ago

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue if you think you have a related problem or query.