Skip to content

Commit

Permalink
cleanup logging
Browse files Browse the repository at this point in the history
  • Loading branch information
merl111 committed Oct 12, 2021
1 parent 0d602f0 commit 3962b2c
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 23 deletions.
33 changes: 16 additions & 17 deletions Spook/Chains/Ethereum/EvmBlockCrawler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@
using InteropTransfers = System.Collections.Generic.Dictionary<string,
System.Collections.Generic.Dictionary<string, System.Collections.Generic.List<Phantasma.Domain.InteropTransfer>>>;

using System.Linq;
using System;

namespace Phantasma.Spook.Chains
{
public class CrawledBlock
Expand Down Expand Up @@ -119,7 +116,7 @@ public InteropTransfers ExtractInteropTransfers(Blockchain.Nexus nexus, Logger l
// RecoverFromSignature() crashed and we cannot avoid it atm.
// Related to EIP-1559, example of probematic tx: https://etherscan.io/tx/0xb022c146d8d1e684de0c1faae43e7ce36afb6969719adfdcafcc5bb7d5913185
// TODO Fix by updating to new Nethereum and dealing with EIP-1559 better.
logger.Message("Warning: Skipping 'Header byte out of range' tx: " + tx.TransactionHash);
logger.Debug("Warning: Skipping 'Header byte out of range' tx: " + tx.TransactionHash);
continue;
}
else
Expand Down Expand Up @@ -155,12 +152,12 @@ public InteropTransfers ExtractInteropTransfers(Blockchain.Nexus nexus, Logger l
continue;
}

logger.Message($"Found ERC20 swap: {blockId} hash: {hash} to: {evt.Event.To} from: {evt.Event.From} value: {evt.Event.Value}");
var asset = EthUtils.FindSymbolFromAsset(this.platform, nexus, evt.Log.Address);
logger.Message("asset: " + asset);
logger.Debug($@"Found {this.platform} swap: {blockId} hash: {hash} to: {evt.Event.To}
from: {evt.Event.From} value: {evt.Event.Value} asset: {asset}");
if (asset == null)
{
logger.Message($"Asset [{evt.Log.Address}] not supported");
logger.Debug($"Asset [{evt.Log.Address}] not supported");
continue;
}

Expand All @@ -169,9 +166,9 @@ public InteropTransfers ExtractInteropTransfers(Blockchain.Nexus nexus, Logger l
var amount = PBigInteger.Parse(evt.Event.Value.ToString());

//logger.Message("nodeSwapAddress: " + nodeSwapAddress);
logger.Message("sourceAddress: " + sourceAddress);
logger.Message("targetAddress: " + targetAddress);
logger.Message("amount: " + amount);
//logger.Message("sourceAddress: " + sourceAddress);
//logger.Message("targetAddress: " + targetAddress);
//logger.Message("amount: " + amount);

if (!interopTransfers[block.BlockHash].ContainsKey(evt.Log.TransactionHash))
{
Expand All @@ -196,12 +193,12 @@ public InteropTransfers ExtractInteropTransfers(Blockchain.Nexus nexus, Logger l

if (tx.Value != null && tx.Value.Value > 0)
{
logger.Message("ETH:");
logger.Message(block.Number.ToString());
logger.Message(tx.TransactionHash);
logger.Message(tx.To);
logger.Message(tx.From);
logger.Message(tx.Value.ToString());
//logger.Message("ETH:");
//logger.Message(block.Number.ToString());
//logger.Message(tx.TransactionHash);
//logger.Message(tx.To);
//logger.Message(tx.From);
//logger.Message(tx.Value.ToString());

var targetAddress = encodeHandler(tx.To);
Console.WriteLine("target eth: " + targetAddress);
Expand All @@ -219,6 +216,8 @@ public InteropTransfers ExtractInteropTransfers(Blockchain.Nexus nexus, Logger l
var sourceAddress = encodeHandler(tx.From);
var amount = PBigInteger.Parse(tx.Value.ToString());

var nativeSymbol = (this.platform == "ethereum") ? "ETH" : "BNB";

interopTransfers[block.BlockHash][tx.TransactionHash].Add
(
new InteropTransfer
Expand All @@ -228,7 +227,7 @@ public InteropTransfers ExtractInteropTransfers(Blockchain.Nexus nexus, Logger l
DomainSettings.PlatformName,
targetAddress,
interopAddress, // interop address
"BNB", // TODO use const
nativeSymbol,
amount
)
);
Expand Down
2 changes: 1 addition & 1 deletion Spook/Interop/BSCInterop.cs
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ public static Tuple<InteropBlock, InteropTransaction[]> MakeInteropBlock(Nexus n
try
{
// TODO pass from outside to not instantiate for each call to MakeInteropBlock
Func<string, Address> addressEncoder = (address) => { Console.WriteLine("BSC ENCODER!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!1"); return BSCWallet.EncodeAddress(address); };
Func<string, Address> addressEncoder = (address) => { return BSCWallet.EncodeAddress(address); };
Func<Nethereum.RPC.Eth.DTOs.Transaction, Address> addressExtractor = (tx) => { return BSCInterop.ExtractInteropAddress(tx); };

var crawler = new EvmBlockCrawler(logger, combinedAddresses.ToArray(), confirmations, api,
Expand Down
2 changes: 0 additions & 2 deletions Spook/Interop/EthereumInterop.cs
Original file line number Diff line number Diff line change
Expand Up @@ -354,14 +354,12 @@ public static Address ExtractInteropAddress(Nethereum.RPC.Eth.DTOs.Transaction t

var point = Cryptography.ECC.ECPoint.DecodePoint(pubKey, Cryptography.ECC.ECCurve.Secp256k1);
pubKey = point.EncodePoint(true);
Console.WriteLine("account recovered: " + accountSenderRecovered.GetPublicAddress());

var bytes = new byte[34];
bytes[0] = (byte)AddressKind.User;
ByteArrayUtils.CopyBytes(pubKey, 0, bytes, 1, 33);

var address = Address.FromBytes(bytes);
Console.WriteLine("account recovered: " + accountSenderRecovered.GetPublicAddress());
return address;
}

Expand Down
4 changes: 2 additions & 2 deletions Spook/Interop/TokenSwapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -424,11 +424,11 @@ private void ProcessCompletedTasks()
if (_pendingSwaps.ContainsKey(swap.hash))
{

Logger.Message($"Already known swap, ignore {swap.platform} swap: {swap.source} => {swap.destination}");
Logger.Debug($"Already known swap, ignore {swap.platform} swap: {swap.source} => {swap.destination}");
continue;
}

Logger.Message($"Detected {swap.platform} swap: {swap.source} => {swap.destination} hash: {swap.hash}");
Logger.Debug($"Detected {swap.platform} swap: {swap.source} => {swap.destination} hash: {swap.hash}");
_pendingSwaps[swap.hash] = swap;
MapSwap(swap.source, swap.hash);
MapSwap(swap.destination, swap.hash);
Expand Down
2 changes: 1 addition & 1 deletion Spook/Spook.Node.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<PropertyGroup>
<Copyright>2018 - 2021 Phantasma.io</Copyright>
<AssemblyTitle>Phantasma.Spook.CLI</AssemblyTitle>
<Version>1.6</Version>
<Version>1.6.1</Version>
<Authors>The Phantasma Team</Authors>
<TargetFramework>netcoreapp3.1</TargetFramework>
<AssemblyName>spook-cli</AssemblyName>
Expand Down

0 comments on commit 3962b2c

Please sign in to comment.