Skip to content

Commit

Permalink
Inject historical quotes into operations
Browse files Browse the repository at this point in the history
  • Loading branch information
Groxan committed Aug 5, 2020
1 parent 0f87556 commit 2879d23
Show file tree
Hide file tree
Showing 22 changed files with 892 additions and 422 deletions.
8 changes: 5 additions & 3 deletions Tzkt.Api/Controllers/AccountsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ public Task<Account> GetByAddress([Address] string address, bool metadata = fals
/// <param name="lastId">Id of the last operation received, which is used as an offset for pagination</param>
/// <param name="limit">Number of items to return</param>
/// <param name="sort">Sort mode (0 - ascending, 1 - descending)</param>
/// <param name="quotes">Comma-separated list of ticker symbols to inject historical prices into response</param>
/// <returns></returns>
[HttpGet("{address}/operations")]
public Task<IEnumerable<Operation>> GetOperations(
Expand All @@ -216,13 +217,14 @@ public Task<Account> GetByAddress([Address] string address, bool metadata = fals
string type,
[Min(0)] int lastId = 0,
[Range(0, 1000)] int limit = 100,
SortMode sort = SortMode.Descending)
SortMode sort = SortMode.Descending,
Symbols quotes = Symbols.None)
{
var types = type != null ? new HashSet<string>(type.Split(',')) : OpTypes.DefaultSet;

return from != null || to != null
? Accounts.GetOperations(address, from ?? DateTime.MinValue, to ?? DateTime.MaxValue, types, sort, lastId, limit)
: Accounts.GetOperations(address, types, sort, lastId, limit);
? Accounts.GetOperations(address, from ?? DateTime.MinValue, to ?? DateTime.MaxValue, types, sort, lastId, limit, quotes)
: Accounts.GetOperations(address, types, sort, lastId, limit, quotes);
}

/// <summary>
Expand Down
10 changes: 6 additions & 4 deletions Tzkt.Api/Controllers/BlocksController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,12 @@ public Task<int> GetCount()
/// </remarks>
/// <param name="hash">Block hash</param>
/// <param name="operations">Flag indicating whether to include block operations into returned object or not</param>
/// <param name="quotes">Comma-separated list of ticker symbols to inject historical prices into response</param>
/// <returns></returns>
[HttpGet("{hash}")]
public Task<Block> GetByHash([BlockHash] string hash, bool operations = false)
public Task<Block> GetByHash([BlockHash] string hash, bool operations = false, Symbols quotes = Symbols.None)
{
return Blocks.Get(hash, operations);
return Blocks.Get(hash, operations, quotes);
}

/// <summary>
Expand All @@ -126,11 +127,12 @@ public Task<Block> GetByHash([BlockHash] string hash, bool operations = false)
/// </remarks>
/// <param name="level">Block level</param>
/// <param name="operations">Flag indicating whether to include block operations into returned object or not</param>
/// <param name="quotes">Comma-separated list of ticker symbols to inject historical prices into response</param>
/// <returns></returns>
[HttpGet("{level:int}")]
public Task<Block> GetByLevel([Min(0)] int level, bool operations = false)
public Task<Block> GetByLevel([Min(0)] int level, bool operations = false, Symbols quotes = Symbols.None)
{
return Blocks.Get(level, operations);
return Blocks.Get(level, operations, quotes);
}

[OpenApiIgnore]
Expand Down
348 changes: 196 additions & 152 deletions Tzkt.Api/Controllers/OperationsController.cs

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions Tzkt.Api/Models/Operations/ActivationOperation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,12 @@ public class ActivationOperation : Operation
/// Account activation balance of tezos tokens that were recommended allocations for donations to the Tezos Foundation’s fundraiser
/// </summary>
public long Balance { get; set; }

#region injecting
/// <summary>
/// Injected historical quote at the time of operation
/// </summary>
public QuoteShort Quote { get; set; }
#endregion
}
}
7 changes: 7 additions & 0 deletions Tzkt.Api/Models/Operations/BakingOperation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,12 @@ public class BakingOperation : Operation
/// Total fee paid by all operations, included in the block
/// </summary>
public long Fees { get; set; }

#region injecting
/// <summary>
/// Injected historical quote at the time of operation
/// </summary>
public QuoteShort Quote { get; set; }
#endregion
}
}
7 changes: 7 additions & 0 deletions Tzkt.Api/Models/Operations/BallotOperation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,12 @@ public class BallotOperation : Operation
/// Vote, given in the ballot (`yay`, `nay`, or `pass`)
/// </summary>
public string Vote { get; set; }

#region injecting
/// <summary>
/// Injected historical quote at the time of operation
/// </summary>
public QuoteShort Quote { get; set; }
#endregion
}
}
7 changes: 7 additions & 0 deletions Tzkt.Api/Models/Operations/DelegationOperation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,5 +96,12 @@ public class DelegationOperation : Operation
/// List of errors provided by the node, injected the operation to the blockchain. `null` if there is no errors
/// </summary>
public List<OperationError> Errors { get; set; }

#region injecting
/// <summary>
/// Injected historical quote at the time of operation
/// </summary>
public QuoteShort Quote { get; set; }
#endregion
}
}
7 changes: 7 additions & 0 deletions Tzkt.Api/Models/Operations/DoubleBakingOperation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,5 +72,12 @@ public class DoubleBakingOperation : Operation
/// Amount of frozen fees, lost by accused baker (delegate)
/// </summary>
public long OffenderLostFees { get; set; }

#region injecting
/// <summary>
/// Injected historical quote at the time of operation
/// </summary>
public QuoteShort Quote { get; set; }
#endregion
}
}
7 changes: 7 additions & 0 deletions Tzkt.Api/Models/Operations/DoubleEndorsingOperation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,5 +73,12 @@ public class DoubleEndorsingOperation : Operation
/// Amount of frozen fees, lost by accused baker (delegate)
/// </summary>
public long OffenderLostFees { get; set; }

#region injecting
/// <summary>
/// Injected historical quote at the time of operation
/// </summary>
public QuoteShort Quote { get; set; }
#endregion
}
}
7 changes: 7 additions & 0 deletions Tzkt.Api/Models/Operations/EndorsementOperation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,12 @@ public class EndorsementOperation : Operation
/// Reward of the baker (delegate) for the operation
/// </summary>
public long Rewards { get; set; }

#region injecting
/// <summary>
/// Injected historical quote at the time of operation
/// </summary>
public QuoteShort Quote { get; set; }
#endregion
}
}
7 changes: 7 additions & 0 deletions Tzkt.Api/Models/Operations/MigrationOperation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,12 @@ public class MigrationOperation : Operation
/// The amount for which the operation updated the balance (micro tez)
/// </summary>
public long BalanceChange { get; set; }

#region injecting
/// <summary>
/// Injected historical quote at the time of operation
/// </summary>
public QuoteShort Quote { get; set; }
#endregion
}
}
7 changes: 7 additions & 0 deletions Tzkt.Api/Models/Operations/NonceRevelationOperation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,12 @@ public class NonceRevelationOperation : Operation
/// Block height of the block, where seed nonce hash is stored
/// </summary>
public int RevealedLevel { get; set; }

#region injecting
/// <summary>
/// Injected historical quote at the time of operation
/// </summary>
public QuoteShort Quote { get; set; }
#endregion
}
}
7 changes: 7 additions & 0 deletions Tzkt.Api/Models/Operations/OriginationOperation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,5 +125,12 @@ public class OriginationOperation : Operation
/// Information about the originated ( deployed / created ) contract
/// </summary>
public OriginatedContract OriginatedContract { get; set; }

#region injecting
/// <summary>
/// Injected historical quote at the time of operation
/// </summary>
public QuoteShort Quote { get; set; }
#endregion
}
}
7 changes: 7 additions & 0 deletions Tzkt.Api/Models/Operations/ProposalOperation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,12 @@ public class ProposalOperation : Operation
/// Indicates whether proposal upvote has already been pushed. Duplicated proposal operations are not counted when selecting proposal-winner.
/// </summary>
public bool Duplicated { get; set; }

#region injecting
/// <summary>
/// Injected historical quote at the time of operation
/// </summary>
public QuoteShort Quote { get; set; }
#endregion
}
}
7 changes: 7 additions & 0 deletions Tzkt.Api/Models/Operations/RevealOperation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,5 +75,12 @@ public class RevealOperation : Operation
/// List of errors provided by the node, injected the operation to the blockchain. `null` if there is no errors
/// </summary>
public List<OperationError> Errors { get; set; }

#region injecting
/// <summary>
/// Injected historical quote at the time of operation
/// </summary>
public QuoteShort Quote { get; set; }
#endregion
}
}
7 changes: 7 additions & 0 deletions Tzkt.Api/Models/Operations/RevelationPenaltyOperation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,12 @@ public class RevelationPenaltyOperation : Operation
/// Lost due to unrevealed seed nonce total fee paid by all operations, included in the block, which was to be revealed (micro tez)
/// </summary>
public long LostFees { get; set; }

#region injecting
/// <summary>
/// Injected historical quote at the time of operation
/// </summary>
public QuoteShort Quote { get; set; }
#endregion
}
}
7 changes: 7 additions & 0 deletions Tzkt.Api/Models/Operations/TransactionOperation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,5 +127,12 @@ public class TransactionOperation : Operation
/// `false` - no internal operations
/// </summary>
public bool HasInternals { get; set; }

#region injecting
/// <summary>
/// Injected historical quote at the time of operation
/// </summary>
public QuoteShort Quote { get; set; }
#endregion
}
}
34 changes: 34 additions & 0 deletions Tzkt.Api/Models/QuoteShort.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using System;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;

namespace Tzkt.Api.Models
{
public class QuoteShort
{
/// <summary>
/// XTZ/BTC price
/// </summary>
public double? Btc { get; set; }

/// <summary>
/// XTZ/EUR price
/// </summary>
public double? Eur { get; set; }

/// <summary>
/// XTZ/USD price
/// </summary>
public double? Usd { get; set; }
}

[Flags]
[JsonConverter(typeof(StringEnumConverter))]
public enum Symbols
{
None = 0,
Btc = 1,
Eur = 2,
Usd = 4
}
}

0 comments on commit 2879d23

Please sign in to comment.