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

NFT updates #95

Merged
merged 7 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
2 changes: 1 addition & 1 deletion src/CodeGen/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ private static string GetMethodBody(string dataInitialization, string? fullRetur
return schema.Properties.Keys.FirstOrDefault();
}

throw new InvalidOperationException("Could not determine result key from schema");
return null;
}


Expand Down
2 changes: 1 addition & 1 deletion src/CodeGen/Properties/launchSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"profiles": {
"CodeGen": {
"commandName": "Project",
"commandLineArgs": "C:\\Users\\don\\src\\github\\dkackman\\chia-api\\src\\wallet.yaml dl_singletons_by_root SingletonRecord"
"commandLineArgs": "C:\\Users\\don\\src\\github\\dkackman\\chia-api\\src\\wallet.yaml nft_calculate_royalties"
}
}
}
22 changes: 22 additions & 0 deletions src/chia-dotnet/ChiaTypes/Asset.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
namespace chia.dotnet
{
public record AssetInfo
{
public string Asset { get; init; } = string.Empty;
public string Address { get; init; } = string.Empty;
public ulong Amount { get; init; }
}

public record FungibleAsset
{
public string Asset { get; init; } = string.Empty;
public ulong Amount { get; init; }
}

public record RoyaltyAsset
{
public string Asset { get; init; } = string.Empty;
public string RoyaltyAddress { get; init; } = string.Empty;
public ushort RoyaltyPercentage { get; init; }
}
}
41 changes: 41 additions & 0 deletions src/chia-dotnet/ChiaTypes/NFTBulkMintingInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using System.Collections.Generic;

namespace chia.dotnet
{
/// <summary>
/// Info for minting NFTs in bulk
/// </summary>
public record NFTBulkMintingInfo
{
public string? RoyaltyAddress { get; init; } = string.Empty;
public ushort? RoyaltyPercentage { get; init; }
public IEnumerable<NftMintEntry> MetadataList { get; init; } = new List<NftMintEntry>();
/// <summary>
/// a list of targets for transferring minted NFTs (aka airdrop)
/// </summary>
public IEnumerable<string>? TargetList { get; init; }
/// <summary>
/// The starting point for mint number used in intermediate launcher puzzle
/// </summary>
public int MintNumberStart { get; init; } = 1;
/// <summary>
/// The total number of NFTs being minted
/// </summary>
public int? MintTotal { get; init; }
/// <summary>
/// For use with bulk minting to provide the coin used for funding the minting spend.
/// This coin can be one that will be created in the future
/// </summary>
public IEnumerable<Coin>? XchCoins { get; init; }
/// <summary>
/// For use with bulk minting, so we can specify the puzzle hash that the change
// from the funding transaction goes to.
/// </summary>
public string? XchChangeTarget { get; init; }
public string? NewInnerpuzhash { get; init; }
public string? NewP2Puzhash { get; init; }
public Coin? DidCoin { get; init; }
public string? DidLineageParentHex { get; init; }
public bool MintFromDid { get; init; }
}
}
2 changes: 1 addition & 1 deletion src/chia-dotnet/ChiaTypes/NFTInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public record NFTInfo
/// <summary>
/// Hash of the metadata
/// </summary>
public string MetaataHash { get; init; } = string.Empty;
public string MetadataHash { get; init; } = string.Empty;
/// <summary>
/// A list of license URIs
/// </summary>
Expand Down
20 changes: 12 additions & 8 deletions src/chia-dotnet/ChiaTypes/NFTMintingInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,9 @@

namespace chia.dotnet
{
/// <summary>
/// Info for minting an NFT
/// </summary>
public record NFTMintingInfo
public record NftMintEntry
{
public string RoyaltyAddress { get; init; } = string.Empty;
public string TargetAddress { get; init; } = string.Empty;
public string? DIDID { get; init; }
public ushort RoyaltyPercentage { get; init; } = 0;
public ushort RoyaltyPercentage { get; init; }
public IEnumerable<string> Uris { get; init; } = new List<string>();
public string Hash { get; init; } = string.Empty;
public IEnumerable<string> MetaUris { get; init; } = new List<string>();
Expand All @@ -20,4 +14,14 @@ public record NFTMintingInfo
public ulong EditionTotal { get; init; } = 1;
public ulong EditionNumber { get; init; } = 1;
}

/// <summary>
/// Info for minting an NFT
/// </summary>
public record NFTMintingInfo : NftMintEntry
{
public string? RoyaltyAddress { get; init; } = string.Empty;
public string? TargetAddress { get; init; }
public string? DidId { get; init; }
}
}
10 changes: 10 additions & 0 deletions src/chia-dotnet/ChiaTypes/NftCoinInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace chia.dotnet
{
public record NftCoinInfo
{

public string NftCoinId { get; init; } = string.Empty;

public int WalletId { get; init; }
}
}
14 changes: 14 additions & 0 deletions src/chia-dotnet/Converters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,20 @@ internal static class Converters
});
}

public static IDictionary<TKey, TValue> ToDictionary<TKey, TValue>(dynamic dictionary)
{
// TODO - this mneeds a unit test
// good data example here https://docs.chia.net/nft-rpc?_highlight=nft_calculate_royalties#nft_calculate_royalties
Debug.Assert(dictionary is not null);
// we're just gonna re-round trip this for now
var settings = new JsonSerializerSettings
{
ContractResolver = new DefaultContractResolver { NamingStrategy = new SnakeCaseNamingStrategy() }
};
var jsonString = JsonConvert.SerializeObject(dictionary, settings);
return JsonConvert.DeserializeObject<IDictionary<TKey, TValue>>(jsonString, settings);
}

public static IEnumerable<T> ToEnumerable<T>(dynamic enumerable)
{
Debug.Assert(enumerable is not null);
Expand Down
2 changes: 1 addition & 1 deletion src/chia-dotnet/DIDWallet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public async Task Spend(string puzzlehash, CancellationToken cancellationToken =
/// </summary>
/// <param name="cancellationToken">A token to allow the call to be cancelled</param>
/// <returns>A DID and optional CoinID</returns>
public async Task<(string MyDID, string? CoinID)> GetDID(CancellationToken cancellationToken = default)
public async Task<(string MyDid, string? CoinID)> GetDid(CancellationToken cancellationToken = default)
{
var response = await WalletProxy.SendMessage("did_get_did", CreateWalletDataObject(), cancellationToken).ConfigureAwait(false);

Expand Down
18 changes: 1 addition & 17 deletions src/chia-dotnet/DataLayerWallet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,27 +30,11 @@ public override async Task Validate(CancellationToken cancellationToken = defaul
await Validate(WalletType.DATA_LAYER, cancellationToken).ConfigureAwait(false);
}

/// <summary>
/// Initialize the new data layer wallets.
/// </summary>
/// <param name="root"></param>
/// <param name="fee"></param>
/// <param name="cancellationToken">A token to allow the call to be cancelled</param>
/// <returns><see cref=""/></returns>
public async Task<(IEnumerable<TransactionRecord> Transactions, string LauncherId)> CreateNewDl(string root, ulong fee = 0, CancellationToken cancellationToken = default)
{
dynamic data = new ExpandoObject();
data.root = root;
data.fee = fee;
var response = await WalletProxy.SendMessage("create_new_dl", data, cancellationToken).ConfigureAwait(false);
return (Converters.ToEnumerable<TransactionRecord>(response.transactions), response.launcher_id);
}

/// <summary>
/// Remove an existing mirror for a specific singleton.
/// </summary>
/// <param name="fee"></param>
/// <param name="coinId"></param>
/// <param name="fee"></param>
/// <param name="cancellationToken">A token to allow the call to be cancelled</param>
/// <returns>A list of <see cref="TransactionRecord"/></returns>
public async Task<IEnumerable<TransactionRecord>> DeleteMirror(string coinId, ulong fee = 0, CancellationToken cancellationToken = default)
Expand Down
Loading