Ejemplo n.º 1
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.º 2
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.º 3
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");
                }
            }
        }