Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        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);
        }