Esempio n. 1
0
        /// <summary>
        /// Fetch the the NetworkSettings, and set the NetworkSettings variable,
        /// which is used for every subsequent request after the initial ones.
        /// </summary>
        /// <param name="initialPeer">Initial Peer <inheritdoc cref="PeerApi"/> from which the settings are fetched.</param>
        /// <returns>Instiate a <inheritdoc cref="PeerApi"/> based on the initial peer provided.</returns>
        private async Task SetNetworkSettings(PeerApi initialPeer)
        {
            // Request the NetworkSettings, Fees, and more peer address from the peers it connects to.
            var responseAutoConfigure = await initialPeer.MakeRequest(ArkStaticStrings.ArkHttpMethods.GET, ArkStaticStrings.ArkApiPaths.Loader.GET_AUTO_CONFIGURE).ConfigureAwait(false);

            var responseFees = await initialPeer.MakeRequest(ArkStaticStrings.ArkHttpMethods.GET, ArkStaticStrings.ArkApiPaths.Block.GET_FEES).ConfigureAwait(false);

            var responsePeer = await initialPeer.MakeRequest(ArkStaticStrings.ArkHttpMethods.GET, string.Format(ArkStaticStrings.ArkApiPaths.Peer.GET, initialPeer.Ip, initialPeer.Port)).ConfigureAwait(false);

            // Auto-configures what has been fetched previously
            var autoConfig = JsonConvert.DeserializeObject <ArkLoaderNetworkResponse>(responseAutoConfigure);
            var fees       = JsonConvert.DeserializeObject <Fees>(JObject.Parse(responseFees)["fees"].ToString());
            var peer       = JsonConvert.DeserializeObject <ArkPeerResponse>(responsePeer);

            // Fill the NetworkSettings with what has been fetched / auto-configured previously.
            NetworkApi.NetworkSettings = new ArkNetworkSettings()
            {
                Port       = initialPeer.Port,
                BytePrefix = (byte)autoConfig.Network.Version,
                Version    = peer.Peer.Version,
                NetHash    = autoConfig.Network.NetHash,
                Fee        = fees
            };

            await NetworkApi.WarmUp(new PeerApi(NetworkApi, initialPeer.Ip, initialPeer.Port)).ConfigureAwait(false);
        }
Esempio n. 2
0
        /// <summary>
        /// Fetch the the NetworkSettings, and set the NetworkSettings variable,
        /// which is used for every subsequent request after the initial ones.
        /// </summary>
        /// <param name="initialPeer">Initial Peer <inheritdoc cref="PeerApi"/> from which the settings are fetched.</param>
        /// <returns>Instiate a <inheritdoc cref="PeerApi"/> based on the initial peer provided.</returns>
        private async Task SetNetworkSettings(PeerApi initialPeer)
        {
            try
            {
                // Request the NetworkSettings, Fees, and more peer address from the peers it connects to.
                var responseAutoConfigure = await initialPeer.MakeRequest(ArkStaticStrings.ArkHttpMethods.GET, ArkStaticStrings.ArkApiPaths.Loader.GET_AUTO_CONFIGURE).ConfigureAwait(false);

                var responseFees = await initialPeer.MakeRequest(ArkStaticStrings.ArkHttpMethods.GET, ArkStaticStrings.ArkApiPaths.Block.GET_FEES).ConfigureAwait(false);

                var responsePeer = await initialPeer.MakeRequest(ArkStaticStrings.ArkHttpMethods.GET, string.Format(ArkStaticStrings.ArkApiPaths.Peer.GET, initialPeer.Ip, initialPeer.Port)).ConfigureAwait(false);

                // Auto-configures what has been fetched previously
                var autoConfig = JsonConvert.DeserializeObject <ArkLoaderNetworkResponse>(responseAutoConfigure);
                var fees       = JsonConvert.DeserializeObject <Fees>(JObject.Parse(responseFees)["fees"].ToString());
                var peer       = JsonConvert.DeserializeObject <ArkPeerResponse>(responsePeer);

                // Fill the NetworkSettings with what has been fetched / auto-configured previously.
                NetworkApi.NetworkSettings = new ArkNetworkSettings()
                {
                    Port       = initialPeer.Port,
                    BytePrefix = (byte)autoConfig.Network.Version,
                    Version    = peer.Peer.Version,
                    NetHash    = autoConfig.Network.NetHash,
                    Fee        = fees,
                    Token      = autoConfig.Network.Token,
                    Symbol     = autoConfig.Network.Symbol,
                    Explorer   = autoConfig.Network.Explorer
                };

                LoggingApi.Info(string.Format("Set network settings to <<{0}>>", JsonConvert.SerializeObject(NetworkApi.NetworkSettings)));

                await NetworkApi.WarmUp(new PeerApi(this, initialPeer.Ip, initialPeer.Port)).ConfigureAwait(false);
            }
            catch (Exception e)
            {
                LoggingApi.Error(e.ToString());
                throw e;
            }
        }