Exemplo n.º 1
0
        private string SendTransaction(JObject opts)
        {
            var from = opts["from"]?.ToString().HexToBytes().ToUInt160() ??
                       _systemContractReader.NodeAddress();
            var to = opts["to"]?.ToString().HexToBytes().ToUInt160() ??
                     throw new Exception($"\"to\" {opts["to"]} is not valid");
            var value = Money.Parse(opts["amount"]?.ToString() ??
                                    throw new Exception($"\"amount\" {opts["amount"]} is not valid")
                                    );
            var invocation = opts["data"]?.ToString().HexToBytes();
            var nonce      = _transactionPool.GetNextNonceForAddress(from);
            var tx         = new Transaction
            {
                To       = to,
                From     = from,
                GasPrice = (ulong)_stateManager.CurrentSnapshot.NetworkGasPrice,
                /* TODO: "calculate gas limit for input size" */
                GasLimit   = 10000000,
                Nonce      = nonce,
                Value      = value.ToUInt256(),
                Invocation = ByteString.CopyFrom(invocation)
            };

            return(AddTxToPool(tx));
        }
Exemplo n.º 2
0
        public static TransactionChainId GetEthTx(this Transaction t, Signature?s, bool useNewId)
        {
            var nonce = t.Nonce == 0
                ? Array.Empty <byte>()
                : new BigInteger(t.Nonce).ToByteArray().Reverse().ToArray().TrimLeadingZeros();
            var sig = s is null?Array.Empty <byte>() : s.Encode().AsSpan();

            var ethTx = new Nethereum.Signer.TransactionChainId(
                nonce,
                new BigInteger(t.GasPrice).ToByteArray().Reverse().ToArray().TrimLeadingZeros(),
                new BigInteger(t.GasLimit).ToByteArray().Reverse().ToArray().TrimLeadingZeros(),
                t.To.ToBytes(), // this may be empty, same as passing null
                t.Value.ToBytes(false, true),
                t.Invocation.ToArray(),
                new BigInteger(ChainId(useNewId)).ToByteArray().Reverse().ToArray().TrimLeadingZeros(),
                sig.IsEmpty ? Array.Empty <byte>() : sig.Slice(0, 32).ToArray().TrimLeadingZeros(),
                sig.IsEmpty ? Array.Empty <byte>() : sig.Slice(32, 32).ToArray().TrimLeadingZeros(),
                sig.IsEmpty ? Array.Empty <byte>() : sig.Slice(64, sig.Length - 64).ToArray().TrimLeadingZeros()
                );

            return(ethTx);
        }
Exemplo n.º 3
0
        private string MakeDummyTx(bool useNewCainId)
        {
            var tx = new Transaction
            {
                From     = "0x6bc32575acb8754886dc283c2c8ac54b1bd93195".HexToBytes().ToUInt160(),
                To       = "0x71B293C2593d4Ff9b534b2e691f56c1D18c95a17".HexToBytes().ToUInt160(),
                Value    = Money.Parse("100").ToUInt256(),
                Nonce    = 0,
                GasPrice = 5000000000,
                GasLimit = 4500000
            };

            var rlp = tx.Rlp(useNewCainId);

            var keyPair = new EcdsaKeyPair("0xd95d6db65f3e2223703c5d8e205d98e3e6b470f067b0f94f6c6bf73d4301ce48"
                                           .HexToBytes().ToPrivateKey());
            var receipt = _transactionSigner.Sign(tx, keyPair, useNewCainId);

            var s     = receipt.Signature;
            var rawTx = tx.RlpWithSignature(s, useNewCainId);

            return(rawTx.ToHex());
        }
Exemplo n.º 4
0
 public static UInt256 FullHash(this Transaction t, Signature s, bool useNewId)
 {
     return(t.RlpWithSignature(s, useNewId).Keccak());
 }
Exemplo n.º 5
0
 public static UInt256 RawHash(this Transaction t, bool useNewId)
 {
     return(t.Rlp(useNewId).Keccak());
 }
Exemplo n.º 6
0
        public static IEnumerable <byte> RlpWithSignature(this Transaction t, Signature s, bool useNewId)
        {
            var ethTx = t.GetEthTx(s, useNewId);

            return(ethTx.GetRLPEncoded());
        }
Exemplo n.º 7
0
        public static IEnumerable <byte> Rlp(this Transaction t, bool useNewId)
        {
            var ethTx = t.GetEthTx(null, useNewId);

            return(ethTx.GetRLPEncodedRaw());
        }