@@ -162,6 +162,56 @@ public enum CfdSighashType
162
162
#pragma warning restore CA1720 // Identifier contains type name
163
163
} ;
164
164
165
+ /// <summary>
166
+ /// Elements pegin data struct.
167
+ /// </summary>
168
+ public struct PeginData : IEquatable < PeginData >
169
+ {
170
+ public Address Address { get ; }
171
+ public Script ClaimScript { get ; }
172
+ public Script TweakedFedpegScript { get ; }
173
+
174
+ public PeginData ( Address peginAddress , Script claimScript , Script tweakedFedpegScript )
175
+ {
176
+ Address = peginAddress ;
177
+ ClaimScript = claimScript ;
178
+ TweakedFedpegScript = tweakedFedpegScript ;
179
+ }
180
+
181
+ public bool Equals ( PeginData other )
182
+ {
183
+ return Address == other . Address ;
184
+ }
185
+
186
+ public override bool Equals ( object obj )
187
+ {
188
+ if ( obj is null )
189
+ {
190
+ return false ;
191
+ }
192
+ if ( obj is PeginData )
193
+ {
194
+ return Equals ( ( PeginData ) obj ) ;
195
+ }
196
+ return false ;
197
+ }
198
+
199
+ public override int GetHashCode ( )
200
+ {
201
+ return Address . GetHashCode ( ) ;
202
+ }
203
+
204
+ public static bool operator == ( PeginData left , PeginData right )
205
+ {
206
+ return left . Equals ( right ) ;
207
+ }
208
+
209
+ public static bool operator != ( PeginData left , PeginData right )
210
+ {
211
+ return ! ( left == right ) ;
212
+ }
213
+ } ;
214
+
165
215
/// <summary>
166
216
/// Bitcoin Address class.
167
217
/// </summary>
@@ -203,6 +253,78 @@ public static Address GetAddressByLockingScript(Script inputLockingScript, CfdNe
203
253
}
204
254
}
205
255
256
+ /// <summary>
257
+ /// Get pegin address.
258
+ /// </summary>
259
+ /// <param name="fedpegScript">fedpeg script</param>
260
+ /// <param name="pubkey">pubkey</param>
261
+ /// <param name="hashType">hash type</param>
262
+ /// <param name="network">network type</param>
263
+ /// <returns>pegin address data</returns>
264
+ public static PeginData GetPeginAddress ( Script fedpegScript , Pubkey pubkey , CfdHashType hashType , CfdNetworkType network )
265
+ {
266
+ if ( fedpegScript is null )
267
+ {
268
+ throw new ArgumentNullException ( nameof ( fedpegScript ) ) ;
269
+ }
270
+ if ( pubkey is null )
271
+ {
272
+ throw new ArgumentNullException ( nameof ( pubkey ) ) ;
273
+ }
274
+ using ( var handle = new ErrorHandle ( ) )
275
+ {
276
+ var ret = NativeMethods . CfdGetPeginAddress (
277
+ handle . GetHandle ( ) , ( int ) network , fedpegScript . ToHexString ( ) , ( int ) hashType ,
278
+ pubkey . ToHexString ( ) , "" ,
279
+ out IntPtr outputPeginAddress , out IntPtr outputClaimScript , out IntPtr outputFedpegScript ) ;
280
+ if ( ret != CfdErrorCode . Success )
281
+ {
282
+ handle . ThrowError ( ret ) ;
283
+ }
284
+ string peginAddress = CCommon . ConvertToString ( outputPeginAddress ) ;
285
+ string claimScript = CCommon . ConvertToString ( outputClaimScript ) ;
286
+ string tweakedFedpegScript = CCommon . ConvertToString ( outputFedpegScript ) ;
287
+ return new PeginData ( new Address ( peginAddress ) , new Script ( claimScript ) ,
288
+ new Script ( tweakedFedpegScript ) ) ;
289
+ }
290
+ }
291
+
292
+ /// <summary>
293
+ /// Get pegin address.
294
+ /// </summary>
295
+ /// <param name="fedpegScript">fedpeg script</param>
296
+ /// <param name="redeemScript">redeem script</param>
297
+ /// <param name="hashType">hash type</param>
298
+ /// <param name="network">network type</param>
299
+ /// <returns>pegin address data</returns>
300
+ public static PeginData GetPeginAddress ( Script fedpegScript , Script redeemScript , CfdHashType hashType , CfdNetworkType network )
301
+ {
302
+ if ( fedpegScript is null )
303
+ {
304
+ throw new ArgumentNullException ( nameof ( fedpegScript ) ) ;
305
+ }
306
+ if ( redeemScript is null )
307
+ {
308
+ throw new ArgumentNullException ( nameof ( redeemScript ) ) ;
309
+ }
310
+ using ( var handle = new ErrorHandle ( ) )
311
+ {
312
+ var ret = NativeMethods . CfdGetPeginAddress (
313
+ handle . GetHandle ( ) , ( int ) network , fedpegScript . ToHexString ( ) , ( int ) hashType ,
314
+ "" , redeemScript . ToHexString ( ) ,
315
+ out IntPtr outputPeginAddress , out IntPtr outputClaimScript , out IntPtr outputFedpegScript ) ;
316
+ if ( ret != CfdErrorCode . Success )
317
+ {
318
+ handle . ThrowError ( ret ) ;
319
+ }
320
+ string peginAddress = CCommon . ConvertToString ( outputPeginAddress ) ;
321
+ string claimScript = CCommon . ConvertToString ( outputClaimScript ) ;
322
+ string tweakedFedpegScript = CCommon . ConvertToString ( outputFedpegScript ) ;
323
+ return new PeginData ( new Address ( peginAddress ) , new Script ( claimScript ) ,
324
+ new Script ( tweakedFedpegScript ) ) ;
325
+ }
326
+ }
327
+
206
328
/// <summary>
207
329
/// empty constructor.
208
330
/// </summary>
0 commit comments