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

fix balance not change for non-transfer tx #181

Merged
merged 18 commits into from
Mar 11, 2020
15 changes: 13 additions & 2 deletions src/RpcNep5Tracker/RpcNep5Tracker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using Neo.Network.P2P.Payloads;
using Neo.Persistence;
using Neo.SmartContract;
using Neo.SmartContract.Native;
using Neo.VM;
using Neo.Wallets;
using System;
Expand Down Expand Up @@ -107,6 +108,8 @@ private void RecordTransferHistory(StoreView snapshot, UInt160 scriptHash, UInt1
var eventName = stateItems[0].GetString();
if (eventName != "Transfer") return;
if (stateItems.Count < 4) return;
if (stateItems[1] is VM.Types.Null) stateItems[1] = null;
bettybao1209 marked this conversation as resolved.
Show resolved Hide resolved
if (stateItems[2] is VM.Types.Null) stateItems[2] = null;

if (!(stateItems[1] is null) && !(stateItems[1] is VM.Types.ByteArray))
return;
Expand All @@ -120,17 +123,19 @@ private void RecordTransferHistory(StoreView snapshot, UInt160 scriptHash, UInt1
byte[] toBytes = stateItems[2]?.GetSpan().ToArray();
if (toBytes?.Length != 20) toBytes = null;
Tommo-L marked this conversation as resolved.
Show resolved Hide resolved
if (fromBytes == null && toBytes == null) return;
shargon marked this conversation as resolved.
Show resolved Hide resolved
var from = new UInt160(fromBytes);
var to = new UInt160(toBytes);
var from = UInt160.Zero;
var to = UInt160.Zero;

if (fromBytes != null)
{
from = new UInt160(fromBytes);
var fromKey = new Nep5BalanceKey(from, scriptHash);
if (!nep5BalancesChanged.ContainsKey(fromKey)) nep5BalancesChanged.Add(fromKey, new Nep5Balance());
}

if (toBytes != null)
{
to = new UInt160(toBytes);
var toKey = new Nep5BalanceKey(to, scriptHash);
if (!nep5BalancesChanged.ContainsKey(toKey)) nep5BalancesChanged.Add(toKey, new Nep5Balance());
}
Expand All @@ -156,6 +161,12 @@ public void OnPersist(StoreView snapshot, IReadOnlyList<Blockchain.ApplicationEx
HandleNotification(snapshot, transaction, notifyEventArgs.ScriptHash, stateItems,
nep5BalancesChanged, ref transferIndex);
}

// Handle SystemFee and NetworkFee GAS burn for each transaction
if (!(appExecuted.Transaction is Transaction tx)) continue;
bettybao1209 marked this conversation as resolved.
Show resolved Hide resolved
HandleNotification(snapshot, appExecuted.Transaction, NativeContract.GAS.Hash,
new VM.Types.Array(new VM.Types.StackItem[] { "Transfer", appExecuted.Transaction.Sender.ToArray(), VM.Types.StackItem.Null, tx.SystemFee + tx.NetworkFee }),
nep5BalancesChanged, ref transferIndex);
}

foreach (var nep5BalancePair in nep5BalancesChanged)
Expand Down