Пример #1
0
        internal static unsafe FFIResult create_peer_manager(
            IntPtr seed,
            UserConfig *userConfig,

            ChannelManagerHandle channelManagerHandle,
            InstallWatchTx installWatchTx,
            InstallWatchOutPoint installWatchOutPoint,
            WatchAllTxn watchAllTxn,
            GetChainUtxo getChainUtxo,
            FilterBlock filterBlock,
            ReEntered reEntered,

            Log log,

            IntPtr ourNodeSecret,
            out PeerManagerHandle handle,
            bool check = true
            ) =>
        MaybeCheck(_create_peer_manager(
                       seed,
                       userConfig,
                       channelManagerHandle,
                       ref installWatchTx,
                       ref installWatchOutPoint,
                       ref watchAllTxn,
                       ref getChainUtxo,
                       ref filterBlock,
                       ref reEntered,

                       ref log,
                       ourNodeSecret,
                       out handle),
                   check);
        internal static FFIResult create_many_channel_monitor(
            InstallWatchTx installWatchTx,
            InstallWatchOutPoint installWatchOutPoint,
            WatchAllTxn watchAllTxn,
            GetChainUtxo getChainUtxo,
            FilterBlock filterBlock,
            ReEntered reEntered,

            BroadcastTransaction broadcastTransaction,
            Log log,
            GetEstSatPer1000Weight getEstSatPer1000Weight,
            out ManyChannelMonitorHandle handle,
            bool check = true
            ) =>
        MaybeCheck(_create_many_channel_monitor(
                       ref installWatchTx,
                       ref installWatchOutPoint,
                       ref watchAllTxn,
                       ref getChainUtxo,
                       ref filterBlock,
                       ref reEntered,
                       ref broadcastTransaction,
                       ref log,
                       ref getEstSatPer1000Weight,
                       out handle
                       ), check);
 static extern FFIResult _create_block_notifier(
     ref InstallWatchTx installWatchTx,
     ref InstallWatchOutPoint installWatchOutPoint,
     ref WatchAllTxn watchAllTxn,
     ref GetChainUtxo getChainUtxo,
     ref FilterBlock filterBlock,
     ref ReEntered reEntered,
     out BlockNotifierHandle handle
     );
 internal static FFIResult create_block_notifier(
     InstallWatchTx installWatchTx,
     InstallWatchOutPoint installWatchOutPoint,
     WatchAllTxn watchAllTxn,
     GetChainUtxo getChainUtxo,
     FilterBlock filterBlock,
     ReEntered reEntered,
     out BlockNotifierHandle handle,
     bool check = true
     ) => MaybeCheck(_create_block_notifier(ref installWatchTx, ref installWatchOutPoint, ref watchAllTxn, ref getChainUtxo, ref filterBlock, ref reEntered, out handle), check);
        private static extern FFIResult _create_many_channel_monitor(
            ref InstallWatchTx installWatchTx,
            ref InstallWatchOutPoint installWatchOutPoint,
            ref WatchAllTxn watchAllTxn,
            ref GetChainUtxo getChainUtxo,
            ref FilterBlock filterBlock,
            ref ReEntered reEntered,

            ref BroadcastTransaction broadcastTransaction,
            ref Log log,
            ref GetEstSatPer1000Weight getEstSatPer1000Weight,
            out ManyChannelMonitorHandle handle
            );
Пример #6
0
        private static extern unsafe FFIResult _create_peer_manager(
            IntPtr seedPtr,
            UserConfig *userConfig,

            ChannelManagerHandle channelManagerHandle,
            ref InstallWatchTx installWatchTx,
            ref InstallWatchOutPoint installWatchOutPoint,
            ref WatchAllTxn watchAllTxn,
            ref GetChainUtxo getChainUtxo,
            ref FilterBlock filterBlock,
            ref ReEntered reEntered,

            ref Log log,

            IntPtr ourNodeSecret,
            out PeerManagerHandle handle
            );
        private static extern FFIResult _deserialize_many_channel_monitor(
            IntPtr bufPtr,
            UIntPtr bufLen,
            ref InstallWatchTx installWatchTx,
            ref InstallWatchOutPoint installWatchOutPoint,
            ref WatchAllTxn watchAllTxn,
            ref GetChainUtxo getChainUtxo,
            ref FilterBlock filterBlock,
            ref ReEntered reEntered,

            ref BroadcastTransaction broadcastTransaction,
            ref Log log,
            ref GetEstSatPer1000Weight getEstSatPer1000Weight,

            IntPtr outputBufPtr,
            UIntPtr outputBufLen,
            out UIntPtr actualBufLen,
            out ManyChannelMonitorHandle manyChannelMonitorHandle
            );
        internal static FFIResult deserialize_many_channel_monitor(
            IntPtr bufPtr,
            UIntPtr bufLen,
            InstallWatchTx installWatchTx,
            InstallWatchOutPoint installWatchOutPoint,
            WatchAllTxn watchAllTxn,
            GetChainUtxo getChainUtxo,
            FilterBlock filterBlock,
            ReEntered reEntered,

            BroadcastTransaction broadcastTransaction,
            Log log,
            GetEstSatPer1000Weight getEstSatPer1000Weight,

            IntPtr outputBufPtr,
            UIntPtr outputBufLen,
            out UIntPtr actualBufLen,
            out ManyChannelMonitorHandle manyChannelMonitorHandle,
            bool check = true
            )
        => MaybeCheck(
            _deserialize_many_channel_monitor(
                bufPtr,
                bufLen,
                ref installWatchTx,
                ref installWatchOutPoint,
                ref watchAllTxn,
                ref getChainUtxo,
                ref filterBlock,
                ref reEntered,

                ref broadcastTransaction,
                ref log,
                ref getEstSatPer1000Weight,
                outputBufPtr,
                outputBufLen,
                out actualBufLen,
                out manyChannelMonitorHandle
                ),
            check);
Пример #9
0
        public ChainWatchInterfaceConverter(IChainWatchInterface chainWatchInterface)
        {
            _filterBlock = (ref byte blockPtr, UIntPtr blockLen, ref UIntPtr indexPtr, ref UIntPtr indexLen) =>
            {
                unsafe
                {
                    var blockS = new Span <byte>(Unsafe.AsPointer(ref blockPtr), (int)blockLen);
                    var block  = Block.Load(blockS.ToArray(), chainWatchInterface.Network);

                    var indexes = chainWatchInterface.FilterBlockImpl(block).Select(uintIndex => (UIntPtr)uintIndex).ToArray();
                    if (indexes.Length == 0)
                    {
                        indexLen = UIntPtr.Zero;
                        indexPtr = UIntPtr.Zero;
                        return;
                    }

                    fixed(UIntPtr *_ = indexes)
                    {
                        Unsafe.Write(Unsafe.AsPointer(ref indexLen), (UIntPtr)indexes.Length);
                        Unsafe.CopyBlockUnaligned(
                            ref Unsafe.As <UIntPtr, byte>(ref indexPtr),
                            ref Unsafe.As <UIntPtr, byte>(ref indexes[0]),
                            (uint)(indexes.Length * Unsafe.SizeOf <UIntPtr>()));
                    }
                }
            };

            _installWatchTx = (ref FFISha256dHash txid, ref FFIScript spk) =>
            {
                chainWatchInterface.InstallWatchTxImpl(txid.ToUInt256(), spk.ToScript());
            };

            _installWatchOutPoint = (ref FFIOutPoint ffiOutPoint, ref FFIScript script) =>
            {
                var t        = ffiOutPoint.ToTuple();
                var outpoint = new OutPoint(t.Item1, t.Item2);
                chainWatchInterface.InstallWatchOutPointImpl(outpoint, script.ToScript());
            };

            _getChainUtxo = (ref FFISha256dHash hash, ulong id, ref ChainError error, ref byte scriptPtr, ref UIntPtr scriptLen,
                             ref ulong satoshis) =>
            {
                if (chainWatchInterface.TryGetChainUtxoImpl(hash.ToUInt256(), id, ref error, out var script, out var a))
                {
                    using var m = new MemoryStream();
                    var stream = new BitcoinStream(m, true);
                    stream.ReadWrite(ref script);
                    var scriptPubKeyBytes = m.ToArray();
                    scriptLen = (UIntPtr)scriptPubKeyBytes.Length;
                    satoshis  = (ulong)a.Satoshi;
                    Unsafe.CopyBlock(ref scriptPtr, ref scriptPubKeyBytes[0], (uint)scriptPubKeyBytes.Length);
                }
            };

            _watchAllTxn = () =>
            {
                chainWatchInterface.WatchAllTxnImpl();
            };

            _reEntered = () => (UIntPtr)chainWatchInterface.ReEntered();
        }