Exemplo n.º 1
0
        public FundingCreatedMessage Handle(AcceptChannelMessage acceptMessage, PendingChannel pendingChannel)
        {
            var oldState    = LocalChannelState.AcceptChannel;
            var openMessage = pendingChannel.OpenMessage;

            _channelLoggingService.LogPendingChannelInfo(openMessage.TemporaryChannelId.ToHex(), oldState, "Remote accepted channel open");
            FundingTransaction fundingTx = _fundingService.CreateFundingTransaction(openMessage.FundingSatoshis, openMessage.FeeratePerKw, openMessage.FundingPubKey, acceptMessage.FundingPubKey);

            var channel = CreateChannel(pendingChannel.ChannelIndex, fundingTx, openMessage, acceptMessage);

            channel.IsFunder = true;

            _commitmentService.CreateInitialCommitmentTransactions(openMessage, acceptMessage, channel, pendingChannel.RevocationKey);
            channel.State = LocalChannelState.FundingCreated;

            var signatureOfRemoteCommitmentTx           = channel.RemoteCommitmentTxParameters.LocalSignature;
            FundingCreatedMessage fundingCreatedMessage = new FundingCreatedMessage
            {
                TemporaryChannelId   = openMessage.TemporaryChannelId,
                FundingTransactionId = fundingTx.Transaction.GetHash().ToBytes(),
                FundingOutputIndex   = fundingTx.FundingOutputIndex,
                Signature            = signatureOfRemoteCommitmentTx.ToRawSignature()
            };

            pendingChannel.Channel = channel;
            _channelLoggingService.LogStateUpdate(channel, oldState, additionalData: fundingTx.Transaction.ToString());

            return(fundingCreatedMessage);
        }