예제 #1
0
        // 生成资产的唯一ID
        private static BigInteger _createID(NftInfo info)
        {
            info.total_supply = info.total_supply + 1;
            BigInteger ID = info.nftid * 10_000_000_000 + (BigInteger)7 * 1_000_000_000 + info.total_supply;

            return(ID);
        }
예제 #2
0
        // 可以动态发行一个新的资产
        private static bool Deploy(BigInteger anftid, BigInteger atype, BigInteger atotal_amount, BigInteger aprice)
        {
            if (!Runtime.CheckWitness(Owner))
            {
                return(false);
            }

            StorageMap nftinfo = Storage.CurrentContext.CreateMap(nameof(nftinfo));

            byte[] ni = nftinfo.Get(anftid.AsByteArray());
            if (ni != null && ni.Length != 0)
            {
                return(false);
            }

            NftInfo info = new NftInfo
            {
                nftid        = anftid,
                type         = atype,
                total_amount = atotal_amount,
                price        = aprice,
                total_supply = 0,
                canbuy       = true
            };

            nftinfo.Put(anftid.AsByteArray(), Helper.Serialize(info));
            return(true);
        }
예제 #3
0
        // 获取某资产的发行信息
        public static NftInfo GetNftSupplyInfo(BigInteger anftid)
        {
            NftInfo    info    = null;
            StorageMap nftinfo = Storage.CurrentContext.CreateMap(nameof(nftinfo));

            byte[] ni = nftinfo.Get(anftid.AsByteArray());
            if (ni != null && ni.Length != 0)
            {
                info = Helper.Deserialize(ni) as NftInfo;
            }
            return(info);
        }
예제 #4
0
        // 从官方购买资产
        private static bool BuyOfficial(byte[] buyer, BigInteger anftid)
        {
            if (!Runtime.CheckWitness(buyer))
            {
                return(false);
            }
            NftInfo    info    = null;
            StorageMap nftinfo = Storage.CurrentContext.CreateMap(nameof(nftinfo));

            byte[] ni = nftinfo.Get(anftid.AsByteArray());
            if (ni == null || ni.Length == 0)
            {
                return(false);
            }

            info = Helper.Deserialize(ni) as NftInfo;
            if (info.total_supply == info.total_amount)
            {
                // 这里需要通知
                NftBuyErr(buyer, anftid, 10002);
                return(false);
            }

            // -----------使用nep5购买
            if (Nep5transfer("transfer", new object[] { buyer, Owner, info.price }) == false)
            {
                NftBuyErr(buyer, anftid, 10001);
                return(false);
            }
            //----------

            BigInteger ID = _createID(info);

            nftinfo.Put(anftid.AsByteArray(), Helper.Serialize(info));

            _saveToAsset(buyer, ID);
            Buyed(buyer, ID, info.nftid, info.type, info.price);
            Transferred(Owner, buyer, ID);
            return(true);
        }