-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for the
CheckMetadataHash
signed extension (#85)
* add check-metadata-hash-signed-ext * fix unit tests * fix some warnings * Fix extrinsic tests * cleanup `CheckMetadataHash` * Fix: initialize `CheckMetadataHash` in Extrinsic constructor
- Loading branch information
Showing
7 changed files
with
109 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
using Substrate.NetApi.Model.Types.Base; | ||
using System; | ||
|
||
namespace Substrate.NetApi.Model.Extrinsics | ||
{ | ||
|
||
/// <summary> | ||
/// If the runtime should expect a metadata hash that has been signed in the additional signed. | ||
/// </summary> | ||
public enum Mode | ||
{ | ||
/// <summary> | ||
/// `None` has been signed in the CheckMetadataHash additional signed. | ||
/// </summary> | ||
Disabled, | ||
/// <summary> | ||
/// `Some(MetadataHash)` has been signed in the CheckMetadataHash additional signed. | ||
/// </summary> | ||
Enabled | ||
} | ||
/// <summary> | ||
/// CheckMetadataHash signed extension. | ||
/// </summary> | ||
public class CheckMetadataHash: BaseType | ||
{ | ||
private Mode _mode; | ||
|
||
/// <summary> | ||
/// Initialize with `Mode.Disabled`. | ||
/// </summary> | ||
public CheckMetadataHash() { | ||
// Don't allow enabling the mode, as we don't support it. | ||
_mode = Mode.Disabled; | ||
} | ||
|
||
/// <summary> | ||
/// Corresponds to the `Extra` that is sent with the extrinsic. | ||
/// </summary> | ||
/// <returns></returns> | ||
public override byte[] Encode() | ||
{ | ||
return EncodeExtra(); | ||
} | ||
|
||
/// <summary> | ||
/// Corresponds to the extra that _is_ sent with the extrinsic. | ||
/// </summary> | ||
/// <returns></returns> | ||
public byte[] EncodeExtra() | ||
{ | ||
return new BaseEnum<Mode>(_mode).Encode(); | ||
} | ||
|
||
/// <summary> | ||
/// Corresponds to the `Additional` that is signed, but _not_ sent with the extrinsic. | ||
/// </summary> | ||
/// <returns></returns> | ||
public byte[] EncodeAdditional() | ||
{ | ||
// We provide no metadata hash in the signer payload to align with the above. | ||
return new byte[1]; | ||
} | ||
|
||
/// <inheritdoc /> | ||
public override void Decode(byte[] byteArray, ref int p) | ||
{ | ||
uint modeByte = byteArray[p++]; | ||
|
||
if (modeByte > 1) { | ||
throw new ArgumentException($"{modeByte} is not a valid representation of CheckMetadata Mode."); | ||
} | ||
|
||
_mode = modeByte == 0 ? Mode.Disabled : Mode.Enabled; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters