Esempio n. 1
0
        static async Task Main(string[] args)
        {
            Rlp.RegisterDecoders(typeof(DepositDecoder).Assembly);
            Rlp.RegisterDecoders(typeof(DepositDetailsDecoder).Assembly);

            string              dbPath      = args[0];
            ConsoleAsyncLogger  asyncLogger = new ConsoleAsyncLogger(LogLevel.Info);
            OneLoggerLogManager logManager  = new OneLoggerLogManager(asyncLogger);

            var deposits = await LoadDeposits(logManager, dbPath);

            IKeyStore         keyStore = BuildKeyStore(logManager);
            DevKeyStoreWallet wallet   = new DevKeyStoreWallet(keyStore, logManager, false);

            foreach (var depositGroup in deposits.Items.GroupBy(d => d.Consumer))
            {
                Console.WriteLine($"Deposits by {depositGroup.Key}");
                foreach (DepositDetails depositDetails in depositGroup)
                {
                    DateTimeOffset dto = DateTimeOffset.FromUnixTimeSeconds(depositDetails.Deposit.ExpiryTime);
                    Console.WriteLine($"  [REFUNDABLE] Deposit by {depositDetails.Consumer} for {depositDetails.DataAsset.Name} {depositDetails.Deposit.Units} expired on {dto.Date:f}");
                }

                Transaction[] refundTxs = GenerateTxsForRefunds(depositGroup, wallet);
                foreach (Transaction transaction in refundTxs)
                {
                    Console.WriteLine();
                    Console.WriteLine("***************************************");
                    TxDecoder decoder = new TxDecoder();
                    Rlp       txRlp   = decoder.Encode(transaction);
                    Console.WriteLine(txRlp.Bytes.ToHexString());
                    Console.WriteLine("***************************************");
                }
            }

            Console.ReadLine();
        }
Esempio n. 2
0
        private static Transaction[] GenerateTxsForRefunds(IGrouping <Address, DepositDetails> depositGroup, DevKeyStoreWallet wallet)
        {
            Console.WriteLine();
            Console.Write($"Provide nonce for {depositGroup.Key}: ");
            int nonce = int.Parse(Console.ReadLine());

            Console.Write($"Provide address to send the refund to: ");
            string       hexAddress   = Console.ReadLine();
            Address      refundTo     = new Address(hexAddress);
            ConsoleUtils consoleUtils = new ConsoleUtils(new ConsoleWrapper());

            SecureString securedPassword = consoleUtils.ReadSecret("Provide password: "******"Password has been accepted.");
                Console.WriteLine();
                Console.WriteLine($"Great, will generate refund transactions for deposits of {depositGroup.Key} starting with nonce {nonce}. ETH/DAI will be sent to {refundTo}.");
                List <Transaction> transactions = new List <Transaction>(depositGroup.Count());
                foreach (DepositDetails depositDetails in depositGroup)
                {
                    Deposit     deposit     = depositDetails.Deposit;
                    RefundClaim refundClaim = new RefundClaim(deposit.Id, depositDetails.DataAsset.Id, deposit.Units,
                                                              deposit.Value, deposit.ExpiryTime, depositDetails.Pepper, depositDetails.DataAsset.Provider.Address, refundTo);
                    UInt256 gasPrice = 20.GWei();

                    AbiEncoder  abiEncoder  = new AbiEncoder();
                    byte[]      txData      = abiEncoder.Encode(AbiEncodingStyle.IncludeSignature, ContractData.ClaimRefundSig, depositDetails.DataAsset.Id, refundClaim.Units, refundClaim.Value, refundClaim.ExpiryTime, refundClaim.Pepper, refundClaim.Provider, depositDetails.Consumer);
                    Transaction transaction = new Transaction();
                    transaction.Value         = 0;
                    transaction.Data          = txData;
                    transaction.To            = new Address("0xb1AD03b75bD9E5AB89968D7a37d99F9dd220796D");
                    transaction.SenderAddress = depositDetails.Consumer;
                    transaction.GasLimit      = 100000;
                    transaction.GasPrice      = gasPrice;
                    transaction.Nonce         = (UInt256)nonce++;
                    wallet.Sign(transaction, ChainId.Mainnet);

                    EthereumEcdsa ecdsa            = new EthereumEcdsa(ChainId.Mainnet, LimboLogs.Instance);
                    Address       recoveredAddress = ecdsa.RecoverAddress(transaction);
                    if (recoveredAddress != transaction.SenderAddress)
                    {
                        Console.WriteLine("Signature failure");
                        return(new Transaction[0]);
                    }

                    transactions.Add(transaction);
                }

                return(transactions.ToArray());
            }

            Console.WriteLine("Incorrect password.");
            return(new Transaction[0]);
        }