本文整理汇总了C#中Transaction.GetSerializedSize方法的典型用法代码示例。如果您正苦于以下问题:C# Transaction.GetSerializedSize方法的具体用法?C# Transaction.GetSerializedSize怎么用?C# Transaction.GetSerializedSize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Transaction
的用法示例。
在下文中一共展示了Transaction.GetSerializedSize方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: WriteTransaction
protected override void WriteTransaction(JsonTextWriter writer, Transaction tx)
{
WritePropertyValue(writer, "hash", tx.GetHash().ToString());
WritePropertyValue(writer, "ver", tx.Version);
WritePropertyValue(writer, "vin_sz", tx.Inputs.Count);
WritePropertyValue(writer, "vout_sz", tx.Outputs.Count);
WritePropertyValue(writer, "lock_time", tx.LockTime.Value);
WritePropertyValue(writer, "size", tx.GetSerializedSize());
writer.WritePropertyName("in");
writer.WriteStartArray();
foreach(var input in tx.Inputs.AsIndexedInputs())
{
var txin = input.TxIn;
writer.WriteStartObject();
writer.WritePropertyName("prev_out");
writer.WriteStartObject();
WritePropertyValue(writer, "hash", txin.PrevOut.Hash.ToString());
WritePropertyValue(writer, "n", txin.PrevOut.N);
writer.WriteEndObject();
if(txin.PrevOut.Hash == uint256.Zero)
{
WritePropertyValue(writer, "coinbase", Encoders.Hex.EncodeData(txin.ScriptSig.ToBytes()));
}
else
{
WritePropertyValue(writer, "scriptSig", txin.ScriptSig.ToString());
}
if(input.WitScript != WitScript.Empty)
{
WritePropertyValue(writer, "witness", input.WitScript.ToString());
}
if(txin.Sequence != uint.MaxValue)
{
WritePropertyValue(writer, "sequence", (uint)txin.Sequence);
}
writer.WriteEndObject();
}
writer.WriteEndArray();
writer.WritePropertyName("out");
writer.WriteStartArray();
foreach(var txout in tx.Outputs)
{
writer.WriteStartObject();
WritePropertyValue(writer, "value", txout.Value.ToString(false, false));
WritePropertyValue(writer, "scriptPubKey", txout.ScriptPubKey.ToString());
writer.WriteEndObject();
}
writer.WriteEndArray();
}
示例2: CanParseWitTransaction
public void CanParseWitTransaction()
{
var hex = "010000000001015d896079097272b13ed9cb22acfabeca9ce83f586d98cc15a08ea2f9c558013b0300000000ffffffff01605af40500000000160014a8cbb5eca9af499cecaa08457690ab367f23d95b0247304402200b6baba4287f3321ae4ec6ba66420d9a48c3f3bc331603e7dca6b12ca75cce6102207fa582041b025605c0474b99a2d3ab5080d6ea14ae3a50b7de92596abf40fb4b012102cdfc0f4701e0c8db3a0913de5f635d0ea76663a8f80925567358d558603fae3500000000";
Transaction tx = new Transaction(hex);
var bytes = tx.ToBytes();
Assert.Equal(Encoders.Hex.EncodeData(bytes), hex);
Assert.Equal("4b3580bbcceb12fee91abc7f9e8e7d092e981d4bb38339204c457a04316d949a", tx.GetHash().ToString());
Assert.Equal("38331098fb804ef2e6dee7826a74b4af07e631a0f1082ffc063667ccb825d701", tx.GetWitHash().ToString());
var noWit = tx.WithOptions(TransactionOptions.None);
Assert.True(noWit.GetSerializedSize() < tx.GetSerializedSize());
tx = new Transaction("010000000001015d896079097272b13ed9cb22acfabeca9ce83f586d98cc15a08ea2f9c558013b0200000000ffffffff01605af40500000000160014a8cbb5eca9af499cecaa08457690ab367f23d95b02483045022100d3edd272c4ff247c36a1af34a2394859ece319f61ee85f759b94ec0ecd61912402206dbdc7c6ca8f7279405464d2d935b5e171dfd76656872f76399dbf333c0ac3a001fd08020000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000000");
ScriptError error;
Assert.False(tx.Inputs.AsIndexedInputs().First().VerifyScript(new Script("0 b7854eb547106248b136ca2bf48d8df2f1167588"), out error));
Assert.Equal(ScriptError.EqualVerify, error);
}
示例3: CanParseWitTransaction
public void CanParseWitTransaction()
{
var hex = "010000000001015d896079097272b13ed9cb22acfabeca9ce83f586d98cc15a08ea2f9c558013b0300000000ffffffff01605af40500000000160014a8cbb5eca9af499cecaa08457690ab367f23d95b0247304402200b6baba4287f3321ae4ec6ba66420d9a48c3f3bc331603e7dca6b12ca75cce6102207fa582041b025605c0474b99a2d3ab5080d6ea14ae3a50b7de92596abf40fb4b012102cdfc0f4701e0c8db3a0913de5f635d0ea76663a8f80925567358d558603fae3500000000";
Transaction tx = new Transaction(hex);
var bytes = tx.ToBytes();
Assert.Equal(Encoders.Hex.EncodeData(bytes), hex);
Assert.Equal("4b3580bbcceb12fee91abc7f9e8e7d092e981d4bb38339204c457a04316d949a", tx.GetHash().ToString());
Assert.Equal("38331098fb804ef2e6dee7826a74b4af07e631a0f1082ffc063667ccb825d701", tx.GetWitHash().ToString());
var noWit = tx.RemoveOption(TransactionOptions.Witness);
Assert.True(noWit.GetSerializedSize() < tx.GetSerializedSize());
}
示例4: Check
public TransactionPolicyError[] Check(Transaction transaction, ICoin[] spentCoins)
{
if(transaction == null)
throw new ArgumentNullException("transaction");
spentCoins = spentCoins ?? new ICoin[0];
List<TransactionPolicyError> errors = new List<TransactionPolicyError>();
foreach(var input in transaction.Inputs.AsIndexedInputs())
{
var coin = spentCoins.FirstOrDefault(s => s.Outpoint == input.PrevOut);
if(coin != null)
{
if(ScriptVerify != null)
{
ScriptError error;
if(!VerifyScript(input, coin.TxOut.ScriptPubKey, ScriptVerify.Value, out error))
{
errors.Add(new ScriptPolicyError(input, error, ScriptVerify.Value, coin.TxOut.ScriptPubKey));
}
}
}
var txin = input.TxIn;
if(txin.ScriptSig.Length > MaxScriptSigLength)
{
errors.Add(new InputPolicyError("Max scriptSig length exceeded actual is " + txin.ScriptSig.Length + ", max is " + MaxScriptSigLength, input));
}
if(!txin.ScriptSig.IsPushOnly)
{
errors.Add(new InputPolicyError("All operation should be push", input));
}
if(!txin.ScriptSig.HasCanonicalPushes)
{
errors.Add(new InputPolicyError("All operation should be canonical push", input));
}
}
foreach(var txout in transaction.Outputs.AsCoins())
{
var template = StandardScripts.GetTemplateFromScriptPubKey(txout.ScriptPubKey);
if(template == null)
errors.Add(new OutputPolicyError("Non-Standard scriptPubKey", (int)txout.Outpoint.N));
}
int txSize = transaction.GetSerializedSize();
if(MaxTransactionSize != null)
{
if(txSize >= MaxTransactionSize.Value)
errors.Add(new TransactionSizePolicyError(txSize, MaxTransactionSize.Value));
}
var fees = transaction.GetFee(spentCoins);
if(fees != null)
{
if(CheckFee)
{
if(MaxTxFee != null)
{
var max = MaxTxFee.GetFee(txSize);
if(fees > max)
errors.Add(new FeeTooHighPolicyError(fees, max));
}
if(MinRelayTxFee != null)
{
if(MinRelayTxFee != null)
{
var min = MinRelayTxFee.GetFee(txSize);
if(fees < min)
errors.Add(new FeeTooLowPolicyError(fees, min));
}
}
}
}
if(MinRelayTxFee != null)
{
foreach(var output in transaction.Outputs)
{
var bytes = output.ScriptPubKey.ToBytes(true);
if(output.IsDust(MinRelayTxFee) && !IsOpReturn(bytes))
errors.Add(new DustPolicyError(output.Value, output.GetDustThreshold(MinRelayTxFee)));
}
}
var opReturnCount = transaction.Outputs.Select(o => o.ScriptPubKey.ToBytes(true)).Count(b => IsOpReturn(b));
if(opReturnCount > 1)
errors.Add(new TransactionPolicyError("More than one op return detected"));
return errors.ToArray();
}