Beispiel #1
0
        public void CreateToken(Address from, string symbol, string name, BigInteger maxSupply, int decimals, TokenFlags flags, byte[] script)
        {
            var Runtime = this;

            Runtime.Expect(Runtime.IsRootChain(), "must be root chain");

            var pow = Runtime.Transaction.Hash.GetDifficulty();

            Runtime.Expect(pow >= (int)ProofOfWork.Minimal, "expected proof of work");

            Runtime.Expect(!string.IsNullOrEmpty(symbol), "token symbol required");
            Runtime.Expect(!string.IsNullOrEmpty(name), "token name required");

            Runtime.Expect(ValidationUtils.IsValidTicker(symbol), "invalid symbol");
            Runtime.Expect(!Runtime.TokenExists(symbol), "token already exists");

            Runtime.Expect(maxSupply >= 0, "token supply cant be negative");
            Runtime.Expect(decimals >= 0, "token decimals cant be negative");
            Runtime.Expect(decimals <= DomainSettings.MAX_TOKEN_DECIMALS, $"token decimals cant exceed {DomainSettings.MAX_TOKEN_DECIMALS}");

            if (symbol == DomainSettings.FuelTokenSymbol)
            {
                Runtime.Expect(flags.HasFlag(TokenFlags.Fuel), "token should be native");
            }
            else
            {
                Runtime.Expect(!flags.HasFlag(TokenFlags.Fuel), "token can't be native");
            }

            if (symbol == DomainSettings.StakingTokenSymbol)
            {
                Runtime.Expect(flags.HasFlag(TokenFlags.Stakable), "token should be stakable");
            }

            if (symbol == DomainSettings.FiatTokenSymbol)
            {
                Runtime.Expect(flags.HasFlag(TokenFlags.Fiat), "token should be fiat");
            }

            if (!flags.HasFlag(TokenFlags.Fungible))
            {
                Runtime.Expect(!flags.HasFlag(TokenFlags.Divisible), "non-fungible token must be indivisible");
            }

            if (flags.HasFlag(TokenFlags.Divisible))
            {
                Runtime.Expect(decimals > 0, "divisible token must have decimals");
            }
            else
            {
                Runtime.Expect(decimals == 0, "indivisible token can't have decimals");
            }

            Runtime.Expect(from.IsUser, "owner address must be user address");
            Runtime.Expect(Runtime.IsStakeMaster(from), "needs to be master");
            Runtime.Expect(Runtime.IsWitness(from), "invalid witness");

            Nexus.CreateToken(RootStorage, symbol, name, maxSupply, decimals, flags, script);
            Runtime.Notify(EventKind.TokenCreate, from, symbol);
        }
Beispiel #2
0
 public bool CreateToken(string symbol, string name, string platform, Hash hash, BigInteger maxSupply, int decimals, TokenFlags flags, byte[] script)
 {
     return(Nexus.CreateToken(symbol, name, platform, hash, maxSupply, decimals, flags, script));
 }