Skip to content
This repository has been archived by the owner on Sep 30, 2021. It is now read-only.

Commit

Permalink
fix: Silence misleading error message when decoding signed tx (#343)
Browse files Browse the repository at this point in the history
* fix: Silence missleading error message when decoding signed tx

* Make tsconfig valid json

* Tidy up
  • Loading branch information
emostov committed Jan 10, 2021
1 parent 985fc46 commit 1c9166e
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 4 deletions.
33 changes: 29 additions & 4 deletions src/decode/decodeSigningPayload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
* @ignore
*/ /** */

import { createTypeUnsafe } from '@polkadot/types/create';
import { Call, ExtrinsicPayload } from '@polkadot/types/interfaces';

import {
createMetadata,
EXTRINSIC_VERSION,
Expand All @@ -27,10 +30,32 @@ export function decodeSigningPayload(

registry.setMetadata(createMetadata(registry, metadataRpc));

const payload = registry.createType('ExtrinsicPayload', signingPayload, {
version: EXTRINSIC_VERSION,
});
const methodCall = registry.createType('Call', payload.method);
// We use `createTypeUnsafe` here because it allows us to specify `withoutLog: true`,
// which silences an internal error message from polkadot-js. This is helpful in `decode`
// which takes in just a string. We determine if the string is a signing payload or a
// signed tx by first attempting to decode it as a signing payload with this function.
// If that fails we catch, knowing through process of elimination it should be a
// signed tx. `withoutLog: true` prevents an alarming error message from bubbling up
// to the user when we catch.
const payload: ExtrinsicPayload = createTypeUnsafe(
registry,
'ExtrinsicPayload',
[
signingPayload,
{
version: EXTRINSIC_VERSION,
},
],
{ withoutLog: true }
);
const methodCall: Call = createTypeUnsafe(
registry,
'Call',
[payload.method],
{
withoutLog: true,
}
);
const method = toTxMethod(registry, methodCall, toInt);

return {
Expand Down
1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"outDir": "lib",
"esModuleInterop": true,
"strict": true,
"skipDefaultLibCheck": true,
"resolveJsonModule": true
}
}
7 changes: 7 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1950,6 +1950,13 @@ dot-prop@>=5.1.1, dot-prop@^5.1.0:
dependencies:
is-obj "^2.0.0"

dot-prop@^6.0.1:
version "6.0.1"
resolved "https://registry.yarnpkg.com/dot-prop/-/dot-prop-6.0.1.tgz#fc26b3cf142b9e59b74dbd39ed66ce620c681083"
integrity sha512-tE7ztYzXHIeyvc7N+hR3oi7FIbf/NIjVP9hmAt3yMXzrQ072/fpjGLx2GxNxGxUl5V73MEqYzioOMoVhGMJ5cA==
dependencies:
is-obj "^2.0.0"

dotgitignore@^2.1.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/dotgitignore/-/dotgitignore-2.1.0.tgz#a4b15a4e4ef3cf383598aaf1dfa4a04bcc089b7b"
Expand Down

0 comments on commit 1c9166e

Please sign in to comment.