|
| 1 | +import 'dart:typed_data'; |
| 2 | +import 'package:coinlib/src/common/serial.dart'; |
1 | 3 | import 'package:coinlib/src/crypto/ec_public_key.dart'; |
2 | 4 | import 'package:coinlib/src/crypto/schnorr_adaptor_signature.dart'; |
3 | 5 | import 'package:coinlib/src/tx/transaction.dart'; |
4 | | -import 'terms.dart'; |
5 | 6 |
|
6 | | -class CETReady { |
| 7 | +class CETReady with Writable { |
7 | 8 |
|
8 | 9 | final Transaction tx; |
9 | 10 | final SchnorrAdaptorSignature adaptorSig; |
10 | 11 |
|
11 | 12 | CETReady(this.tx, this.adaptorSig); |
| 13 | + CETReady.fromReader(BytesReader reader) |
| 14 | + : tx = Transaction.fromReader(reader), |
| 15 | + adaptorSig = SchnorrAdaptorSignature.fromReader(reader); |
| 16 | + CETReady.fromBytes(Uint8List bytes) : this.fromReader(BytesReader(bytes)); |
| 17 | + |
| 18 | + @override |
| 19 | + void write(Writer writer) { |
| 20 | + tx.write(writer); |
| 21 | + adaptorSig.write(writer); |
| 22 | + } |
12 | 23 |
|
13 | 24 | } |
14 | 25 |
|
15 | | -class DLCReady { |
| 26 | +/// Carries data for a DLC with fully signed [cets] and a [refundTransaction]. |
| 27 | +/// After this has been created, the DLC requires funding before it can be used. |
| 28 | +class DLCReady with Writable { |
16 | 29 |
|
17 | | - final DLCTerms terms; |
18 | 30 | final Transaction refundTransaction; |
19 | | - // TODO: Make immutable |
20 | 31 | final Map<ECPublicKey, CETReady> cets; |
21 | 32 |
|
22 | 33 | DLCReady({ |
23 | | - required this.terms, |
24 | 34 | required this.refundTransaction, |
25 | | - required this.cets, |
26 | | - }); |
| 35 | + required Map<ECPublicKey, CETReady> cets, |
| 36 | + }) : cets = Map.unmodifiable(cets); |
| 37 | + DLCReady.fromReader(BytesReader reader) |
| 38 | + : refundTransaction = Transaction.fromReader(reader), |
| 39 | + cets = reader.readXPubKeyMap(() => CETReady.fromReader(reader)); |
| 40 | + DLCReady.fromBytes(Uint8List bytes) : this.fromReader(BytesReader(bytes)); |
| 41 | + |
| 42 | + @override |
| 43 | + void write(Writer writer) { |
| 44 | + refundTransaction.write(writer); |
| 45 | + writer.writeOrderedXPubkeyMap(cets, (cet) => cet.write(writer)); |
| 46 | + } |
27 | 47 |
|
28 | 48 | } |
0 commit comments