コード例 #1
0
ファイル: Details.cshtml.cs プロジェクト: nervosnetwork/tippy
        private static MockCellDep[] GetMockCellDep(Client client, CellDep cellDep)
        {
            TransactionWithStatus?txWithStatus = client.GetTransaction(cellDep.OutPoint.TxHash);

            if (txWithStatus == null)
            {
                throw new Exception($"Cannot find cell dep: {{ tx_hash: {cellDep.OutPoint.TxHash}, index: {cellDep.OutPoint.Index} }}!");
            }
            int index = (int)TypesConvert.HexToUInt32(cellDep.OutPoint.Index);

            string data   = txWithStatus.Transaction.OutputsData[index];
            Output output = txWithStatus.Transaction.Outputs[index];

            List <MockCellDep> mockCellDeps = new();

            mockCellDeps.Add(new MockCellDep()
            {
                CellDep = cellDep,
                Output  = output,
                Data    = data,
            });

            if (cellDep.DepType == "dep_group")
            {
                CellDep[] cellDeps = UnpackDepGroup(data);
                foreach (CellDep dep in cellDeps)
                {
                    mockCellDeps.AddRange(GetMockCellDep(client, dep));
                }
            }

            return(mockCellDeps.ToArray());
        }
コード例 #2
0
ファイル: Details.cshtml.cs プロジェクト: nervosnetwork/tippy
        private static OutPoint DeserializeOutPoint(byte[] bytes)
        {
            byte[] txHashBytes = bytes.Take(32).ToArray();
            int    index       = (int)BitConverter.ToUInt32(bytes.Skip(32).Take(4).ToArray());

            OutPoint outPoint = new()
            {
                TxHash = TypesConvert.BytesToHexString(txHashBytes),
                Index  = TypesConvert.Int32ToHex(index),
            };

            return(outPoint);
        }
コード例 #3
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());
        }
コード例 #4
0
ファイル: Details.cshtml.cs プロジェクト: nervosnetwork/tippy
        private static MockInput GetMockInput(Client client, Input input)
        {
            TransactionWithStatus?txWithStatus = client.GetTransaction(input.PreviousOutput.TxHash);

            if (txWithStatus == null)
            {
                throw new Exception("Cannot find input cell");
            }
            int index = (int)TypesConvert.HexToUInt32(input.PreviousOutput.Index);

            MockInput mockInput = new MockInput
            {
                Input  = input,
                Output = txWithStatus.Transaction.Outputs[index],
                Data   = txWithStatus.Transaction.OutputsData[index],
            };

            return(mockInput);
        }
コード例 #5
0
ファイル: Details.cshtml.cs プロジェクト: nervosnetwork/tippy
        public async Task <IActionResult> OnGet(string?txHash, string?ioType, int?ioIndex, int?scriptType, string?filePath, int?txId = null)
        {
            if (ioType != "input" && ioType != "output")
            {
                throw new Exception("ioType must be `input` or `output`!");
            }
            if (ioIndex == null)
            {
                throw new Exception("ioIndex cannot be null!");
            }
            if (scriptType == null)
            {
                throw new Exception("scriptType cannot be null!");
            }
            if (txId == null && (txHash == null || txHash == ""))
            {
                throw new Exception("txId and txHash cannot be all null!");
            }

            Client client = Rpc();

            Transaction transaction;

            if (txId != null)
            {
                RecordedTransaction?failedTransaction = await DbContext.RecordedTransactions.FirstOrDefaultAsync(t => t.Id == txId);

                if (failedTransaction == null)
                {
                    throw new Exception($"Failed transaction not found, check your txID: {txId}");
                }
                try
                {
                    transaction = Transaction.FromJson(failedTransaction.RawTransaction);
                }
                catch
                {
                    throw new Exception("Failed Transaction cannot parsed to Transaction!");
                }
            }
            else
            {
                TransactionWithStatus?txWithStatus = client.GetTransaction(txHash !);
                if (txWithStatus == null)
                {
                    throw new Exception($"Transaction not found: {txHash}");
                }
                transaction = txWithStatus.Transaction;
            }

            Output output = transaction.Outputs[(int)ioIndex];

            if (ioType == "input")
            {
                Input input = transaction.Inputs[(int)ioIndex];
                TransactionWithStatus originTx = client.GetTransaction(input.PreviousOutput.TxHash) !;
                output = originTx.Transaction.Outputs[TypesConvert.HexToUInt32(input.PreviousOutput.Index)];
            }
            if (scriptType == 1 && output.Type == null)
            {
                throw new Exception($"Type script not found in {{tx_hash: {txHash}, index: {ioIndex}, ioType: {ioType}}}");
            }

            Script          script     = scriptType == 0 ? output.Lock : output.Type;
            string          scriptHash = ComputeScriptHash(script);
            MockTransaction mockTx     = DumpTransaction(client, transaction);

            mockTx.Tx.Hash = null;

            string targetContractData = GetCellDepData(mockTx, script);

            string binaryFilePath = WriteToFile(scriptHash, targetContractData);

            string?binaryForDebugger = null;

            if (filePath != null)
            {
                binaryFilePath    = filePath;
                binaryForDebugger = filePath;
            }

            string mockTxFilePath = WriteMockTx(scriptHash, mockTx.ToJson());

            string scriptGroupType = scriptType == 0 ? "lock" : "type";

            try
            {
                DebuggerProcessManager.Start(ActiveProject !, scriptGroupType, scriptHash, mockTxFilePath, binaryFilePath, ioType, (int)ioIndex, binaryForDebugger);
            }
            catch (System.InvalidOperationException e)
            {
                TempData["ErrorMessage"] = e.Message;
            }

            return(Page());
        }
コード例 #6
0
ファイル: Details.cshtml.cs プロジェクト: nervosnetwork/tippy
 private static string ComputeDataHash(string data)
 {
     return(TypesConvert.BytesToHexString(Blake2bHasher.ComputeHash(TypesConvert.HexStringToBytes(data))));
 }
コード例 #7
0
ファイル: Details.cshtml.cs プロジェクト: nervosnetwork/tippy
 private static string ComputeScriptHash(Script script)
 {
     return(TypesConvert.BytesToHexString(Blake2bHasher.ComputeHash(new ScriptSerializer(script).Serialize())));
 }