Ejemplo n.º 1
0
        void UpdateBranchData(ErrorHandle handle, TreeHandle treeHandle)
        {
            if (handle is null)
            {
                throw new ArgumentNullException(nameof(handle));
            }
            if (treeHandle is null)
            {
                throw new ArgumentNullException(nameof(treeHandle));
            }

            var ret = NativeMethods.CfdGetTaprootScriptTreeSrting(handle.GetHandle(),
                                                                  treeHandle.GetHandle(), out IntPtr treeString);

            if (ret != CfdErrorCode.Success)
            {
                handle.ThrowError(ret);
            }
            this.treeString = CCommon.ConvertToString(treeString);
            if (branches.Length != 0)
            {
                var index = branches.Length - 1;
                ret = NativeMethods.CfdGetTapBranchData(handle.GetHandle(),
                                                        treeHandle.GetHandle(), (byte)index, true, out IntPtr branchHash,
                                                        out _, out IntPtr tempScript, out byte _);
                if (ret != CfdErrorCode.Success)
                {
                    handle.ThrowError(ret);
                }
                CCommon.ConvertToString(tempScript);
                topHash = new ByteData256(CCommon.ConvertToString(branchHash));
            }
            else if (topHash.IsEmpty())
            {
                ret = NativeMethods.CfdGetBaseTapLeaf(handle.GetHandle(),
                                                      treeHandle.GetHandle(), out byte _,
                                                      out IntPtr tapscript, out IntPtr tapLeafHash);
                if (ret != CfdErrorCode.Success)
                {
                    handle.ThrowError(ret);
                }
                CCommon.ConvertToString(tapscript);
                string tapLeafHashStr = CCommon.ConvertToString(tapLeafHash);
                topHash = new ByteData256(tapLeafHashStr);
            }
        }