-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added handling of new Smart contracts (#189)
* Added mark as used for NFTs * Added readers for methods that can not be indexed --------- Co-authored-by: TheDude <[email protected]>
- Loading branch information
1 parent
39cfbae
commit f8a0ad7
Showing
7 changed files
with
74 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
...kcore.Indexer.Cirrus/Storage/Mongo/SmartContracts/NonFungibleToken/GetMethodsLogReader.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<NonFungibleTokenContractTable,NonFungibleTokenTable> | ||
{ | ||
public bool CanReadLogForMethodType(string methodType) => methodType is "TokenURI" or "RoyaltyInfo"; | ||
|
||
public bool IsTransactionLogComplete(LogResponse[] logs) => true; | ||
|
||
public WriteModel<NonFungibleTokenTable>[] UpdateContractFromTransactionLog(CirrusContractTable contractTransaction, | ||
NonFungibleTokenContractTable computedTable) => new WriteModel<NonFungibleTokenTable>[]{}; | ||
} |
31 changes: 31 additions & 0 deletions
31
...kcore.Indexer.Cirrus/Storage/Mongo/SmartContracts/NonFungibleToken/MarkAsUsedLogReader.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<NonFungibleTokenContractTable,NonFungibleTokenTable> | ||
{ | ||
public bool CanReadLogForMethodType(string methodType) => methodType.Equals("MarkAsUsed"); | ||
|
||
public bool IsTransactionLogComplete(LogResponse[] logs) => logs?.Any(_ => _.Log.Event == "MarkAsUsedLog") ?? false; | ||
|
||
public WriteModel<NonFungibleTokenTable>[] 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<NonFungibleTokenTable>(Builders<NonFungibleTokenTable>.Filter | ||
.Where(_ => _.Id.TokenId == tokenId && _.Id.ContractAddress == computedTable.ContractAddress), | ||
Builders<NonFungibleTokenTable>.Update.Set(_ => _.IsUsed, true)) | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
...ore.Indexer.Cirrus/Storage/Mongo/SmartContracts/NonFungibleToken/SetRoyaltiesLogReader.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<NonFungibleTokenContractTable,NonFungibleTokenTable> | ||
{ | ||
public bool CanReadLogForMethodType(string methodType) => methodType is "SetRoyalties"; | ||
|
||
public bool IsTransactionLogComplete(LogResponse[] logs) => logs.Length > 0; | ||
|
||
public WriteModel<NonFungibleTokenTable>[] 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<NonFungibleTokenTable>[]{}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters