diff --git a/src/Blockcore.Indexer.Cirrus/Models/QueryAddressAsset.cs b/src/Blockcore.Indexer.Cirrus/Models/QueryAddressAsset.cs index d75ee2e..9acef1f 100644 --- a/src/Blockcore.Indexer.Cirrus/Models/QueryAddressAsset.cs +++ b/src/Blockcore.Indexer.Cirrus/Models/QueryAddressAsset.cs @@ -8,6 +8,8 @@ public class QueryAddressAsset public string Creator { get; set; } public string Uri { get; set; } public bool IsBurned { get; set; } + + public bool IsUsed { get; set; } public long? PricePaid { get; set; } public string TransactionId { get; set; } diff --git a/src/Blockcore.Indexer.Cirrus/Storage/Mongo/CirrusMongoData.cs b/src/Blockcore.Indexer.Cirrus/Storage/Mongo/CirrusMongoData.cs index 16ab73a..4f6abc2 100644 --- a/src/Blockcore.Indexer.Cirrus/Storage/Mongo/CirrusMongoData.cs +++ b/src/Blockcore.Indexer.Cirrus/Storage/Mongo/CirrusMongoData.cs @@ -407,6 +407,7 @@ public async Task> GetNonFungibleTokensForAddress Id = _.Id.TokenId, Uri = _.Uri, IsBurned = _.IsBurned, + IsUsed = _.IsUsed, TransactionId = _.SalesHistory.LastOrDefault()?.TransactionId, PricePaid = _.SalesHistory.LastOrDefault() switch { diff --git a/src/Blockcore.Indexer.Cirrus/Storage/Mongo/SmartContracts/NonFungibleToken/GetMethodsLogReader.cs b/src/Blockcore.Indexer.Cirrus/Storage/Mongo/SmartContracts/NonFungibleToken/GetMethodsLogReader.cs new file mode 100644 index 0000000..1981b50 --- /dev/null +++ b/src/Blockcore.Indexer.Cirrus/Storage/Mongo/SmartContracts/NonFungibleToken/GetMethodsLogReader.cs @@ -0,0 +1,15 @@ +using Blockcore.Indexer.Cirrus.Client.Types; +using Blockcore.Indexer.Cirrus.Storage.Mongo.Types; +using MongoDB.Driver; + +namespace Blockcore.Indexer.Cirrus.Storage.Mongo.SmartContracts.NonFungibleToken; + +public class GetMethodsLogReader : ILogReader +{ + public bool CanReadLogForMethodType(string methodType) => methodType is "TokenURI" or "RoyaltyInfo"; + + public bool IsTransactionLogComplete(LogResponse[] logs) => true; + + public WriteModel[] UpdateContractFromTransactionLog(CirrusContractTable contractTransaction, + NonFungibleTokenContractTable computedTable) => new WriteModel[]{}; +} diff --git a/src/Blockcore.Indexer.Cirrus/Storage/Mongo/SmartContracts/NonFungibleToken/MarkAsUsedLogReader.cs b/src/Blockcore.Indexer.Cirrus/Storage/Mongo/SmartContracts/NonFungibleToken/MarkAsUsedLogReader.cs new file mode 100644 index 0000000..4a1890d --- /dev/null +++ b/src/Blockcore.Indexer.Cirrus/Storage/Mongo/SmartContracts/NonFungibleToken/MarkAsUsedLogReader.cs @@ -0,0 +1,31 @@ +using System; +using System.Linq; +using Blockcore.Indexer.Cirrus.Client.Types; +using Blockcore.Indexer.Cirrus.Storage.Mongo.Types; +using MongoDB.Driver; + +namespace Blockcore.Indexer.Cirrus.Storage.Mongo.SmartContracts.NonFungibleToken; + +public class MarkAsUsedLogReader : ILogReader +{ + public bool CanReadLogForMethodType(string methodType) => methodType.Equals("MarkAsUsed"); + + public bool IsTransactionLogComplete(LogResponse[] logs) => logs?.Any(_ => _.Log.Event == "MarkAsUsedLog") ?? false; + + public WriteModel[] UpdateContractFromTransactionLog(CirrusContractTable contractTransaction, + NonFungibleTokenContractTable computedTable) + { + var log = contractTransaction.Logs.FirstOrDefault(_ => _.Log.Event == "MarkAsUsedLog")?.Log + ?? throw new InvalidOperationException($"missing MarkAsUsedLog in MarkAsRead transaction - {contractTransaction.TransactionId}"); + + object tokenId = log.Data["tokenId"]; + string id = tokenId is string ? (string)tokenId : Convert.ToString(tokenId); + + return new[] + { + new UpdateOneModel(Builders.Filter + .Where(_ => _.Id.TokenId == tokenId && _.Id.ContractAddress == computedTable.ContractAddress), + Builders.Update.Set(_ => _.IsUsed, true)) + }; + } +} diff --git a/src/Blockcore.Indexer.Cirrus/Storage/Mongo/SmartContracts/NonFungibleToken/SafeMintLogReader.cs b/src/Blockcore.Indexer.Cirrus/Storage/Mongo/SmartContracts/NonFungibleToken/SafeMintLogReader.cs index 37e1a9c..6faace0 100644 --- a/src/Blockcore.Indexer.Cirrus/Storage/Mongo/SmartContracts/NonFungibleToken/SafeMintLogReader.cs +++ b/src/Blockcore.Indexer.Cirrus/Storage/Mongo/SmartContracts/NonFungibleToken/SafeMintLogReader.cs @@ -16,9 +16,9 @@ public class SafeMintLogReader : ILogReader[] UpdateContractFromTransactionLog(CirrusContractTable contractTransaction, NonFungibleTokenContractTable computedTable) { - LogData log = contractTransaction.Logs[0].Log; - LogData saleLog = contractTransaction.Logs[1].Log; - LogData uriLog = contractTransaction.Logs[2].Log; + LogData log = contractTransaction.Logs.First(_ => _.Log.Event == "TransferLog").Log; + LogData saleLog = contractTransaction.Logs[1].Log; //TODO change this to get a list from sales event reader + LogData uriLog = contractTransaction.Logs.First(_ => _.Log.Event == "MintExtract").Log; object tokenId = log.Data["tokenId"]; string id = tokenId is string ? (string)tokenId : Convert.ToString(tokenId); diff --git a/src/Blockcore.Indexer.Cirrus/Storage/Mongo/SmartContracts/NonFungibleToken/SetRoyaltiesLogReader.cs b/src/Blockcore.Indexer.Cirrus/Storage/Mongo/SmartContracts/NonFungibleToken/SetRoyaltiesLogReader.cs new file mode 100644 index 0000000..aad0413 --- /dev/null +++ b/src/Blockcore.Indexer.Cirrus/Storage/Mongo/SmartContracts/NonFungibleToken/SetRoyaltiesLogReader.cs @@ -0,0 +1,21 @@ +using System; +using Blockcore.Indexer.Cirrus.Client.Types; +using Blockcore.Indexer.Cirrus.Storage.Mongo.Types; +using MongoDB.Driver; + +namespace Blockcore.Indexer.Cirrus.Storage.Mongo.SmartContracts.NonFungibleToken; + +public class SetRoyaltiesLogReader : ILogReader +{ + public bool CanReadLogForMethodType(string methodType) => methodType is "SetRoyalties"; + + public bool IsTransactionLogComplete(LogResponse[] logs) => logs.Length > 0; + + public WriteModel[] UpdateContractFromTransactionLog(CirrusContractTable contractTransaction, + NonFungibleTokenContractTable computedTable) + { + //TODO the logs are empty for this method so we need to find another way to get the data + + return new WriteModel[]{}; + } +} diff --git a/src/Blockcore.Indexer.Cirrus/Storage/Mongo/Types/NonFungibleTokenTable.cs b/src/Blockcore.Indexer.Cirrus/Storage/Mongo/Types/NonFungibleTokenTable.cs index 555d886..d327e9e 100644 --- a/src/Blockcore.Indexer.Cirrus/Storage/Mongo/Types/NonFungibleTokenTable.cs +++ b/src/Blockcore.Indexer.Cirrus/Storage/Mongo/Types/NonFungibleTokenTable.cs @@ -8,6 +8,6 @@ public class NonFungibleTokenTable : SmartContractData public string Owner { get; set; } public string Uri { get; set; } public bool IsBurned { get; set; } - + public bool IsUsed { get; set; } public List SalesHistory { get; set; } = new(); }