Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DID stuffs #98

Merged
merged 10 commits into from
Aug 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions src/chia-dotnet/ChiaTypes/DidInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System.Collections.Generic;

namespace chia.dotnet
{
public record DidInfo
{
public string DidId { get; init; } = string.Empty;
public string LastestCoin { get; init; } = string.Empty;
public string P2Address { get; init; } = string.Empty;
public string PublicKey { get; init; } = string.Empty;
public string RecoveryListHash { get; init; } = string.Empty;
public int NumVerifications { get; init; }
public IDictionary<string, string> Metadata { get; init; } = new Dictionary<string, string>();
public string LauncherId { get; init; } = string.Empty;
public string FullPuzzle { get; init; } = string.Empty;
public string Solution { get; init; } = string.Empty;
public IEnumerable<string> Hints { get; init; } = new List<string>();
}
}
40 changes: 32 additions & 8 deletions src/chia-dotnet/DIDWallet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,11 @@ public override async Task Validate(CancellationToken cancellationToken = defaul
/// Updates recovery ID's
/// </summary>
/// <param name="newList">The new ids</param>
/// <param name="numVerificationsRequired">The number of verifications required</param>
/// <param name="reusePuzhash"></param>
/// <param name="cancellationToken">A token to allow the call to be cancelled</param>
/// <returns>An awaitable <see cref="Task"/></returns>
public async Task UpdateRecoveryIds(IEnumerable<string> newList, CancellationToken cancellationToken = default)
public async Task UpdateRecoveryIds(IEnumerable<string> newList, ulong? numVerificationsRequired = null, bool reusePuzhash = false, CancellationToken cancellationToken = default)
{
if (newList is null)
{
Expand All @@ -45,8 +47,13 @@ public async Task UpdateRecoveryIds(IEnumerable<string> newList, CancellationTok

dynamic data = CreateWalletDataObject();
data.new_list = newList.ToList();
if (numVerificationsRequired is not null)
{
data.num_verifications_required = numVerificationsRequired;
}
data.reuse_puzhash = reusePuzhash;

_ = await WalletProxy.SendMessage("did_update_recovery_ids", data, cancellationToken).ConfigureAwait(false);
await WalletProxy.SendMessage("did_update_recovery_ids", data, cancellationToken).ConfigureAwait(false);
}

/// <summary>
Expand Down Expand Up @@ -138,9 +145,22 @@ public async Task<string> GetPubKey(CancellationToken cancellationToken = defaul
/// <returns>The name</returns>
public async Task<string> GetName(CancellationToken cancellationToken = default)
{
var response = await WalletProxy.SendMessage("did_get_wallet_name", CreateWalletDataObject(), cancellationToken).ConfigureAwait(false);
return await WalletProxy.SendMessage("did_get_wallet_name", CreateWalletDataObject(), "name", cancellationToken).ConfigureAwait(false);
}

return response.name;
/// <summary>
/// Spends a DID message.
/// </summary>
/// <param name="puzzleAnnouncements"></param>
/// <param name="coinAnnouncements"></param>
/// <param name="cancellationToken">A token to allow the call to be cancelled</param>
/// <returns><see cref="SpendBundle"/></returns>
public async Task<SpendBundle> MessageSpend(IEnumerable<string> puzzleAnnouncements, IEnumerable<string> coinAnnouncements, CancellationToken cancellationToken = default)
{
dynamic data = CreateWalletDataObject();
data.coin_announcements = coinAnnouncements.ToList();
data.puzzle_announcements = puzzleAnnouncements.ToList();
return await WalletProxy.SendMessage<SpendBundle>("did_message_spend", data, "spend_bundle", cancellationToken).ConfigureAwait(false);
}

/// <summary>
Expand Down Expand Up @@ -173,13 +193,15 @@ public async Task<IDictionary<string, string>> GetMetadata(CancellationToken can
/// Updates the metadata
/// </summary>
/// <param name="metadata">The name</param>
/// <param name="reusePuzhash"></param>
/// <param name="fee">Transaction fee</param>
/// <param name="cancellationToken">A token to allow the call to be cancelled</param>
/// <returns>An awaitable <see cref="Task"/></returns>
public async Task<SpendBundle> UpdateMetadata(string metadata, ulong fee = 0, CancellationToken cancellationToken = default)
public async Task<SpendBundle> UpdateMetadata(string metadata, bool reusePuzhash = false, ulong fee = 0, CancellationToken cancellationToken = default)
{
dynamic data = CreateWalletDataObject();
data.metadata = metadata;
data.reuse_puzhash = reusePuzhash;
data.fee = fee;

return await WalletProxy.SendMessage<SpendBundle>("did_update_metadata", "spend_bundle", data, cancellationToken).ConfigureAwait(false);
Expand Down Expand Up @@ -305,18 +327,20 @@ public async Task<string> CreateBackupFile(CancellationToken cancellationToken =
/// Transfer the DID wallet to another owner
/// </summary>
/// <param name="innerAddress">the address</param>
/// <param name="wtihRecoveryInfo">Indiciator whether to include recovery infor</param>
/// <param name="withRecoveryInfo">Indiciator whether to include recovery infor</param>
/// <param name="reusePuzhash"></param>
/// <param name="fee">Trasnaction fee</param>
/// <param name="cancellationToken">A token to allow the call to be cancelled</param>
/// <returns>The backup data</returns>
public async Task<TransactionRecord> Transfer(string innerAddress, bool withRecoveryInfo = true, ulong fee = 0, CancellationToken cancellationToken = default)
public async Task<TransactionRecord> Transfer(string innerAddress, bool withRecoveryInfo = true, bool reusePuzhash = false, ulong fee = 0, CancellationToken cancellationToken = default)
{
dynamic data = CreateWalletDataObject();
data.inner_address = innerAddress;
data.with_recovery_info = withRecoveryInfo;
data.reuse_puzhash = reusePuzhash;
data.fee = fee;

return await WalletProxy.SendMessage<TransactionRecord>("did_create_backup_file", "transaction", data, cancellationToken).ConfigureAwait(false);
return await WalletProxy.SendMessage<TransactionRecord>("did_transfer_did", "transaction", data, cancellationToken).ConfigureAwait(false);
}
}
}
1 change: 0 additions & 1 deletion src/chia-dotnet/NFTWallet.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Collections.Generic;
using System.Dynamic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
Expand Down
28 changes: 28 additions & 0 deletions src/chia-dotnet/WalletProxy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -772,5 +772,33 @@ public async Task<IDictionary<string, IEnumerable<AssetInfo>>> CalculateRoyaltie
var response = await SendMessage("nft_transfer_bulk", data, cancellationToken).ConfigureAwait(false);
return (response.tx_num, Converters.ToObject<SpendBundle>(response.spend_bundle));
}

/// <summary>
/// Retrieves information about a DID.
/// </summary>
/// <param name="coinId"></param>
/// <param name="latest"></param>
/// <param name="cancellationToken">A token to allow the call to be cancelled</param>
/// <returns><see cref=""/></returns>
public async Task<DidInfo> DidGetInfo(string coinId, bool latest = true, CancellationToken cancellationToken = default)
{
dynamic data = new ExpandoObject();
data.coin_id = coinId;
data.latest = latest;
return await SendMessage<DidInfo>("did_get_info", data, null, cancellationToken).ConfigureAwait(false);
}

/// <summary>
/// Recover a missing or unspendable DID wallet by a coin id of the DID.
/// </summary>
/// <param name="coinId"></param>
/// <param name="cancellationToken">A token to allow the call to be cancelled</param>
/// <returns><see cref="string"/></returns>
public async Task<string> DidFindLostDid(string coinId, CancellationToken cancellationToken = default)
{
dynamic data = new ExpandoObject();
data.coin_id = coinId;
return await SendMessage<string>("did_find_lost_did", data, "latest_coin_id", cancellationToken).ConfigureAwait(false);
}
}
}
Loading