Ejemplo n.º 1
0
        public static TransactionContract ToContract(
            this Transaction transaction,
            bool confirmed = true)
        {
            var contract = new TransactionContract
            {
                From                = transaction.From,
                To                  = transaction.To,
                Value               = transaction.Value,
                Fee                 = transaction.Fee,
                DateCreated         = transaction.DateCreated.Iso8601Formatted(),
                Data                = transaction.Data,
                SenderPubKey        = transaction.SenderPublicKey,
                TransactionDataHash = transaction.DataHash.ToHex(),
                SenderSignature     = new string[]
                {
                    transaction.SenderSignature[0],
                    transaction.SenderSignature[1]
                }
            };

            if (confirmed)
            {
                contract.MinedInBlockIndex  = transaction.MinedInBlockIndex;
                contract.TransferSuccessful = transaction.TransferSuccessful;
            }

            return(contract);
        }
Ejemplo n.º 2
0
        public async Task BroadcastNewTransaction(Transaction transaction)
        {
            CreateTransactionRequest request = transaction.ToCreateRequest();

            foreach (string peerBaseUrl in _peers.Values)
            {
                await SendCreateTransactionRequest(request, peerBaseUrl, 5).ConfigureAwait(false);
            }
        }
Ejemplo n.º 3
0
        public bool VerifySignature(Transaction transaction)
        {
            byte[]     transactionDataHash = transaction.DataHash;
            BigInteger r         = new BigInteger(transaction.SenderSignature[0], 16);
            BigInteger s         = new BigInteger(transaction.SenderSignature[1], 16);
            ECPoint    publicKey = EncryptionUtils.DecompressKey(transaction.SenderPublicKey);

            bool signatureVerified = EncryptionUtils.VerifySignature(
                publicKey, r, s, transactionDataHash);

            return(signatureVerified);
        }
        public IActionResult CreateTransaction([FromBody] CreateTransactionRequest request)
        {
            Transaction             newTransaction = request.ToDomainModel();
            CreateTransactionResult result         = NodeService.TryCreateTransaction(
                newTransaction);

            if (result != CreateTransactionResult.Ok)
            {
                return(BadRequest(new Error(result.GetEnumDescription())));
            }

            return(CreatedAtRoute(
                       "GetTransaction", new
            {
                transactionDataHash = newTransaction.DataHash.ToHex()
            },
                       newTransaction.ToContract(false)));
        }
Ejemplo n.º 5
0
 public static CreateTransactionRequest ToCreateRequest(this Transaction transaction)
 {
     return(new CreateTransactionRequest
     {
         From = transaction.From,
         To = transaction.To,
         Value = transaction.Value,
         Fee = transaction.Fee,
         DateCreated = transaction.DateCreated.Iso8601Formatted(),
         Data = transaction.Data,
         SenderPubKey = transaction.SenderPublicKey,
         SenderSignature = new string[]
         {
             transaction.SenderSignature[0],
             transaction.SenderSignature[1]
         }
     });
 }