Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
Ashuaidehao committed Aug 9, 2021
1 parent 98a33fe commit 84080cb
Showing 1 changed file with 39 additions and 26 deletions.
65 changes: 39 additions & 26 deletions neo3-gui/neo3-gui/Common/Scanners/ExecuteResultScanner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,21 @@ public async Task<bool> Sync(uint blockHeight)
return true;
}


var block = blockHeight.GetBlock();
var blockTime = block.Timestamp.FromTimestampMS();
if (blockHeight == 0)
{
SyncNativeContracts(blockTime);
}

if (block.Transactions.Length == 0)
{
_db.AddSyncIndex(blockHeight);
return true;
}

SyncContracts(blockHeight, blockTime);

foreach (var transaction in block.Transactions)
{
Expand All @@ -108,7 +121,6 @@ public async Task<bool> Sync(uint blockHeight)
//}
}

SyncContracts(blockHeight, blockTime);

var transfers = new List<TransferInfo>();
var transferItems = _levelDb.GetTransfers(blockHeight);
Expand Down Expand Up @@ -163,38 +175,39 @@ public async Task<bool> Sync(uint blockHeight)
}


private void SyncNativeContracts(DateTime blockTime)
{
foreach (var nativeContract in NativeContract.Contracts)
{
var entity = new ContractEntity()
{
Name = nativeContract.Name,
Hash = nativeContract.Hash.ToBigEndianHex(),
CreateTime = blockTime,
};
if (nativeContract is NeoToken neo)
{
entity.Symbol = neo.Symbol;
entity.Decimals = neo.Decimals;
entity.AssetType = AssetType.Nep17;
}
if (nativeContract is GasToken gas)
{
entity.Symbol = gas.Symbol;
entity.Decimals = gas.Decimals;
entity.AssetType = AssetType.Nep17;
}
_db.CreateContract(entity);
}
}

/// <summary>
/// sync contract create\update\delete state
/// </summary>
/// <param name="blockHeight"></param>
/// <param name="blockTime"></param>
private void SyncContracts(uint blockHeight, DateTime blockTime)
{
if (blockHeight == 0)
{
foreach (var nativeContract in NativeContract.Contracts)
{
var entity = new ContractEntity()
{
Name = nativeContract.Name,
Hash = nativeContract.Hash.ToBigEndianHex(),
CreateTime = blockTime,
};
if (nativeContract is NeoToken neo)
{
entity.Symbol = neo.Symbol;
entity.Decimals = neo.Decimals;
entity.AssetType = AssetType.Nep17;
}
if (nativeContract is GasToken gas)
{
entity.Symbol = gas.Symbol;
entity.Decimals = gas.Decimals;
entity.AssetType = AssetType.Nep17;
}
_db.CreateContract(entity);
}
}
var contractEvents = _levelDb.GetContractEvent(blockHeight);
if (contractEvents.NotEmpty())
{
Expand Down

0 comments on commit 84080cb

Please sign in to comment.