Esempio n. 1
0
        public Response <IOperation[]> Read(string hex)
        {
            Response <IOperation[]> resp = new Response <IOperation[]>();

            if (!Base16.IsValid(hex))
            {
                resp.Errors.Add("Invalid base-16 string.");
            }
            else
            {
                byte[]     data   = Base16.ToByteArray(hex);
                int        offset = 0;
                CompactInt len    = new CompactInt(data.Length);
                data = len.ToByteArray().ConcatFast(data);

                Script scr = new Helper();
                if (scr.TryDeserialize(data, ref offset, out string error))
                {
                    resp.Result = scr.OperationList;
                }
                else
                {
                    resp.Errors.Add(error);
                }
            }

            return(resp);
        }
Esempio n. 2
0
        private void SetJson()
        {
            if (!Base16.IsValid(_rawTx))
            {
                TxJson = "Invalid hex.";
            }
            else
            {
                Transaction tx     = new Transaction();
                int         offset = 0;

                TxJson = tx.TryDeserialize(Base16.ToByteArray(_rawTx), ref offset, out string error)
                    ? JsonConvert.SerializeObject(tx, Formatting.Indented, jSetting)
                    : "Error while deserializing transaction:" + Environment.NewLine + error;
            }
        }
        public override bool SetOperations()
        {
            Errors = null;

            try
            {
                byte[] ba = new byte[0];
                if (!string.IsNullOrEmpty(Data))
                {
                    switch (SelectedEncoder)
                    {
                    case Encoders.UTF8:
                        ba = Encoding.UTF8.GetBytes(Data);
                        break;

                    case Encoders.Base16:
                        if (!Base16.IsValid(Data))
                        {
                            Errors = "Invalid base16 (hexadecimal) string.";
                            return(false);
                        }
                        else
                        {
                            ba = Base16.ToByteArray(Data);
                        }
                        break;

                    default:
                        Errors = "Undefined encoder.";
                        return(false);
                    }
                }

                ReturnOp op = new ReturnOp(ba, true);
                OpsToAdd = new IOperation[1] {
                    op
                };
            }
            catch (Exception ex)
            {
                Errors = $"An unexpected error happened. Message: {ex.Message}";
                return(false);
            }

            return(true);
        }
Esempio n. 4
0
 public void IsValid_FalseTest(string hex)
 {
     Assert.False(Base16.IsValid(hex));
 }
Esempio n. 5
0
 public void IsValidTest(string hex)
 {
     Assert.True(Base16.IsValid(hex));
 }