コード例 #1
0
        public static Script Parse(string witness)
        {
            byte[] witnessSerialization = Convert.HexStringToBytes(witness);

            byte[] s = witnessSerialization.Skip(4).Take(4).ToArray();

            UInt32 scriptOffset = Convert.LEBytesToUInt32(s);

            UInt32 messageOffset = Convert.LEBytesToUInt32(
                witnessSerialization.Skip(8).Take(4).ToArray()
                );

            byte[] scriptSerialization = witnessSerialization
                                         .Skip((int)scriptOffset)
                                         .Take((int)(messageOffset - scriptOffset))
                                         .ToArray();
            UInt32 codeHashOffset = Convert.LEBytesToUInt32(
                scriptSerialization.Skip(4).Take(4).ToArray()
                );
            UInt32 hashTypeOffset = Convert.LEBytesToUInt32(
                scriptSerialization.Skip(8).Take(4).ToArray()
                );
            UInt32 argsOffset = Convert.LEBytesToUInt32(
                scriptSerialization.Skip(12).Take(4).ToArray());

            byte[] codeHashSerialization = scriptSerialization
                                           .Skip((int)codeHashOffset)
                                           .Take((int)(hashTypeOffset - codeHashOffset))
                                           .ToArray();
            byte[] hashTypeSerialization = scriptSerialization
                                           .Skip((int)hashTypeOffset)
                                           .Take((int)(argsOffset - hashTypeOffset))
                                           .ToArray();
            byte[] argsSerialization = scriptSerialization
                                       .Skip((int)hashTypeOffset + 5)
                                       .ToArray();

            string codeHash = Convert.BytesToHexString(codeHashSerialization);
            string hashType = Convert.BytesToHexString(hashTypeSerialization) == "0x00" ? "data" : "type";
            string args     = Convert.BytesToHexString(argsSerialization);

            return(new Script()
            {
                CodeHash = codeHash,
                HashType = hashType,
                Args = args,
            });
        }
コード例 #2
0
ファイル: Details.cshtml.cs プロジェクト: nervosnetwork/tippy
        private static OutPoint[] DeserializeOutPointVec(string data)
        {
            byte[] bytes      = TypesConvert.HexStringToBytes(data);
            int    size       = (int)BitConverter.ToUInt32(bytes.Take(4).ToArray());
            int    totalSize  = bytes.Skip(4).ToArray().Length;
            int    singleSize = totalSize / size;

            List <OutPoint> outPoints = new();

            for (int i = 0; i < size; i++)
            {
                int      startAt       = i * singleSize + 4;
                byte[]   outPointBytes = bytes.Skip(startAt).Take(singleSize).ToArray();
                OutPoint outPoint      = DeserializeOutPoint(outPointBytes);
                outPoints.Add(outPoint);
            }

            return(outPoints.ToArray());
        }
コード例 #3
0
        // return shannon
        public ulong MinimalCellCapacity()
        {
            if (Data == null)
            {
                // throw new Exception("Data can't be null!");
                return(0);
            }
            int bytes = 8;

            bytes += Convert.HexStringToBytes(Lock.CodeHash).Length;
            bytes += Convert.HexStringToBytes(Lock.Args).Length;
            // hash_type field
            bytes += 1;

            if (Type != null)
            {
                bytes += Convert.HexStringToBytes(Type.CodeHash).Length;
                bytes += Convert.HexStringToBytes(Type.Args).Length;
                // hash_type
                bytes += 1;
            }
            bytes += Convert.HexStringToBytes(Data).Length;
            return((ulong)bytes * (ulong)100000000);
        }
コード例 #4
0
ファイル: Details.cshtml.cs プロジェクト: nervosnetwork/tippy
 private static string ComputeDataHash(string data)
 {
     return(TypesConvert.BytesToHexString(Blake2bHasher.ComputeHash(TypesConvert.HexStringToBytes(data))));
 }