private void RecordTransferHistory(Snapshot snapshot, UInt160 scriptHash, UInt160 from, UInt160 to, BigInteger amount, UInt256 txHash, ref ushort transferIndex) { if (!_shouldTrackHistory) { return; } if (_recordNullAddressHistory || from != UInt160.Zero) { _transfersSent.Add(new Nep5TransferKey(from, snapshot.GetHeader(snapshot.Height).Timestamp, scriptHash, transferIndex), new Nep5Transfer { Amount = amount, UserScriptHash = to, BlockIndex = snapshot.Height, TxHash = txHash }); } if (_recordNullAddressHistory || to != UInt160.Zero) { _transfersReceived.Add(new Nep5TransferKey(to, snapshot.GetHeader(snapshot.Height).Timestamp, scriptHash, transferIndex), new Nep5Transfer { Amount = amount, UserScriptHash = from, BlockIndex = snapshot.Height, TxHash = txHash }); } transferIndex++; }
private void RecordTransferHistory(Snapshot snapshot, UInt160 scriptHash, UInt160 from, UInt160 to, BigInteger amount, UInt256 txHash, ref ushort transferIndex) { Header header = snapshot.GetHeader(snapshot.Height); JObject transfer = new JObject(); transfer["from"] = from.ToAddress(); transfer["to"] = to.ToAddress(); transfer["time"] = header.Timestamp; transfer["scripthash"] = scriptHash.ToString(); transfer["amount"] = amount.ToString(); transfer["block"] = snapshot.Height; transfer["txid"] = txHash.ToString(); transfer["transferindex"] = $"{snapshot.Height}.{transferIndex}"; Document a = Document.FromJson(transfer.ToString()); TransfersTable.UpdateItemAsync(a); transferIndex++; // store the asset metadata if this is the first time we're seeing this scripthash if (Assets.Count == 0) { PreloadAssets(); } if (!Assets.Contains(scriptHash.ToString())) { AddAsset(snapshot, scriptHash); } }
private void AddBlock(Snapshot snapshot) { Block block = snapshot.PersistingBlock; ulong idx = block.Index; Console.WriteLine($"Adding block {idx} to DynamoDB table"); ulong blocktime = 0; if (block.Index > 0) { ulong timestamp = block.Timestamp; Header header = snapshot.GetHeader((uint)idx - 1); ulong lasttimestamp = header.Timestamp; blocktime = timestamp - lasttimestamp; } JObject j = block.ToJson(); j["blocktime"] = blocktime; Document d = Document.FromJson(j.ToString()); BlocksTable.UpdateItemAsync(d); }
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++; }