示例#1
0
        private static ExecutionState Runtime_SwapTokens(RuntimeVM Runtime)
        {
            ExpectStackSize(Runtime, 5);

            VMObject temp;

            temp = Runtime.Stack.Pop();
            Runtime.Expect(temp.Type == VMType.String, "expected string for target chain");
            var targetChain = temp.AsString();

            var source      = PopAddress(Runtime);
            var destination = PopAddress(Runtime);

            temp = Runtime.Stack.Pop();
            Runtime.Expect(temp.Type == VMType.String, "expected string for symbol");
            var symbol = temp.AsString();

            temp = Runtime.Stack.Pop();
            Runtime.Expect(temp.Type == VMType.Number, "expected number for amount");
            var value = temp.AsNumber();

            var token = Runtime.GetToken(symbol);

            if (token.IsFungible())
            {
                Runtime.SwapTokens(Runtime.Chain.Name, source, targetChain, destination, symbol, value, null, null);
            }
            else
            {
                var nft = Runtime.ReadToken(symbol, value);
                Runtime.SwapTokens(Runtime.Chain.Name, source, targetChain, destination, symbol, value, nft.ROM, nft.ROM);
            }

            return(ExecutionState.Running);
        }
示例#2
0
        private static ExecutionState Runtime_TransferBalance(RuntimeVM vm)
        {
            vm.ExpectStackSize(3);

            var source      = vm.PopAddress();
            var destination = vm.PopAddress();

            var symbol = vm.PopString("symbol");

            var token = vm.GetToken(symbol);

            vm.Expect(token.IsFungible(), "must be fungible");

            var amount = vm.GetBalance(symbol, source);

            vm.TransferTokens(symbol, source, destination, amount);

            return(ExecutionState.Running);
        }
示例#3
0
        private static ExecutionState Runtime_TokenGetFlags(RuntimeVM vm)
        {
            vm.ExpectStackSize(1);

            var symbol = vm.PopString("symbol");

            if (!vm.TokenExists(symbol))
            {
                return(ExecutionState.Fault);
            }

            var token = vm.GetToken(symbol);

            var result = new VMObject();

            result.SetValue(token.Flags);
            vm.Stack.Push(result);

            return(ExecutionState.Running);
        }
示例#4
0
        private static ExecutionState Runtime_TransferBalance(RuntimeVM Runtime)
        {
            ExpectStackSize(Runtime, 3);

            VMObject temp;

            var source      = PopAddress(Runtime);
            var destination = PopAddress(Runtime);

            temp = Runtime.Stack.Pop();
            Runtime.Expect(temp.Type == VMType.String, "expected string for symbol");
            var symbol = temp.AsString();

            var token = Runtime.GetToken(symbol);

            Runtime.Expect(token.IsFungible(), "must be fungible");

            var amount = Runtime.GetBalance(symbol, source);

            Runtime.TransferTokens(symbol, source, destination, amount);

            return(ExecutionState.Running);
        }