Пример #1
0
        private async Task <string> getLatestNonce()
        {
            var latest = await daemon.ExecuteCmdSingleAsync <string>(logger, AionCommands.GetTransactionCount, new[] { poolConfig.Address });

            if (AionUtils.fromHex(latest.Response).Equals(latestNonce) || usedLatestNonce)
            {
                latestNonce     = latestNonce + 1;
                usedLatestNonce = false;
            }
            else
            {
                latestNonce     = AionUtils.fromHex(latest.Response);
                usedLatestNonce = true;
            }

            return(AionUtils.AppendHexStart(latestNonce.ToString("X")));
        }
Пример #2
0
        private async Task <DaemonResponse <string> > SendTransactionPrivateKey(Balance balance)
        {
            logger.Info(() => $"[{LogCategory}] Sending {FormatAmount(balance.Amount)} to {balance.Address} using the private key.");
            var latestNonce = await getLatestNonce();

            var txData = new AionTransaction
            {
                Nonce     = AionUtils.AppendHexStart(latestNonce),
                To        = balance.Address,
                Value     = AionUtils.AppendHexStart(((BigInteger)Math.Floor(balance.Amount * AionConstants.Wei)).ToString("x")),
                Data      = "",
                Gas       = AionUtils.AppendHexStart(new BigInteger(22000).ToString("x")),
                GasPrice  = AionUtils.AppendHexStart(new BigInteger(10000000000).ToString("x")),
                Timestamp = AionUtils.AppendHexStart(DateTime.Now.Ticks.ToString("x2")),
                Type      = "0x01"
            };

            txData.Sign(extraConfig.PrivateKey);
            string serializedTx = txData.Serialize();

            return(await daemon.ExecuteCmdSingleAsync <string>(logger, AionCommands.SendRawTx, new[] { serializedTx }));
        }