コード例 #1
0
ファイル: Web3.cs プロジェクト: xchit/Nethereum
 protected virtual void InitialiseInnerServices()
 {
     Eth      = new EthApiContractService(Client);
     Shh      = new ShhApiService(Client);
     Net      = new NetApiService(Client);
     Personal = new PersonalApiService(Client);
 }
コード例 #2
0
 public ContractHandler(string contractAddress, EthApiContractService ethApiContractService,
                        string addressFrom = null)
 {
     ContractAddress       = contractAddress;
     EthApiContractService = ethApiContractService;
     AddressFrom           = addressFrom;
 }
コード例 #3
0
        public void ShouldDecodeMultipleParamsIncludingArray()
        {
            var abi =
                @"[{""constant"":false,""inputs"":[{""name"":""a"",""type"":""uint256""},{""name"":""b"",""type"":""string""},{""name"":""c"",""type"":""uint[3]""} ],""name"":""test"",""outputs"":[{""name"":""d"",""type"":""uint256""}],""type"":""function""}]";

            var ethApi = new EthApiContractService(null, null);

            var contract = ethApi.GetContract(abi, "ContractAddress");

            //get the function by name
            var testFunction = contract.GetFunction("test");
            var array        = new[] { 1, 2, 3 };

            var str    = "hello";
            var data   = testFunction.GetData(69, str, array);
            var decode = testFunction.DecodeInput(data);

            Assert.Equal(69, (BigInteger)decode[0].Result);
            Assert.Equal(str, (string)decode[1].Result);

            var listObjects = decode[2].Result as List <object>;

            if (listObjects != null)
            {
                //System.Array.ConvertAll(listObjects.ToArray(), x => (int)((BigInteger)x));
                var newArray = listObjects.Select(x => (int)(BigInteger)x).ToArray();
                Assert.Equal(array, newArray);
            }
        }
コード例 #4
0
 protected virtual void InitialiseInnerServices()
 {
     Eth         = new EthApiContractService(Client);
     Shh         = new ShhApiService(Client);
     Net         = new NetApiService(Client);
     Personal    = new PersonalApiService(Client);
     Convert     = new UnitConversion();
     sha3Keccack = new Sha3Keccack();
     OfflineTransactionSigner = new TransactionSigner();
     addressUtil = new AddressUtil();
 }
コード例 #5
0
        /// <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);
        }
コード例 #6
0
        public void ShouldDecodeInt()
        {
            var abi =
                @"[{""constant"":false,""inputs"":[{""name"":""a"",""type"":""uint256""}],""name"":""multiply"",""outputs"":[{""name"":""d"",""type"":""uint256""}],""type"":""function""}]";

            var ethApi = new EthApiContractService(null);

            var contract = ethApi.GetContract(abi, "ContractAddress");

            //get the function by name
            var multiplyFunction = contract.GetFunction("multiply");
            var data             = multiplyFunction.GetData(69);
            var decode           = multiplyFunction.DecodeInput(data);

            Assert.Equal(69, (BigInteger)decode[0].Result);
        }
コード例 #7
0
 public void Initialise(EthApiContractService ethApiContractService)
 {
     Eth = ethApiContractService;
 }
コード例 #8
0
 public void Initialise(IClient client, ITransactionManager transactionManager)
 {
     Eth = new EthApiContractService(client, transactionManager);
 }
コード例 #9
0
 public void Initialise(IClient client, IAccount account)
 {
     Eth = new EthApiContractService(client, account.TransactionManager);
 }