69 lines
2.6 KiB
C#
69 lines
2.6 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using Newtonsoft.Json.Linq;
|
|
|
|
namespace Swarmops.Logic.Support
|
|
{
|
|
public class BlockchainTransaction
|
|
{
|
|
static public BlockchainTransaction FromBlockchainInfoJson (JObject json)
|
|
{
|
|
BlockchainTransaction thisTx = new BlockchainTransaction();
|
|
|
|
System.DateTime transactionDateTimeUtc = new DateTime(1970, 1, 1, 0, 0, 0, 0, System.DateTimeKind.Utc);
|
|
thisTx.TransactionDateTimeUtc = transactionDateTimeUtc.AddSeconds(Int64.Parse((string)json["time"]));
|
|
thisTx.TransactionHash = (string) json["hash"];
|
|
|
|
Int64 satoshiCount = 0;
|
|
thisTx.Inputs = new List<BlockchainTransactionRow>();
|
|
foreach (JObject inputRow in json["inputs"])
|
|
{
|
|
BlockchainTransactionRow newRow =
|
|
BlockchainTransactionRow.FromBlockchainInfoJson ((JObject) inputRow["prev_out"]);
|
|
thisTx.Inputs.Add (newRow);
|
|
satoshiCount += newRow.ValueSatoshis;
|
|
}
|
|
foreach (JObject outputRow in json["out"])
|
|
{
|
|
BlockchainTransactionRow newRow =
|
|
BlockchainTransactionRow.FromBlockchainInfoJson(outputRow);
|
|
thisTx.Outputs.Add(newRow);
|
|
satoshiCount -= newRow.ValueSatoshis;
|
|
}
|
|
|
|
thisTx.FeeSatoshis = satoshiCount; // inputs minus outputs equals fee
|
|
|
|
return thisTx;
|
|
}
|
|
|
|
public DateTime TransactionDateTimeUtc { get; private set; }
|
|
public Int64 FeeSatoshis { get; private set; }
|
|
public string TransactionHash { get; private set; }
|
|
|
|
public List<BlockchainTransactionRow> Inputs { get; private set; }
|
|
public List<BlockchainTransactionRow> Outputs { get; private set; }
|
|
}
|
|
|
|
public class BlockchainTransactionRow
|
|
{
|
|
static public BlockchainTransactionRow FromBlockchainInfoJson (JObject json)
|
|
{
|
|
BlockchainTransactionRow newRow = new BlockchainTransactionRow();
|
|
newRow.Address = (string) json["addr"];
|
|
newRow.ValueSatoshis = Int64.Parse ((string) json["value"]);
|
|
newRow.Index = Int32.Parse ((string) json["n"]);
|
|
newRow.Spent = Boolean.Parse ((string) json["spent"]);
|
|
|
|
return newRow;
|
|
}
|
|
|
|
public string Address { get; private set; }
|
|
public bool Spent { get; private set; }
|
|
public Int64 ValueSatoshis { get; private set; }
|
|
public int Index { get; private set; }
|
|
}
|
|
}
|