Skip to content

Commit 198fba7

Browse files
authored
Add Wallet domain model and abstractions (#262)
* Add Angor.Wallet * Simplify things a bit * Switch to long
1 parent f99fcaf commit 198fba7

25 files changed

+198
-0
lines changed

src/Angor.Avalonia.sln

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Angor.UI.Model.Implementati
2222
EndProject
2323
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Core", "Core", "{5B7EE527-242E-4C87-9BB7-AD4E05EABC4C}"
2424
EndProject
25+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Angor.Wallet", "Angor\Avalonia\Angor.Wallet\Angor.Wallet.csproj", "{287F370D-D680-4BE5-8577-7A180BD0A0E3}"
26+
EndProject
2527
Global
2628
GlobalSection(SolutionConfigurationPlatforms) = preSolution
2729
Debug|Any CPU = Debug|Any CPU
@@ -52,6 +54,10 @@ Global
5254
{B84751C6-1B82-4DE8-9FBE-F0A67D981C43}.Debug|Any CPU.Build.0 = Debug|Any CPU
5355
{B84751C6-1B82-4DE8-9FBE-F0A67D981C43}.Release|Any CPU.ActiveCfg = Release|Any CPU
5456
{B84751C6-1B82-4DE8-9FBE-F0A67D981C43}.Release|Any CPU.Build.0 = Release|Any CPU
57+
{287F370D-D680-4BE5-8577-7A180BD0A0E3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
58+
{287F370D-D680-4BE5-8577-7A180BD0A0E3}.Debug|Any CPU.Build.0 = Debug|Any CPU
59+
{287F370D-D680-4BE5-8577-7A180BD0A0E3}.Release|Any CPU.ActiveCfg = Release|Any CPU
60+
{287F370D-D680-4BE5-8577-7A180BD0A0E3}.Release|Any CPU.Build.0 = Release|Any CPU
5561
EndGlobalSection
5662
GlobalSection(SolutionProperties) = preSolution
5763
HideSolutionNode = FALSE
@@ -64,5 +70,6 @@ Global
6470
{539B4D21-F2A9-46A6-84F1-9A51884A62E9} = {5B7EE527-242E-4C87-9BB7-AD4E05EABC4C}
6571
{B84751C6-1B82-4DE8-9FBE-F0A67D981C43} = {5B7EE527-242E-4C87-9BB7-AD4E05EABC4C}
6672
{700DF0C4-C965-4662-A91F-CD3BE043AC9E} = {5B7EE527-242E-4C87-9BB7-AD4E05EABC4C}
73+
{287F370D-D680-4BE5-8577-7A180BD0A0E3} = {5B7EE527-242E-4C87-9BB7-AD4E05EABC4C}
6774
EndGlobalSection
6875
EndGlobal
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net9.0</TargetFramework>
5+
<ImplicitUsings>enable</ImplicitUsings>
6+
<Nullable>enable</Nullable>
7+
</PropertyGroup>
8+
9+
<ItemGroup>
10+
<PackageReference Include="CSharpFunctionalExtensions" />
11+
</ItemGroup>
12+
13+
</Project>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
using Angor.Wallet.Domain;
2+
3+
namespace Angor.Wallet.Application;
4+
5+
public interface ITransactionWatcher
6+
{
7+
IObservable<BroadcastedTransaction> Watch(WalletId id);
8+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using Angor.Wallet.Domain;
2+
using CSharpFunctionalExtensions;
3+
4+
namespace Angor.Wallet.Application;
5+
6+
public interface IWalletAppService
7+
{
8+
Task<Result<TxId>> SendAmount(WalletId walletId, Amount amount, Address address, DomainFeeRate feeRate);
9+
Task<Result<IEnumerable<(WalletId Id, string Name)>>> GetWallets();
10+
Task<Result<IEnumerable<BroadcastedTransaction>>> GetTransactions(WalletId walletId);
11+
Task<Result<Balance>> GetBalance(WalletId walletId);
12+
Task<Result<Fee>> EstimateFee(WalletId walletId, Amount amount, Address address, DomainFeeRate feeRate);
13+
Task<Result<Address>> GetNextReceiveAddress(WalletId id);
14+
Task<Result<WalletId>> ImportWallet(string name, string seedwords, Maybe<string> passphrase, string encryptionKey, BitcoinNetwork network);
15+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
namespace Angor.Wallet.Domain;
2+
3+
public record Address(string Value);
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
namespace Angor.Wallet.Domain;
2+
3+
public record Amount(long Value);
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
namespace Angor.Wallet.Domain;
2+
3+
public record Balance(long Value);
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
namespace Angor.Wallet.Domain;
2+
3+
public enum BitcoinNetwork
4+
{
5+
Mainnet,
6+
Testnet
7+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
namespace Angor.Wallet.Domain;
2+
3+
public record BroadcastedTransaction(
4+
Balance Balance,
5+
string Id,
6+
IEnumerable<TransactionInputInfo> WalletInputs,
7+
IEnumerable<TransactionOutputInfo> WalletOutputs,
8+
IEnumerable<TransactionAddressInfo> AllInputs,
9+
IEnumerable<TransactionAddressInfo> AllOutputs,
10+
long Fee,
11+
bool IsConfirmed,
12+
int? BlockHeight,
13+
DateTimeOffset? BlockTime,
14+
string RawJson
15+
);
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
namespace Angor.Wallet.Domain;
2+
3+
public record DerivationPath
4+
{
5+
public uint Purpose { get; }
6+
public uint CoinType { get; }
7+
public uint Account { get; }
8+
9+
private DerivationPath(uint purpose, uint coinType, uint account)
10+
{
11+
Purpose = purpose;
12+
CoinType = coinType;
13+
Account = account;
14+
}
15+
16+
public static DerivationPath Create(uint purpose, uint coinType, uint account) =>
17+
new(purpose, coinType, account);
18+
19+
public override string ToString() => $"{Purpose}'{CoinType}'{Account}'";
20+
}

0 commit comments

Comments
 (0)