MySQL
database.AppProtocolVersionToken
, StorePath
, PeerStrings
, MySqlConnectionString
properties MUST be filled to run the program.StorePath
, download and extract the latest mainnet snapshot to a desired location.
$ dotnet run --project ./NineChronicles.DataProvider.Executable/ --
dotnet ef database update -- [Connection String]
TransferAssetModel.cs
.In general, TxId
, BlockIndex
, Date
, and Timestamp
are useful to add as default properties in a model because these values will help with query speed when table size increases.
namespace NineChronicles.DataProvider.Store.Models
{
using System;
using System.ComponentModel.DataAnnotations;
public class TransferAssetModel
{
[Key]
public string? TxId { get; set; }
public long BlockIndex { get; set; }
public string? Sender { get; set; }
public string? Recipient { get; set; }
public decimal Amount { get; set; }
public DateOnly Date { get; set; }
public DateTimeOffset TimeStamp { get; set; }
}
}
- In [NineChronicles.DataProvider/NineChronicles.DataProvider/Store/NineChroniclesContext.cs](https://github.com/planetarium/NineChronicles.DataProvider/blob/development/NineChronicles.DataProvider/Store/NineChroniclesContext.cs), add a DbSet called `TransferAssets` and its description for reference.
// Table for storing TransferAsset actions
public DbSet
### 2. Create Store Method
- In [NineChronicles.DataProvider/NineChronicles.DataProvider/Store/MySqlStore.cs](https://github.com/planetarium/NineChronicles.DataProvider/blob/development/NineChronicles.DataProvider/Store/MySqlStore.cs), add a following method that stores the `TransferAsset` data into MySQL.
public void StoreTransferAsset(TransferAssetModel model) { using NineChroniclesContext ctx = _dbContextFactory.CreateDbContext(); TransferAssetModel? prevModel = ctx.TransferAssets.FirstOrDefault(r => r.TxId == model.TxId); if (prevModel is null) { ctx.TransferAssets.Add(model); } else { prevModel.BlockIndex = model.BlockIndex; prevModel.Sender = model.Sender; prevModel.Recipient = model.Recipient; prevModel.Amount = model..Amount; prevModel.Date = model.Date; prevModel.TimeStamp = model.TimeStamp; ctx.TransferAssets.Update(prevModel); }
ctx.SaveChanges();
}
### 3. (Optional) Add Data Getter
In some cases, you need to handle state to get data to make model.
To do this easily, you can make your own data getter inside [NineChronicles.DataProvider/DataRendering/](https://github.com/planetarium/NineChronicles.DataProvider/tree/development/NineChronicles.DataProvider/DataRendering).
### 4. Render & Store Action Data
- In [NineChronicles.DataProvider/NineChronicles.DataProvider/RenderSubscriber.cs](https://github.com/planetarium/NineChronicles.DataProvider/blob/development/NineChronicles.DataProvider/RenderSubscriber.cs), add a following render code
_actionRenderer.EveryRender
### 5. Add Database Migration
- Navigate to [NineChronicles.DataProvider/NineChronicles.DataProvider.Executable](https://github.com/planetarium/NineChronicles.DataProvider/tree/development/NineChronicles.DataProvider.Executable) directory on your terminal and run the following migration command
dotnet ef migrations add AddTransferAsset -- [Connection String]
NineChronicles.DataProvider
stores data into are listed in NineChroniclesContext.cs.DbSet
's comment in NineChroniclesContext.cs for table descriptions.offset
and limit
are provided to specify which block data to migrate.state
data in the blocks you want to migrate (If your chain store lacks the state
data, this tool will not work).
Usage: NineChronicles.DataProvider.Executable mysql-migration [--store-path <String>] [--mysql-server <String>] [--mysql-port <UInt32>] [--mysql-username <String>] [--mysql-password <String>] [--mysql-database <String>] [--offset <I
nt32>] [--limit <Int32>] [--help]
Migrate action data in rocksdb store to mysql db.
Options:
-o, --store-path
### Migrate Battle Arena Ranking Data
- This command calculates the `battle arena` ranking of all participants at a specific block index (`migration-block-index`) and inserts the data to a designated mysql database.
Usage: NineChronicles.DataProvider.Executable battle-arena-ranking-migration [--store-path
Migrate battle arena ranking data at a specific block index to a mysql database.
Options:
-o, --store-path
### Migrate User Staking Data
- This command calculates the `NCG staking amount` of all participants at a specific block index (`migration-block-index`) and inserts the data to a designated mysql database.
- Currently, the `slack-token` and `slack-channel` options for sending the data in `csv` format are required, however, these will be changed to optional in the near future.
Usage: NineChronicles.DataProvider.Executable user-staking-migration [--store-path
Migrate staking amounts of users at a specific block index to a mysql database.
Options:
-o, --store-path