@@ -34,8 +34,6 @@ use bc::{Tx, TxMerkleNode, Txid};
34
34
use commit_verify:: mpc:: { self , Message , ProtocolId } ;
35
35
use strict_encoding:: { StrictDumb , StrictEncode } ;
36
36
37
- use crate :: opret:: OpretProof ;
38
- use crate :: tapret:: TapretProof ;
39
37
use crate :: { DbcMethod , Method , LIB_NAME_BPCORE } ;
40
38
41
39
mod dbc {
@@ -115,7 +113,7 @@ impl TxWitness {
115
113
derive( Serialize , Deserialize ) ,
116
114
serde( crate = "serde_crate" , rename_all = "camelCase" )
117
115
) ]
118
- pub struct EtxWitness < L : mpc:: Proof + StrictDumb , D : dbc:: Proof < M > , M : DbcMethod = Method > {
116
+ pub struct Anchor < L : mpc:: Proof + StrictDumb , D : dbc:: Proof < M > , M : DbcMethod = Method > {
119
117
/// Structured multi-protocol LNPBP-4 data the transaction commits to.
120
118
pub mpc_proof : L ,
121
119
@@ -127,7 +125,7 @@ pub struct EtxWitness<L: mpc::Proof + StrictDumb, D: dbc::Proof<M>, M: DbcMethod
127
125
pub _method : PhantomData < M > ,
128
126
}
129
127
130
- impl < L : mpc:: Proof + StrictDumb , D : dbc:: Proof < M > , M : DbcMethod > EtxWitness < L , D , M > {
128
+ impl < L : mpc:: Proof + StrictDumb , D : dbc:: Proof < M > , M : DbcMethod > Anchor < L , D , M > {
131
129
/// Constructs extra-transaction witness for a given MPC and DBC
132
130
/// proofs.
133
131
pub fn new ( mpc_proof : L , dbc_proof : D ) -> Self {
@@ -156,16 +154,16 @@ pub enum MergeError {
156
154
DbcMismatch ,
157
155
}
158
156
159
- impl < D : dbc:: Proof < M > , M : DbcMethod > EtxWitness < mpc:: MerkleProof , D , M > {
157
+ impl < D : dbc:: Proof < M > , M : DbcMethod > Anchor < mpc:: MerkleProof , D , M > {
160
158
/// Reconstructs anchor containing merkle block
161
159
pub fn into_merkle_block (
162
160
self ,
163
161
protocol_id : impl Into < ProtocolId > ,
164
162
message : impl Into < Message > ,
165
- ) -> Result < EtxWitness < mpc:: MerkleBlock , D , M > , mpc:: InvalidProof > {
163
+ ) -> Result < Anchor < mpc:: MerkleBlock , D , M > , mpc:: InvalidProof > {
166
164
let lnpbp4_proof =
167
165
mpc:: MerkleBlock :: with ( & self . mpc_proof , protocol_id. into ( ) , message. into ( ) ) ?;
168
- Ok ( EtxWitness {
166
+ Ok ( Anchor {
169
167
mpc_proof : lnpbp4_proof,
170
168
dbc_proof : self . dbc_proof ,
171
169
_method : default ! ( ) ,
@@ -177,7 +175,7 @@ impl<D: dbc::Proof<M>, M: DbcMethod> EtxWitness<mpc::MerkleProof, D, M> {
177
175
& self ,
178
176
protocol_id : impl Into < ProtocolId > ,
179
177
message : impl Into < Message > ,
180
- ) -> Result < EtxWitness < mpc:: MerkleBlock , D , M > , mpc:: InvalidProof > {
178
+ ) -> Result < Anchor < mpc:: MerkleBlock , D , M > , mpc:: InvalidProof > {
181
179
self . clone ( ) . into_merkle_block ( protocol_id, message)
182
180
}
183
181
@@ -207,13 +205,13 @@ impl<D: dbc::Proof<M>, M: DbcMethod> EtxWitness<mpc::MerkleProof, D, M> {
207
205
}
208
206
}
209
207
210
- impl < D : dbc:: Proof < M > , M : DbcMethod > EtxWitness < mpc:: MerkleBlock , D , M > {
208
+ impl < D : dbc:: Proof < M > , M : DbcMethod > Anchor < mpc:: MerkleBlock , D , M > {
211
209
/// Conceals all LNPBP-4 data except specific protocol and produces merkle
212
210
/// proof anchor.
213
211
pub fn to_merkle_proof (
214
212
& self ,
215
213
protocol : impl Into < ProtocolId > ,
216
- ) -> Result < EtxWitness < mpc:: MerkleProof , D , M > , mpc:: LeafNotKnown > {
214
+ ) -> Result < Anchor < mpc:: MerkleProof , D , M > , mpc:: LeafNotKnown > {
217
215
self . clone ( ) . into_merkle_proof ( protocol)
218
216
}
219
217
@@ -222,9 +220,9 @@ impl<D: dbc::Proof<M>, M: DbcMethod> EtxWitness<mpc::MerkleBlock, D, M> {
222
220
pub fn into_merkle_proof (
223
221
self ,
224
222
protocol : impl Into < ProtocolId > ,
225
- ) -> Result < EtxWitness < mpc:: MerkleProof , D , M > , mpc:: LeafNotKnown > {
223
+ ) -> Result < Anchor < mpc:: MerkleProof , D , M > , mpc:: LeafNotKnown > {
226
224
let lnpbp4_proof = self . mpc_proof . to_merkle_proof ( protocol. into ( ) ) ?;
227
- Ok ( EtxWitness {
225
+ Ok ( Anchor {
228
226
mpc_proof : lnpbp4_proof,
229
227
dbc_proof : self . dbc_proof ,
230
228
_method : default ! ( ) ,
@@ -248,110 +246,3 @@ impl<D: dbc::Proof<M>, M: DbcMethod> EtxWitness<mpc::MerkleBlock, D, M> {
248
246
Ok ( self )
249
247
}
250
248
}
251
-
252
- #[ derive( Clone , Eq , PartialEq , Debug ) ]
253
- #[ derive( StrictType , StrictEncode , StrictDecode ) ]
254
- #[ strict_type( lib = LIB_NAME_BPCORE , tags = custom) ]
255
- #[ cfg_attr(
256
- feature = "serde" ,
257
- derive( Serialize , Deserialize ) ,
258
- serde( crate = "serde_crate" , rename_all = "camelCase" , untagged)
259
- ) ]
260
- pub enum Anchor < P : mpc:: Proof + StrictDumb = mpc:: MerkleProof > {
261
- #[ strict_type( tag = 0x01 ) ]
262
- Tapret {
263
- tapret : EtxWitness < P , TapretProof > ,
264
- txw : TxWitness ,
265
- } ,
266
- #[ strict_type( tag = 0x02 ) ]
267
- Opret {
268
- opret : EtxWitness < P , OpretProof > ,
269
- txw : TxWitness ,
270
- } ,
271
- #[ strict_type( tag = 0x03 ) ]
272
- Dual {
273
- tapret : EtxWitness < P , TapretProof > ,
274
- opret : EtxWitness < P , OpretProof > ,
275
- txw : TxWitness ,
276
- } ,
277
- }
278
-
279
- impl < P : mpc:: Proof + StrictDumb > StrictDumb for Anchor < P > {
280
- fn strict_dumb ( ) -> Self {
281
- Self :: Tapret {
282
- tapret : strict_dumb ! ( ) ,
283
- txw : strict_dumb ! ( ) ,
284
- }
285
- }
286
- }
287
-
288
- impl < P : mpc:: Proof + StrictDumb > Anchor < P > {
289
- pub fn txid ( & self ) -> Txid {
290
- match self {
291
- Anchor :: Tapret { txw, .. } | Anchor :: Opret { txw, .. } | Anchor :: Dual { txw, .. } => {
292
- txw. txid ( )
293
- }
294
- }
295
- }
296
-
297
- pub fn tx_witness ( & self ) -> & TxWitness {
298
- match self {
299
- Anchor :: Tapret { txw, .. } | Anchor :: Opret { txw, .. } | Anchor :: Dual { txw, .. } => {
300
- txw
301
- }
302
- }
303
- }
304
-
305
- pub fn mpc_proofs ( & self ) -> impl Iterator < Item = & P > {
306
- let ( t, o) = match self {
307
- Anchor :: Tapret { tapret, txw : _ } => ( Some ( tapret) , None ) ,
308
- Anchor :: Opret { opret, txw : _ } => ( None , Some ( opret) ) ,
309
- Anchor :: Dual {
310
- tapret,
311
- opret,
312
- txw : _,
313
- } => ( Some ( tapret) , Some ( opret) ) ,
314
- } ;
315
- t. map ( |a| & a. mpc_proof )
316
- . into_iter ( )
317
- . chain ( o. map ( |a| & a. mpc_proof ) )
318
- }
319
-
320
- fn split (
321
- self ,
322
- ) -> ( TxWitness , Option < EtxWitness < P , TapretProof > > , Option < EtxWitness < P , OpretProof > > ) {
323
- match self {
324
- Anchor :: Tapret { tapret, txw } => ( txw, Some ( tapret) , None ) ,
325
- Anchor :: Opret { opret, txw } => ( txw, None , Some ( opret) ) ,
326
- Anchor :: Dual { tapret, opret, txw } => ( txw, Some ( tapret) , Some ( opret) ) ,
327
- }
328
- }
329
- }
330
-
331
- impl Anchor < mpc:: MerkleBlock > {
332
- /// Merges two anchors keeping revealed data.
333
- pub fn merge_reveal ( self , other : Self ) -> Result < Self , MergeError > {
334
- if self == other {
335
- return Ok ( self ) ;
336
- }
337
- let ( txw1, tapret1, opret1) = self . split ( ) ;
338
- let ( txw2, tapret2, opret2) = other. split ( ) ;
339
- let txw = txw1. merge_reveal ( txw2) ?;
340
- let tapret = match ( tapret1, tapret2) {
341
- ( None , None ) => None ,
342
- ( Some ( tapret) , None ) | ( None , Some ( tapret) ) => Some ( tapret) ,
343
- ( Some ( tapret1) , Some ( tapret2) ) => Some ( tapret1. merge_reveal ( tapret2) ?) ,
344
- } ;
345
- let opret = match ( opret1, opret2) {
346
- ( None , None ) => None ,
347
- ( Some ( opret) , None ) | ( None , Some ( opret) ) => Some ( opret) ,
348
- ( Some ( opret1) , Some ( opret2) ) => Some ( opret1. merge_reveal ( opret2) ?) ,
349
- } ;
350
- Ok ( match ( tapret, opret) {
351
- ( None , None ) => unreachable ! ( ) ,
352
- ( Some ( tapret) , None ) => Self :: Tapret { tapret, txw } ,
353
- ( None , Some ( opret) ) => Self :: Opret { opret, txw } ,
354
- ( Some ( tapret) , Some ( opret) ) => Self :: Dual { tapret, opret, txw } ,
355
- } )
356
- }
357
- }
0 commit comments