Skip to content

Commit 05437e9

Browse files
authored
update to v0.3.1 (#19)
* update from cryptogarageinc v0.3.2
1 parent b9e0f0b commit 05437e9

16 files changed

+1981
-213
lines changed

.github/workflows/check_pre-merge.yml

+2
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@ on:
66
- master
77
- develop
88
- features/sprint*
9+
- stable_v*
910
pull_request:
1011
branches:
1112
- master
1213
- develop
1314
- features/sprint*
15+
- stable_v*
1416

1517
jobs:
1618
test-dotnet5:

.github/workflows/code_scanner.yml

-4
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,6 @@ jobs:
4343
with:
4444
dotnet-version: 5.0.x
4545

46-
# If this run was triggered by a pull request event, then checkout the head of the pull request instead of the merge commit.
47-
- run: git checkout HEAD^2
48-
if: ${{ github.event_name == 'pull_request' }}
49-
5046
# Initializes the CodeQL tools for scanning.
5147
- name: Initialize CodeQL
5248
uses: github/codeql-action/init@v1

.github/workflows/workflow_modify_checker.yml

-72
This file was deleted.

external/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ if(CFD_TARGET_VERSION)
4646
set(CFD_TARGET_TAG ${CFD_TARGET_VERSION})
4747
message(STATUS "[external project local] cfd target=${CFD_TARGET_VERSION}")
4848
else()
49-
set(CFD_TARGET_TAG v0.3.0)
49+
set(CFD_TARGET_TAG v0.3.1)
5050
endif()
5151
if(CFD_TARGET_URL)
5252
set(CFD_TARGET_REP ${CFD_TARGET_URL})

src/Address.cs

+122
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,56 @@ public enum CfdSighashType
162162
#pragma warning restore CA1720 // Identifier contains type name
163163
};
164164

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+
165215
/// <summary>
166216
/// Bitcoin Address class.
167217
/// </summary>
@@ -203,6 +253,78 @@ public static Address GetAddressByLockingScript(Script inputLockingScript, CfdNe
203253
}
204254
}
205255

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+
206328
/// <summary>
207329
/// empty constructor.
208330
/// </summary>

src/BlockHash.cs

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
using System;
2+
3+
namespace Cfd
4+
{
5+
/// <summary>
6+
/// block hash class.
7+
/// </summary>
8+
public class BlockHash : Txid
9+
{
10+
/// <summary>
11+
/// Constructor. (empty)
12+
/// </summary>
13+
public BlockHash() : base()
14+
{
15+
}
16+
17+
public BlockHash(string hash) : base(hash)
18+
{
19+
}
20+
21+
public BlockHash(byte[] bytes) : base(bytes)
22+
{
23+
}
24+
}
25+
}

0 commit comments

Comments
 (0)