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

update neo to 3.2.1 #8

Open
wants to merge 76 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 43 commits
Commits
Show all changes
76 commits
Select commit Hold shift + click to select a range
830f895
增加对于market合约的通知处理
vikkkko Nov 24, 2021
f4a6479
回退neo版本
vikkkko Nov 24, 2021
cf987b6
增加对destroy通知的处理
vikkkko Nov 25, 2021
2652189
add
vikkkko Nov 25, 2021
4f160fa
修改数据格式
vikkkko Nov 25, 2021
b4d8d09
market表增加timestamp字段
vikkkko Dec 3, 2021
810d1f7
修改market中的timestamp类型
vikkkko Dec 6, 2021
9090ecf
记录market通知中的nonce字段
vikkkko Dec 11, 2021
90b43cd
修复market过滤条件错误
vikkkko Dec 13, 2021
936dc35
update neo to v3.1
vikkkko Dec 16, 2021
47db7fd
更新market表的index
vikkkko Dec 16, 2021
6db427d
过滤异常的script
vikkkko Dec 20, 2021
274a8a4
增加索引
vikkkko Dec 21, 2021
0f0366e
增加totalburn和totalmint字段
vikkkko Dec 24, 2021
f4ebaed
修复合约update之后assettype没有变化的问题
vikkkko Dec 24, 2021
29addcf
marketnotification表增加market字段,适配多个market合约情况
vikkkko Jan 6, 2022
a377389
修复cancel事件中赋值错误的问题
vikkkko Jan 7, 2022
9031c24
fix获取marketid异常
vikkkko Jan 7, 2022
2a48f47
fix
vikkkko Jan 7, 2022
93644ac
修复gasburn计算total时的错误
vikkkko Jan 7, 2022
09356a1
修复gasburn中total计算错误
vikkkko Jan 7, 2022
cc27243
修复market表在同一高度index低的通知会覆盖index高的通知
vikkkko Jan 11, 2022
205e4d7
监听market新增的白名单通知
vikkkko Jan 12, 2022
a414b92
补上个提交遗漏
vikkkko Jan 12, 2022
5c3c822
修复地址类型bytestring解析为utf字符串类型时没有处理的问题
vikkkko Jan 12, 2022
cd813e4
GetNep11BalanceOf时增加uint160地址的多种判断
vikkkko Jan 13, 2022
2ac9129
修复market中数据丢失问题
vikkkko Jan 17, 2022
0137d34
更新market的索引
vikkkko Jan 18, 2022
e057b74
修复market中index的bug
vikkkko Jan 18, 2022
b3f70dc
fix bug
vikkkko Jan 18, 2022
0d7ab6b
修复交易中stacks过大导致的内存异常
vikkkko Mar 4, 2022
449506b
修改stack的限制
vikkkko Mar 8, 2022
dcc873e
限制runvm时的指令费用
vikkkko Mar 9, 2022
71eafe9
增加notification处理限制
vikkkko Mar 9, 2022
e0ad9cc
remove log
vikkkko Mar 9, 2022
6d3c802
修改对于notification数量的限制
vikkkko Mar 16, 2022
f66208e
优化合约更新删除时入库逻辑
vikkkko Mar 18, 2022
e80f7ca
增加nns setadmin通知监听
vikkkko Mar 30, 2022
5679700
过滤异常指令
vikkkko Apr 22, 2022
dc89ca6
过滤异常指令
vikkkko Apr 22, 2022
d9005e2
update neo to 3.2.1
vikkkko Apr 26, 2022
2361b04
Merge pull request #1 from vikkkko/3.2.1
vikkkko May 9, 2022
35bcf76
为nep11和nep17增加特殊的名单,以防有些token不加标识漏记录。
vikkkko May 18, 2022
5fe7a66
revert neo to 3.1.0
vikkkko Jun 10, 2022
4c548ef
fix bug
vikkkko Jun 10, 2022
8b7bf51
update to 331
vikkkko Jun 16, 2022
581f5ef
fix
vikkkko Jun 16, 2022
47ec05c
修复读取fura路径问题
vikkkko Jun 17, 2022
ee84ab9
增加market中offer相关事件的监听
vikkkko Jun 23, 2022
e9f869c
completeOffer通知增加售卖人的信息
vikkkko Jun 24, 2022
bcc6f62
增加market特殊事件处理
vikkkko Jul 5, 2022
086e966
completeOffer通知修改字段含义
vikkkko Jul 6, 2022
e4d2347
修复查询不存在的tokenid时报错的问题
vikkkko Aug 16, 2022
489360f
增加过大的decimal128处理
vikkkko Aug 22, 2022
03497cf
修复资产burn时没有更新totalsupply的问题
vikkkko Aug 22, 2022
478d67c
update neo to 340
vikkkko Sep 13, 2022
1d140cd
增加nns新的通知监控
vikkkko Sep 22, 2022
8ee2b20
增加自己发布的nft的特殊处理
vikkkko Oct 19, 2022
43eaf08
补交
vikkkko Oct 19, 2022
7ebbaf9
fix
vikkkko Oct 20, 2022
f539f34
fix
vikkkko Oct 20, 2022
8c446e0
fix
vikkkko Oct 20, 2022
88fb7bb
增加对nns的特殊处理
vikkkko Oct 20, 2022
52ccc77
适配market最新改动
vikkkko Oct 31, 2022
69ff019
update neo to 3.5.0
vikkkko Dec 8, 2022
d3f7736
提高每个交易最多处理notification的数量
vikkkko Jan 13, 2023
95fcd55
回滚错误修改
vikkkko Jan 17, 2023
3e8cf33
增加GetNep11BalanceOf异常处理
vikkkko Aug 28, 2023
879cd89
update neo to 3.6.0
vikkkko Sep 15, 2023
64f6bff
update to net7.0
vikkkko Sep 15, 2023
0852cb7
增加log
vikkkko Sep 24, 2023
0017e7c
增加log
vikkkko Sep 24, 2023
a92e774
add log
vikkkko Nov 13, 2023
140f512
add trycatch
vikkkko Nov 13, 2023
158f53e
update neo to 3.6.3
vikkkko Dec 4, 2023
1dc69db
fix
vikkkko Feb 28, 2024
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
4 changes: 2 additions & 2 deletions Converter/Converter.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<None Remove="Neo" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Neo" Version="3.0.2" />
<PackageReference Include="Neo" Version="3.0.3" />
</ItemGroup>
</Project>
8 changes: 8 additions & 0 deletions Fura/Cache/Cache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,14 @@ public static DBCache Ins
}
public CacheAddress cacheAddress { get; }
public CacheAddressAsset cacheAddressAsset { get; }
public CacheMarket cacheMarket { get; }
public CacheAsset cacheAsset { get; }
public CacheCandidate cacheCandidate { get; }
public CacheContract cacheContract { get; }
public CacheNep11TransferNotification cacheNep11TransferNotification { get; }
public CacheScVoteCall cacheScVoteCall { get; }
public CacheTransferNotification cacheTransferNotification;
public CacheMatketNotification cacheMatketNotification;
public CacheVote cacheVote { get; }
public CacheScCall cacheScCall { get; }
public CacheExecution cacheExecution { get; }
Expand All @@ -57,6 +59,9 @@ public DBCache()
cacheAddressAsset = new CacheAddressAsset();
caches.Add(cacheAddressAsset);

cacheMarket = new CacheMarket();
caches.Add(cacheMarket);

cacheAsset = new CacheAsset();
caches.Add(cacheAsset);

Expand All @@ -75,6 +80,9 @@ public DBCache()
cacheTransferNotification = new CacheTransferNotification();
caches.Add(cacheTransferNotification);

cacheMatketNotification = new CacheMatketNotification();
caches.Add(cacheMatketNotification);

cacheVote = new CacheVote();
caches.Add(cacheVote);

Expand Down
22 changes: 10 additions & 12 deletions Fura/Cache/Cache_Contract.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public class CacheContractParams
public UInt160 Hash;
public ulong Time;
public UInt256 Txid;
public bool IsDestroy;
}

public class CacheContract : IDBCache
Expand All @@ -33,9 +34,9 @@ public void Clear()
D_Contract = new ConcurrentDictionary<UInt160, CacheContractParams>();
}

public void AddNeedUpdate(UInt160 contractHash, ulong createTime, UInt256 txid)
public void AddNeedUpdate(UInt160 contractHash, ulong createTime, UInt256 txid, bool isDestroy = false)
{
D_Contract[contractHash] = new() { Hash = contractHash, Time = createTime, Txid = txid };
D_Contract[contractHash] = new() { Hash = contractHash, Time = createTime, Txid = txid , IsDestroy = isDestroy };
}

public List<CacheContractParams> GetNeedUpdate()
Expand All @@ -48,7 +49,7 @@ public void Update(NeoSystem system, DataCache snapshot)
List<CacheContractParams> list = GetNeedUpdate();
Parallel.For(0, list.Count, (i) =>
{
AddOrUpdate(list[i].Hash, snapshot, list[i].Time, list[i].Txid);
AddOrUpdate(list[i].Hash, snapshot, list[i].Time, list[i].Txid, list[i].IsDestroy);
});
}

Expand All @@ -64,24 +65,21 @@ public ContractModel Get(UInt160 contractHash)
}
}

public void AddOrUpdate(UInt160 contractHash, DataCache snapshot, ulong createTime, UInt256 txid)
public void AddOrUpdate(UInt160 contractHash, DataCache snapshot, ulong createTime, UInt256 txid, bool isDestroy)
{
ContractModel contractModel = Get(contractHash);
if (contractModel is null)

if (isDestroy)
{
StorageKey key = new KeyBuilder(Neo.SmartContract.Native.NativeContract.ContractManagement.Id, 8).Add(contractHash);
ContractState contract = snapshot.TryGet(key)?.GetInteroperable<ContractState>();
contractModel = new(contractHash, contract.Manifest.Name, contract.Id, contract.UpdateCounter, contract.Nef.ToJson(), contract.Manifest.ToJson(), createTime, txid);
contractModel = new ContractModel() { UpdateCounter = -1, CreateTime = createTime, Hash = contractHash, _ID = -999, CreateTxid = txid, Manifest = "", Name = "", Nef = ""};
}
else
{
if (contractModel.CreateTime == createTime)
return;
StorageKey key = new KeyBuilder(Neo.SmartContract.Native.NativeContract.ContractManagement.Id, 8).Add(contractHash);
ContractState contract = snapshot.TryGet(key)?.GetInteroperable<ContractState>();
if (contractModel.UpdateCounter == contract.UpdateCounter)
if (contractModel is not null && (contract is null || contractModel.CreateTxid == txid || contractModel.UpdateCounter == contract.UpdateCounter))
return;
contractModel = new(contractHash, contract.Manifest.Name, contract.Id, contract.UpdateCounter, contract.Nef.ToJson(), contract.Manifest.ToJson(), createTime, txid);
contractModel = new(contractHash, contract.Manifest.Name, contract.Id, (short)contract.UpdateCounter, contract.Nef.ToJson(), contract.Manifest.ToJson(), createTime, txid);
}
D_ContractModel[contractHash] = contractModel;
}
Expand Down
19 changes: 16 additions & 3 deletions Fura/Cache/Cache_GasMintBurn.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,24 @@ public void Clear()

public void Save(Transaction tran)
{
if(GasMintBurnParams.BlockIndex > 0 || GasMintBurnParams.BurnAmount > 0 || GasMintBurnParams.MintAmount > 0)
BigInteger totalBurnAmount = 0;
BigInteger totalMintAmount = 0;
if(GasMintBurnParams.BlockIndex > 0)
{
GasMintBurnModel gasMintBurnModel = new GasMintBurnModel() { BurnAmount = BsonDecimal128.Create(GasMintBurnParams.BurnAmount.ToString()), MintAmount = BsonDecimal128.Create(GasMintBurnParams.MintAmount.ToString()), BlockIndex = GasMintBurnParams.BlockIndex };
tran.SaveAsync(gasMintBurnModel).Wait();
//获取上一个块的total来计算本块的数据
GasMintBurnModel gasMintBurnModel_Pre = GasMintBurnModel.Get(GasMintBurnParams.BlockIndex - 1);
totalBurnAmount = BigInteger.Parse(gasMintBurnModel_Pre.TotalBurnAmount.ToString());
totalMintAmount = BigInteger.Parse(gasMintBurnModel_Pre.TotalMintAmount.ToString());
}
GasMintBurnModel gasMintBurnModel = new GasMintBurnModel()
{
BurnAmount = BsonDecimal128.Create(GasMintBurnParams.BurnAmount.ToString()),
TotalBurnAmount = BsonDecimal128.Create((totalBurnAmount + GasMintBurnParams.BurnAmount).ToString()),
MintAmount = BsonDecimal128.Create(GasMintBurnParams.MintAmount.ToString()),
TotalMintAmount = BsonDecimal128.Create((totalMintAmount + GasMintBurnParams.MintAmount).ToString()),
BlockIndex = GasMintBurnParams.BlockIndex
};
tran.SaveAsync(gasMintBurnModel).Wait();
}

public void Add(uint blockIndex, BigInteger burnAmount, BigInteger mintAmount)
Expand Down
173 changes: 173 additions & 0 deletions Fura/Cache/Cache_Market.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using MongoDB.Entities;
using Neo.Persistence;
using Neo.Plugins.Models;
using System.Numerics;
using System.Threading.Tasks;

namespace Neo.Plugins.Cache
{
public class CacheMarketParams
{
public int NotificationIndex;
public bool SimpleUpdate;
public UInt160 Owner;
public UInt160 Asset;
public string TokenId;
public BigInteger Amount;
public UInt160 Market;
public uint AuctionType;
public UInt160 Auctor;
public UInt160 AuctionAsset;
public BigInteger AuctionAmount;
public ulong Deadline;
public UInt160 Bidder;
public BigInteger BidAmount;
public BigInteger Timestamp;
}

public class CacheMarket : IDBCache
{
private ConcurrentDictionary<(UInt160, UInt160, string), CacheMarketParams> D_Market;

private ConcurrentDictionary<(UInt160, UInt160, string), MarketModel> D_MarketModel;

public void AddNeedUpdate(int notificationIndex, bool simpleUpdate, UInt160 asset, UInt160 owner, string tokenid, BigInteger timestamp)
{
lock (D_Market)
{
if (!D_Market.ContainsKey((asset, owner, tokenid)) || notificationIndex > D_Market[(asset, owner, tokenid)].NotificationIndex )
{
D_Market[(asset, owner, tokenid)] = new()
{
NotificationIndex = notificationIndex,
SimpleUpdate = simpleUpdate,
Asset = asset,
TokenId = tokenid,
Owner = owner,
Timestamp = timestamp
};
}
}

}

public void AddNeedUpdate(int notificationIndex, bool simpleUpdate, UInt160 asset, UInt160 owner, string tokenid, UInt160 market, BigInteger auctionType, UInt160 auctor, UInt160 auctionAsset, BigInteger auctionAmount, BigInteger deadline, UInt160 bidder, BigInteger bidAmount, BigInteger timestamp)
{
lock (D_Market)
{
if (!D_Market.ContainsKey((asset, owner, tokenid)) || notificationIndex > D_Market[(asset, owner, tokenid)].NotificationIndex)
{
D_Market[(asset, owner, tokenid)] = new()
{
SimpleUpdate = simpleUpdate,
Asset = asset,
TokenId = tokenid,
Owner = owner,
Market = market,
AuctionType = (uint)auctionType,
Auctor = auctor,
AuctionAsset = auctionAsset,
AuctionAmount = auctionAmount,
Deadline = (ulong)deadline,
Bidder = bidder,
BidAmount = bidAmount,
Timestamp = timestamp,
NotificationIndex = notificationIndex
};
}
}
}

public List<CacheMarketParams> GetNeedUpdate()
{
return D_Market.Values.ToList();
}

public void Update(NeoSystem system, DataCache snapshot)
{
List<CacheMarketParams> list = GetNeedUpdate();
Parallel.For(0, list.Count, (i) =>
{
list[i].Amount = Neo.Plugins.VM.Helper.GetNep11BalanceOf(system, snapshot, list[i].Asset, list[i].TokenId, list[i].Owner);
AddOrUpdate(list[i]);
});
}

public MarketModel Get(UInt160 owner, UInt160 asset, string tokenid)
{
if (D_MarketModel.ContainsKey((owner, asset, tokenid)))
{
return D_MarketModel[(owner, asset, tokenid)];
}
else
{
return MarketModel.Get(owner, asset, tokenid);
}
}

public void AddOrUpdate(CacheMarketParams cacheMarketParams)
{
if (cacheMarketParams.Owner == null || cacheMarketParams.Asset == null)
return;
MarketModel marketModel = Get(cacheMarketParams.Owner, cacheMarketParams.Asset, cacheMarketParams.TokenId);
if (marketModel is null)
{
marketModel = new MarketModel()
{
Asset = cacheMarketParams.Asset,
TokenId = cacheMarketParams.TokenId,
Owner = cacheMarketParams.Owner,
Amount = MongoDB.Bson.BsonDecimal128.Create(cacheMarketParams.Amount.ToString()),
Market = cacheMarketParams.Market,
AuctionType = cacheMarketParams.AuctionType,
AuctionAmount = MongoDB.Bson.BsonDecimal128.Create(cacheMarketParams.AuctionAmount.ToString()),
AuctionAsset = cacheMarketParams.AuctionAsset,
Auctor = cacheMarketParams.Auctor,
BidAmount = MongoDB.Bson.BsonDecimal128.Create(cacheMarketParams.BidAmount.ToString()),
Bidder = cacheMarketParams.Bidder,
Deadline = cacheMarketParams.Deadline,
Timestamp = (ulong)cacheMarketParams.Timestamp
};
}
else if(cacheMarketParams.SimpleUpdate)
{
marketModel.Timestamp = (ulong)cacheMarketParams.Timestamp;
marketModel.Amount = MongoDB.Bson.BsonDecimal128.Create(cacheMarketParams.Amount.ToString());
}
else
{
marketModel.Asset = cacheMarketParams.Asset;
marketModel.TokenId = cacheMarketParams.TokenId;
marketModel.Owner = cacheMarketParams.Owner;
marketModel.Amount = MongoDB.Bson.BsonDecimal128.Create(cacheMarketParams.Amount.ToString());
marketModel.Market = cacheMarketParams.Market;
marketModel.AuctionType = cacheMarketParams.AuctionType;
marketModel.AuctionAmount = MongoDB.Bson.BsonDecimal128.Create(cacheMarketParams.AuctionAmount.ToString());
marketModel.AuctionAsset = cacheMarketParams.AuctionAsset;
marketModel.Auctor = cacheMarketParams.Auctor;
marketModel.BidAmount = MongoDB.Bson.BsonDecimal128.Create(cacheMarketParams.BidAmount.ToString());
marketModel.Bidder = cacheMarketParams.Bidder;
marketModel.Deadline = cacheMarketParams.Deadline;
marketModel.Timestamp = (ulong)cacheMarketParams.Timestamp;
}
D_MarketModel[((marketModel.Owner, marketModel.Asset, marketModel.TokenId))] = marketModel;
}

public void Clear()
{
D_Market = new ConcurrentDictionary<(UInt160, UInt160, string), CacheMarketParams>();
D_MarketModel = new ConcurrentDictionary<(UInt160, UInt160, string), MarketModel>();
}

public void Save(Transaction tran)
{
if (D_MarketModel.Values.Count > 0)
tran.SaveAsync(D_MarketModel.Values).Wait();
}
}
}

41 changes: 41 additions & 0 deletions Fura/Cache/Cache_MarketNotification.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using System;
using System.Collections.Generic;
using Neo.Plugins.Models;
using System.Numerics;
using MongoDB.Entities;
using System.Collections.Concurrent;
using Neo.Persistence;

namespace Neo.Plugins.Cache
{
public class CacheMatketNotification : IDBCache
{
private ConcurrentBag<MarketNotificationModel> L_MarketNotificationModel;

public CacheMatketNotification()
{
L_MarketNotificationModel = new ConcurrentBag<MarketNotificationModel>();
}

public void Clear()
{
L_MarketNotificationModel = new ConcurrentBag<MarketNotificationModel>();
}

public void Add(UInt256 txid, UInt256 blockHash, UInt160 market, BigInteger nonce, UInt160 user, UInt160 asset, string tokenId, string eventName, string extendData, ulong timestamp)
{
MarketNotificationModel marketNotificationModel = new(txid, blockHash, nonce, user, market, asset, tokenId, eventName, extendData, timestamp);
L_MarketNotificationModel.Add(marketNotificationModel);
}

public void Update(NeoSystem system, DataCache snapshot)
{
}

public void Save(Transaction tran)
{
if (L_MarketNotificationModel.Count > 0)
tran.SaveAsync(L_MarketNotificationModel).Wait();
}
}
}
17 changes: 13 additions & 4 deletions Fura/Fura.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using System.Threading.Tasks;
using System.IO;
using System.Reflection;
using Neo.Plugins.Notification;

namespace Neo.Plugins
{
Expand Down Expand Up @@ -247,9 +248,17 @@ void ExecApplicationExecuted(Blockchain.ApplicationExecuted applicationExecuted,
executionModel = new ExecutionModel(applicationExecuted.Transaction.Hash, block.Hash, block.Timestamp, applicationExecuted.Trigger.ToString(), applicationExecuted.VMState.ToString(), applicationExecuted.Exception?.ToString(), applicationExecuted.GasConsumed, applicationExecuted.Stack); ;
if(executionModel.VmState == "HALT")
{
//通过解析script得到调用了哪些合约哪些方法,从而处理一些特殊数据
list_ScCall = VM.Helper.Script2ScCallModels(applicationExecuted.Transaction.Script, applicationExecuted.Transaction.Hash, applicationExecuted.Transaction.Sender, applicationExecuted.VMState.ToString());
}
try
{
//通过解析script得到调用了哪些合约哪些方法,从而处理一些特殊数据
list_ScCall = VM.Helper.Script2ScCallModels(applicationExecuted.Transaction.Script, applicationExecuted.Transaction.Hash, applicationExecuted.Transaction.Sender, applicationExecuted.VMState.ToString());
}
catch(Exception e)
{
DebugModel debugModel = new(e.Message);
debugModel.SaveAsync().Wait();
}
}
}
else
{
Expand All @@ -270,7 +279,7 @@ void ExecApplicationExecuted(Blockchain.ApplicationExecuted applicationExecuted,
var notificationModel = new NotificationModel(executionModel.Txid, i, executionModel.BlockHash, executionModel.Timestamp, n.ScriptHash, n.EventName, executionModel.VmState, n.State);
notificationModels.Add(notificationModel);
}
if (notificationModels.Count > 0)
if (notificationModels.Count > 0 && notificationModels.Count < 500)
{
DBCache.Ins.cacheNotification.Add(notificationModels);
NotificationMgr.Ins.Filter(notificationModels, system, block, snapshot);
Expand Down
Loading