public void CanExtractValue()
 {
     Assert.Equal(
         "test_action",
         ActionTypeAttribute.ValueOf(typeof(TestAction))
         );
 }
Beispiel #2
0
        public IActionResult GetTransaction(string txIdString)
        {
            Transaction <T> tx;
            TxId            txId;
            BlockChain <T>  chain = GetBlockChain();

            try
            {
                txId = new TxId(ByteUtil.ParseHex(txIdString));
            }
            catch (ArgumentException)
            {
                return(BadRequest(new Dictionary <string, string>
                {
                    {
                        "message",
                        $"\"{txIdString}\" is not a proper transaction id."
                    }
                }));
            }

            try
            {
                tx = chain.Transactions[txId];
            }
            catch (KeyNotFoundException)
            {
                return(NotFound(new Dictionary <string, string>
                {
                    { "message", $"Transaction(\"{txIdString}\") is not found" }
                }));
            }

            var model = new TransactionViewModel
            {
                Id               = tx.Id.ToString(),
                Signature        = tx.Signature,
                Timestamp        = tx.Timestamp,
                Signer           = tx.Signer.ToHex(),
                UpdatedAddresses = tx.UpdatedAddresses
                                   .Select(a => a.ToHex()).ToArray(),
                Actions = tx.Actions
                          .Select(act => new Dictionary <string, object>
                {
                    {
                        "type_id",
                        ActionTypeAttribute.ValueOf(act.GetType())
                    },
                }).ToList()
            };

            return(Ok(model));
        }
Beispiel #3
0
        public RawTransaction ToRawTransaction(bool includeSign)
        {
            var rawTx = new RawTransaction(
                sender: Sender.ToByteArray(),
                recipient: Recipient.ToByteArray(),
                publicKey: PublicKey.Format(false),
                timestamp: Timestamp.ToString(TimestampFormat),
                actions: Actions.Select(a => new Dictionary <string, object>
            {
                { "type_id", ActionTypeAttribute.ValueOf(a.GetType()) },
                { "values", a.PlainValue },
            })
                );

            if (includeSign)
            {
                rawTx = rawTx.AddSignature(Signature);
            }

            return(rawTx);
        }