Skip to content

Commit

Permalink
Started implementing /tx view.
Browse files Browse the repository at this point in the history
  • Loading branch information
bonesoul committed Sep 29, 2014
1 parent 3a84936 commit 2c41b4b
Show file tree
Hide file tree
Showing 10 changed files with 91 additions and 13 deletions.
3 changes: 3 additions & 0 deletions src/CoiniumServ/CoiniumServ.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -944,6 +944,9 @@
<None Include="web\default\views\pool\round.cshtml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="web\default\views\pool\transaction.cshtml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="web\default\views\pool\workers.cshtml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
Expand Down
2 changes: 2 additions & 0 deletions src/CoiniumServ/Payments/IPaymentRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,7 @@ namespace CoiniumServ.Payments
public interface IPaymentRepository
{
IList<IPaymentDetails> GetPaymentsForBlock(uint height);

IPaymentDetails GetTransactionById(uint id);
}
}
5 changes: 5 additions & 0 deletions src/CoiniumServ/Payments/PaymentRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,10 @@ public IList<IPaymentDetails> GetPaymentsForBlock(uint height)
{
return _storageLayer.GetPaymentsForBlock(height);
}

public IPaymentDetails GetTransactionById(uint id)
{
return _storageLayer.GetTransactionById(id);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

using System;
using System.Collections.Generic;
using System.Linq;
using CoiniumServ.Payments;
using CoiniumServ.Persistance.Query;
using Dapper;
Expand Down Expand Up @@ -173,6 +174,35 @@ public IList<IPaymentDetails> GetPaymentsForAccount(int id, IPaginationQuery pag
return payouts;
}

public IPaymentDetails GetTransactionById(uint id)
{
try
{
if (!IsEnabled)
return null;

using (var connection = new MySqlConnection(_mySqlProvider.ConnectionString))
{
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
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",
new {id}).Single();
}
}
catch (InvalidOperationException) // fires when no result is found.
{
return null;
}
catch (Exception e)
{
_logger.Error("An exception occured while gettin transaction: {0:l}", e.Message);
return null;
}
}

public void AddTransaction(ITransaction transaction)
{
try
Expand Down
2 changes: 2 additions & 0 deletions src/CoiniumServ/Persistance/Layers/IStorageLayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,8 @@ public interface IStorageLayer
/// <returns></returns>
IList<IPaymentDetails> GetPaymentsForAccount(int id, IPaginationQuery paginationQuery);

IPaymentDetails GetTransactionById(uint id);

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

public IPaymentDetails GetTransactionById(uint id)
{
throw new NotImplementedException();
}

public void AddTransaction(ITransaction transaction)
{
// this function is not supported as this functionality is only required by payment processors which mpos itself is already one so and handles itself.
Expand Down
5 changes: 5 additions & 0 deletions src/CoiniumServ/Persistance/Layers/Null/NullStorage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,11 @@ public IList<IPaymentDetails> GetPaymentsForAccount(int id, IPaginationQuery pag
throw new System.NotImplementedException();
}

public IPaymentDetails GetTransactionById(uint id)
{
throw new System.NotImplementedException();
}

public void AddTransaction(ITransaction transaction)
{
return;
Expand Down
40 changes: 34 additions & 6 deletions src/CoiniumServ/Server/Web/Modules/PoolModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public PoolModule(IPoolManager poolManager)
}];
};

Get["/{slug}/blocks/paid/{page?1}"] = _ =>
Get["/{slug}/blocks/{page?1}"] = _ =>
{
var pool = (IPool)poolManager.Get(HttpUtility.HtmlEncode(_.slug)); // find the requested pool.
Expand All @@ -121,7 +121,7 @@ public PoolModule(IPoolManager poolManager)
var paginationQuery = new PaginationQuery(page);
var blocks = pool.BlockRepository.GetPaidBlocks(paginationQuery);
var blocks = pool.BlockRepository.GetBlocks(paginationQuery);
if (blocks.Count == 0)
{
Expand All @@ -135,14 +135,14 @@ public PoolModule(IPoolManager poolManager)
{
Blocks = blocks,
Coin = pool.Config.Coin,
Filter = BlockFilter.PaidOnly,
Filter = BlockFilter.All,
PaginationQuery = paginationQuery
};
return View["blocks", model];
};

Get["/{slug}/blocks/{page?1}"] = _ =>
Get["/{slug}/blocks/paid/{page?1}"] = _ =>
{
var pool = (IPool)poolManager.Get(HttpUtility.HtmlEncode(_.slug)); // find the requested pool.
Expand All @@ -160,7 +160,7 @@ public PoolModule(IPoolManager poolManager)
var paginationQuery = new PaginationQuery(page);
var blocks = pool.BlockRepository.GetBlocks(paginationQuery);
var blocks = pool.BlockRepository.GetPaidBlocks(paginationQuery);
if (blocks.Count == 0)
{
Expand All @@ -174,7 +174,7 @@ public PoolModule(IPoolManager poolManager)
{
Blocks = blocks,
Coin = pool.Config.Coin,
Filter = BlockFilter.All,
Filter = BlockFilter.PaidOnly,
PaginationQuery = paginationQuery
};
Expand Down Expand Up @@ -216,6 +216,34 @@ public PoolModule(IPoolManager poolManager)
return View["block", model];
};

Get["/{slug}/tx/{id:int}"] = _ =>
{
var pool = (IPool)poolManager.Get(HttpUtility.HtmlEncode(_.slug)); // find the requested pool.
if (pool == null) // make sure queried pool exists.
{
return View["error", new ErrorViewModel
{
Details = string.Format("The requested pool does not exist: {0}", _.slug)
}];
}
var transaction = pool.PaymentRepository.GetTransactionById((uint)_.id);
if (transaction == null)
{
return View["error", new ErrorViewModel
{
Details = string.Format("The requested transaction does not exist.")
}];
}
ViewBag.Header = string.Format("Transaction Details");
ViewBag.SubHeader = string.Format("{0}", transaction.TransactionId);
return View["transaction", transaction];
};

Get["/{slug}/account/address/{address:length(26,34)}/{page?1}"] = _ =>
{
var pool = (IPool)poolManager.Get(HttpUtility.HtmlEncode(_.slug)); // find the requested pool.
Expand Down
10 changes: 3 additions & 7 deletions src/CoiniumServ/Server/Web/Modules/PoolsModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,10 @@ public class PoolsModule : NancyModule
public PoolsModule(IPoolManager poolManager)
: base("/pools")
{
Get["/"] = _ =>
Get["/"] = _ => View["pools", new PoolsModel
{
// return our view
return View["pools", new PoolsModel
{
Pools = poolManager.GetAllAsReadOnly()
}];
};
Pools = poolManager.GetAllAsReadOnly()
}];
}
}
}
2 changes: 2 additions & 0 deletions src/CoiniumServ/web/default/views/pool/transaction.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
@inherits Nancy.ViewEngines.Razor.NancyRazorViewBase<CoiniumServ.Payments.IPaymentDetails>
@{ Layout = "layout/main.cshtml"; }

0 comments on commit 2c41b4b

Please sign in to comment.