From 852395777bd549e0a5a59d226f2d480160dd9a3f Mon Sep 17 00:00:00 2001 From: Don Kackman Date: Sat, 5 Aug 2023 15:37:48 -0500 Subject: [PATCH] Wallet 1 8 2 (#98) * through dl_owned_singletons * DL methods * nft_mint_bulk * nft updates * more nft stuffs * DID stuffs * remove using --- src/chia-dotnet/ChiaTypes/DidInfo.cs | 19 +++++++++++++ src/chia-dotnet/DIDWallet.cs | 40 ++++++++++++++++++++++------ src/chia-dotnet/NFTWallet.cs | 1 - src/chia-dotnet/WalletProxy.cs | 28 +++++++++++++++++++ 4 files changed, 79 insertions(+), 9 deletions(-) create mode 100644 src/chia-dotnet/ChiaTypes/DidInfo.cs diff --git a/src/chia-dotnet/ChiaTypes/DidInfo.cs b/src/chia-dotnet/ChiaTypes/DidInfo.cs new file mode 100644 index 00000000..bed7867d --- /dev/null +++ b/src/chia-dotnet/ChiaTypes/DidInfo.cs @@ -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 Metadata { get; init; } = new Dictionary(); + public string LauncherId { get; init; } = string.Empty; + public string FullPuzzle { get; init; } = string.Empty; + public string Solution { get; init; } = string.Empty; + public IEnumerable Hints { get; init; } = new List(); + } +} diff --git a/src/chia-dotnet/DIDWallet.cs b/src/chia-dotnet/DIDWallet.cs index 0c112d9e..d8f177d2 100644 --- a/src/chia-dotnet/DIDWallet.cs +++ b/src/chia-dotnet/DIDWallet.cs @@ -34,9 +34,11 @@ public override async Task Validate(CancellationToken cancellationToken = defaul /// Updates recovery ID's /// /// The new ids + /// The number of verifications required + /// /// A token to allow the call to be cancelled /// An awaitable - public async Task UpdateRecoveryIds(IEnumerable newList, CancellationToken cancellationToken = default) + public async Task UpdateRecoveryIds(IEnumerable newList, ulong? numVerificationsRequired = null, bool reusePuzhash = false, CancellationToken cancellationToken = default) { if (newList is null) { @@ -45,8 +47,13 @@ public async Task UpdateRecoveryIds(IEnumerable 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); } /// @@ -138,9 +145,22 @@ public async Task GetPubKey(CancellationToken cancellationToken = defaul /// The name public async Task 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; + /// + /// Spends a DID message. + /// + /// + /// + /// A token to allow the call to be cancelled + /// + public async Task MessageSpend(IEnumerable puzzleAnnouncements, IEnumerable coinAnnouncements, CancellationToken cancellationToken = default) + { + dynamic data = CreateWalletDataObject(); + data.coin_announcements = coinAnnouncements.ToList(); + data.puzzle_announcements = puzzleAnnouncements.ToList(); + return await WalletProxy.SendMessage("did_message_spend", data, "spend_bundle", cancellationToken).ConfigureAwait(false); } /// @@ -173,13 +193,15 @@ public async Task> GetMetadata(CancellationToken can /// Updates the metadata /// /// The name + /// /// Transaction fee /// A token to allow the call to be cancelled /// An awaitable - public async Task UpdateMetadata(string metadata, ulong fee = 0, CancellationToken cancellationToken = default) + public async Task 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("did_update_metadata", "spend_bundle", data, cancellationToken).ConfigureAwait(false); @@ -305,18 +327,20 @@ public async Task CreateBackupFile(CancellationToken cancellationToken = /// Transfer the DID wallet to another owner /// /// the address - /// Indiciator whether to include recovery infor + /// Indiciator whether to include recovery infor + /// /// Trasnaction fee /// A token to allow the call to be cancelled /// The backup data - public async Task Transfer(string innerAddress, bool withRecoveryInfo = true, ulong fee = 0, CancellationToken cancellationToken = default) + public async Task 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("did_create_backup_file", "transaction", data, cancellationToken).ConfigureAwait(false); + return await WalletProxy.SendMessage("did_transfer_did", "transaction", data, cancellationToken).ConfigureAwait(false); } } } diff --git a/src/chia-dotnet/NFTWallet.cs b/src/chia-dotnet/NFTWallet.cs index 700ad714..61e48961 100644 --- a/src/chia-dotnet/NFTWallet.cs +++ b/src/chia-dotnet/NFTWallet.cs @@ -1,5 +1,4 @@ using System.Collections.Generic; -using System.Dynamic; using System.Linq; using System.Threading; using System.Threading.Tasks; diff --git a/src/chia-dotnet/WalletProxy.cs b/src/chia-dotnet/WalletProxy.cs index 63a357af..d949e06d 100644 --- a/src/chia-dotnet/WalletProxy.cs +++ b/src/chia-dotnet/WalletProxy.cs @@ -772,5 +772,33 @@ public async Task>> CalculateRoyaltie var response = await SendMessage("nft_transfer_bulk", data, cancellationToken).ConfigureAwait(false); return (response.tx_num, Converters.ToObject(response.spend_bundle)); } + + /// + /// Retrieves information about a DID. + /// + /// + /// + /// A token to allow the call to be cancelled + /// + public async Task DidGetInfo(string coinId, bool latest = true, CancellationToken cancellationToken = default) + { + dynamic data = new ExpandoObject(); + data.coin_id = coinId; + data.latest = latest; + return await SendMessage("did_get_info", data, null, cancellationToken).ConfigureAwait(false); + } + + /// + /// Recover a missing or unspendable DID wallet by a coin id of the DID. + /// + /// + /// A token to allow the call to be cancelled + /// + public async Task DidFindLostDid(string coinId, CancellationToken cancellationToken = default) + { + dynamic data = new ExpandoObject(); + data.coin_id = coinId; + return await SendMessage("did_find_lost_did", data, "latest_coin_id", cancellationToken).ConfigureAwait(false); + } } }