Exemplo n.º 1
0
        protected virtual bool Asset_GetAssetType(ExecutionEngine engine)
        {
            AssetState asset = engine.EvaluationStack.Pop().GetInterface <AssetState>();

            if (asset == null)
            {
                return(false);
            }
            engine.EvaluationStack.Push((int)asset.AssetType);
            return(true);
        }
Exemplo n.º 2
0
        protected virtual bool Asset_GetIssuer(ExecutionEngine engine)
        {
            AssetState asset = engine.EvaluationStack.Pop().GetInterface <AssetState>();

            if (asset == null)
            {
                return(false);
            }
            engine.EvaluationStack.Push(asset.Issuer.ToArray());
            return(true);
        }
Exemplo n.º 3
0
        protected virtual bool Asset_GetOwner(ExecutionEngine engine)
        {
            AssetState asset = engine.EvaluationStack.Pop().GetInterface <AssetState>();

            if (asset == null)
            {
                return(false);
            }
            engine.EvaluationStack.Push(asset.Owner.EncodePoint(true));
            return(true);
        }
Exemplo n.º 4
0
        protected virtual bool Asset_GetAvailable(ExecutionEngine engine)
        {
            AssetState asset = engine.EvaluationStack.Pop().GetInterface <AssetState>();

            if (asset == null)
            {
                return(false);
            }
            engine.EvaluationStack.Push(asset.Available.GetData());
            return(true);
        }
Exemplo n.º 5
0
        protected virtual bool Asset_GetAdmin(ExecutionEngine engine)
        {
            AssetState asset = (engine.EvaluationStack.Pop() as VM.Types.InteropInterface).GetInterface <AssetState>();

            if (asset == null)
            {
                return(false);
            }
            engine.EvaluationStack.Push(asset.Admin.ToArray());
            return(true);
        }
Exemplo n.º 6
0
        protected virtual bool Asset_GetPrecision(ExecutionEngine engine)
        {
            AssetState asset = (engine.EvaluationStack.Pop() as VM.Types.InteropInterface).GetInterface <AssetState>();

            if (asset == null)
            {
                return(false);
            }
            engine.EvaluationStack.Push((int)asset.Precision);
            return(true);
        }
Exemplo n.º 7
0
        protected override bool Blockchain_GetAsset(ExecutionEngine engine)
        {
            UInt256    hash  = new UInt256(engine.EvaluationStack.Pop().GetByteArray());
            AssetState asset = assets.TryGet(hash);

            if (asset == null)
            {
                return(false);
            }
            engine.EvaluationStack.Push(StackItem.FromInterface(asset));
            return(true);
        }
Exemplo n.º 8
0
        private bool Blockchain_GetAsset(ExecutionEngine engine)
        {
            UInt256    hash  = new UInt256(engine.CurrentContext.EvaluationStack.Pop().GetByteArray());
            AssetState asset = Snapshot.Assets.TryGet(hash);

            if (asset == null)
            {
                return(false);
            }
            engine.CurrentContext.EvaluationStack.Push(StackItem.FromInterface(asset));
            return(true);
        }
Exemplo n.º 9
0
 private bool Asset_GetIssuer(ExecutionEngine engine)
 {
     if (engine.CurrentContext.EvaluationStack.Pop() is InteropInterface _interface)
     {
         AssetState asset = _interface.GetInterface <AssetState>();
         if (asset == null)
         {
             return(false);
         }
         engine.CurrentContext.EvaluationStack.Push(asset.Issuer.ToArray());
         return(true);
     }
     return(false);
 }
Exemplo n.º 10
0
 private bool Asset_GetPrecision(ExecutionEngine engine)
 {
     if (engine.CurrentContext.EvaluationStack.Pop() is InteropInterface _interface)
     {
         AssetState asset = _interface.GetInterface <AssetState>();
         if (asset == null)
         {
             return(false);
         }
         engine.CurrentContext.EvaluationStack.Push((int)asset.Precision);
         return(true);
     }
     return(false);
 }
Exemplo n.º 11
0
 protected virtual bool Asset_GetAmount(ExecutionEngine engine)
 {
     if (engine.EvaluationStack.Pop() is InteropInterface _interface)
     {
         AssetState asset = _interface.GetInterface <AssetState>();
         if (asset == null)
         {
             return(false);
         }
         engine.EvaluationStack.Push(asset.Amount.GetData());
         return(true);
     }
     return(false);
 }
Exemplo n.º 12
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);
        }