Skip to content

Commit

Permalink
Renamed hybrid-storage transaction table TxId column as TxHash.
Browse files Browse the repository at this point in the history
Renamed transaction.cshtml view as paymentdetails.cshtml.
Done implementing /tx/id view.
  • Loading branch information
bonesoul committed Oct 1, 2014
1 parent 505a8ad commit 5bdb963
Show file tree
Hide file tree
Showing 15 changed files with 193 additions and 28 deletions.
3 changes: 2 additions & 1 deletion src/CoiniumServ/CoiniumServ.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@
<Compile Include="Server\Web\Models\GettingStarted\GettingStartedModel.cs" />
<Compile Include="Server\Web\Models\GettingStarted\GettingStartedPoolModel.cs" />
<Compile Include="Server\Web\Models\Pool\AccountModel.cs" />
<Compile Include="Server\Web\Models\Pool\PaymentDetailsModel.cs" />
<Compile Include="Server\Web\Modules\AlgorithmModule.cs" />
<Compile Include="Utils\Metrics\IMetricsManager.cs" />
<Compile Include="Utils\Metrics\MetricsManager.cs" />
Expand Down Expand Up @@ -944,7 +945,7 @@
<None Include="web\default\views\pool\round.cshtml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="web\default\views\pool\transaction.cshtml">
<None Include="web\default\views\pool\paymentdetails.cshtml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="web\default\views\pool\workers.cshtml">
Expand Down
4 changes: 2 additions & 2 deletions src/CoiniumServ/Payments/IPaymentRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ namespace CoiniumServ.Payments
{
public interface IPaymentRepository
{
IList<IPaymentDetails> GetPaymentsForBlock(uint height);
IList<IPaymentDetails> GetPaymentDetailsForBlock(uint height);

IPaymentDetails GetTransactionById(uint id);
IPaymentDetails GetPaymentDetailsByTransactionId(uint id);
}
}
2 changes: 1 addition & 1 deletion src/CoiniumServ/Payments/ITransaction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public interface ITransaction

string Currency { get; }

string TxId { get; set; }
string TxHash { get; set; }

DateTime CreatedAt { get; }
}
Expand Down
4 changes: 2 additions & 2 deletions src/CoiniumServ/Payments/PaymentProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -139,12 +139,12 @@ private IList<ITransaction> ExecutePayments(IEnumerable<KeyValuePair<string, Lis
var outputs = filtered.ToDictionary(x => x.Key, x => x.Value.Sum(y => y.Payment.Amount));

// send the payments all-together.
var txId = _daemonClient.SendMany(_poolAccount, outputs);
var txHash = _daemonClient.SendMany(_poolAccount, outputs);

// loop through all executed payments
filtered.ToList().ForEach(x => x.Value.ForEach(y =>
{
y.TxId = txId; // set transaction id.
y.TxHash = txHash; // set transaction id.
y.Payment.Completed = true; // set as completed.
}));

Expand Down
6 changes: 3 additions & 3 deletions src/CoiniumServ/Payments/PaymentRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@ public PaymentRepository(IStorageLayer storageLayer)
_storageLayer = storageLayer;
}

public IList<IPaymentDetails> GetPaymentsForBlock(uint height)
public IList<IPaymentDetails> GetPaymentDetailsForBlock(uint height)
{
return _storageLayer.GetPaymentsForBlock(height);
}

public IPaymentDetails GetTransactionById(uint id)
public IPaymentDetails GetPaymentDetailsByTransactionId(uint id)
{
return _storageLayer.GetTransactionById(id);
return _storageLayer.GetPaymentDetailsByTransactionId(id);
}
}
}
2 changes: 1 addition & 1 deletion src/CoiniumServ/Payments/Transaction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class Transaction:ITransaction
public IAccount Account { get; private set; }
public IPayment Payment { get; private set; }
public string Currency { get; private set; }
public string TxId { get; set; }
public string TxHash { get; set; }
public DateTime CreatedAt { get; private set; }

public Transaction(IAccount account, IPayment payout, string currency)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public IList<IPaymentDetails> GetPaymentsForBlock(uint height)
{
var results = connection.Query<PaymentDetails>(
@"SELECT p.Id as PaymentId, t.Id as TransactionId, p.AccountId, a.Address, p.Block, p.Amount as Amount,
t.Amount as SentAmount, t.Currency, t.TxId as TxHash, p.CreatedAt as PaymentDate, t.CreatedAt as TransactionDate, p.Completed
t.Amount as SentAmount, t.Currency, t.TxHash, p.CreatedAt as PaymentDate, t.CreatedAt as TransactionDate, p.Completed
FROM Payment p
INNER JOIN Account as a ON p.AccountId = a.Id
LEFT OUTER JOIN Transaction t On p.Id = t.PaymentId Where Block = @height",
Expand Down Expand Up @@ -151,7 +151,7 @@ public IList<IPaymentDetails> GetPaymentsForAccount(int id, IPaginationQuery pag
{
var results = connection.Query<PaymentDetails>(
@"SELECT p.Id as PaymentId, t.Id as TransactionId, p.AccountId, a.Address, p.Block, p.Amount as Amount,
t.Amount as SentAmount, t.Currency, t.TxId as TxHash, p.CreatedAt as PaymentDate, t.CreatedAt as TransactionDate, p.Completed
t.Amount as SentAmount, t.Currency, t.TxHash, p.CreatedAt as PaymentDate, t.CreatedAt as TransactionDate, p.Completed
FROM Payment p
INNER JOIN Account as a ON p.AccountId = a.Id
LEFT OUTER JOIN Transaction t On p.Id = t.PaymentId Where a.Id = @id
Expand All @@ -174,7 +174,7 @@ public IList<IPaymentDetails> GetPaymentsForAccount(int id, IPaginationQuery pag
return payouts;
}

public IPaymentDetails GetTransactionById(uint id)
public IPaymentDetails GetPaymentDetailsByTransactionId(uint id)
{
try
{
Expand All @@ -185,7 +185,7 @@ public IPaymentDetails GetTransactionById(uint id)
{
return connection.Query<PaymentDetails>(
@"SELECT p.Id as PaymentId, t.Id as TransactionId, p.AccountId, a.Address, p.Block, p.Amount as Amount,
t.Amount as SentAmount, t.Currency, t.TxId as TxHash, p.CreatedAt as PaymentDate, t.CreatedAt as TransactionDate, p.Completed
t.Amount as SentAmount, t.Currency, t.TxHash, p.CreatedAt as PaymentDate, t.CreatedAt as TransactionDate, p.Completed
FROM Payment p
INNER JOIN Account as a ON p.AccountId = a.Id
LEFT OUTER JOIN Transaction t On p.Id = t.PaymentId Where t.Id = @id",
Expand Down Expand Up @@ -213,15 +213,15 @@ public void AddTransaction(ITransaction transaction)
using (var connection = new MySqlConnection(_mySqlProvider.ConnectionString))
{
connection.Execute(
@"INSERT INTO Transaction(AccountId, PaymentId, Amount, Currency, TxId, CreatedAt)
VALUES(@accountId, @paymentId, @amount, @currency, @txId, @createdAt)",
@"INSERT INTO Transaction(AccountId, PaymentId, Amount, Currency, TxHash, CreatedAt)
VALUES(@accountId, @paymentId, @amount, @currency, @txHash, @createdAt)",
new
{
accountId = transaction.Account.Id,
paymentId = transaction.Payment.Id,
amount = transaction.Payment.Amount,
currency = transaction.Currency,
txId = transaction.TxId,
txHash = transaction.TxHash,
createdAt = transaction.CreatedAt
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public override void Up()
.WithColumn("PaymentId").AsInt32().ForeignKey("Payment", "Id")
.WithColumn("Amount").AsDecimal().NotNullable()
.WithColumn("Currency").AsString(4).NotNullable()
.WithColumn("TxId").AsString(64).NotNullable()
.WithColumn("TxHash").AsString(64).NotNullable()
.WithColumn("CreatedAt").AsDateTime().NotNullable();
}

Expand Down
2 changes: 1 addition & 1 deletion src/CoiniumServ/Persistance/Layers/IStorageLayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ public interface IStorageLayer
/// <returns></returns>
IList<IPaymentDetails> GetPaymentsForAccount(int id, IPaginationQuery paginationQuery);

IPaymentDetails GetTransactionById(uint id);
IPaymentDetails GetPaymentDetailsByTransactionId(uint id);

/// <summary>
/// Adds a transaction.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public IList<IPaymentDetails> GetPaymentsForAccount(int id, IPaginationQuery pag
throw new NotImplementedException();
}

public IPaymentDetails GetTransactionById(uint id)
public IPaymentDetails GetPaymentDetailsByTransactionId(uint id)
{
throw new NotImplementedException();
}
Expand Down
2 changes: 1 addition & 1 deletion src/CoiniumServ/Persistance/Layers/Null/NullStorage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public IList<IPaymentDetails> GetPaymentsForAccount(int id, IPaginationQuery pag
throw new System.NotImplementedException();
}

public IPaymentDetails GetTransactionById(uint id)
public IPaymentDetails GetPaymentDetailsByTransactionId(uint id)
{
throw new System.NotImplementedException();
}
Expand Down
41 changes: 41 additions & 0 deletions src/CoiniumServ/Server/Web/Models/Pool/PaymentDetailsModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#region License
//
// CoiniumServ - Crypto Currency Mining Pool Server Software
// Copyright (C) 2013 - 2014, CoiniumServ Project - http://www.coinium.org
// http://www.coiniumserv.com - https://github.com/CoiniumServ/CoiniumServ
//
// This software is dual-licensed: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// For the terms of this license, see licenses/gpl_v3.txt.
//
// Alternatively, you can license this software under a commercial
// license or white-label it as set out in licenses/commercial.txt.
//
#endregion

using CoiniumServ.Accounts;
using CoiniumServ.Coin.Config;
using CoiniumServ.Payments;
using CoiniumServ.Persistance.Blocks;

namespace CoiniumServ.Server.Web.Models.Pool
{
public class PaymentDetailsModel
{
public IPaymentDetails Details { get; set; }

public IAccount Account { get; set; }

public IPersistedBlock Block { get; set; }

public ICoinConfig Coin { get; set; }
}
}
21 changes: 16 additions & 5 deletions src/CoiniumServ/Server/Web/Modules/PoolModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ public PoolModule(IPoolManager poolManager)
{
Block = block,
Coin = pool.Config.Coin,
Payments = pool.PaymentRepository.GetPaymentsForBlock((uint)_.height)
Payments = pool.PaymentRepository.GetPaymentDetailsForBlock((uint)_.height)
};
ViewBag.Header = string.Format("Block {0}", block.Height);
Expand All @@ -228,20 +228,31 @@ public PoolModule(IPoolManager poolManager)
}];
}
var transaction = pool.PaymentRepository.GetTransactionById((uint)_.id);
var details = pool.PaymentRepository.GetPaymentDetailsByTransactionId((uint)_.id);
if (transaction == null)
if (details == null)
{
return View["error", new ErrorViewModel
{
Details = string.Format("The requested transaction does not exist.")
}];
}
var account = pool.AccountManager.GetAccountById(details.AccountId);
var block = pool.BlockRepository.Get((uint) details.Block);
ViewBag.Header = string.Format("Transaction Details");
ViewBag.SubHeader = string.Format("{0}", transaction.TransactionId);
ViewBag.SubHeader = string.Format("{0}", details.TransactionId);
var model = new PaymentDetailsModel
{
Details = details,
Account = account,
Block = block,
Coin = pool.Config.Coin
};
return View["transaction", transaction];
return View["paymentdetails", model];
};

Get["/{slug}/account/address/{address:length(26,34)}/{page?1}"] = _ =>
Expand Down
114 changes: 114 additions & 0 deletions src/CoiniumServ/web/default/views/pool/paymentdetails.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
@using CoiniumServ.Persistance.Blocks
@inherits Nancy.ViewEngines.Razor.NancyRazorViewBase<CoiniumServ.Server.Web.Models.Pool.PaymentDetailsModel>
@{ Layout = "layout/main.cshtml"; }

<div class="row">
<div class="col-md-6">
<div class="box box-solid box-warning">
<div class="box-header">
<h3 class="box-title">Block Details</h3>
</div>
<div class="box-body no-padding">
<div class="list-group">
<div class="list-group-item" title="Height of the block">
<div class="row">
<div class="col-xs-6"><i class="fa fa-cube"></i> Height</div>
<div class="col-xs-6 text-right"><a href="/pool/@Model.Coin.Symbol/block/@Model.Block.Height">@Model.Block.Height</a></div>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="col-md-6">
<div class="box box-solid box-success">
<div class="box-header">
<h3 class="box-title">Account Details</h3>
</div>
<div class="box-body no-padding">
<div class="list-group">
<div class="list-group-item" title="Payment address for the account">
<div class="row">
<div class="col-xs-6"><i class="fa fa-dollar"></i> Address</div>
<div class="col-xs-6 text-right"><a href="/pool/@Model.Coin.Symbol/account/address/@Model.Account.Address">@Model.Account.Address</a></div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>

<div class="row">
<div class="col-md-6">
<div class="box box-solid box-danger">
<div class="box-header">
<h3 class="box-title">Payment Details</h3>
</div>
<div class="box-body no-padding">
<div class="list-group">
<div class="list-group-item" title="The id of the payment">
<div class="row">
<div class="col-xs-6"><i class="fa fa-dollar"></i> Id</div>
<div class="col-xs-6 text-right"><a href="/pool/@Model.Coin.Symbol/payment/@Model.Details.PaymentId">@Model.Details.PaymentId</a></div>
</div>
</div>
<div class="list-group-item" title="The amount of the payment">
<div class="row">
<div class="col-xs-6"><i class="fa fa-dollar"></i> Amount</div>
<div class="col-xs-6 text-right">@Model.Details.Amount @Model.Coin.Symbol</div>
</div>
</div>
<div class="list-group-item" title="Is the payment fullfilled?">
<div class="row">
<div class="col-xs-6"><i class="fa fa-dollar"></i> Fullfilled</div>
<div class="col-xs-6 text-right"><div class="label @(Model.Details.Completed ?"bg-green":"bg-red")">@(Model.Details.Completed ? "Yes" : "No")</div></div>
</div>
</div>
<div class="list-group-item" title="Date of the payment">
<div class="row">
<div class="col-xs-6"><i class="fa fa-dollar"></i> Date</div>
<div class="col-xs-6 text-right">@Model.Details.PaymentDate</div>
</div>
</div>
</div>
</div>
</div>
</div>

<div class="col-md-6">
<div class="box box-solid box-primary">
<div class="box-header">
<h3 class="box-title">Transaction Details</h3>
</div>
<div class="box-body no-padding">
<div class="list-group">
<div class="list-group-item" title="The id of the payment">
<div class="row">
<div class="col-xs-6"><i class="fa fa-dollar"></i> Id</div>
<div class="col-xs-6 text-right"><a href="/pool/@Model.Coin.Symbol/tx/@Model.Details.TransactionId">@Model.Details.TransactionId</a></div>
</div>
</div>
<div class="list-group-item" title="The amount of the sent coins">
<div class="row">
<div class="col-xs-6"><i class="fa fa-dollar"></i> Amount</div>
<div class="col-xs-6 text-right">@Model.Details.SentAmount @Model.Details.Currency</div>
</div>
</div>
<div class="list-group-item" title="The hash of the transaction">
<div class="row">
<div class="col-xs-6"><i class="fa fa-dollar"></i> Hash</div>
<div class="col-xs-6 text-right"><a href="@Model.Coin.BlockExplorer.Tx@Model.Details.TxHash" target="_blank">@Model.Details.TxHash.Substring(0, 10)</a></div>
</div>
</div>
<div class="list-group-item" title="Date of the transaction">
<div class="row">
<div class="col-xs-6"><i class="fa fa-dollar"></i> Date</div>
<div class="col-xs-6 text-right">@Model.Details.TransactionDate</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
2 changes: 0 additions & 2 deletions src/CoiniumServ/web/default/views/pool/transaction.cshtml

This file was deleted.

0 comments on commit 5bdb963

Please sign in to comment.