diff --git a/packages/polkadart/lib/extrinsic/extrinsic_payload.dart b/packages/polkadart/lib/extrinsic/extrinsic_payload.dart index 4be01f1d..310f0bb2 100644 --- a/packages/polkadart/lib/extrinsic/extrinsic_payload.dart +++ b/packages/polkadart/lib/extrinsic/extrinsic_payload.dart @@ -30,7 +30,7 @@ class Extrinsic { this.assetId, }); - toEncodedMap() { + toEncodedMap(dynamic registry) { return { 'signer': signer, 'method': method, @@ -39,7 +39,7 @@ class Extrinsic { ? '00' : Era.codec.encodeMortal(blockNumber, eraPeriod), 'nonce': encodeHex(CompactCodec.codec.encode(nonce)), - 'assetId': assetId != null ? assetId!.toRadixString(16) : '', + 'assetId': maybeAssetIdEncoded(registry), 'tip': tip is int ? encodeHex(CompactCodec.codec.encode(tip)) : encodeHex(CompactBigIntCodec.codec.encode(tip)), @@ -68,15 +68,18 @@ class Extrinsic { final List extras = []; late final SignedExtensions signedExtensions; - if (assetId != null) { + + if (_usesChargeAssetTxPayment(registry)) { signedExtensions = SignedExtensions.assetHubSignedExtensions; } else { signedExtensions = SignedExtensions.substrateSignedExtensions; } for (final signedExtensiontype in registry.getSignedExtensionTypes()) { - final payload = - signedExtensions.signedExtension(signedExtensiontype, toEncodedMap()); + final payload = signedExtensions.signedExtension( + signedExtensiontype, + toEncodedMap(registry), + ); if (payload.isNotEmpty) { extras.add(payload); @@ -108,4 +111,16 @@ class Extrinsic { dynamic registry, SignatureType signatureType, keyring.KeyPair keyPair) { return keyPair.sign(encode(registry, signatureType)); } + + bool _usesChargeAssetTxPayment(dynamic registry) { + return registry.getSignedExtensionTypes().contains('ChargeAssetTxPayment'); + } + + String maybeAssetIdEncoded(dynamic registry) { + if (_usesChargeAssetTxPayment(registry)) { + return assetId != null ? assetId!.toRadixString(16) : '00'; + } else { + return ''; + } + } } diff --git a/packages/polkadart/lib/extrinsic/signing_payload.dart b/packages/polkadart/lib/extrinsic/signing_payload.dart index 342b6760..3859bb2c 100644 --- a/packages/polkadart/lib/extrinsic/signing_payload.dart +++ b/packages/polkadart/lib/extrinsic/signing_payload.dart @@ -30,7 +30,7 @@ class SigningPayload { this.assetId, }); - toEncodedMap() { + toEncodedMap(dynamic registry) { return { 'method': method, 'specVersion': encodeHex(U32Codec.codec.encode(specVersion)), @@ -42,7 +42,7 @@ class SigningPayload { ? '00' : Era.codec.encodeMortal(blockNumber, eraPeriod), 'nonce': encodeHex(CompactCodec.codec.encode(nonce)), - 'assetId': assetId != null ? assetId!.toRadixString(16) : '', + 'assetId': maybeAssetIdEncoded(registry), 'tip': tip is int ? encodeHex(CompactCodec.codec.encode(tip)) : encodeHex(CompactBigIntCodec.codec.encode(tip)), @@ -58,7 +58,7 @@ class SigningPayload { final List additionalExtras = []; late final SignedExtensions signedExtensions; - if (assetId != null) { + if (_usesChargeAssetTxPayment(registry)) { signedExtensions = SignedExtensions.assetHubSignedExtensions; } else { signedExtensions = SignedExtensions.substrateSignedExtensions; @@ -66,7 +66,7 @@ class SigningPayload { registry.getSignedExtensionTypes().forEach((extension) { final payload = - signedExtensions.signedExtension(extension, toEncodedMap()); + signedExtensions.signedExtension(extension, toEncodedMap(registry)); if (payload.isNotEmpty) { extras.add(payload); @@ -74,8 +74,10 @@ class SigningPayload { }); registry.getSignedExtensionExtra().forEach((extension) { - final payload = - signedExtensions.additionalSignedExtension(extension, toEncodedMap()); + final payload = signedExtensions.additionalSignedExtension( + extension, + toEncodedMap(registry), + ); if (payload.isNotEmpty) { additionalExtras.add(payload); @@ -88,4 +90,16 @@ class SigningPayload { return Uint8List.fromList(hex.decode(payload)); } + + bool _usesChargeAssetTxPayment(dynamic registry) { + return registry.getSignedExtensionTypes().contains('ChargeAssetTxPayment'); + } + + String maybeAssetIdEncoded(dynamic registry) { + if (_usesChargeAssetTxPayment(registry)) { + return assetId != null ? assetId!.toRadixString(16) : '00'; + } else { + return ''; + } + } }