private bool Validator_Register(ExecutionEngine engine) { ECPoint pubkey = ECPoint.DecodePoint(engine.EvaluationStack.Pop().GetByteArray(), ECCurve.Secp256r1); if (pubkey.IsInfinity) { return(false); } if (!CheckWitness(engine, pubkey)) { return(false); } ValidatorState validator = validators.GetOrAdd(pubkey, () => new ValidatorState { PublicKey = pubkey }); engine.EvaluationStack.Push(StackItem.FromInterface(validator)); return(true); }
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()); Fixed8 a_fee = new Fixed8((long)engine.EvaluationStack.Pop().GetBigInteger()); Fixed8 t_fee = new Fixed8((long)engine.EvaluationStack.Pop().GetBigInteger()); Fixed8 t_fee_min = new Fixed8((long)engine.EvaluationStack.Pop().GetBigInteger()); Fixed8 t_fee_max = new Fixed8((long)engine.EvaluationStack.Pop().GetBigInteger()); UInt160 feeAddress = 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 = t_fee, FeeMin = t_fee_min, FeeMax = t_fee_max, FeeAddress = feeAddress, Owner = owner, Admin = admin, Issuer = issuer, Expiration = Blockchain.Default.Height + 1 + 4000000, // 2 Years IsFrozen = false, AFee = a_fee }); engine.EvaluationStack.Push(StackItem.FromInterface(asset)); return(true); }