/// <summary>
        /// Returns a <see cref="Contract"/> instance for one of the known cryptokitty contracts.
        /// </summary>
        /// <param name="instance">The <see cref="EthApiContractService"/> being extended.</param>
        /// <param name="contract">A <see cref="CryptoKittyContractType"/> identifying the desired contract.</param>
        /// <returns>A <see cref="Contract"/> instance.</returns>
        /// <exception cref="ArgumentOutOfRangeException">Thrown if <paramref name="contract"/> is not a recognized value.</exception>
        /// <exception cref="InvalidOperationException">Thrown if there is some failure attaching to a valid contract.</exception>
        public static Contract GetKittyContract(this EthApiContractService instance, CryptoKittyContractType contract)
        {
            // Note that ForContract will throw on an invalid contract type
            var address = Globals.Contracts.Address.ForContract(contract);
            // If we made it this far then we know we were givven a good contract
            var ret = instance.GetContract(Globals.Contracts.ABI.ForContract(contract), address);

            if (ret == null)
            {
                throw new InvalidOperationException(Res.FatalContractFailure);
            }
            return(ret);
        }
Esempio n. 2
0
                /// <summary>
                /// Returns the ABI for known cryptokitty contracts.
                /// </summary>
                /// <param name="contractType">A <see cref="CryptoKittyContractType"/> identifying the kitty contractType.</param>
                /// <returns>A <see cref="string"/> that contains the specified ABI.</returns>
                /// <exception cref="ArgumentOutOfRangeException">Thrown when <paramref name="contractType"/> is not a supported value.</exception>
                public static string ForContract(CryptoKittyContractType contractType)
                {
                    switch (contractType)
                    {
                    case CryptoKittyContractType.Core:
                        return(KittyCore);

                    case CryptoKittyContractType.Sales:
                        return(SalesAuction);

                    case CryptoKittyContractType.Siring:
                        return(SiringAuction);
                    }
                    throw new ArgumentOutOfRangeException(nameof(contractType), contractType, Res.UnsupportedKittyContractValue);
                }