public void CreateValue(string name, BigInteger initial, BigInteger minimum, BigInteger maximum)
        {
            Runtime.Expect(!HasName(name), "name already exists");
            Runtime.Expect(IsWitness(Runtime.Nexus.GenesisAddress), "genesis must be witness");

            Runtime.Expect(minimum < maximum, "invalid minimum");
            Runtime.Expect(minimum <= initial, "initial should be equal or greater than minimum");
            Runtime.Expect(maximum >= initial, "initial should be equal or lesser than maximum");

            if (name == ValidatorContract.ValidatorCountTag)
            {
                Runtime.Expect(initial == 1, "initial number of validators must always be one");
            }

            var value = new ChainValue()
            {
                Name    = name,
                Current = initial,
                Minimum = minimum,
                Maximum = maximum,
            };

            _valueMap.Set <string, ChainValue>(name, value);
            Runtime.Notify(EventKind.ValueCreate, Runtime.Nexus.GenesisAddress, new ChainValueEventData()
            {
                Name = name, Value = initial
            });
        }
Example #2
0
        public void CreateValue(string name, BigInteger initial, BigInteger minimum, BigInteger maximum)
        {
            Runtime.Expect(!HasName(name), "name already exists");
            Runtime.Expect(IsWitness(Runtime.Nexus.GenesisAddress), "genesis must be witness");

            Runtime.Expect(minimum < maximum, "invalid minimum");
            Runtime.Expect(minimum <= initial, "initial should be equal or greater than minimum");
            Runtime.Expect(maximum >= initial, "initial should be equal or lesser than maximum");

            var value = new ChainValue()
            {
                Name    = name,
                Current = initial,
                Minimum = minimum,
                Maximum = maximum,
                Hash    = Runtime.Transaction.Hash
            };

            _valueMap.Set <string, ChainValue>(name, value);
            Runtime.Notify(EventKind.ValueCreate, Runtime.Nexus.GenesisAddress, new ChainValueEventData()
            {
                Name = name, Value = initial
            });
        }