Example #1
0
        public static string ComputeHash(Script script)
        {
            var serializer = new ScriptSerializer(script);
            var hash       = Blake2bHasher.ComputeHash(serializer.Serialize());

            return(Util.Hex.BytesToHexString(hash));
        }
Example #2
0
        public void TestWithInputs()
        {
            var tx = new Transaction
            {
                Version  = "0x0",
                CellDeps = new CellDep[]
                {
                    new CellDep
                    {
                        OutPoint = new OutPoint
                        {
                            TxHash = "0x29f94532fb6c7a17f13bcde5adb6e2921776ee6f357adf645e5393bd13442141",
                            Index  = "0x0",
                        },
                        DepType = "code"
                    }
                },
                HeaderDeps = new string[]
                {
                    "0x8033e126475d197f2366bbc2f30b907d15af85c9d9533253c6f0787dcbbb509e"
                },
                Inputs = new Input[]
                {
                    new Input
                    {
                        PreviousOutput = new OutPoint
                        {
                            TxHash = "0x5ba156200c6310bf140fbbd3bfe7e8f03d4d5f82b612c1a8ec2501826eaabc17",
                            Index  = "0x0"
                        },
                        Since = "0x0",
                    }
                },
                Outputs = new Output[]
                {
                    new Output
                    {
                        Capacity = "0x" + 100000000000.ToString("x"),
                        Lock     = new Script
                        {
                            CodeHash = "0x28e83a1277d48add8e72fadaa9248559e1b632bab2bd60b27955ebc4c03800a5",
                            HashType = "data",
                            Args     = "0x",
                        }
                    }
                },
                OutputsData = new string[] { "0x" },
            };

            var expected = "0x6f6b16079884d8127490aac5e0f87274e81f15ea1fd6c9672a5b0326bd8ce76d";

            Assert.Equal(RawTransactionSerializer.HexStringToBytes(expected), Blake2bHasher.ComputeHash(new RawTransactionSerializer(tx).Serialize()));
        }
Example #3
0
        public void TestSerializer()
        {
            var tx = new Transaction
            {
                Version  = "0x0",
                CellDeps = new CellDep[]
                {
                    new CellDep
                    {
                        OutPoint = new OutPoint
                        {
                            TxHash = "0xbffab7ee0a050e2cb882de066d3dbf3afdd8932d6a26eda44f06e4b23f0f4b5a",
                            Index  = "0x0",
                        },
                        DepType = "code",
                    }
                },
                HeaderDeps = Array.Empty <string>(),
                Inputs     = Array.Empty <Input>(),
                Outputs    = new Output[]
                {
                    new Output
                    {
                        Capacity = "0x" + 100000000000.ToString("x"),
                        Lock     = new Script
                        {
                            CodeHash = "0x9e3b3557f11b2b3532ce352bfe8017e9fd11d154c4c7f9b7aaaa1e621b539a08",
                            HashType = "data",
                            Args     = "0xe2193df51d78411601796b35b17b4f8f2cd85bd0",
                        }
                    },
                    new Output
                    {
                        Capacity = "0x" + 4900000000000.ToString("x"),
                        Lock     = new Script
                        {
                            CodeHash = "0x9e3b3557f11b2b3532ce352bfe8017e9fd11d154c4c7f9b7aaaa1e621b539a08",
                            HashType = "data",
                            Args     = "0x36c329ed630d6ce750712a477543672adab57f4c",
                        }
                    }
                },
                OutputsData = new string[] { "0x", "0x" },
                Witnesses   = new string[] { "0x" },
            };

            var expected = "0x4c02905db773301f73bbc6cd5a400c928caf410bbb13136f6f48bec0a79c22e4";

            Assert.Equal(TransactionSerializer.HexStringToBytes(expected), Blake2bHasher.ComputeHash(new RawTransactionSerializer(tx).Serialize()));
        }
Example #4
0
 private static string ComputeDataHash(string data)
 {
     return(TypesConvert.BytesToHexString(Blake2bHasher.ComputeHash(TypesConvert.HexStringToBytes(data))));
 }
Example #5
0
 private static string ComputeScriptHash(Script script)
 {
     return(TypesConvert.BytesToHexString(Blake2bHasher.ComputeHash(new ScriptSerializer(script).Serialize())));
 }