示例#1
0
		private bool ReadScript(Script script)
		{
			var bytes = script.ToBytes(true);
			if(bytes.Length == 0 || bytes[0] != (byte)OpcodeType.OP_RETURN)
				return false;
			foreach(var op in script.ToOps())
			{
				if(op.PushData != null && !op.IsInvalid)
				{
					if(ReadData(op.PushData))
						return true;
				}
			}
			return false;
		}
示例#2
0
		private static bool Fill(StealthMetadata output, Script metadata)
		{
			var ops = metadata.ToOps().ToArray();
			if(ops.Length != 2 || ops[0].Code != OpcodeType.OP_RETURN)
				return false;
			var data = ops[1].PushData;
			if(data == null || data.Length != 1 + 4 + 33)
				return false;
			MemoryStream ms = new MemoryStream(data);
			output.Version = ms.ReadByte();
			if(output.Version != 6)
				return false;
			output.Nonce = ms.ReadBytes(4);
			output.EphemKey = new PubKey(ms.ReadBytes(33));
			output.Script = metadata;
			output.Hash = Hashes.Hash256(data);
			var msprefix = new MemoryStream(output.Hash.ToBytes(false));
			output.BitField = Utils.ToUInt32(msprefix.ReadBytes(4), true);
			return true;
		}
示例#3
0
		/// <summary>
		/// Register the specified ScriptPubKey
		/// </summary>
		/// <param name="scriptPubKey">The ScriptPubKey</param>
		/// <param name="isRedeemScript">If true, the P2SH of the destination's script will be tracked (Default: false)</param>
		/// <param name="isInternal">If true, the scriptPubKey will not belong to tracked data, typically, change addresses (Default: false)</param>
		/// <param name="filter">The filter in which this key will appear (http://eprint.iacr.org/2014/763.pdf)</param>
		/// <param name="wallet">The wallet name to which it belongs</param>
		public bool Add(Script scriptPubKey, bool isRedeemScript = false, bool isInternal = false, string filter = "a", string wallet = "default")
		{
			if(filter == null)
				throw new ArgumentNullException("filter");
			if(wallet == null)
				throw new ArgumentNullException("wallet");
			Script redeem = isRedeemScript ? scriptPubKey : null;
			scriptPubKey = isRedeemScript ? scriptPubKey.Hash.ScriptPubKey : scriptPubKey;
			var data = scriptPubKey.ToOps().First(o => o.PushData != null).PushData;

			var trackedScript = new TrackedScript()
			{
				ScriptPubKey = scriptPubKey,
				RedeemScript = redeem,
				AddedDate = DateTimeOffset.UtcNow,
				IsInternal = isInternal,
				Filter = filter,
				Wallet = wallet
			};

			bool added = false;
			lock(cs)
			{
				added = _TrackedScripts.TryAdd(trackedScript.GetId(), trackedScript);
			}
			return added;
		}