public byte[] Encode()
        {
            if (Signed && Signature == null)
            {
                throw new Exception("Missing payload signature for signed transaction.");
            }

            var list = new List <byte>();

            // 4 is the TRANSACTION_VERSION constant and it is 7 bits long, the highest bit 1 for signed transaction, 0 for unsigned.
            list.Add((byte)(Constants.EXTRINSIC_VERSION | (Signed ? 0x80 : 0)));

            // 32 bytes
            list.AddRange(Account.PublicKey);

            // key type ed = 00 and sr = FF
            list.Add(Account.KeyTypeByte);

            list.AddRange(Signature);

            list.AddRange(Era.Encode());

            list.AddRange(Nonce.Encode());

            list.AddRange(Tip.Encode());

            list.AddRange(Method.Encode());

            return(Utils.SizePrefixedByteArray(list));;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Encodes this instance.
        /// </summary>
        /// <returns></returns>
        /// <exception cref="Exception">Missing payload signature for signed transaction.</exception>
        public byte[] Encode()
        {
            if (Signed && Signature == null)
            {
                throw new Exception("Missing payload signature for signed transaction.");
            }

            var list = new List <byte>();

            // 4 is the TRANSACTION_VERSION constant and it is 7 bits long, the highest bit 1 for signed transaction, 0 for unsigned.
            list.Add((byte)(Constants.ExtrinsicVersion | (Signed ? 0x80 : 0)));

            // 32 bytes + prefix depending on address encoding in chain, see Constants.Address_version
            list.AddRange(Account.Encode());

            // key type ed = 00 and sr = FF
            list.Add(Account.KeyTypeByte);

            // add signature if exists
            if (Signature != null)
            {
                list.AddRange(Signature);
            }
            else
            {
            }

            list.AddRange(Era.Encode());

            list.AddRange(Nonce.Encode());

            list.AddRange(Tip.Encode());

            list.AddRange(Method.Encode());

            return(Utils.SizePrefixedByteArray(list));
        }