File tree Expand file tree Collapse file tree 4 files changed +60
-0
lines changed
Expand file tree Collapse file tree 4 files changed +60
-0
lines changed Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change @@ -28,6 +28,8 @@ import 'package:collection/collection.dart';
2828part "builder.dart" ;
2929part "create_apo_transaction.dart" ;
3030part "errors.dart" ;
31+ part "funding_collector.dart" ;
3132part "outcome.dart" ;
33+ part "participant_funding_commitment.dart" ;
3234part "ready.dart" ;
3335part "terms.dart" ;
Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff 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}
You can’t perform that action at this time.
0 commit comments