public void Serialize_WrongJson() { Assert.ThrowsException <FormatException>(() => JsonSerializer.Serialize(StackItem.FromInterface(new object()))); }
private bool Contract_Migrate(ExecutionEngine engine) { byte[] script = engine.EvaluationStack.Pop().GetByteArray(); if (script.Length > 1024 * 1024) { return(false); } ContractParameterType[] parameter_list = engine.EvaluationStack.Pop().GetByteArray().Select(p => (ContractParameterType)p).ToArray(); if (parameter_list.Length > 252) { return(false); } ContractParameterType return_type = (ContractParameterType)(byte)engine.EvaluationStack.Pop().GetBigInteger(); bool need_storage = engine.EvaluationStack.Pop().GetBoolean(); if (engine.EvaluationStack.Peek().GetByteArray().Length > 252) { return(false); } string name = Encoding.UTF8.GetString(engine.EvaluationStack.Pop().GetByteArray()); if (engine.EvaluationStack.Peek().GetByteArray().Length > 252) { return(false); } string version = Encoding.UTF8.GetString(engine.EvaluationStack.Pop().GetByteArray()); if (engine.EvaluationStack.Peek().GetByteArray().Length > 252) { return(false); } string author = Encoding.UTF8.GetString(engine.EvaluationStack.Pop().GetByteArray()); if (engine.EvaluationStack.Peek().GetByteArray().Length > 252) { return(false); } string email = Encoding.UTF8.GetString(engine.EvaluationStack.Pop().GetByteArray()); if (engine.EvaluationStack.Peek().GetByteArray().Length > 65536) { return(false); } string description = Encoding.UTF8.GetString(engine.EvaluationStack.Pop().GetByteArray()); UInt160 hash = script.ToScriptHash(); ContractState contract = contracts.TryGet(hash); if (contract == null) { contract = new ContractState { Script = script, ParameterList = parameter_list, ReturnType = return_type, HasStorage = need_storage, Name = name, CodeVersion = version, Author = author, Email = email, Description = description }; contracts.Add(hash, contract); contracts_created.Add(hash, new UInt160(engine.CurrentContext.ScriptHash)); if (need_storage) { foreach (var pair in storages.Find(engine.CurrentContext.ScriptHash).ToArray()) { storages.Add(new StorageKey { ScriptHash = hash, Key = pair.Key.Key }, new StorageItem { Value = pair.Value.Value }); } } } engine.EvaluationStack.Push(StackItem.FromInterface(contract)); return(true); }
private static bool Block_GetTransactions(ApplicationEngine engine) { if (engine.CurrentContext.EvaluationStack.Pop() is InteropInterface _interface) { Block block = _interface.GetInterface <Block>(); if (block == null) { return(false); } if (block.Transactions.Length > engine.MaxArraySize) { return(false); } engine.CurrentContext.EvaluationStack.Push(block.Transactions.Select(p => StackItem.FromInterface(p)).ToArray()); return(true); } return(false); }
private bool Asset_Create(ExecutionEngine engine) { InvocationTransaction tx = (InvocationTransaction)engine.ScriptContainer; AssetType asset_type = (AssetType)(byte)engine.EvaluationStack.Pop().GetBigInteger(); if (!Enum.IsDefined(typeof(AssetType), asset_type) || asset_type == AssetType.CreditFlag || asset_type == AssetType.DutyFlag || asset_type == AssetType.GoverningToken || asset_type == AssetType.UtilityToken) { return(false); } if (engine.EvaluationStack.Peek().GetByteArray().Length > 1024) { return(false); } string name = Encoding.UTF8.GetString(engine.EvaluationStack.Pop().GetByteArray()); Fixed8 amount = new Fixed8((long)engine.EvaluationStack.Pop().GetBigInteger()); if (amount == Fixed8.Zero || amount < -Fixed8.Satoshi) { return(false); } if (asset_type == AssetType.Invoice && amount != -Fixed8.Satoshi) { return(false); } byte precision = (byte)engine.EvaluationStack.Pop().GetBigInteger(); if (precision > 8) { return(false); } if (asset_type == AssetType.Share && precision != 0) { return(false); } if (amount != -Fixed8.Satoshi && amount.GetData() % (long)Math.Pow(10, 8 - precision) != 0) { return(false); } ECPoint owner = ECPoint.DecodePoint(engine.EvaluationStack.Pop().GetByteArray(), ECCurve.Secp256r1); if (owner.IsInfinity) { return(false); } if (!CheckWitness(engine, owner)) { return(false); } UInt160 admin = new UInt160(engine.EvaluationStack.Pop().GetByteArray()); UInt160 issuer = new UInt160(engine.EvaluationStack.Pop().GetByteArray()); AssetState asset = assets.GetOrAdd(tx.Hash, () => new AssetState { AssetId = tx.Hash, AssetType = asset_type, Name = name, Amount = amount, Available = Fixed8.Zero, Precision = precision, Fee = Fixed8.Zero, FeeAddress = new UInt160(), Owner = owner, Admin = admin, Issuer = issuer, Expiration = Blockchain.Default.Height + 1 + 2000000, IsFrozen = false }); engine.EvaluationStack.Push(StackItem.FromInterface(asset)); return(true); }
private static bool ExecutionEngine_GetScriptContainer(ApplicationEngine engine) { engine.CurrentContext.EvaluationStack.Push(StackItem.FromInterface(engine.ScriptContainer)); return(true); }