Length check in for extrinsic/call detect (#8703)

* Length check in for extrinsic/call detect

* s/lenght/length/

* Sprinkle in comments
This commit is contained in:
Jaco 2023-01-06 08:16:14 +02:00 committed by GitHub
parent 1745de889d
commit 9c4cbfcd67
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -60,12 +60,21 @@ function Decoder ({ className, defaultValue, setLast }: Props): React.ReactEleme
let isCall = true;
try {
// cater for an extrinsic input...
decoded = api.tx(hex);
// cater for an extrinsic input
const tx = api.tx(hex);
// ensure that the full data matches here
assert(tx.toHex() === hex, 'Cannot decode data as extrinsic, length mismatch');
decoded = tx;
extrinsicCall = api.createType('Call', decoded.method);
isCall = false;
} catch (e) {
// attempt to decode as Call
extrinsicCall = api.createType('Call', hex);
// ensure we used all bytes (as we did above)
assert(extrinsicCall.toHex() === hex, 'Unable to decode data as Call, length mismatch in supplied data');
}
const { method, section } = api.registry.findMetaCall(extrinsicCall.callIndex);