public async Task <ActionResult <TransactionJson> > GetTransactionById(int id)
        {
            try
            {
                Transaction transaction = await serviceManager.GetTransactionById(id);

                TransactionJson response = new TransactionJson()
                {
                    id          = transaction.Id,
                    accountFrom = transaction.AccountFrom.Id,
                    accountTo   = transaction.AccountTo.Id,
                    amount      = transaction.Amount,
                    description = transaction.Description
                };
                return(Ok(response));
            }
            catch
            {
                return(NotFound());
            }
        }
Esempio n. 2
0
        private static Transaction Convert(TransactionJson transactionJson)
        {
            Transaction transaction = new Transaction();

            transaction.ChainId  = ChainId.MainNet;
            transaction.Value    = Hex.ToBytes(transactionJson.Value).ToUnsignedBigInteger();
            transaction.GasLimit = Hex.ToBytes(transactionJson.GasLimit).ToUnsignedBigInteger();
            transaction.GasPrice = Hex.ToBytes(transactionJson.GasPrice).ToUnsignedBigInteger();
            transaction.Nonce    = Hex.ToBytes(transactionJson.Nonce).ToUnsignedBigInteger();
            transaction.To       = string.IsNullOrWhiteSpace(transactionJson.To) ? null : new Address(new Hex(transactionJson.To));
            transaction.Data     = transaction.To == null ? null : Hex.ToBytes(transactionJson.Data);
            transaction.Init     = transaction.To == null?Hex.ToBytes(transactionJson.Data) : null;

            Signature signature = new Signature(
                Hex.ToBytes(transactionJson.R).PadLeft(32),
                Hex.ToBytes(transactionJson.S).PadLeft(32),
                Hex.ToBytes(transactionJson.V)[0]);

            transaction.Signature = signature;

            return(transaction);
        }
        public void Can_load_access_lists()
        {
            const string lists =
                "{\"accessLists\": [[{address: \"0x0001020304050607080900010203040506070809\", storageKeys: [\"0x00\", \"0x01\"]}]]}";

            EthereumJsonSerializer serializer = new EthereumJsonSerializer();
            TransactionJson        txJson     = serializer.Deserialize <TransactionJson>(lists);

            txJson.SecretKey = TestItem.PrivateKeyA.KeyBytes;
            txJson.Value     = new UInt256[1];
            txJson.GasLimit  = new long[1];
            txJson.Data      = new byte[1][];
            txJson.AccessLists.Should().NotBeNull();
            txJson.AccessLists[0][0].Address.Should()
            .BeEquivalentTo(new Address("0x0001020304050607080900010203040506070809"));
            txJson.AccessLists[0][0].StorageKeys[1][0].Should().Be((byte)1);

            Transaction tx = JsonToEthereumTest.Convert(new PostStateJson {
                Indexes = new IndexesJson()
            }, txJson);

            tx.AccessList.Should().NotBeNull();
        }
Esempio n. 4
0
        private static IEnumerable <TransactionTest> LoadTests(string testSet)
        {
            Directory.SetCurrentDirectory(AppDomain.CurrentDomain.BaseDirectory);
            IEnumerable <string> testDirs = Directory.EnumerateDirectories(".", "tt" + testSet);
            Dictionary <string, Dictionary <string, TransactionTestJson> > testJsons =
                new Dictionary <string, Dictionary <string, TransactionTestJson> >();

            foreach (string testDir in testDirs)
            {
                testJsons[testDir] = new Dictionary <string, TransactionTestJson>();
                IEnumerable <string> testFiles = Directory.EnumerateFiles(testDir).ToList();
                foreach (string testFile in testFiles)
                {
                    // am I sure?
                    if (testFile.Contains("_gnv") || testFile.Contains("TransactionWithRvaluePrefixed00"))
                    {
                        continue;
                    }

                    string json = File.ReadAllText(testFile);
                    Dictionary <string, TransactionTestJson> testsInFile = JsonConvert.DeserializeObject <Dictionary <string, TransactionTestJson> >(json);
                    foreach (KeyValuePair <string, TransactionTestJson> namedTest in testsInFile)
                    {
                        testJsons[testDir].Add(namedTest.Key, namedTest.Value);
                    }
                }
            }

            List <TransactionTest> tests = new List <TransactionTest>();

            foreach (KeyValuePair <string, Dictionary <string, TransactionTestJson> > byDir in testJsons)
            {
                foreach (KeyValuePair <string, TransactionTestJson> byName in byDir.Value)
                {
                    TransactionJson transactionJson = byName.Value.Transaction;
                    TransactionTest test;
                    if (transactionJson != null)
                    {
                        test = new ValidTransactionTest(byDir.Key, byName.Key, byName.Value.Rlp);
                        ValidTransactionTest validTest = (ValidTransactionTest)test;
                        validTest.BlockNumber = Bytes.FromHexString(byName.Value.BlockNumber).ToUInt256();
                        validTest.Data        = Bytes.FromHexString(transactionJson.Data);
                        validTest.GasLimit    = Bytes.FromHexString(transactionJson.GasLimit).ToUInt256();
                        validTest.GasPrice    = Bytes.FromHexString(transactionJson.GasPrice).ToUInt256();
                        validTest.Nonce       = Bytes.FromHexString(transactionJson.Nonce).ToUInt256();
                        validTest.R           = Bytes.FromHexString(transactionJson.R).ToUInt256();
                        validTest.S           = Bytes.FromHexString(transactionJson.S).ToUInt256();
                        validTest.V           = Bytes.FromHexString(transactionJson.V)[0];
                        validTest.Sender      = new Address(byName.Value.Sender);
                        validTest.Value       = Bytes.FromHexString(transactionJson.Value).ToUInt256();
                        validTest.To          = string.IsNullOrEmpty(transactionJson.To) ? null : new Address(transactionJson.To);
                    }
                    else
                    {
                        test = new TransactionTest(byDir.Key, byName.Key, byName.Value.Rlp);
                    }

                    tests.Add(test);
                }
            }

            return(tests);
        }