Esempio n. 1
0
        public byte[] ToByteArray()
        {
            using (var ms = new MemoryStream())
            {
                using (var writer = new NearBinaryWriter(ms))
                {
                    switch (PermissionType)
                    {
                    case AccessKeyPermissionType.FullAccessPermission:
                    {
                        writer.Write((byte)AccessKeyPermissionType.FullAccessPermission);
                        writer.Write(FullAccess.ToByteArray());
                        return(ms.ToArray());
                    }

                    case AccessKeyPermissionType.FunctionCallPermission:
                    {
                        writer.Write((byte)AccessKeyPermissionType.FunctionCallPermission);
                        writer.Write(FunctionCall.ToByteArray());
                        return(ms.ToArray());
                    }

                    default:
                        throw new NotSupportedException("Unsupported access key permission type");
                    }
                }
            }
        }
Esempio n. 2
0
 public byte[] ToByteArray()
 {
     using (var ms = new MemoryStream())
     {
         using (var writer = new NearBinaryWriter(ms))
         {
             writer.Write(Nonce);
             writer.Write(Permission.ToByteArray());
             return(ms.ToArray());
         }
     }
 }
Esempio n. 3
0
 public byte[] ToByteArray()
 {
     using (var ms = new MemoryStream())
     {
         using (var writer = new NearBinaryWriter(ms))
         {
             writer.Write(Transaction.ToByteArray());
             writer.Write(Signature.ToByteArray());
             return(ms.ToArray());
         }
     }
 }
Esempio n. 4
0
 public byte[] ToByteArray()
 {
     using (var ms = new MemoryStream())
     {
         using (var writer = new NearBinaryWriter(ms))
         {
             writer.Write((byte)_keyType);
             writer.Write(_data.Buffer);
             return(ms.ToArray());
         }
     }
 }
Esempio n. 5
0
        public byte[] ToByteArray()
        {
            using (var ms = new MemoryStream())
            {
                using (var writer = new NearBinaryWriter(ms))
                {
                    if (Allowance == null)
                    {
                        writer.Write((byte)0);
                    }
                    else
                    {
                        writer.Write((byte)1);
                        writer.Write((UInt128)Allowance);
                    }

                    writer.Write(ReceiverId);

                    writer.Write((uint)MethodNames.Length);

                    foreach (var mn in MethodNames)
                    {
                        writer.Write(mn);
                    }

                    return(ms.ToArray());
                }
            }
        }
Esempio n. 6
0
        public byte[] ToByteArray()
        {
            using (var ms = new MemoryStream())
            {
                using (var writer = new NearBinaryWriter(ms))
                {
                    writer.Write(SignerId);
                    writer.Write(PublicKey.ToByteArray());
                    writer.Write(Nonce);
                    writer.Write(ReceiverId);
                    writer.Write(BlockHash.Buffer);

                    writer.Write((uint)Actions.Length);
                    foreach (var action in Actions)
                    {
                        writer.Write(action.ToByteArray());
                    }

                    return(ms.ToArray());
                }
            }
        }
Esempio n. 7
0
        public byte[] ToByteArray()
        {
            using (var ms = new MemoryStream())
            {
                using (var writer = new NearBinaryWriter(ms))
                {
                    writer.Write((byte)_type);

                    switch (_type)
                    {
                    case ActionType.AddKey:
                    {
                        writer.Write(_args.PublicKey.ToByteArray());
                        writer.Write(_args.AccessKey.ToByteArray());
                        return(ms.ToArray());
                    }

                    case ActionType.DeleteKey:
                    {
                        writer.Write(_args.PublicKey.ToByteArray());
                        return(ms.ToArray());
                    }

                    case ActionType.CreateAccount:
                    {
                        return(ms.ToArray());
                    }

                    case ActionType.DeleteAccount:
                    {
                        writer.Write((string)_args.BeneficiaryId);
                        return(ms.ToArray());
                    }

                    case ActionType.DeployContract:
                    {
                        writer.Write((uint)_args.Code.Length);
                        writer.Write((byte[])_args.Code);
                        return(ms.ToArray());
                    }

                    case ActionType.FunctionCall:
                    {
                        writer.Write((string)_args.MethodName);
                        writer.Write((uint)_args.MethodArgs.Length);
                        writer.Write((byte[])_args.MethodArgs);
                        writer.Write((ulong)_args.Gas);
                        writer.Write((UInt128)_args.Deposit);
                        return(ms.ToArray());
                    }

                    case ActionType.Stake:
                    {
                        writer.Write((UInt128)_args.Stake);
                        writer.Write(_args.PublicKey.ToByteArray());
                        return(ms.ToArray());
                    }

                    case ActionType.Transfer:
                    {
                        writer.Write((UInt128)_args.Deposit);
                        return(ms.ToArray());
                    }

                    default:
                        throw new NotSupportedException("Unsupported action type");
                    }
                }
            }
        }