Exemple #1
0
        public TokenSwapper(Spook node, PhantasmaKeys swapKey, NeoAPI neoAPI, EthAPI ethAPI, BigInteger minFee, string[] supportedPlatforms)
        {
            this.Node         = node;
            this.SwapKeys     = swapKey;
            this.OracleReader = Nexus.GetOracleReader();
            this.MinimumFee   = minFee;
            this.neoAPI       = neoAPI;
            this.ethAPI       = ethAPI;

            this.Storage = new KeyStoreStorage(Nexus.CreateKeyStoreAdapter("swaps"));

            this.interopBlocks = new Dictionary <string, BigInteger>();

            interopBlocks[DomainSettings.PlatformName] = BigInteger.Parse(Settings.Oracle.PhantasmaInteropHeight);
            interopBlocks["neo"]      = BigInteger.Parse(Settings.Oracle.NeoInteropHeight);
            interopBlocks["ethereum"] = BigInteger.Parse(Settings.Oracle.EthInteropHeight);

            _supportedPlatforms.Add(DomainSettings.PlatformName);
            foreach (var entry in supportedPlatforms)
            {
                if (_supportedPlatforms.Contains(entry))
                {
                    throw new SwapException($"Duplicated swap platform {entry}, check config");
                }

                if (!interopBlocks.ContainsKey(entry))
                {
                    throw new SwapException($"Unknown swap platform {entry}, check config");
                }

                _supportedPlatforms.Add(entry);
            }
        }
Exemple #2
0
        public CommandDispatcher(Spook cli)
        {
            _cli = cli;
            RegisterCommandHandler <string>((args, canConsumeAll) =>
            {
                return(CommandToken.ReadString(args, canConsumeAll));
            });

            RegisterCommandHandler <string[]>((args, canConsumeAll) =>
            {
                if (canConsumeAll)
                {
                    var ret = CommandToken.ToString(args);
                    args.Clear();
                    return(ret.Split(new char[] { ',', ' ' }, StringSplitOptions.RemoveEmptyEntries));
                }
                else
                {
                    return(CommandToken.ReadString(args, false).Split(',', ' '));
                }
            });

            RegisterCommandHandler <string, byte>(false, (str) => byte.Parse(str));
            RegisterCommandHandler <string, bool>(false, (str) => str == "1" || str == "yes" || str == "y" || bool.Parse(str));
            RegisterCommandHandler <string, ushort>(false, (str) => ushort.Parse(str));
            RegisterCommandHandler <string, uint>(false, (str) => uint.Parse(str));

            RegisterCommandHandler <string, JObject>((str) => JObject.Parse(str));
            //RegisterCommandHandler<JObject, JArray>((obj) => (JArray)obj);

            RegisterCommand(this);
        }
Exemple #3
0
        public TokenSwapper(Spook node, PhantasmaKeys swapKey, NeoAPI neoAPI, EthAPI ethAPI, EthAPI bscAPI, BigInteger minFee)
        {
            this.Node         = node;
            this.SwapKeys     = swapKey;
            this.OracleReader = Nexus.GetOracleReader();
            this.MinimumFee   = minFee;
            this.neoAPI       = neoAPI;
            this.ethAPI       = ethAPI;
            this.bscAPI       = bscAPI;

            this.Storage = new KeyStoreStorage(Nexus.CreateKeyStoreAdapter("swaps"));

            this._interopBlocks = new Dictionary <SwapPlatformChain, BigInteger>();

            foreach (var platform in Settings.Oracle.SwapPlatforms)
            {
                _interopBlocks[platform.Chain] = platform.InteropHeight;
            }

            var inProgressMap = new StorageMap(InProgressTag, this.Storage);

            Console.WriteLine($"inProgress count: {inProgressMap.Count()}");
            inProgressMap.Visit <Hash, string>((key, value) =>
            {
                if (!string.IsNullOrEmpty(value))
                {
                    Console.WriteLine($"inProgress: {key} - {value}");
                }
            });
        }
Exemple #4
0
        public SpookOracle(Spook cli, Nexus nexus, Logger logger) : base(nexus)
        {
            this._cli = cli;
            nexus.Attach(this);
            platforms   = new KeyValueStore <string, string>(CreateKeyStoreAdapter(StorageConst.Platform.ToString()));
            this.logger = logger;

            logger.Message("Platform count: " + platforms.Count);

            var nexusPlatforms = (nexus as Nexus).GetPlatforms(nexus.RootStorage);

            foreach (var nexusPlatform in nexusPlatforms)
            {
                if (!platforms.ContainsKey(nexusPlatform))
                {
                    platforms.Set(nexusPlatform, nexusPlatform);
                }

                _keyValueStore.Add(nexusPlatform + StorageConst.Block, new KeyValueStore <string, InteropBlock>(CreateKeyStoreAdapter(nexusPlatform + StorageConst.Block)));
                _keyValueStore.Add(nexusPlatform + StorageConst.Transaction, new KeyValueStore <string, InteropTransaction>(CreateKeyStoreAdapter(nexusPlatform + StorageConst.Transaction)));
                _keyValueStore.Add(nexusPlatform + StorageConst.CurrentHeight, new KeyValueStore <string, string>(CreateKeyStoreAdapter(nexusPlatform + StorageConst.CurrentHeight)));
            }
        }
Exemple #5
0
 public SpookShell(string[] args, SpookSettings conf, Spook node)
 {
     _node = node;
 }