当前位置: 首页>>代码示例>>C#>>正文


C# Transaction.GetSerializedSize方法代码示例

本文整理汇总了C#中NBitcoin.Transaction.GetSerializedSize方法的典型用法代码示例。如果您正苦于以下问题:C# Transaction.GetSerializedSize方法的具体用法?C# Transaction.GetSerializedSize怎么用?C# Transaction.GetSerializedSize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在NBitcoin.Transaction的用法示例。


在下文中一共展示了Transaction.GetSerializedSize方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CheckTransaction

		//struct GetRejectReason()  { return strRejectReason; }

		public bool CheckTransaction(Transaction tx)
		{
			// Basic checks that don't depend on any context
			if(tx.Inputs.Count == 0)
				return DoS(10, Utils.error("CheckTransaction() : vin empty"),
								 RejectCode.INVALID, "bad-txns-vin-empty");
			if(tx.Outputs.Count == 0)
				return DoS(10, Utils.error("CheckTransaction() : vout empty"),
								 RejectCode.INVALID, "bad-txns-vout-empty");
			// Size limits
			if(tx.GetSerializedSize() > MAX_BLOCK_SIZE)
				return DoS(100, Utils.error("CheckTransaction() : size limits failed"),
								 RejectCode.INVALID, "bad-txns-oversize");

			// Check for negative or overflow output values
			long nValueOut = 0;
			foreach(var txout in tx.Outputs)
			{
				if(txout.Value < 0)
					return DoS(100, Utils.error("CheckTransaction() : txout.nValue negative"),
									 RejectCode.INVALID, "bad-txns-vout-negative");
				if(txout.Value > MAX_MONEY)
					return DoS(100, Utils.error("CheckTransaction() : txout.nValue too high"),
									 RejectCode.INVALID, "bad-txns-vout-toolarge");
				nValueOut += txout.Value;
				if(!((nValueOut >= 0 && nValueOut <= (long)MAX_MONEY)))
					return DoS(100, Utils.error("CheckTransaction() : txout total out of range"),
									 RejectCode.INVALID, "bad-txns-txouttotal-toolarge");
			}

			// Check for duplicate inputs
			var vInOutPoints = new HashSet<OutPoint>();
			foreach(var txin in tx.Inputs)
			{
				if(vInOutPoints.Contains(txin.PrevOut))
					return DoS(100, Utils.error("CheckTransaction() : duplicate inputs"),
									 RejectCode.INVALID, "bad-txns-inputs-duplicate");
				vInOutPoints.Add(txin.PrevOut);
			}

			if(tx.IsCoinBase)
			{
				if(tx.Inputs[0].ScriptSig.Length < 2 || tx.Inputs[0].ScriptSig.Length > 100)
					return DoS(100, Utils.error("CheckTransaction() : coinbase script size"),
									 RejectCode.INVALID, "bad-cb-length");
			}
			else
			{
				foreach(var txin in tx.Inputs)
					if(txin.PrevOut.IsNull)
						return DoS(10, Utils.error("CheckTransaction() : prevout is null"),
										 RejectCode.INVALID, "bad-txns-prevout-null");
			}

			return true;
		}
开发者ID:vebin,项目名称:NBitcoin,代码行数:58,代码来源:ValidationState.cs

示例2: IsStandardTransaction

		public static bool IsStandardTransaction(Transaction tx)
		{
			if(tx.Version > Transaction.CURRENT_VERSION || tx.Version < 1)
			{
				return false;
			}

			//// Treat non-final transactions as non-standard to prevent a specific type
			//// of double-spend attack, as well as DoS attacks. (if the transaction
			//// can't be mined, the attacker isn't expending resources broadcasting it)
			//// Basically we don't want to propagate transactions that can't included in
			//// the next block.
			////
			//// However, IsFinalTx() is confusing... Without arguments, it uses
			//// chainActive.Height() to evaluate nLockTime; when a block is accepted, chainActive.Height()
			//// is set to the value of nHeight in the block. However, when IsFinalTx()
			//// is called within CBlock::AcceptBlock(), the height of the block *being*
			//// evaluated is what is used. Thus if we want to know if a transaction can
			//// be part of the *next* block, we need to call IsFinalTx() with one more
			//// than chainActive.Height().
			////
			//// Timestamps on the other hand don't get any special treatment, because we
			//// can't know what timestamp the next block will have, and there aren't
			//// timestamp applications where it matters.
			//if (!IsFinalTx(tx, chainActive.Height() + 1)) {
			//	reason = "non-final";
			//	return false;
			//}

			// Extremely large transactions with lots of inputs can cost the network
			// almost as much to process as they cost the sender in fees, because
			// computing signature hashes is O(ninputs*txsize). Limiting transactions
			// to MAX_STANDARD_TX_SIZE mitigates CPU exhaustion attacks.
			int sz = tx.GetSerializedSize();
			if(sz >= Transaction.MAX_STANDARD_TX_SIZE)
				return false;


			foreach(TxIn txin in tx.Inputs)
			{
				// Biggest 'standard' txin is a 15-of-15 P2SH multisig with compressed
				// keys. (remember the 520 byte limit on redeemScript size) That works
				// out to a (15*(33+1))+3=513 byte redeemScript, 513+1+15*(73+1)+3=1627
				// bytes of scriptSig, which we round off to 1650 bytes for some minor
				// future-proofing. That's also enough to spend a 20-of-20
				// CHECKMULTISIG scriptPubKey, though such a scriptPubKey is not
				// considered standard)
				if (txin.ScriptSig.Length > 1650)
				{
					return false;
				}
				if(!txin.ScriptSig.IsPushOnly)
				{
					return false;
				}
				if(!txin.ScriptSig.HasCanonicalPushes)
				{
					return false;
				}
			}

			uint nDataOut = 0;
			foreach(TxOut txout in tx.Outputs)
			{
				var template = StandardScripts.GetTemplateFromScriptPubKey(txout.ScriptPubKey);
				if(template == null)
					return false;

				if(template.Type == TxOutType.TX_NULL_DATA)
					nDataOut++;
				else if(txout.IsDust)
					return false;
			}
			// only one OP_RETURN txout is permitted
			if(nDataOut > 1)
			{
				return false;
			}

			return true;
		}
开发者ID:xcrash,项目名称:NBitcoin,代码行数:81,代码来源:StandardScripts.cs

示例3: GetFee

		public Money GetFee(Transaction tx)
		{
			return GetFee(tx.GetSerializedSize());
		}
开发者ID:crowar,项目名称:NBitcoin,代码行数:4,代码来源:FeeRate.cs


注:本文中的NBitcoin.Transaction.GetSerializedSize方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。