I know that the payload and extrinsics are dynamic, and even different between parachains/base chains(kusama,polkadot,rococo,westend). But I am struggling to find good documentation on how these payloads/extrinsics are constrcuted from the metadata. I am trying to get a C# code working with the RPC, basing it on the Ajuna.NetApi, but I have so far only managed to write a simple method call.
Now I am trying to write a transaction call, and I am getting "Invalid signature" error. I am very convinced that I have something wrong/missing from my payload generation code. This is the code for the payload construction:
public byte[] Encode()
{
var bytes = new List<byte>();
SignedExtensionMetadataStruct[] extensions = Globals.LatestMetadata.RuntimeMetadataData.Extrinsic.SignedExtensions.Value;
if (extensions.Any(e => e.SignedIdentifier.Value == "CheckMortality"))
bytes.AddRange(_mortality.Encode());
if (extensions.Any(e => e.SignedIdentifier.Value == "CheckNonce"))
bytes.AddRange(_nonce.Encode());
if (extensions.Any(e => e.SignedIdentifier.Value == "ChargeTransactionPayment"))
bytes.AddRange(_assetTxPayment.Encode());
if (extensions.Any(e => e.SignedIdentifier.Value == "CheckSpecVersion"))
bytes.AddRange(Utils.Value2Bytes(_specVersion));
if (extensions.Any(e => e.SignedIdentifier.Value == "CheckTxVersion"))
bytes.AddRange(Utils.Value2Bytes(_txVersion));
if (extensions.Any(e => e.SignedIdentifier.Value == "CheckGenesis"))
bytes.AddRange(_genesis.Encode());
if (extensions.Any(e => e.SignedIdentifier.Value == "CheckGenesis"))
bytes.AddRange(_genesis.Bytes);
// CheckMortality, Additional Blockhash check. Immortal = genesis_hash, Mortal = logic
if (extensions.Any(e => e.SignedIdentifier.Value == "CheckMortality"))
bytes.AddRange(_startEra.Bytes);
return bytes.ToArray();
}
Is there a good example/documentation on the payload/extrinsic construction other than the text on the wiki page (which is good but barely scratched the issue of reading the metadata and constructing the payload from it) ?
Im also a bit confused as in what order these parameters should be included in the payload.