private void HandleNotification(Snapshot snapshot, Transaction transaction, UInt160 scriptHash, VM.Types.Array stateItems, Dictionary <Nep5BalanceKey, Nep5Balance> nep5BalancesChanged, ref ushort transferIndex) { if (stateItems.Count == 0) { return; } // Event name should be encoded as a byte array. if (!(stateItems[0] is VM.Types.ByteArray)) { return; } var eventName = Encoding.UTF8.GetString(stateItems[0].GetByteArray()); if (eventName != "Transfer") { return; } if (stateItems.Count < 4) { return; } if (!(stateItems[1] is null) && !(stateItems[1] is VM.Types.ByteArray)) { return; } if (!(stateItems[2] is null) && !(stateItems[2] is VM.Types.ByteArray)) { return; } var amountItem = stateItems[3]; if (!(amountItem is VM.Types.ByteArray || amountItem is VM.Types.Integer)) { return; } byte[] fromBytes = stateItems[1]?.GetByteArray(); if (fromBytes?.Length != 20) { fromBytes = null; } byte[] toBytes = stateItems[2]?.GetByteArray(); if (toBytes?.Length != 20) { toBytes = null; } if (fromBytes == null && toBytes == null) { return; } var from = new UInt160(fromBytes); var to = new UInt160(toBytes); if (fromBytes != null) { var fromKey = new Nep5BalanceKey(from, scriptHash); if (!nep5BalancesChanged.ContainsKey(fromKey)) { nep5BalancesChanged.Add(fromKey, new Nep5Balance()); } } if (toBytes != null) { var toKey = new Nep5BalanceKey(to, scriptHash); if (!nep5BalancesChanged.ContainsKey(toKey)) { nep5BalancesChanged.Add(toKey, new Nep5Balance()); } } RecordTransferHistory(snapshot, scriptHash, from, to, amountItem.GetBigInteger(), transaction.Hash, ref transferIndex); }
private void HandleNotification(Snapshot snapshot, Transaction transaction, UInt160 scriptHash, VM.Types.Array stateItems, Dictionary <Nep5BalanceKey, Nep5Balance> nep5BalancesChanged, ref ushort transferIndex) { if (stateItems.Count == 0) { return; } // Event name should be encoded as a byte array. if (!(stateItems[0] is VM.Types.ByteArray)) { return; } var eventName = Encoding.UTF8.GetString(stateItems[0].GetByteArray()); if (_shouldTrackNonStandardMintTokensEvent && eventName == "mintTokens") { if (stateItems.Count < 4) { return; } // This is not an official standard but at least one token uses it, and so it is needed for proper // balance tracking to support all tokens in use. if (!(stateItems[2] is VM.Types.ByteArray)) { return; } byte[] mintToBytes = stateItems[2].GetByteArray(); if (mintToBytes.Length != 20) { return; } var mintTo = new UInt160(mintToBytes); var mintAmountItem = stateItems[3]; if (!(mintAmountItem is VM.Types.ByteArray || mintAmountItem is VM.Types.Integer)) { return; } var toKey = new Nep5BalanceKey(mintTo, scriptHash); if (!nep5BalancesChanged.ContainsKey(toKey)) { nep5BalancesChanged.Add(toKey, new Nep5Balance()); } RecordTransferHistory(snapshot, scriptHash, UInt160.Zero, mintTo, mintAmountItem.GetBigInteger(), transaction.Hash, ref transferIndex); return; } if (eventName != "transfer") { return; } if (stateItems.Count < 4) { return; } if (!(stateItems[1] is null) && !(stateItems[1] is VM.Types.ByteArray)) { return; } if (!(stateItems[2] is null) && !(stateItems[2] is VM.Types.ByteArray)) { return; } var amountItem = stateItems[3]; if (!(amountItem is VM.Types.ByteArray || amountItem is VM.Types.Integer)) { return; } byte[] fromBytes = stateItems[1]?.GetByteArray(); if (fromBytes?.Length != 20) { fromBytes = null; } byte[] toBytes = stateItems[2]?.GetByteArray(); if (toBytes?.Length != 20) { toBytes = null; } if (fromBytes == null && toBytes == null) { return; } var from = new UInt160(fromBytes); var to = new UInt160(toBytes); if (fromBytes != null) { var fromKey = new Nep5BalanceKey(from, scriptHash); if (!nep5BalancesChanged.ContainsKey(fromKey)) { nep5BalancesChanged.Add(fromKey, new Nep5Balance()); } } if (toBytes != null) { var toKey = new Nep5BalanceKey(to, scriptHash); if (!nep5BalancesChanged.ContainsKey(toKey)) { nep5BalancesChanged.Add(toKey, new Nep5Balance()); } } RecordTransferHistory(snapshot, scriptHash, from, to, amountItem.GetBigInteger(), transaction.Hash, ref transferIndex); }
private void HandleNotification(StoreView snapshot, IVerifiable scriptContainer, UInt160 scriptHash, VM.Types.Array stateItems, Dictionary <Nep5BalanceKey, Nep5Balance> nep5BalancesChanged, ref ushort transferIndex) { if (stateItems.Count == 0) { return; } // Event name should be encoded as a byte array. if (!(stateItems[0] is VM.Types.ByteString)) { return; } var eventName = stateItems[0].GetString(); if (eventName != "Transfer") { return; } if (stateItems.Count < 4) { return; } if (!(stateItems[1].IsNull) && !(stateItems[1] is VM.Types.ByteString)) { return; } if (!(stateItems[2].IsNull) && !(stateItems[2] is VM.Types.ByteString)) { return; } var amountItem = stateItems[3]; if (!(amountItem is VM.Types.ByteString || amountItem is VM.Types.Integer)) { return; } byte[] fromBytes = stateItems[1].IsNull ? null : stateItems[1].GetSpan().ToArray(); if (fromBytes != null && fromBytes.Length != UInt160.Length) { return; } byte[] toBytes = stateItems[2].IsNull ? null : stateItems[2].GetSpan().ToArray(); if (toBytes != null && toBytes.Length != UInt160.Length) { return; } if (fromBytes == null && toBytes == null) { return; } 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()); } } if (scriptContainer is Transaction transaction) { RecordTransferHistory(snapshot, scriptHash, from, to, amountItem.GetBigInteger(), transaction.Hash, ref transferIndex); } }
private void HandleNotification(Snapshot snapshot, Transaction transaction, UInt160 scriptHash, VM.Types.Array stateItems, Dictionary <Nep5BalanceKey, Nep5Balance> nep5BalancesChanged, ref ushort transferIndex) { // Event name should be encoded as a byte array. if (!(stateItems[0] is VM.Types.ByteArray)) { return; } var eventName = Encoding.UTF8.GetString(stateItems[0].GetByteArray()); // Only care about transfers if (eventName != "transfer") { return; } if (!(stateItems[1] is VM.Types.ByteArray)) { return; } if (!(stateItems[2] is VM.Types.ByteArray)) { return; } var amountItem = stateItems[3]; if (!(amountItem is VM.Types.ByteArray || amountItem is VM.Types.Integer)) { return; } byte[] fromBytes = stateItems[1].GetByteArray(); if (fromBytes.Length != 20) { fromBytes = null; } byte[] toBytes = stateItems[2].GetByteArray(); if (toBytes.Length != 20) { toBytes = null; } if (fromBytes == null && toBytes == null) { return; } var from = new UInt160(fromBytes); var to = new UInt160(toBytes); var fromKey = new Nep5BalanceKey(from, scriptHash); if (!nep5BalancesChanged.ContainsKey(fromKey)) { nep5BalancesChanged.Add(fromKey, new Nep5Balance()); } var toKey = new Nep5BalanceKey(to, scriptHash); if (!nep5BalancesChanged.ContainsKey(toKey)) { nep5BalancesChanged.Add(toKey, new Nep5Balance()); } if (!_shouldTrackHistory) { return; } BigInteger amount = amountItem.GetBigInteger(); _transfersSent.Add(new Nep5TransferKey(from, snapshot.GetHeader(snapshot.Height).Timestamp, scriptHash, transferIndex), new Nep5Transfer { Amount = amount, UserScriptHash = to, BlockIndex = snapshot.Height, TxHash = transaction.Hash }); _transfersReceived.Add(new Nep5TransferKey(to, snapshot.GetHeader(snapshot.Height).Timestamp, scriptHash, transferIndex), new Nep5Transfer { Amount = amount, UserScriptHash = from, BlockIndex = snapshot.Height, TxHash = transaction.Hash }); transferIndex++; }