Skip to content

Commit a2955c9

Browse files
committed
1.4.0-beta-01
1 parent a4d030c commit a2955c9

File tree

7 files changed

+290
-5
lines changed

7 files changed

+290
-5
lines changed

src/chia-dotnet/ChiaTypes/NFTInfo.cs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
using System.Collections.Generic;
2+
3+
namespace chia.dotnet
4+
{
5+
/// <summary>
6+
/// NFT Info for displaying NFT on the UI
7+
/// </summary>
8+
public record NFTInfo
9+
{
10+
public string LauncherId { get; init; } = string.Empty;
11+
public string NFTCoinID { get; init; } = string.Empty;
12+
public string? OwnerDID { get; init; }
13+
public ushort? RoyaltyPercentage { get; init; }
14+
public string? RoyaltyPuzzleHash { get; init; } = string.Empty;
15+
public IEnumerable<string> DataUris { get; init; } = new List<string>();
16+
public string DataHash { get; init; } = string.Empty;
17+
public IEnumerable<string> MetadataUris { get; init; } = new List<string>();
18+
public string MetaataHash { get; init; } = string.Empty;
19+
public IEnumerable<string> LicenseUris { get; init; } = new List<string>();
20+
public ulong SeriesTotal { get; init; }
21+
public ulong SeriesNumber { get; init; }
22+
public string UpdaterPuzhash { get; init; } = string.Empty;
23+
public string ChainInfo { get; init; } = string.Empty;
24+
public uint MintHeight { get; init; }
25+
public bool SupportsDID { get; init; }
26+
public bool PendingTransaction { get; init; }
27+
public string LauncherPuzhash { get; init; } = string.Empty;
28+
}
29+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using System.Collections.Generic;
2+
3+
namespace chia.dotnet
4+
{
5+
/// <summary>
6+
/// Info for minting an NFT
7+
/// </summary>
8+
public record NFTMintingInfo
9+
{
10+
public string RoyaltyAddress { get; init; } = string.Empty;
11+
public string TargetAddress { get; init; } = string.Empty;
12+
public string? DIDID { get; init; }
13+
public ushort RoyaltyPercentage { get; init; } = 0;
14+
public IEnumerable<string> Uris { get; init; } = new List<string>();
15+
public string Hash { get; init; } = string.Empty;
16+
public IEnumerable<string> MetaUris { get; init; } = new List<string>();
17+
public string? MetaHash { get; init; }
18+
public IEnumerable<string> LicenseUris { get; init; } = new List<string>();
19+
public string? LicenseHash { get; init; }
20+
public ulong SeriesTotal { get; init; } = 1;
21+
public ulong SeriesNumber { get; init; } = 1;
22+
}
23+
}

src/chia-dotnet/ChiaTypes/WalletType.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ public enum WalletType : byte
1414
CAT = 6,
1515
RECOVERABLE = 7,
1616
DISTRIBUTED_ID = 8,
17-
POOLING_WALLET = 9
17+
POOLING_WALLET = 9,
18+
NFT = 10
1819
}
1920
}

src/chia-dotnet/Converters.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,13 @@ public static IEnumerable<T> ToEnumerable<T>(dynamic enumerable)
4747
return e is null ? Enumerable.Empty<T>() : e.Select(item => (T)item);
4848
}
4949

50+
public static IEnumerable<T> ToEnumerable<T>(dynamic enumerable, Func<dynamic, T> converter)
51+
{
52+
Debug.Assert(enumerable is not null);
53+
var e = (IEnumerable<dynamic>)enumerable;
54+
return e is null ? Enumerable.Empty<T>() : e.Select(item => (T)converter(item));
55+
}
56+
5057
public static DateTime? ToDateTime(this ulong? epoch)
5158
{
5259
if (epoch.HasValue)

src/chia-dotnet/NFTWallet.cs

Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Threading;
5+
using System.Threading.Tasks;
6+
7+
namespace chia.dotnet
8+
{
9+
/// <summary>
10+
/// Wraps an NFT wallet
11+
/// </summary>
12+
public sealed class NFTWallet : Wallet
13+
{
14+
/// <summary>
15+
/// ctor
16+
/// </summary>
17+
/// <param name="walletId">The wallet_id to wrap</param>
18+
/// <param name="walletProxy">Wallet RPC proxy to use for communication</param>
19+
public NFTWallet(uint walletId, WalletProxy walletProxy)
20+
: base(walletId, walletProxy)
21+
{
22+
}
23+
24+
/// <summary>
25+
/// Validates that <see cref="Wallet.WalletId"/> is a <see cref="WalletType.NFT"/>
26+
/// </summary>
27+
/// <returns>True if the wallet is an NFT wallet</returns>
28+
public override async Task Validate(CancellationToken cancellationToken = default)
29+
{
30+
await Validate(WalletType.NFT, cancellationToken).ConfigureAwait(false);
31+
}
32+
33+
/// <summary>
34+
/// Adds an Uri to an NFT
35+
/// </summary>
36+
/// <param name="uri">The uri</param>
37+
/// <param name="key">The uri key</param>
38+
/// <param name="nftCoinId">The nft coin id</param>
39+
/// <param name="fee">Transaction fee</param>
40+
/// <param name="cancellationToken">A token to allow the call to be cancelled</param>
41+
/// <returns>An <see cref="SpendBundle"/></returns>
42+
public async Task<SpendBundle> AddUri(string uri, string key, string nftCoinId, ulong fee = 0, CancellationToken cancellationToken = default)
43+
{
44+
dynamic data = CreateWalletDataObject();
45+
data.uri = uri;
46+
data.key = key;
47+
data.nft_coin_id = nftCoinId;
48+
data.fee = fee;
49+
50+
return await WalletProxy.SendMessage<SpendBundle>("nft_add_uri", "spend_bundle", data, cancellationToken).ConfigureAwait(false);
51+
}
52+
53+
/// <summary>
54+
/// Gets NFTs from a wallet
55+
/// </summary>
56+
/// <param name="cancellationToken">A token to allow the call to be cancelled</param>
57+
/// <returns>The DID id</returns>
58+
public async Task<IEnumerable<NFTInfo>> GetNFTs(CancellationToken cancellationToken = default)
59+
{
60+
var response = await WalletProxy.SendMessage("nft_get_nfts", CreateWalletDataObject(), cancellationToken).ConfigureAwait(false);
61+
62+
return Converters.ToObject<IEnumerable<NFTInfo>>(response, "nft_list");
63+
}
64+
65+
/// <summary>
66+
/// Gets the DID
67+
/// </summary>
68+
/// <param name="cancellationToken">A token to allow the call to be cancelled</param>
69+
/// <returns>The list of NFTs</returns>
70+
public async Task<string> GetDID(CancellationToken cancellationToken = default)
71+
{
72+
var response = await WalletProxy.SendMessage("nft_get_wallet_did", CreateWalletDataObject(), cancellationToken).ConfigureAwait(false);
73+
74+
return response.did_id;
75+
}
76+
77+
/// <summary>
78+
/// Mints an NFT
79+
/// </summary>
80+
/// <param name="info">Info about the NFT to be minted</param>
81+
/// <param name="fee">Transaction fee</param>
82+
/// <param name="cancellationToken">A token to allow the call to be cancelled</param>
83+
/// <returns>A <see cref="SpendBundle"/></returns>
84+
public async Task<SpendBundle> MintNFT(NFTMintingInfo info, ulong fee = 0, CancellationToken cancellationToken = default)
85+
{
86+
dynamic data = CreateWalletDataObject();
87+
data.royalty_address = info.RoyaltyAddress;
88+
data.target_address = info.TargetAddress;
89+
data.uris = info.Uris;
90+
data.meta_uris = info.MetaUris;
91+
data.license_uris = info.LicenseUris;
92+
data.hash = info.Hash;
93+
data.series_number = info.SeriesNumber;
94+
data.series_total = info.SeriesTotal;
95+
data.meta_hash = info.MetaHash;
96+
data.license_hash = info.LicenseHash;
97+
data.did_id = info.DIDID;
98+
data.royalty_percentage = info.RoyaltyPercentage;
99+
data.fee = fee;
100+
101+
return await WalletProxy.SendMessage<SpendBundle>("nft_mint_nft", "spend_bundle", data, cancellationToken).ConfigureAwait(false);
102+
}
103+
104+
/// <summary>
105+
/// Sets the DID for an NFT
106+
/// </summary>
107+
/// <param name="didId">The DID ID</param>
108+
/// <param name="cancellationToken">A token to allow the call to be cancelled</param>
109+
/// <returns>A <see cref="SpendBundle"/></returns>
110+
public async Task<SpendBundle> SetDID(string didId, CancellationToken cancellationToken = default)
111+
{
112+
dynamic data = CreateWalletDataObject();
113+
data.did_id = didId;
114+
115+
return await WalletProxy.SendMessage<SpendBundle>("nft_set_nft_did", "spend_bundle", data, cancellationToken).ConfigureAwait(false);
116+
}
117+
118+
/// <summary>
119+
/// Sets the status of an NFT
120+
/// </summary>
121+
/// <param name="coinId">The coin ID</param>
122+
/// <param name="inTransaction">In transaction idicator</param>
123+
/// <param name="cancellationToken">A token to allow the call to be cancelled</param>
124+
/// <returns>An awaitable <see cref="Task"/></returns>
125+
public async Task SetStatus(string coinId, bool inTransaction = true, CancellationToken cancellationToken = default)
126+
{
127+
dynamic data = CreateWalletDataObject();
128+
data.coin_id = coinId;
129+
data.in_transaction = inTransaction;
130+
131+
await WalletProxy.SendMessage("nft_set_nft_status", data, cancellationToken).ConfigureAwait(false);
132+
}
133+
134+
/// <summary>
135+
/// Sets the status of an NFT
136+
/// </summary>
137+
/// <param name="targetAddress">The target address</param>
138+
/// <param name="coinId">The coin ID</param>
139+
/// <param name="fee">Transaction fee</param>
140+
/// <param name="cancellationToken">A token to allow the call to be cancelled</param>
141+
/// <returns>A <see cref="SpendBundle"/></returns>
142+
public async Task<SpendBundle> Transfer(string targetAddress, string coinId, ulong fee = 0, CancellationToken cancellationToken = default)
143+
{
144+
dynamic data = CreateWalletDataObject();
145+
data.target_address = targetAddress;
146+
data.nft_coin_id = coinId;
147+
data.fee = fee;
148+
149+
return await WalletProxy.SendMessage<SpendBundle>("nft_transfer_nft", "spend_bundle", data, cancellationToken).ConfigureAwait(false);
150+
}
151+
}
152+
}

src/chia-dotnet/WalletProxy.cs

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,79 @@ public async Task<IEnumerable<string>> GenerateMnemonic(CancellationToken cancel
421421
);
422422
}
423423

424+
/// <summary>
425+
/// Get an NFT wallet by DID ID
426+
/// </summary>
427+
/// <param name="didId">The DID ID</param>
428+
/// <param name="cancellationToken">A token to allow the call to be cancelled</param>
429+
/// <returns>The wallet id</returns>
430+
public async Task<uint> GetNFTByDID(string didId, CancellationToken cancellationToken = default)
431+
{
432+
dynamic data = new ExpandoObject();
433+
data.did_id = didId;
434+
435+
var response = await SendMessage("nft_get_by_did", data, cancellationToken).ConfigureAwait(false);
436+
437+
return (uint)response.wallet_id;
438+
}
439+
440+
/// <summary>
441+
/// Gets all the wallets with DIDs
442+
/// </summary>
443+
/// <param name="cancellationToken">A token to allow the call to be cancelled</param>
444+
/// <returns>The list of wallets</returns>
445+
public async Task<IEnumerable<(uint WalletId, string DIDId, uint DIDWalletID)>> GetWalletsWithDIDs(CancellationToken cancellationToken = default)
446+
{
447+
var response = await SendMessage("nft_get_wallets_with_dids", cancellationToken).ConfigureAwait(false);
448+
449+
var list = new List<(uint, string, uint)>();
450+
foreach (var d in response.nft_wallets)
451+
{
452+
list.Add((d.wallet_id, d.did_id, d.did_wallet_id));
453+
}
454+
455+
return list;
456+
}
457+
458+
/// <summary>
459+
/// Get info about an NFT
460+
/// </summary>
461+
/// <param name="didId">The coin id</param>
462+
/// <param name="latest">Get latest NFT</param>
463+
/// <param name="cancellationToken">A token to allow the call to be cancelled</param>
464+
/// <returns>The wallet id</returns>
465+
public async Task<NFTInfo> GetNFTInfo(string coinId, bool latest = true, CancellationToken cancellationToken = default)
466+
{
467+
dynamic data = new ExpandoObject();
468+
data.coin_id = coinId;
469+
data.latest = latest;
470+
471+
return await SendMessage("nft_get_info", "nft_info", data, cancellationToken).ConfigureAwait(false);
472+
}
473+
474+
/// <summary>
475+
/// Creates a new NFT wallet
476+
/// </summary>
477+
/// <param name="didId">An optional DID ID</param>
478+
/// <param name="cancellationToken">A token to allow the call to be cancelled</param>
479+
/// <returns>Information about the wallet</returns>
480+
public async Task<(uint Id, WalletType Type)> CreateNFTWallet(string? didId = null, CancellationToken cancellationToken = default)
481+
{
482+
dynamic data = new ExpandoObject();
483+
data.wallet_type = "nft_wallet";
484+
if (!string.IsNullOrEmpty(didId))
485+
{
486+
data.did_id = didId;
487+
}
488+
489+
var response = await SendMessage("create_new_wallet", data, cancellationToken).ConfigureAwait(false);
490+
491+
return (
492+
(uint)response.id,
493+
(WalletType)response.type
494+
);
495+
}
496+
424497
/// <summary>
425498
/// Creates a new DID wallet
426499
/// </summary>

src/chia-dotnet/chia-dotnet.csproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<RootNamespace>chia.dotnet</RootNamespace>
66
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
77
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
8-
<Version>1.2.0</Version>
8+
<Version>1.4.0-beta-01</Version>
99
<Authors>dkackman</Authors>
1010
<Company>dkackman</Company>
1111
<Description>A .net 5 client library for chia™ RPC interfaces that runs on linux and windows.</Description>
@@ -16,11 +16,11 @@
1616
<RepositoryUrl>https://github.com/dkackman/chia-dotnet</RepositoryUrl>
1717
<RepositoryType>git</RepositoryType>
1818
<PackageTags>chia</PackageTags>
19-
<PackageReleaseNotes>Chia 1.3.5 support</PackageReleaseNotes>
19+
<PackageReleaseNotes>Chia 1.4.0 support</PackageReleaseNotes>
2020
<PackageIcon>chia-leaf-logo-384x384.png</PackageIcon>
2121
<PackageIconUrl />
22-
<AssemblyVersion>1.2.0.0</AssemblyVersion>
23-
<FileVersion>1.2.0.0</FileVersion>
22+
<AssemblyVersion>1.4.0.0</AssemblyVersion>
23+
<FileVersion>1.4.0.0</FileVersion>
2424
<Nullable>enable</Nullable>
2525
</PropertyGroup>
2626

0 commit comments

Comments
 (0)