private async Task <bool> ConfirmConnectionAsync() { var inputWeight = 4 * Constants.P2wpkhInputVirtualSize; var inputRemainingWeights = new[] { (long)ArenaClient.ProtocolMaxWeightPerAlice - Coins.Count() * inputWeight }; var amountCredentials = ArenaClient.AmountCredentialClient.Credentials; var totalFeeToPay = FeeRate.GetFee(Coins.Sum(c => c.ScriptPubKey.EstimateInputVsize())); var totalAmount = Coins.Sum(coin => coin.Amount); if (totalFeeToPay > totalAmount) { throw new InvalidOperationException($"Round({ RoundId }), Alice({ AliceId}): Not enough funds to pay for the fees."); } var amountsToRequest = new[] { totalAmount - totalFeeToPay }; return(await ArenaClient .ConfirmConnectionAsync( RoundId, AliceId, inputRemainingWeights, amountCredentials.ZeroValue.Take(ArenaClient.ProtocolCredentialNumber), amountsToRequest) .ConfigureAwait(false)); }
private async Task <bool> TryConfirmConnectionAsync(IEnumerable <long> amountsToRequest, IEnumerable <long> vsizesToRequest, CancellationToken cancellationToken) { var inputVsize = Coin.ScriptPubKey.EstimateInputVsize(); var totalFeeToPay = FeeRate.GetFee(Coin.ScriptPubKey.EstimateInputVsize()); var totalAmount = Coin.Amount; var effectiveAmount = totalAmount - totalFeeToPay; if (effectiveAmount <= Money.Zero) { throw new InvalidOperationException($"Round({ RoundId }), Alice({ AliceId}): Adding this input is uneconomical."); } var response = await ArenaClient .ConfirmConnectionAsync( RoundId, AliceId, amountsToRequest, vsizesToRequest, IssuedAmountCredentials, IssuedVsizeCredentials, cancellationToken) .ConfigureAwait(false); IssuedAmountCredentials = response.IssuedAmountCredentials; IssuedVsizeCredentials = response.IssuedVsizeCredentials; var isConfirmed = response.Value; return(isConfirmed); }
private async Task <bool> TryConfirmConnectionAsync(long vsizeAllocationToRequest, CancellationToken cancellationToken) { var inputVsize = Coin.ScriptPubKey.EstimateInputVsize(); var vsizesToRequest = new[] { vsizeAllocationToRequest - inputVsize }; var totalFeeToPay = FeeRate.GetFee(Coin.ScriptPubKey.EstimateInputVsize()); var totalAmount = Coin.Amount; var effectiveAmount = totalAmount - totalFeeToPay; if (effectiveAmount <= Money.Zero) { throw new InvalidOperationException($"Round({ RoundId }), Alice({ AliceId}): Not enough funds to pay for the fees."); } var amountsToRequest = new[] { effectiveAmount.Satoshi }; var response = await ArenaClient .ConfirmConnectionAsync( RoundId, AliceId, amountsToRequest, vsizesToRequest, RealAmountCredentials, RealVsizeCredentials, cancellationToken) .ConfigureAwait(false); var isConfirmed = response.Value; if (isConfirmed) { RealAmountCredentials = response.RealAmountCredentials; RealVsizeCredentials = response.RealVsizeCredentials; } return(isConfirmed); }