Пример #1
0
 public void ResyncBlock()
 {
     if (ClassBlockCache.RemoveWalletBlockCache())
     {
         ClassFormPhase.WalletXiropht.ListBlockHashShowed.Clear();
         ClassWalletObject.DisconnectWholeRemoteNodeSyncAsync(true, true);
     }
 }
Пример #2
0
 public void ResyncTransaction()
 {
     ClassWalletObject.BlockTransactionSync = true;
     ClassFormPhase.WalletXiropht.StopUpdateTransactionHistory(true, true);
     if (ClassWalletTransactionCache.RemoveWalletCache(ClassWalletObject.WalletConnect.WalletAddress))
     {
         if (ClassWalletTransactionAnonymityCache.RemoveWalletCache(ClassWalletObject.WalletConnect.WalletAddress))
         {
             ClassWalletTransactionCache.ListTransaction.Clear();
             ClassWalletTransactionAnonymityCache.ListTransaction.Clear();
             ClassWalletObject.InSyncTransaction          = false;
             ClassWalletObject.InSyncTransactionAnonymity = false;
             ClassWalletObject.BlockTransactionSync       = false;
             ClassWalletObject.DisconnectWholeRemoteNodeSyncAsync(true, true);
             ClassFormPhase.WalletXiropht.EnableUpdateTransactionWallet = false;
             ClassFormPhase.WalletXiropht.StopAndRestartTransactionHistory();
         }
     }
 }
Пример #3
0
        /// <summary>
        /// Add transaction to the list.
        /// </summary>
        /// <param name="transaction"></param>
        public static async Task AddWalletTransactionAsync(string transaction)
        {
            try
            {
#if DEBUG
                Log.WriteLine("Wallet transaction history received: " + transaction
                              .Replace(
                                  ClassRemoteNodeCommandForWallet.RemoteNodeRecvPacketEnumeration
                                  .WalletTransactionPerId, ""));
#endif
                var splitTransaction = transaction.Replace(
                    ClassRemoteNodeCommandForWallet.RemoteNodeRecvPacketEnumeration.WalletTransactionPerId,
                    "").Split(new[] { "#" }, StringSplitOptions.None);
                var type              = splitTransaction[0];
                var timestamp         = splitTransaction[3]; // Timestamp Send CEST.
                var hashTransaction   = splitTransaction[4]; // Transaction Hash.
                var realFeeAmountSend = splitTransaction[7]; // Real fee and amount crypted for sender.
                var realFeeAmountRecv = splitTransaction[8]; // Real fee and amount crypted for sender.


                var decryptKey =
                    ClassWalletObject.WalletConnect.WalletAddress + ClassWalletObject.WalletConnect.WalletKey;      // Wallet Address + Wallet Public Key

                var amountAndFeeDecrypted = "NULL";
                if (type == "SEND")
                {
                    amountAndFeeDecrypted = ClassAlgo.GetDecryptedResultManual(ClassAlgoEnumeration.Rijndael,
                                                                               realFeeAmountSend, decryptKey, ClassWalletNetworkSetting.KeySize); // AES
                }
                else if (type == "RECV")
                {
                    amountAndFeeDecrypted = ClassAlgo.GetDecryptedResultManual(ClassAlgoEnumeration.Rijndael,
                                                                               realFeeAmountRecv, decryptKey, ClassWalletNetworkSetting.KeySize); // AES
                }
                if (amountAndFeeDecrypted != "NULL" && amountAndFeeDecrypted != ClassAlgoErrorEnumeration.AlgoError)
                {
                    var splitDecryptedAmountAndFee =
                        amountAndFeeDecrypted.Split(new[] { "-" }, StringSplitOptions.None);
                    var amountDecrypted = splitDecryptedAmountAndFee[0];
                    var feeDecrypted    = splitDecryptedAmountAndFee[1];
                    var walletDstOrSrc  = splitDecryptedAmountAndFee[2];


                    var timestampRecv    = splitTransaction[5]; // Timestamp Recv CEST.
                    var blockchainHeight = splitTransaction[6]; // Blockchain height.

                    var finalTransaction = type + "#" + hashTransaction + "#" + walletDstOrSrc + "#" +
                                           amountDecrypted + "#" + feeDecrypted + "#" + timestamp + "#" +
                                           timestampRecv + "#" + blockchainHeight;

                    var finalTransactionEncrypted =
                        ClassAlgo.GetEncryptedResultManual(ClassAlgoEnumeration.Rijndael, finalTransaction,
                                                           ClassWalletObject.WalletConnect.WalletAddress + ClassWalletObject.WalletConnect.WalletKey,
                                                           ClassWalletNetworkSetting.KeySize); // AES

                    if (finalTransactionEncrypted == ClassAlgoErrorEnumeration.AlgoError)      // Ban bad remote node.
                    {
                        if (!ClassConnectorSetting.SeedNodeIp.ContainsKey(ClassWalletObject.ListWalletConnectToRemoteNode[8].RemoteNodeHost))
                        {
                            if (!ClassWalletObject.ListRemoteNodeBanned.ContainsKey(ClassWalletObject.ListWalletConnectToRemoteNode[8].RemoteNodeHost))
                            {
                                ClassWalletObject.ListRemoteNodeBanned.Add(ClassWalletObject.ListWalletConnectToRemoteNode[8].RemoteNodeHost, ClassUtils.DateUnixTimeNowSecond());
                            }
                            else
                            {
                                ClassWalletObject.ListRemoteNodeBanned[ClassWalletObject.ListWalletConnectToRemoteNode[8].RemoteNodeHost] = ClassUtils.DateUnixTimeNowSecond();
                            }
                        }
                        ClassWalletObject.DisconnectWholeRemoteNodeSyncAsync(true, true);
                    }
                    else
                    {
                        var existTransaction = false;

                        if (ListTransaction.ContainsValue(finalTransactionEncrypted))
                        {
                            existTransaction = true;
                        }

                        if (!existTransaction)
                        {
                            ListTransaction.Add(ListTransaction.Count, finalTransactionEncrypted);


                            await SaveWalletCache(ClassWalletObject.WalletConnect.WalletAddress, finalTransactionEncrypted, false);

#if DEBUG
                            Log.WriteLine("Total transactions downloaded: " +
                                          ListTransaction.Count + "/" +
                                          ClassWalletObject.TotalTransactionInSync + ".");
#endif
                        }
                    }
                }
                else
                {
#if DEBUG
                    Log.WriteLine("Can't decrypt transaction: " + transaction + " result: " +
                                  amountAndFeeDecrypted);
#endif
                    if (!ClassConnectorSetting.SeedNodeIp.ContainsKey(ClassWalletObject.ListWalletConnectToRemoteNode[8].RemoteNodeHost))
                    {
                        if (!ClassWalletObject.ListRemoteNodeBanned.ContainsKey(ClassWalletObject.ListWalletConnectToRemoteNode[8].RemoteNodeHost))
                        {
                            ClassWalletObject.ListRemoteNodeBanned.Add(ClassWalletObject.ListWalletConnectToRemoteNode[8].RemoteNodeHost, ClassUtils.DateUnixTimeNowSecond());
                        }
                        else
                        {
                            ClassWalletObject.ListRemoteNodeBanned[ClassWalletObject.ListWalletConnectToRemoteNode[8].RemoteNodeHost] = ClassUtils.DateUnixTimeNowSecond();
                        }
                    }
                    ClassWalletObject.DisconnectWholeRemoteNodeSyncAsync(true, true);
                }
            }
            catch
            {
            }
            ClassWalletObject.InReceiveTransaction = false;
        }