Skip to content

Commit 7c2ff0e

Browse files
committed
Add foundation for determining funding transaction inputs and change
1 parent 0abd30d commit 7c2ff0e

File tree

4 files changed

+60
-0
lines changed

4 files changed

+60
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
part of "library.dart";
2+
3+
/// Collects the inputs and change outputs for each participant for the
4+
/// construction of a Funding Transaction.
5+
///
6+
/// This can only be created through a [DLCReady] object to remind consumers of
7+
/// the library to create DLCs in the correct order as the Refund Transaction
8+
/// and Contract Execution Transactions must first be created through a
9+
/// [DLCStatefulBuilder].
10+
class DLCFundingCollector {
11+
12+
final DLCTerms terms;
13+
final Map<ECPublicKey, DLCParticipantFundingCommitment> fundingCommitments;
14+
15+
DLCFundingCollector._(this.terms) : fundingCommitments = {};
16+
17+
// TODO: Create funding transaction without inputs and change, determine total
18+
// contribution requirements for each participant.
19+
// TODO: Allow adding DLCParticipantFundingCommitment and verify contribution
20+
// meets requirement including fee
21+
22+
}

coinlib/lib/src/dlc/library.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ import 'package:collection/collection.dart';
2828
part "builder.dart";
2929
part "create_apo_transaction.dart";
3030
part "errors.dart";
31+
part "funding_collector.dart";
3132
part "outcome.dart";
33+
part "participant_funding_commitment.dart";
3234
part "ready.dart";
3335
part "terms.dart";
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
part of "library.dart";
2+
3+
/// The proposed inputs and change for a DLC funding participant. Their net
4+
/// contribution must reach their amount in [DLCTerms.fundAmounts] plus a share
5+
/// of the fee that includes the fee specific to their inputs and change input
6+
/// and a fraction of all other transaction data.
7+
/// TODO: The required commitment should probably be determined by
8+
/// [DLCFundingCollector] and this docstring updated accordingly.
9+
class DLCParticipantFundingCommitment {
10+
11+
/// The change output to include in the outputs
12+
final Output change;
13+
/// The inputs provided by the participant. The [InputCandidate] contains the
14+
/// input value but this must be validated against the actual output value to
15+
/// be correct.
16+
final List<InputCandidate> inputs;
17+
18+
DLCParticipantFundingCommitment({
19+
required this.change,
20+
required this.inputs,
21+
});
22+
23+
// TODO: Add coin selector to meet required contribution and fee, making this
24+
// easier for consumers of the library to fund their contribution.
25+
26+
/// Amount contributed after subtracting change from inputs
27+
BigInt get netAmount
28+
=> addBigInts(inputs.map((input) => input.value)) - change.value;
29+
30+
}

coinlib/lib/src/dlc/ready.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,10 @@ class DLCReady with Writable {
4141
writer.writeOrderedXPubkeyMap(cets, (cet) => cet.write(writer));
4242
}
4343

44+
/// Create the [DLCFundingCollector] class to start construction of the
45+
/// Funding Transaction. The [terms] must correspond to this [DLCReady] object
46+
/// though this is not validated.
47+
DLCFundingCollector beginFunding(DLCTerms terms)
48+
=> DLCFundingCollector._(terms);
49+
4450
}

0 commit comments

Comments
 (0)