示例#1
0
        public void Initialize()
        {
            _interlocutor = new CordInterlocutorMock();
            _contract     = new CallContract();

            OriginContractLinker.Link <ICallContract>(_contract, _interlocutor);
        }
示例#2
0
        private static BigInteger GetVaultBalance()
        {
            object[]     args = new object[] { ExecutionEngine.ExecutingScriptHash };
            CallContract call = (CallContract)TargetToken.ToDelegate();

            return((BigInteger)call("balanceOf", args));
        }
示例#3
0
        // user
        private static object CallTarget(string key, string method, object[] args)
        {
            StorageMap mapping = Storage.CurrentContext.CreateMap(nameof(mapping));

            byte[]       hash = mapping.Get(key);
            CallContract call = (CallContract)hash.ToDelegate();

            return(call(method, args));
        }
示例#4
0
        // util
        private static void RefundToken(string key, BigInteger num)
        {
            StorageMap           contract = Storage.CurrentContext.CreateMap(nameof(contract));
            Map <string, byte[]> map      = (Map <string, byte[]>)contract.Get("actions").Deserialize();

            byte[]       hash = map[key];
            object[]     args = new object[] { num };
            CallContract call = (CallContract)hash.ToDelegate();

            call("refund", args);
        }
示例#5
0
        // strategist
        private static void DoAction(string key, object[] args)
        {
            CheckStrategist();
            CheckKey(key);
            StorageMap           contract = Storage.CurrentContext.CreateMap(nameof(contract));
            Map <string, byte[]> map      = (Map <string, byte[]>)contract.Get("actions").Deserialize();

            byte[]       hash = map[key];
            CallContract call = (CallContract)hash.ToDelegate();

            call("do", args);
        }
示例#6
0
        private static void SendTarget(byte[] hash, BigInteger amount)
        {
            CallContract call = (CallContract)TargetToken.ToDelegate();

            object[] args = new object[] { ExecutionEngine.ExecutingScriptHash, hash, amount };
            bool     ret  = (bool)call("transfer", args);

            if (ret)
            {
                return;
            }
            throw new InvalidOperationException(nameof(SendTarget));
        }
示例#7
0
        // readonly
        private static BigInteger GetExternBalance()
        {
            BigInteger           num      = 0;
            StorageMap           contract = Storage.CurrentContext.CreateMap(nameof(contract));
            Map <string, byte[]> map      = (Map <string, byte[]>)contract.Get("actions").Deserialize();

            foreach (byte[] hash in map.Values)
            {
                object[]     args = new object[] { };
                CallContract call = (CallContract)hash.ToDelegate();
                num += (BigInteger)call("balance", args);
            }
            return(num);
        }