-
Notifications
You must be signed in to change notification settings - Fork 851
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for wallet policies (BIP388)
- Loading branch information
1 parent
d99cc4e
commit 20467b8
Showing
13 changed files
with
2,879 additions
and
6 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#if !NO_RECORDS | ||
namespace NBitcoin.WalletPolicies | ||
{ | ||
public enum AddressIntent | ||
{ | ||
Deposit, | ||
Change | ||
} | ||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
#if !NO_RECORDS | ||
#nullable enable | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Reflection; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace NBitcoin.WalletPolicies | ||
{ | ||
public class DeriveParameters | ||
{ | ||
/// <summary> | ||
/// | ||
/// </summary> | ||
/// <param name="intent">Whether this is a deposit or change address</param> | ||
/// <param name="index">The address index</param> | ||
public DeriveParameters(AddressIntent intent, int index) | ||
{ | ||
if (index < 0) | ||
throw new ArgumentOutOfRangeException(nameof(index), "index should be positive"); | ||
Intent = intent; | ||
AddressIndexes = new int[] { index }; | ||
} | ||
/// <summary> | ||
/// | ||
/// </summary> | ||
/// <param name="intent">Whether this is a deposit or change address</param> | ||
/// <param name="indexes">The addresses to derive</param> | ||
public DeriveParameters(AddressIntent intent, int[]? indexes) | ||
{ | ||
Intent = intent; | ||
AddressIndexes = indexes ?? Array.Empty<int>(); | ||
foreach (var idx in AddressIndexes) | ||
if (idx < 0) | ||
throw new ArgumentOutOfRangeException(nameof(indexes), "indexes should be positive"); | ||
} | ||
/// <summary> | ||
/// | ||
/// </summary> | ||
/// <param name="intent">Whether this is a deposit or change address</param> | ||
/// <param name="startIndex">The first address to start generating</param> | ||
/// <param name="count">The number of addresses to generate</param> | ||
/// <exception cref="ArgumentOutOfRangeException"></exception> | ||
public DeriveParameters(AddressIntent intent, int startIndex, int count) | ||
{ | ||
if (startIndex < 0) | ||
throw new ArgumentOutOfRangeException(nameof(startIndex), "startIndex should be positive"); | ||
if (startIndex < 0) | ||
throw new ArgumentOutOfRangeException(nameof(count), "count should be positive"); | ||
Intent = intent; | ||
AddressIndexes = Enumerable.Range(startIndex, count).ToArray(); | ||
} | ||
public AddressIntent Intent { get; } | ||
public int[] AddressIndexes { get; set; } | ||
} | ||
} | ||
#endif |
Oops, something went wrong.