public static bool TryFromScript(byte[] script, out ScriptHash scriptHash) { if (script == null) { throw new ArgumentNullException(nameof(script)); } var isScriptHash = script.Length == 23 && script[0] == (byte)Opcode.OpHash160 && script[1] == (byte)Opcode.OpData20 && script[22] == (byte)Opcode.OpEqual; if (!isScriptHash) { scriptHash = null; return(false); } var hash160 = new byte[Ripemd160Hash.Length]; Array.Copy(script, 2, hash160, 0, Ripemd160Hash.Length); scriptHash = new ScriptHash(script, hash160); return(true); }
public static OutputScript ParseScript(byte[] script) { PubKeyHash pubKeyHash; if (PubKeyHash.TryFromScript(script, out pubKeyHash)) { return(pubKeyHash); } ScriptHash scriptHash; if (ScriptHash.TryFromScript(script, out scriptHash)) { return(scriptHash); } PubKey pubKey; if (PubKey.TryFromScript(script, out pubKey)) { return(pubKey); } return(new Unrecognized(script)); }
public void Write(SerializedWriter writer) { if (HasScriptType(writer.Generation)) { writer.Write((int)ClassID); writer.Write(IsStrippedType); writer.Write(ScriptID); } else { writer.Write(UniqueTypeID); } if (HasHash(writer.Generation)) { if (ClassID == ClassIDType.MonoBehaviour) { ScriptHash.Write(writer); } TypeHash.Write(writer); } // isSerializeTypeTrees Tree?.Write(writer); }
public void Read(SerializedFileStream stream) { ClassID = (ClassIDType)stream.ReadInt32(); if (IsReadUnknown(stream.Generation)) { Unknown = stream.ReadByte(); ScriptID = stream.ReadInt16(); } if (IsReadHash(stream.Generation)) { if (IsOldHashType(stream.Generation)) { if ((int)ClassID <= -1) { ScriptHash.Read(stream); } } else { if (ClassID == ClassIDType.MonoBehaviour) { ScriptHash.Read(stream); } } TypeHash.Read(stream); } // isSerializeTypeTrees if (Tree != null) { Tree.Read(stream); } }
public static OutputScript ParseScript(byte[] script) { Secp256k1PubKeyHash secp256k1PubKeyHash; if (Secp256k1PubKeyHash.TryFromScript(script, out secp256k1PubKeyHash)) { return(secp256k1PubKeyHash); } Ed25519PubKeyHash ed25519PubKeyHash; if (Ed25519PubKeyHash.TryFromScript(script, out ed25519PubKeyHash)) { return(ed25519PubKeyHash); } SecSchnorrPubKeyHash secSchnorrPubKeyHash; if (SecSchnorrPubKeyHash.TryFromScript(script, out secSchnorrPubKeyHash)) { return(secSchnorrPubKeyHash); } ScriptHash scriptHash; if (ScriptHash.TryFromScript(script, out scriptHash)) { return(scriptHash); } return(new Unrecognized(script)); }
public void Read(SerializedReader reader) { if (HasScriptType(reader.Generation)) { ClassID = (ClassIDType)reader.ReadInt32(); IsStrippedType = reader.ReadBoolean(); ScriptID = reader.ReadInt16(); } else { UniqueTypeID = reader.ReadInt32(); } if (HasHash(reader.Generation)) { if (ClassID == ClassIDType.MonoBehaviour) { ScriptHash.Read(reader); } TypeHash.Read(reader); } // isSerializeTypeTrees Tree?.Read(reader); }
public void Read(SerializedFileReader reader) { ClassID = (ClassIDType)reader.ReadInt32(); if (IsReadScriptType(reader.Generation)) { IsStrippedType = reader.ReadBoolean(); ScriptID = reader.ReadInt16(); } else { // For old version it specifies ClassIDType or -ScriptID for MonoBehaviour int uniqueTypeID = (int)ClassID; if (uniqueTypeID < 0) { ClassID = ClassIDType.MonoBehaviour; ScriptID = (short)(-uniqueTypeID - 1); } } if (IsReadHash(reader.Generation)) { if (ClassID == ClassIDType.MonoBehaviour) { ScriptHash.Read(reader); } TypeHash.Read(reader); } // isSerializeTypeTrees if (Tree != null) { Tree.Read(reader); } }
public StackItem ToStackItem(ReferenceCounter referenceCounter) { return(new Array(referenceCounter) { ScriptHash.ToArray(), EventName, State }); }
public int CompareTo(Contract other) { if (ReferenceEquals(this, other)) { return(0); } return(ScriptHash.ToHexString().CompareTo(other.ScriptHash.ToHexString())); }
public override bool Equals(object obj) { if (obj is NEP6Account acc) { return(ScriptHash.Equals(acc.ScriptHash)); } return(false); }
public JObject ToJson() { return(new JObject { ["asset"] = Asset.ToString(), ["value"] = Value, ["address"] = ScriptHash.ToAddress(), }); }
public JObject ToJson(ProtocolSettings protocolSettings) { return(new JObject { ["asset"] = Asset.ToString(), ["value"] = Value, ["address"] = ScriptHash.ToAddress(protocolSettings.AddressVersion), }); }
/// <summary> /// 比较与另一个对象是否相等 /// </summary> /// <param name="other">另一个对象</param> /// <returns>返回比较的结果</returns> public bool Equals(Contract other) { if (ReferenceEquals(this, other)) { return(true); } if (ReferenceEquals(null, other)) { return(false); } return(ScriptHash.Equals(other.ScriptHash)); }
public bool Equals(VerificationContract other) { if (ReferenceEquals(this, other)) { return(true); } if (other is null) { return(false); } return(ScriptHash.Equals(other.ScriptHash)); }
/// <summary> /// 比较与另一个对象是否相等 /// </summary> /// <param name="other">另一个对象</param> /// <returns>返回比较的结果</returns> public bool Equals(VerificationContract other) { TR.Enter(); if (ReferenceEquals(this, other)) { return(TR.Exit(true)); } if (ReferenceEquals(null, other)) { return(TR.Exit(false)); } return(TR.Exit(ScriptHash.Equals(other.ScriptHash))); }
public JObject ToJson() { JObject account = new JObject(); account["address"] = ScriptHash.ToAddress(); account["label"] = Label; account["isDefault"] = IsDefault; account["lock"] = Lock; account["key"] = nep2key; account["contract"] = ((NEP6Contract)Contract)?.ToJson(); account["extra"] = Extra; return(account); }
public ExpressWalletAccount ToExpressWalletAccount() => new ExpressWalletAccount() { PrivateKey = key?.PrivateKey.ToHexString() ?? string.Empty, ScriptHash = ScriptHash.ToAddress(ProtocolSettings.AddressVersion), Label = Label, IsDefault = IsDefault, Contract = new ExpressWalletAccount.AccountContract() { Script = Contract.Script.ToHexString(), Parameters = Contract.ParameterList .Select(p => Enum.GetName(typeof(ContractParameterType), p) ?? string.Empty) .ToList() } };
public bool ScriptExists(string script, CommandFlags flags = CommandFlags.None) { var msg = Message.Create(-1, flags, RedisCommand.SCRIPT, RedisLiterals.EXISTS, ScriptHash.Hash(script)); return(ExecuteSync(msg, ResultProcessor.Boolean)); }
public Task <bool> ScriptExistsAsync(byte[] sha1, CommandFlags flags = CommandFlags.None) { var msg = Message.Create(-1, flags, RedisCommand.SCRIPT, RedisLiterals.EXISTS, ScriptHash.Encode(sha1)); return(ExecuteAsync(msg, ResultProcessor.Boolean)); }
public override int GetHashCode() { return(ScriptHash.GetHashCode()); }
/// <summary> /// 获得HashCode /// </summary> /// <returns>返回HashCode</returns> public override int GetHashCode() { TR.Enter(); return(TR.Exit(ScriptHash.GetHashCode())); }
/// <summary> /// String representation /// </summary> public override string ToString() { return($"[{ScriptHash.ToHexString()}-{InstructionPointer:x6}] {NextInstruction}"); }
public static bool TryFromScript(byte[] script, out ScriptHash scriptHash) { if (script == null) throw new ArgumentNullException(nameof(script)); var isScriptHash = script.Length == 23 && script[0] == (byte)Opcode.OpHash160 && script[1] == (byte)Opcode.OpData20 && script[22] == (byte)Opcode.OpEqual; if (!isScriptHash) { scriptHash = null; return false; } var hash160 = new byte[Ripemd160Hash.Length]; Array.Copy(script, 2, hash160, 0, Ripemd160Hash.Length); scriptHash = new ScriptHash(script, hash160); return true; }
public bool Equals(NEP6Account obj) { return(ScriptHash.Equals(obj)); }
public StackItem ToStackItem(ReferenceCounter referenceCounter) { return(new Array(referenceCounter, new[] { ScriptHash.ToArray(), State })); }
public override string ToString() { return($"{ScriptHash.ToAddress()}\t{Value}\t{AssetName}"); }
public override string ToString() { return($"{ScriptHash.ToAddress(Program.Service.NeoSystem.Settings.AddressVersion)}\t{Value}\t{AssetName}"); }
public object Execute(string script, string fileName, bool unwrap) { if (script == null) throw new ArgumentNullException("script"); var key = new ScriptHash(fileName, script); JsMain @delegate; if (!_cachedScripts.TryGetValue(key, out @delegate)) { var compilationResult = CompileProgram(script, fileName); if (compilationResult.Main != null) { @delegate = compilationResult.Main; _cachedScripts.Add(key, @delegate); } else { var literalResult = compilationResult.LiteralResult; Debug.Assert(literalResult != null); if (unwrap) literalResult = Global.Marshaller.MarshalJsValue<object>(literalResult); return literalResult; } } // Don't wrap exceptions while debugging to make stack traces // easier to read. object result; #if !DEBUG try { #endif result = @delegate(_runtime); #if !DEBUG } catch (SecurityException) { throw; } catch (JsException e) { throw new JintException(e.Message, e); } catch (Exception e) { throw new JintException(e.Message, e); } #endif if (result == null) return null; if (unwrap) return Global.Marshaller.MarshalJsValue<object>(result); return result; }