Ejemplo n.º 1
0
        private static Transaction FromRawDataStream(MemoryStream stream)
        {
            using (var reader = new NearBinaryReader(stream, true))
            {
                var signerId   = reader.ReadString();
                var publicKey  = PublicKey.FromStream(ref stream);
                var nonce      = reader.ReadULong();
                var receiverId = reader.ReadString();
                var blockHash  = new ByteArray32()
                {
                    Buffer = reader.ReadBytes(32)
                };
                var actionsCount = reader.ReadUInt();
                var actions      = new List <Action>();

                for (var i = 0; i < actionsCount; i++)
                {
                    actions.Add(Action.FromStream(ref stream));
                }

                return(new Transaction()
                {
                    SignerId = signerId,
                    PublicKey = publicKey,
                    Nonce = nonce,
                    ReceiverId = receiverId,
                    BlockHash = blockHash,
                    Actions = actions.ToArray()
                });
            }
        }
Ejemplo n.º 2
0
        private static FunctionCallPermission FromRawDataStream(MemoryStream stream)
        {
            using (var reader = new NearBinaryReader(stream, true))
            {
                UInt128?allowance = null;

                var allowanceFlag = reader.ReadByte();

                if ((int)allowanceFlag == 1)
                {
                    allowance = reader.ReadUInt128();
                }

                var receiverId = reader.ReadString();

                var methodNamesCount = reader.ReadUInt();

                var methodNames = new List <string>();

                for (var i = 0; i < methodNamesCount; i++)
                {
                    methodNames.Add(reader.ReadString());
                }

                return(new FunctionCallPermission()
                {
                    Allowance = allowance,
                    ReceiverId = receiverId,
                    MethodNames = methodNames.ToArray()
                });
            }
        }
Ejemplo n.º 3
0
 private static FullAccessPermission FromRawDataStream(MemoryStream stream)
 {
     using (var reader = new NearBinaryReader(stream, true))
     {
         return(new FullAccessPermission());
     }
 }
Ejemplo n.º 4
0
        private static AccessKeyPermission FromRawDataStream(MemoryStream stream)
        {
            using (var reader = new NearBinaryReader(stream, true))
            {
                var permissionType = (AccessKeyPermissionType)reader.ReadByte();

                switch (permissionType)
                {
                case AccessKeyPermissionType.FullAccessPermission:
                {
                    var fullAccess = FullAccessPermission.FromStream(ref stream);

                    return(new AccessKeyPermission()
                        {
                            PermissionType = permissionType,
                            FullAccess = fullAccess,
                        });
                }

                case AccessKeyPermissionType.FunctionCallPermission:
                {
                    var functionCall = FunctionCallPermission.FromStream(ref stream);

                    return(new AccessKeyPermission()
                        {
                            PermissionType = permissionType,
                            FunctionCall = functionCall,
                        });
                }

                default:
                    throw new NotSupportedException("Unsupported access key permission type");
                }
            }
        }
Ejemplo n.º 5
0
        private static NearSignature FromRawDataStream(MemoryStream stream)
        {
            using (var reader = new NearBinaryReader(stream, true))
            {
                KeyType keyType;
                switch ((int)reader.ReadByte())
                {
                case 0:
                {
                    keyType = KeyType.Ed25519;
                    break;
                }

                default:
                {
                    throw new NotSupportedException("Invalid key type in raw bytes for public key");
                }
                }

                var data = new ByteArray64
                {
                    Buffer = reader.ReadBytes(64)
                };

                return(new NearSignature(keyType, data));
            }
        }
Ejemplo n.º 6
0
        private static AccessKey FromRawDataStream(MemoryStream stream)
        {
            using (var reader = new NearBinaryReader(stream, true))
            {
                var nonce      = reader.ReadULong();
                var permission = AccessKeyPermission.FromStream(ref stream);

                return(new AccessKey()
                {
                    Nonce = nonce,
                    Permission = permission
                });
            }
        }
Ejemplo n.º 7
0
        private static SignedTransaction FromRawDataStream(MemoryStream stream)
        {
            using (var reader = new NearBinaryReader(stream, true))
            {
                var transaction = Transaction.FromStream(ref stream);
                var signature   = NearSignature.FromStream(ref stream);

                return(new SignedTransaction()
                {
                    Transaction = transaction,
                    Signature = signature,
                });
            }
        }
Ejemplo n.º 8
0
        private static Action FromRawDataStream(MemoryStream stream)
        {
            using (var reader = new NearBinaryReader(stream, true))
            {
                var actionType = (ActionType)reader.ReadByte();

                switch (actionType)
                {
                case ActionType.AddKey:
                {
                    dynamic args = new ExpandoObject();
                    args.PublicKey = PublicKey.FromStream(ref stream);
                    args.AccessKey = AccessKey.FromStream(ref stream);
                    return(new Action(ActionType.AddKey, args));
                }

                case ActionType.DeleteKey:
                {
                    dynamic args = new ExpandoObject();
                    args.PublicKey = PublicKey.FromStream(ref stream);
                    return(new Action(ActionType.DeleteKey, args));
                }

                case ActionType.CreateAccount:
                {
                    return(new Action(ActionType.CreateAccount, null));
                }

                case ActionType.DeleteAccount:
                {
                    dynamic args = new ExpandoObject();
                    args.BeneficiaryId = reader.ReadString();
                    return(new Action(ActionType.DeleteAccount, args));
                }

                case ActionType.DeployContract:
                {
                    dynamic args = new ExpandoObject();

                    var byteCount = reader.ReadUInt();

                    var code = new List <byte>();

                    for (var i = 0; i < byteCount; i++)
                    {
                        code.Add(reader.ReadByte());
                    }

                    args.Code = code.ToArray();
                    return(new Action(ActionType.DeployContract, args));
                }

                case ActionType.FunctionCall:
                {
                    dynamic args = new ExpandoObject();

                    var methodName = reader.ReadString();

                    var methodArgsCount = reader.ReadUInt();

                    var methodArgs = new List <byte>();

                    for (var i = 0; i < methodArgsCount; i++)
                    {
                        methodArgs.Add(reader.ReadByte());
                    }

                    var gas = reader.ReadULong();

                    var deposit = reader.ReadUInt128();

                    args.MethodName = methodName;
                    args.MethodArgs = methodArgs.ToArray();
                    args.Gas        = gas;
                    args.Deposit    = deposit;

                    return(new Action(ActionType.FunctionCall, args));
                }

                case ActionType.Stake:
                {
                    dynamic args = new ExpandoObject();

                    var stake = reader.ReadUInt128();

                    var publicKey = PublicKey.FromStream(ref stream);

                    args.Stake     = stake;
                    args.PublicKey = publicKey;

                    return(new Action(ActionType.Stake, args));
                }

                case ActionType.Transfer:
                {
                    dynamic args = new ExpandoObject();

                    var deposit = reader.ReadUInt128();

                    args.Deposit = deposit;

                    return(new Action(ActionType.Transfer, args));
                }

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