public async IAsyncEnumerable <SpendableOutputDescriptor?> GetSpendableOutputDescriptors(IEnumerable <OutPoint> outpoints, [EnumeratorCancellation] CancellationToken ct = default) { if (outpoints == null) { throw new ArgumentNullException(nameof(outpoints)); } using var tx = await _engine.OpenTransaction(ct); var table = tx.GetTable(DBKeys.OutpointsToStaticOutputDescriptor); foreach (var op in outpoints) { var raw = await table.Get(op.ToBytes()); if (raw is null) { yield return(null); continue; } var b = await raw.ReadValue(); yield return(SpendableOutputDescriptor.ParseUnsafe(b.ToArray())); } }
public async Task TrackSpendableOutput(NRustLightningNetwork network, SpendableOutputDescriptor desc, CancellationToken ct = default) { var client = _nbXplorerClientProvider.GetClient(network); switch (desc) { case SpendableOutputDescriptor.StaticOutput staticOutput: { var addr = staticOutput.Item.Output.ScriptPubKey.GetDestinationAddress(network.NBitcoinNetwork); var s = new AddressTrackedSource(addr); await client.TrackAsync(s, ct); await client.RPCClient.ImportAddressAsync(addr); break; } case SpendableOutputDescriptor.DynamicOutputP2WSH p2wshOutput: { var(param1, param2) = p2wshOutput.Item.KeyDerivationParams.ToValueTuple(); var amountSat = (ulong)p2wshOutput.Item.Output.Value.Satoshi; var channelKeys = _keysRepository.DeriveChannelKeys(amountSat, param1, param2); var delayedPaymentKey = Generators.derivePrivKey(_secp256k1Ctx, channelKeys.DelayedPaymentBaseKey, p2wshOutput.Item.PerCommitmentPoint.PubKey); var toSelfDelay = p2wshOutput.Item.ToSelfDelay; var revokeableRedeemScript = _keysRepository.GetRevokeableRedeemScript(p2wshOutput.Item.RemoteRevocationPubKey, toSelfDelay, delayedPaymentKey.PubKey); Debug.Assert(p2wshOutput.Item.Output.ScriptPubKey.Equals(revokeableRedeemScript.WitHash.ScriptPubKey)); var addr = revokeableRedeemScript.WitHash.ScriptPubKey.GetDestinationAddress(network.NBitcoinNetwork); var s = new AddressTrackedSource(addr); await client.TrackAsync(s, ct); await client.RPCClient.ImportAddressAsync(addr); break; } case SpendableOutputDescriptor.StaticOutputRemotePayment remoteOutput: { var(p1, p2) = remoteOutput.Item.KeyDerivationParams.ToValueTuple(); var amountSat = (ulong)remoteOutput.Item.Output.Value; var keys = _keysRepository.DeriveChannelKeys(amountSat, p1, p2); Debug.Assert( keys.PaymentKey.PubKey.WitHash.ScriptPubKey.Equals(remoteOutput.Item.Output.ScriptPubKey)); var addr = remoteOutput.Item.Output.ScriptPubKey.GetDestinationAddress(network.NBitcoinNetwork); await client.TrackAsync(new AddressTrackedSource(addr), ct); await client.RPCClient.ImportAddressAsync(addr); break; } } }
public async IAsyncEnumerable <SpendableOutputDescriptor> GetAllSpendableOutputDescriptors([EnumeratorCancellation] CancellationToken ct = default) { using var tx = await _engine.OpenTransaction(ct); var table = tx.GetTable(DBKeys.OutpointsToStaticOutputDescriptor); await foreach (var item in table.Enumerate().WithCancellation(ct)) { yield return(SpendableOutputDescriptor.ParseUnsafe((await item.ReadValue()).ToArray())); } }
public async Task SetSpendableOutputDescriptor(SpendableOutputDescriptor outputDescriptor, CancellationToken ct = default) { if (outputDescriptor == null) { throw new ArgumentNullException(nameof(outputDescriptor)); } using var tx = await _engine.OpenTransaction(ct); var t = tx.GetTable(DBKeys.OutpointsToStaticOutputDescriptor); await t.Insert(outputDescriptor.OutPoint.Value.ToBytes(), outputDescriptor.ToBytes()); await tx.Commit(); }
public Task TrackSpendableOutput(NRustLightningNetwork network, SpendableOutputDescriptor desc, CancellationToken ct = default) { return(Task.CompletedTask); }
public static UTXOKind GetKind(this SpendableOutputDescriptor desc) => desc switch {
public Task SetSpendableOutputDescriptor(SpendableOutputDescriptor outputDescriptor, CancellationToken ct = default) { _outputDescriptors.TryAdd(outputDescriptor.OutPoint.Value, outputDescriptor); return(Task.CompletedTask); }