├── config ├── dev.exs ├── test.exs └── config.exs ├── test ├── test_helper.exs ├── support │ ├── http_client_mock.ex │ └── crypto_kitties.json └── eth_contract_test.exs ├── .formatter.exs ├── .gitignore ├── lib ├── eth_contract │ └── util.ex └── eth_contract.ex ├── mix.exs ├── README.md ├── mix.lock └── LICENSE /config/dev.exs: -------------------------------------------------------------------------------- 1 | use Mix.Config 2 | 3 | -------------------------------------------------------------------------------- /test/test_helper.exs: -------------------------------------------------------------------------------- 1 | ExUnit.start() 2 | -------------------------------------------------------------------------------- /config/test.exs: -------------------------------------------------------------------------------- 1 | use Mix.Config 2 | 3 | config :eth_contract, :json_rpc_client, EthContract.HttpClientMock 4 | -------------------------------------------------------------------------------- /.formatter.exs: -------------------------------------------------------------------------------- 1 | # Used by "mix format" 2 | [ 3 | inputs: ["mix.exs", "{config,lib,test}/**/*.{ex,exs}"] 4 | ] 5 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # The directory Mix will write compiled artifacts to. 2 | /_build/ 3 | 4 | # If you run "mix test --cover", coverage assets end up here. 5 | /cover/ 6 | 7 | # The directory Mix downloads your dependencies sources to. 8 | /deps/ 9 | 10 | # Where 3rd-party dependencies like ExDoc output generated docs. 11 | /doc/ 12 | 13 | # Ignore .fetch files in case you like to edit your project deps locally. 14 | /.fetch 15 | 16 | # If the VM crashes, it generates a dump, let's ignore it too. 17 | erl_crash.dump 18 | 19 | # Also ignore archive artifacts (built via "mix archive.build"). 20 | *.ez 21 | 22 | # Ignore package tarball (built via "mix hex.build"). 23 | elixir_blockchain-*.tar 24 | 25 | *.swp 26 | *.swo 27 | -------------------------------------------------------------------------------- /lib/eth_contract/util.ex: -------------------------------------------------------------------------------- 1 | defmodule EthContract.Util do 2 | def total_supply_hex() do 3 | ABI.encode("totalSupply()", []) 4 | |> Base.encode16(case: :lower) 5 | end 6 | 7 | def owner_of_hex(token_index) do 8 | ABI.encode("ownerOf(uint256)", [token_index]) 9 | |> Base.encode16(case: :lower) 10 | end 11 | 12 | def balance_of_hex(address) do 13 | case address_to_bytes(address) do 14 | {:ok, address } -> 15 | case ABI.encode("balanceOf(address)", [address]) |> Base.encode16(case: :lower) do 16 | {:error, _ } -> { :error, "Error decoding data" } 17 | signature -> 18 | {:ok, signature} 19 | end 20 | {:error, message } -> { :error, message } 21 | end 22 | end 23 | 24 | def address_to_bytes(address) do 25 | address = address 26 | |> String.slice(2..-1) 27 | 28 | case Base.decode16(address, case: :mixed) do 29 | {:ok, address } -> {:ok, address} 30 | :error -> {:error, "Error converting address to bytes" } 31 | end 32 | end 33 | 34 | def meta_for_hex(token_id, method) do 35 | ABI.encode("#{method}(uint256)", [token_id]) 36 | |> Base.encode16(case: :lower) 37 | end 38 | end 39 | -------------------------------------------------------------------------------- /config/config.exs: -------------------------------------------------------------------------------- 1 | # This file is responsible for configuring your application 2 | # and its dependencies with the aid of the Mix.Config module. 3 | use Mix.Config 4 | 5 | # This configuration is loaded before any dependency and is restricted 6 | # to this project. If another project depends on this project, this 7 | # file won't be loaded nor affect the parent project. For this reason, 8 | # if you want to provide default values for your application for 9 | # 3rd-party users, it should be done in your "mix.exs" file. 10 | 11 | # You can configure your application as: 12 | # 13 | # config :elixir_blockchain, key: :value 14 | # 15 | # and access this configuration in your application as: 16 | # 17 | # Application.get_env(:elixir_blockchain, :key) 18 | # 19 | # You can also configure a 3rd-party app: 20 | # 21 | # config :logger, level: :info 22 | # 23 | 24 | # It is also possible to import configuration files, relative to this 25 | # directory. For example, you can emulate configuration per environment 26 | # by uncommenting the line below and defining dev.exs, test.exs and such. 27 | # Configuration from the imported file will override the ones defined 28 | # here (which is why it is important to import them last). 29 | # 30 | 31 | import_config "#{Mix.env}.exs" 32 | -------------------------------------------------------------------------------- /mix.exs: -------------------------------------------------------------------------------- 1 | defmodule EthContract.MixProject do 2 | use Mix.Project 3 | 4 | def project do 5 | [ 6 | app: :eth_contract, 7 | version: "0.2.9", 8 | elixir: "~> 1.6", 9 | start_permanent: Mix.env() == :prod, 10 | name: "ETHContract", 11 | elixirc_paths: elixirc_paths(Mix.env), 12 | description: description(), 13 | package: package(), 14 | deps: deps() 15 | ] 16 | end 17 | 18 | defp elixirc_paths(:test), do: ["lib", "test/support"] 19 | defp elixirc_paths(_), do: ["lib"] 20 | 21 | # Run "mix help compile.app" to learn about applications. 22 | def application do 23 | [ 24 | extra_applications: [:logger] 25 | ] 26 | end 27 | 28 | defp description() do 29 | "A set of helper methods for calling ETH Smart Contracts via JSON RPC." 30 | end 31 | 32 | defp package() do 33 | [ 34 | # This option is only needed when you don't want to use the OTP application name 35 | name: "eth_contract", 36 | # These are the default files included in the package 37 | files: ["lib", "mix.exs", "README*"], 38 | maintainers: ["Razvan Draghici"], 39 | licenses: ["Apache 2.0"], 40 | links: %{"GitHub" => "https://github.com/agilealpha/eth_contract"} 41 | ] 42 | end 43 | 44 | # Run "mix help deps" to learn about dependencies. 45 | defp deps do 46 | [ 47 | {:ethereumex, "~> 0.3.2"}, 48 | {:abi, "~> 0.1.8"}, 49 | {:ex_doc, "~> 0.14", only: :dev} 50 | ] 51 | end 52 | end 53 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # EthContract 2 | 3 | A set of helper methods to help query ETH smart contracts 4 | 5 | ## Installation 6 | 7 | If [available in Hex](https://hex.pm/docs/publish), the package can be installed 8 | by adding `eth_contract` to your list of dependencies in `mix.exs`: 9 | 10 | ```elixir 11 | def deps do 12 | [ 13 | {:eth_contract, "~> 0.1.0"} 14 | ] 15 | end 16 | ``` 17 | 18 | Documentation can be generated with [ExDoc](https://github.com/elixir-lang/ex_doc) 19 | and published on [HexDocs](https://hexdocs.pm). Once published, the docs can 20 | be found at [https://hexdocs.pm/eth_contract](https://hexdocs.pm/eth_contract). 21 | 22 | ## Configuration 23 | 24 | Add your JSON RPC provider URL in config.exs 25 | 26 | ```elixir 27 | config :ethereumex, 28 | url: "http://" 29 | ``` 30 | 31 | ## Usage 32 | 33 | Load and parse the ABI 34 | 35 | ``` 36 | abi = EthContract.parse_abi("crypto_kitties.json") 37 | ``` 38 | 39 | Get meta given a token_id and method name 40 | 41 | ``` 42 | EthContract.meta(%{token_id: 45, method: "getKitty", contract: "0x06012c8cf97BEaD5deAe237070F9587f8E7A266d", abi: abi}) 43 | ``` 44 | 45 | This will return a map with all the meta: 46 | 47 | ``` 48 | %{ "birthTime" => 1511417999, 49 | "cooldownIndex" => 0, 50 | "generation" => 0, 51 | "genes" => 626837621154801616088980922659877168609154386318304496692374110716999053, 52 | "isGestating" => false, 53 | "isReady" => true, 54 | "matronId" => 0, 55 | "nextActionAt" => 0, 56 | "sireId" => 0, 57 | "siringWithId" => 0 58 | } 59 | ``` 60 | -------------------------------------------------------------------------------- /test/support/http_client_mock.ex: -------------------------------------------------------------------------------- 1 | defmodule EthContract.HttpClientMock do 2 | import EthContract.Util 3 | 4 | @address "0xC0BB964A7e51393e7F89c5513eAadbE5208Dec89" 5 | 6 | def eth_call(%{ to: _to, data: data }) do 7 | {:ok, balance_of_sig } = balance_of_hex(@address) 8 | 9 | cond do 10 | data == "0x" <> owner_of_hex(1) -> {:ok, owner_of() } 11 | data == "0x" <> balance_of_sig -> {:ok, "0x" <> balance_of() } 12 | data == "0x" <> total_supply_hex() -> {:ok, total_supply() } 13 | data == "0x" <> meta_for_hex(1, "getKitty") -> {:ok, meta()} 14 | end 15 | end 16 | 17 | defp owner_of do 18 | "0x00000000000000000000000079bd592415ff6c91cfe69a7f9cd091354fc65a18" 19 | end 20 | 21 | defp balance_of do 22 | "0000000000000000000000000000000000000000000000000000000000000003" 23 | end 24 | 25 | defp total_supply do 26 | "0x00000000000000000000000000000000000000000000000000000000000cc7b3" 27 | end 28 | 29 | # %{ token_id: 1, method: "getKitty", contract: "0x06012c8cf97bead5deae237070f9587f8e7a266d", abi: abi } 30 | defp meta do 31 | "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000005a16688f00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000005ad2b318e6724ce4b9290146531884721ad18c63298a5308a55ad6b6b58d" 32 | end 33 | end 34 | -------------------------------------------------------------------------------- /mix.lock: -------------------------------------------------------------------------------- 1 | %{ 2 | "abi": {:hex, :abi, "0.1.12", "87ae04cb09e2308db7b3c350584dc3934de0e308f6a056ba82be5756b081a1ca", [:mix], [{:exth_crypto, "~> 0.1.4", [hex: :exth_crypto, repo: "hexpm", optional: false]}], "hexpm"}, 3 | "binary": {:hex, :binary, "0.0.5", "20d816f7274ea34f1b673b4cff2fdb9ebec9391a7a68c349070d515c66b1b2cf", [:mix], [], "hexpm"}, 4 | "certifi": {:hex, :certifi, "2.3.1", "d0f424232390bf47d82da8478022301c561cf6445b5b5fb6a84d49a9e76d2639", [:rebar3], [{:parse_trans, "3.2.0", [hex: :parse_trans, repo: "hexpm", optional: false]}], "hexpm"}, 5 | "earmark": {:hex, :earmark, "1.2.5", "4d21980d5d2862a2e13ec3c49ad9ad783ffc7ca5769cf6ff891a4553fbaae761", [:mix], [], "hexpm"}, 6 | "ethereumex": {:hex, :ethereumex, "0.3.2", "ee01a49c781c9751317b2918f799e84185203c81c8314ebebb1f1e22b754db3e", [:mix], [{:httpoison, "~> 1.0.0", [hex: :httpoison, repo: "hexpm", optional: false]}, {:poison, "~> 3.1.0", [hex: :poison, repo: "hexpm", optional: false]}], "hexpm"}, 7 | "ex_doc": {:hex, :ex_doc, "0.18.3", "f4b0e4a2ec6f333dccf761838a4b253d75e11f714b85ae271c9ae361367897b7", [:mix], [{:earmark, "~> 1.1", [hex: :earmark, repo: "hexpm", optional: false]}], "hexpm"}, 8 | "ex_rlp": {:hex, :ex_rlp, "0.3.0", "76eb293a743b17d6071693014c1a57eb0f3f71fbf560716046d62c8a14340628", [:mix], [], "hexpm"}, 9 | "exth_crypto": {:hex, :exth_crypto, "0.1.4", "11f9084dfd70d4f9e96f2710a472f4e6b23044b97530c719550c2b0450ffeb61", [:mix], [{:binary, "~> 0.0.4", [hex: :binary, repo: "hexpm", optional: false]}, {:keccakf1600, "~> 2.0.0", [hex: :keccakf1600_orig, repo: "hexpm", optional: false]}, {:libsecp256k1, "~> 0.1.3", [hex: :libsecp256k1, repo: "hexpm", optional: false]}], "hexpm"}, 10 | "exw3": {:hex, :exw3, "0.1.3", "b60587ba241b914e6f7f8751adc65384dd3f5ee692162f644ea74dd7c60d9a3f", [], [{:abi, "~> 0.1.8", [hex: :abi, repo: "hexpm", optional: false]}, {:ethereumex, "~> 0.3.2", [hex: :ethereumex, repo: "hexpm", optional: false]}, {:poison, "~> 3.1", [hex: :poison, repo: "hexpm", optional: false]}], "hexpm"}, 11 | "hackney": {:hex, :hackney, "1.13.0", "24edc8cd2b28e1c652593833862435c80661834f6c9344e84b6a2255e7aeef03", [:rebar3], [{:certifi, "2.3.1", [hex: :certifi, repo: "hexpm", optional: false]}, {:idna, "5.1.2", [hex: :idna, repo: "hexpm", optional: false]}, {:metrics, "1.0.1", [hex: :metrics, repo: "hexpm", optional: false]}, {:mimerl, "1.0.2", [hex: :mimerl, repo: "hexpm", optional: false]}, {:ssl_verify_fun, "1.1.1", [hex: :ssl_verify_fun, repo: "hexpm", optional: false]}], "hexpm"}, 12 | "hexate": {:hex, :hexate, "0.6.1", "1cea42e462c1daa32223127d4752e71016c3d933d492b9bb7fa4709a4a0fd50d", [:mix], [], "hexpm"}, 13 | "httpoison": {:hex, :httpoison, "1.0.0", "1f02f827148d945d40b24f0b0a89afe40bfe037171a6cf70f2486976d86921cd", [:mix], [{:hackney, "~> 1.8", [hex: :hackney, repo: "hexpm", optional: false]}], "hexpm"}, 14 | "idna": {:hex, :idna, "5.1.2", "e21cb58a09f0228a9e0b95eaa1217f1bcfc31a1aaa6e1fdf2f53a33f7dbd9494", [:rebar3], [{:unicode_util_compat, "0.3.1", [hex: :unicode_util_compat, repo: "hexpm", optional: false]}], "hexpm"}, 15 | "keccakf1600": {:hex, :keccakf1600_orig, "2.0.0", "0a7217ddb3ee8220d449bbf7575ec39d4e967099f220a91e3dfca4dbaef91963", [:rebar3], [], "hexpm"}, 16 | "libsecp256k1": {:hex, :libsecp256k1, "0.1.4", "42b7f76d8e32f85f578ccda0abfdb1afa0c5c231d1fd8aeab9cda352731a2d83", [:rebar3], [], "hexpm"}, 17 | "metrics": {:hex, :metrics, "1.0.1", "25f094dea2cda98213cecc3aeff09e940299d950904393b2a29d191c346a8486", [:rebar3], [], "hexpm"}, 18 | "mimerl": {:hex, :mimerl, "1.0.2", "993f9b0e084083405ed8252b99460c4f0563e41729ab42d9074fd5e52439be88", [:rebar3], [], "hexpm"}, 19 | "parse_trans": {:hex, :parse_trans, "3.2.0", "2adfa4daf80c14dc36f522cf190eb5c4ee3e28008fc6394397c16f62a26258c2", [:rebar3], [], "hexpm"}, 20 | "poison": {:hex, :poison, "3.1.0", "d9eb636610e096f86f25d9a46f35a9facac35609a7591b3be3326e99a0484665", [:mix], [], "hexpm"}, 21 | "ssl_verify_fun": {:hex, :ssl_verify_fun, "1.1.1", "28a4d65b7f59893bc2c7de786dec1e1555bd742d336043fe644ae956c3497fbe", [:make, :rebar], [], "hexpm"}, 22 | "unicode_util_compat": {:hex, :unicode_util_compat, "0.3.1", "a1f612a7b512638634a603c8f401892afbf99b8ce93a45041f8aaca99cadb85e", [:rebar3], [], "hexpm"}, 23 | } 24 | -------------------------------------------------------------------------------- /test/eth_contract_test.exs: -------------------------------------------------------------------------------- 1 | defmodule EthContractTest do 2 | use ExUnit.Case 3 | 4 | setup do 5 | abi = EthContract.parse_abi(Path.expand("./support/crypto_kitties.json", __DIR__)) 6 | {:ok, abi: abi } 7 | end 8 | 9 | describe "decode_log/4" do 10 | test "it decodes fully indexed Transfer event" do 11 | abi = %{ 12 | "Transfer" => %{ 13 | "anonymous" => false, 14 | "inputs" => [ 15 | %{ 16 | "indexed" => true, 17 | "name" => "from", 18 | "type" => "address" 19 | }, 20 | %{ 21 | "indexed" => true, 22 | "name" => "to", 23 | "type" => "address" 24 | }, 25 | %{ 26 | "indexed" => true, 27 | "name" => "tokenId", 28 | "type" => "uint256" 29 | } 30 | ], 31 | "name" => "Transfer", 32 | "type" => "event" 33 | } 34 | } 35 | 36 | {:ok, log_data } = EthContract.decode_log("0x", ["0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef", "0x000000000000000000000000b7282d0d208f1fc533ba60a4a3dc03adc2aab8e7", "0x0000000000000000000000007192bb75777dab47ef6fbf6f6c0e4bcbb2294f38", "0x000000000000000000000000000000000000000000000000000000000000048f"], abi, "Transfer") 37 | 38 | assert log_data === %{"tokenId" => 1167, "from" => "0xb7282d0d208f1fc533ba60a4a3dc03adc2aab8e7", "to" => "0x7192bb75777dab47ef6fbf6f6c0e4bcbb2294f38"} 39 | 40 | end 41 | 42 | test "it decodes coin Transfer event" do 43 | abi = %{ 44 | "Transfer" => %{ 45 | "anonymous" => false, 46 | "inputs" => [ 47 | %{ 48 | "indexed" => true, 49 | "name" => "from", 50 | "type" => "address" 51 | }, 52 | %{ 53 | "indexed" => true, 54 | "name" => "to", 55 | "type" => "address" 56 | }, 57 | %{ 58 | "indexed" => false, 59 | "name" => "_value", 60 | "type" => "uint256" 61 | } 62 | ], 63 | "name" => "Transfer", 64 | "type" => "event" 65 | } 66 | } 67 | 68 | {:ok, log_data } = EthContract.decode_log("0x00000000000000000000000000000000000000000000029c0ac134e35dc00000", ["0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef", "0x000000000000000000000000d551234ae421e3bcba99a0da6d736074f22192ff", "0x0000000000000000000000008ca78fbaabff9660ae57e949c390162cc1e34c50"], abi, "Transfer") 69 | 70 | assert log_data === %{"_value" => 12323200000000000000000, "from" => "0xd551234ae421e3bcba99a0da6d736074f22192ff", "to" => "0x8ca78fbaabff9660ae57e949c390162cc1e34c50"} 71 | end 72 | 73 | test "it returns the log data for non indexed event", %{ abi: abi } do 74 | {:ok, log_data } = EthContract.decode_log("0x000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003b16ab6e23bdbeeab719d8e4c49d6367487625300000000000000000000000000000000000000000000000000000000000cc7f6", ["0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef"], abi, "Transfer") 75 | assert log_data == %{"from" => "0x0000000000000000000000000000000000000000", "to" => "0x03b16ab6e23bdbeeab719d8e4c49d63674876253", "tokenId" => 837622} 76 | end 77 | 78 | test "it decode payload" do 79 | abi = %{"Birth" => %{"anonymous" => false, "inputs" => [%{"indexed" => false, "name" => "owner", "type" => "address"}, %{"indexed" => false, "name" => "kittyId", "type" => "uint256"}, %{"indexed" => false, "name" => "matronId", "type" => "uint256"}, %{"indexed" => false, "name" => "sireId", "type" => "uint256"}, %{"indexed" => false, "name" => "genes", "type" => "uint256"}], "name" => "Birth", "type" => "event"}} 80 | {:ok, log_data } = EthContract.decode_log("0x00000000000000000000000006012c8cf97bead5deae237070f9587f8e7a266d00000000000000000000000000000000000000000000000000000000000cf3c80000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000005a56b411ce01969730ee135ac794a3190622248f6a187534ca1082f03c64", ["0x0a5311bd2a6608f08a180df2ee7c5946819a649b204b554bb8e39825b2c50ad5"], abi, "Birth") 81 | assert log_data == %{ 82 | "genes" => 623494690161459611489819703807996780065503703761012687510071662227766372, 83 | "kittyId" => 848840, 84 | "matronId" => 0, 85 | "owner" => "0x06012c8cf97bead5deae237070f9587f8e7a266d", 86 | "sireId" => 0 87 | } 88 | end 89 | 90 | test "it returns the log data for non indexed event - Birth" do 91 | abi = %{ 92 | "Birth" => %{ 93 | "anonymous" => false, 94 | "inputs" => [ 95 | %{"indexed" => false, "name" => "owner", "type" => "address"}, 96 | %{"indexed" => false, "name" => "kittyId", "type" => "uint256"}, 97 | %{"indexed" => false, "name" => "matronId", "type" => "uint256"}, 98 | %{"indexed" => false, "name" => "sireId", "type" => "uint256"}, 99 | %{"indexed" => false, "name" => "genes", "type" => "uint256"} 100 | ], 101 | "name" => "Birth", 102 | "type" => "event" 103 | } 104 | } 105 | 106 | {:ok, log_data } = EthContract.decode_log("0x000000000000000000000000ca97a04e562a71d6fc95f335cb6adc5e07e2e8d800000000000000000000000000000000000000000000000000000000000cf31900000000000000000000000000000000000000000000000000000000000cf31000000000000000000000000000000000000000000000000000000000000aea3600005b16b094c770cc312cee71ae56854e588a300009095c11a9ab7bd52084f9", ["0x0a5311bd2a6608f08a180df2ee7c5946819a649b204b554bb8e39825b2c50ad5"], abi, "Birth") 107 | 108 | assert log_data == %{ 109 | "genes" => 628670632552109618658954045183678035112166633548495867316966897081156857, 110 | "kittyId" => 848665, 111 | "matronId" => 848656, 112 | "owner" => "0xca97a04e562a71d6fc95f335cb6adc5e07e2e8d8", 113 | "sireId" => 715318 114 | } 115 | end 116 | 117 | test "it returns the log data for indexed event" do 118 | indexed_abi = %{ 119 | "Transfer" => %{ 120 | "anonymous" => false, 121 | "inputs" => [ 122 | %{"indexed" => true, "name" => "from", "type" => "address"}, 123 | %{"indexed" => true, "name" => "to", "type" => "address"}, 124 | %{"indexed" => false, "name" => "value", "type" => "uint256"} 125 | ], 126 | "name" => "Transfer", 127 | "type" => "event" 128 | } 129 | } 130 | 131 | {:ok, log_data } = EthContract.decode_log("0x000000000000000000000000000000000000000000000000000000012a05f200", ["0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef", "0x00000000000000000000000000b46c2526e227482e2ebb8f4c69e4674d262e75", "0x00000000000000000000000054a2d42a40f51259dedd1978f6c118a0f0eff078"], indexed_abi, "Transfer") 132 | 133 | assert log_data == %{ "to" => "0x54a2d42a40f51259dedd1978f6c118a0f0eff078", "from" => "0x00b46c2526e227482e2ebb8f4c69e4674d262e75", "value" => 5000000000} 134 | end 135 | end 136 | 137 | describe "meta/1" do 138 | test "it returns the meta information associated with a token id", %{ abi: abi } do 139 | {:ok, meta } = EthContract.meta(%{ token_id: 1, method: "getKitty", contract: "0x06012c8cf97BEaD5deAe237070F9587f8E7A266d", abi: abi}) 140 | 141 | assert meta === %{"birthTime" => 1511417999, "cooldownIndex" => 0, "generation" => 0, "genes" => 626837621154801616088980922659877168609154386318304496692374110716999053, "isGestating" => false, "isReady" => true, "matronId" => 0, "nextActionAt" => 0, "sireId" => 0, "siringWithId" => 0} 142 | end 143 | end 144 | 145 | describe "owner_of/1" do 146 | test "it successfully returns the owner of a token id" do 147 | {:ok, address } = EthContract.owner_of(%{token_id: 1, contract: "0x06012c8cf97bead5deae237070f9587f8e7a266d"}) 148 | assert address === "0x79bd592415ff6c91cfe69a7f9cd091354fc65a18" 149 | end 150 | end 151 | 152 | describe "parse_abi/2" do 153 | test "it successfully parses the abi into a Map", %{ abi: abi } do 154 | keys = abi 155 | |> Map.keys 156 | 157 | assert Kernel.length(keys) == 65 158 | end 159 | end 160 | 161 | describe "balance_of/1" do 162 | test "it returns the balance_of for address" do 163 | {:ok, balance } = EthContract.balance_of(%{ address: "0xC0BB964A7e51393e7F89c5513eAadbE5208Dec89", contract: "0x06012c8cf97BEaD5deAe237070F9587f8E7A266d" }) 164 | assert balance == 3 165 | end 166 | end 167 | 168 | describe "total_supply/1" do 169 | test "it returns the total supply method call" do 170 | {:ok, total_supply } = EthContract.total_supply(%{ contract: "0x06012c8cf97BEaD5deAe237070F9587f8E7A266d"}) 171 | assert total_supply === 837555 172 | end 173 | end 174 | end 175 | -------------------------------------------------------------------------------- /lib/eth_contract.ex: -------------------------------------------------------------------------------- 1 | defmodule EthContract do 2 | @moduledoc """ 3 | Provides a few convenience methods for getting information about tokens from ETH smart contracts. Uses JSON-RPC for requests. 4 | """ 5 | 6 | import EthContract.Util 7 | 8 | alias Ethereumex.HttpClient 9 | alias ABI.TypeDecoder 10 | 11 | @json_rpc_client Application.get_env(:eth_contract, :json_rpc_client) || HttpClient 12 | 13 | @callback balance_of(map()) :: map() 14 | @callback owner_of(map()) :: map() 15 | @callback meta(map()) :: map() 16 | @callback parse_abi(file_path :: String.t()) :: map() 17 | @callback decode_data( 18 | data :: String.t(), 19 | abi :: String.t(), 20 | method :: String.t(), 21 | signatures_key :: String.t() 22 | ) :: map() 23 | @callback decode_log( 24 | data :: String.t(), 25 | topics :: String.t(), 26 | abi :: String.t(), 27 | method :: String.t() 28 | ) :: map() 29 | @callback total_supply(map()) :: map() 30 | 31 | @doc """ 32 | Get the wallet address given a contract and a token id 33 | 34 | ## Examples 35 | 36 | iex> EthContract.owner_of(%{token_id: 1, contract: "0x06012c8cf97bead5deae237070f9587f8e7a266d"}) 37 | 0x79bd592415ff6c91cfe69a7f9cd091354fc65a18 38 | 39 | """ 40 | def owner_of(%{token_id: token_id, contract: contract}) do 41 | with {:ok, address } <- @json_rpc_client.eth_call(%{ data: "0x" <> owner_of_hex(token_id), to: contract }) do 42 | with {:ok, address } <- address |> String.slice(2..-1) |> decode_address do 43 | {:ok, address} 44 | else 45 | err -> { :error, err } 46 | end 47 | else 48 | err -> { :error, err } 49 | end 50 | end 51 | 52 | @doc """ 53 | Get the balance given a wallet address. This was tested against ERC20 and ERC721 standard contracts. 54 | 55 | ## Examples 56 | 57 | iex> EthContract.balance_of(%{address: '0x123', contract: '0x234'}) 58 | 2 59 | 60 | """ 61 | def balance_of(%{address: address, contract: contract}) do 62 | with {:ok, signature } <- balance_of_hex(address) do 63 | with {:ok, balance } <- @json_rpc_client.eth_call(%{ data: "0x" <> signature, to: contract }) do 64 | {:ok, balance |> bytes_to_int } 65 | else 66 | err -> {:error, err } 67 | end 68 | else 69 | err -> {:error, err } 70 | end 71 | end 72 | 73 | @doc """ 74 | Get the account balance given a wallet address. 75 | """ 76 | 77 | def account_balance(%{ address: address }) do 78 | with {:ok, balance } <- @json_rpc_client.eth_get_balance(address) do 79 | with {balance, _ } <- balance |> String.slice(2..-1) |> Integer.parse(16) do 80 | {:ok, balance } 81 | else 82 | err -> {:error, err } 83 | end 84 | else 85 | err -> 86 | {:error, err} 87 | end 88 | end 89 | 90 | @doc """ 91 | Get the total supply given a contract address. This was tested against ERC20 and ERC721 standard contracts. 92 | 93 | ## Examples 94 | 95 | iex> EthContract.total_supply(%{contract: '0x234'}) 96 | :ok 97 | 98 | """ 99 | def total_supply(%{contract: contract}) do 100 | with {:ok, total_supply } <- @json_rpc_client.eth_call(%{ data: "0x" <> total_supply_hex(), to: contract}) do 101 | {:ok, total_supply |> bytes_to_int } 102 | else 103 | err -> {:error, err } 104 | end 105 | end 106 | 107 | @doc """ 108 | ERC721 Meta. This will return a Map with the meta information associated with a token. You have to provide the name of the method to use (ie. CryptoKitties uses getKitty) 109 | 110 | ## Examples 111 | 112 | iex> abi = EthContract.parse_abi("test/support/crypto_kitties.json") 113 | iex> EthContract.meta(%{token_id: 45, method: "getKitty", contract: "0x06012c8cf97BEaD5deAe237070F9587f8E7A266d", abi: abi}) 114 | %{ 115 | "birthTime" => 1511417999, 116 | "cooldownIndex" => 0, 117 | "generation" => 0, 118 | "genes" => 626837621154801616088980922659877168609154386318304496692374110716999053, 119 | "isGestating" => false, 120 | "isReady" => true, 121 | "matronId" => 0, 122 | "nextActionAt" => 0, 123 | "sireId" => 0, 124 | "siringWithId" => 0 125 | } 126 | 127 | """ 128 | def meta(%{token_id: token_id, method: method, contract: contract, abi: abi}) do 129 | with {:ok, meta } <- @json_rpc_client.eth_call(%{ data: "0x" <> meta_for_hex(token_id, method), to: contract }) do 130 | case meta do 131 | "0x" -> 132 | {:error, "Meta is 0x" } 133 | meta -> 134 | with {:ok, output } <- decode_data(meta, abi, method, "outputs") do 135 | {:ok, output } 136 | else 137 | _err -> 138 | {:error, "Error in decode_data"} 139 | end 140 | end 141 | else 142 | _err -> 143 | {:error, "Error in eth_call" } 144 | end 145 | 146 | end 147 | 148 | # Taken from https://github.com/hswick/exw3/blob/master/lib/exw3.ex#L159 149 | @doc """ 150 | Parses abi into a map with the name of the method as key. 151 | 152 | ## Examples 153 | 154 | iex> abi = EthContract.parse_abi("test/support/crypto_kitties.json") 155 | %{} 156 | 157 | """ 158 | def parse_abi(file_path) do 159 | case File.read(file_path) do 160 | {:ok, abi } -> Poison.Parser.parse!(abi) 161 | |> Enum.map(fn x -> {x["name"], x} end) 162 | |> Enum.into(%{}) 163 | err -> err 164 | end 165 | end 166 | 167 | defp trim_data(data) do 168 | {:ok, trimmed_output } = data 169 | |> String.slice(2..-1) 170 | |> Base.decode16(case: :lower) 171 | 172 | trimmed_output 173 | end 174 | 175 | defp output_signature(abi, method, signatures_key) do 176 | output_types = Enum.map(abi[method][signatures_key], fn x -> x["type"] end) 177 | output_names = Enum.map(abi[method][signatures_key], fn x -> x["name"] end) 178 | 179 | types_signature = Enum.join(["(", Enum.join(output_types, ","), ")"]) 180 | output_signature = "#{method}(#{types_signature})" 181 | 182 | %{ output_signature: output_signature, output_names: output_names } 183 | end 184 | 185 | @doc """ 186 | Decodes general smart contract calls 187 | 188 | """ 189 | 190 | def decode_data(data, abi, method, signatures_key \\ "inputs") 191 | def decode_data("0x", _abi, _method, _signatures_key) do 192 | {:error, %{}} 193 | end 194 | def decode_data(data, abi, method, signatures_key) do 195 | trimmed_output = trim_data(data) 196 | 197 | %{ output_signature: output_signature, output_names: output_names } = output_signature(abi, method, signatures_key) 198 | 199 | outputs = 200 | ABI.decode(output_signature, trimmed_output) 201 | |> List.first() 202 | |> Tuple.to_list() 203 | |> Enum.map(&maybe_encode_binary/1) 204 | 205 | {:ok, combine_data(output_names, outputs)} 206 | end 207 | 208 | defp maybe_encode_binary( << data :: binary>>) do 209 | enc = Base.encode16(data, case: :lower) 210 | "0x" <> enc 211 | end 212 | defp maybe_encode_binary(data), do: data 213 | 214 | defp combine_data(names, items) do 215 | Enum.zip(names, items) 216 | |> Enum.into(%{}) 217 | end 218 | 219 | @doc """ 220 | Decodes events that have indexed elements. 221 | 222 | """ 223 | def decode_log(data, topics, abi, method) when Kernel.length(topics) > 1 do 224 | trimmed_data = trim_data(data) 225 | 226 | not_indexed = Enum.reject(abi[method]["inputs"], fn x -> x["indexed"] == true end) 227 | indexed = Enum.reject(abi[method]["inputs"], fn x -> x["indexed"] == false end) 228 | 229 | output_types_no_index = Enum.map(not_indexed, fn x -> x["type"] end) # ["uint256"] 230 | 231 | types_signature = Enum.join(["(", Enum.join(output_types_no_index, ","), ")"]) 232 | output_signature = "#{method}(#{types_signature})" 233 | 234 | [ _ | topics ] = topics 235 | 236 | decoded_data = trimmed_data 237 | |> ABI.TypeDecoder.decode(ABI.Parser.parse!(output_signature)) 238 | |> List.first 239 | |> Tuple.to_list 240 | 241 | decoded_names = not_indexed 242 | |> Enum.map( fn x -> x["name"] end) 243 | 244 | non_indexed_result = combine_data(decoded_names, decoded_data) 245 | 246 | res = 247 | Enum.zip(indexed, topics) 248 | |> Enum.map(fn x -> 249 | { map, data } = x 250 | type = String.to_atom(map["type"]) 251 | 252 | decoded = case type do 253 | :address -> 254 | result = data 255 | |> trim_data 256 | |> ABI.TypeDecoder.decode_raw([type]) 257 | |> List.first 258 | |> Base.encode16(case: :lower) 259 | "0x" <> result 260 | :uint256 -> 261 | data 262 | |> trim_data 263 | |> :binary.decode_unsigned 264 | end 265 | 266 | {map["name"], decoded} 267 | end) 268 | 269 | indexed_result = 270 | res 271 | |> Enum.into(%{}) 272 | 273 | {:ok, Map.merge(indexed_result, non_indexed_result) } 274 | end 275 | 276 | @doc """ 277 | Decodes events with no indexes. 278 | 279 | """ 280 | def decode_log(data, _topics, abi, method) do 281 | decode_data(data, abi, method) 282 | end 283 | 284 | defp decode_address("") do 285 | {:ok, "0x" } 286 | end 287 | 288 | defp decode_address(bytes) do 289 | {address, _} = TypeDecoder.decode_bytes(bytes, 40, :left) 290 | {:ok, "0x" <> address } 291 | end 292 | 293 | 294 | defp bytes_to_int("0x") do 295 | 0 296 | end 297 | 298 | defp bytes_to_int(bytes) do 299 | bytes 300 | |> String.slice(2..-1) 301 | |> Base.decode16!(case: :lower) 302 | |> TypeDecoder.decode_raw([{:uint, 256}]) 303 | |> List.first 304 | end 305 | end 306 | -------------------------------------------------------------------------------- /test/support/crypto_kitties.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "constant": true, 4 | "inputs": [ 5 | { 6 | "name": "_interfaceID", 7 | "type": "bytes4" 8 | } 9 | ], 10 | "name": "supportsInterface", 11 | "outputs": [ 12 | { 13 | "name": "", 14 | "type": "bool" 15 | } 16 | ], 17 | "payable": false, 18 | "stateMutability": "view", 19 | "type": "function" 20 | }, 21 | { 22 | "constant": true, 23 | "inputs": [], 24 | "name": "cfoAddress", 25 | "outputs": [ 26 | { 27 | "name": "", 28 | "type": "address" 29 | } 30 | ], 31 | "payable": false, 32 | "stateMutability": "view", 33 | "type": "function" 34 | }, 35 | { 36 | "constant": true, 37 | "inputs": [ 38 | { 39 | "name": "_tokenId", 40 | "type": "uint256" 41 | }, 42 | { 43 | "name": "_preferredTransport", 44 | "type": "string" 45 | } 46 | ], 47 | "name": "tokenMetadata", 48 | "outputs": [ 49 | { 50 | "name": "infoUrl", 51 | "type": "string" 52 | } 53 | ], 54 | "payable": false, 55 | "stateMutability": "view", 56 | "type": "function" 57 | }, 58 | { 59 | "constant": true, 60 | "inputs": [], 61 | "name": "promoCreatedCount", 62 | "outputs": [ 63 | { 64 | "name": "", 65 | "type": "uint256" 66 | } 67 | ], 68 | "payable": false, 69 | "stateMutability": "view", 70 | "type": "function" 71 | }, 72 | { 73 | "constant": true, 74 | "inputs": [], 75 | "name": "name", 76 | "outputs": [ 77 | { 78 | "name": "", 79 | "type": "string" 80 | } 81 | ], 82 | "payable": false, 83 | "stateMutability": "view", 84 | "type": "function" 85 | }, 86 | { 87 | "constant": false, 88 | "inputs": [ 89 | { 90 | "name": "_to", 91 | "type": "address" 92 | }, 93 | { 94 | "name": "_tokenId", 95 | "type": "uint256" 96 | } 97 | ], 98 | "name": "approve", 99 | "outputs": [], 100 | "payable": false, 101 | "stateMutability": "nonpayable", 102 | "type": "function" 103 | }, 104 | { 105 | "constant": true, 106 | "inputs": [], 107 | "name": "ceoAddress", 108 | "outputs": [ 109 | { 110 | "name": "", 111 | "type": "address" 112 | } 113 | ], 114 | "payable": false, 115 | "stateMutability": "view", 116 | "type": "function" 117 | }, 118 | { 119 | "constant": true, 120 | "inputs": [], 121 | "name": "GEN0_STARTING_PRICE", 122 | "outputs": [ 123 | { 124 | "name": "", 125 | "type": "uint256" 126 | } 127 | ], 128 | "payable": false, 129 | "stateMutability": "view", 130 | "type": "function" 131 | }, 132 | { 133 | "constant": false, 134 | "inputs": [ 135 | { 136 | "name": "_address", 137 | "type": "address" 138 | } 139 | ], 140 | "name": "setSiringAuctionAddress", 141 | "outputs": [], 142 | "payable": false, 143 | "stateMutability": "nonpayable", 144 | "type": "function" 145 | }, 146 | { 147 | "constant": true, 148 | "inputs": [], 149 | "name": "totalSupply", 150 | "outputs": [ 151 | { 152 | "name": "", 153 | "type": "uint256" 154 | } 155 | ], 156 | "payable": false, 157 | "stateMutability": "view", 158 | "type": "function" 159 | }, 160 | { 161 | "constant": true, 162 | "inputs": [], 163 | "name": "pregnantKitties", 164 | "outputs": [ 165 | { 166 | "name": "", 167 | "type": "uint256" 168 | } 169 | ], 170 | "payable": false, 171 | "stateMutability": "view", 172 | "type": "function" 173 | }, 174 | { 175 | "constant": true, 176 | "inputs": [ 177 | { 178 | "name": "_kittyId", 179 | "type": "uint256" 180 | } 181 | ], 182 | "name": "isPregnant", 183 | "outputs": [ 184 | { 185 | "name": "", 186 | "type": "bool" 187 | } 188 | ], 189 | "payable": false, 190 | "stateMutability": "view", 191 | "type": "function" 192 | }, 193 | { 194 | "constant": true, 195 | "inputs": [], 196 | "name": "GEN0_AUCTION_DURATION", 197 | "outputs": [ 198 | { 199 | "name": "", 200 | "type": "uint256" 201 | } 202 | ], 203 | "payable": false, 204 | "stateMutability": "view", 205 | "type": "function" 206 | }, 207 | { 208 | "constant": true, 209 | "inputs": [], 210 | "name": "siringAuction", 211 | "outputs": [ 212 | { 213 | "name": "", 214 | "type": "address" 215 | } 216 | ], 217 | "payable": false, 218 | "stateMutability": "view", 219 | "type": "function" 220 | }, 221 | { 222 | "constant": false, 223 | "inputs": [ 224 | { 225 | "name": "_from", 226 | "type": "address" 227 | }, 228 | { 229 | "name": "_to", 230 | "type": "address" 231 | }, 232 | { 233 | "name": "_tokenId", 234 | "type": "uint256" 235 | } 236 | ], 237 | "name": "transferFrom", 238 | "outputs": [], 239 | "payable": false, 240 | "stateMutability": "nonpayable", 241 | "type": "function" 242 | }, 243 | { 244 | "constant": false, 245 | "inputs": [ 246 | { 247 | "name": "_address", 248 | "type": "address" 249 | } 250 | ], 251 | "name": "setGeneScienceAddress", 252 | "outputs": [], 253 | "payable": false, 254 | "stateMutability": "nonpayable", 255 | "type": "function" 256 | }, 257 | { 258 | "constant": false, 259 | "inputs": [ 260 | { 261 | "name": "_newCEO", 262 | "type": "address" 263 | } 264 | ], 265 | "name": "setCEO", 266 | "outputs": [], 267 | "payable": false, 268 | "stateMutability": "nonpayable", 269 | "type": "function" 270 | }, 271 | { 272 | "constant": false, 273 | "inputs": [ 274 | { 275 | "name": "_newCOO", 276 | "type": "address" 277 | } 278 | ], 279 | "name": "setCOO", 280 | "outputs": [], 281 | "payable": false, 282 | "stateMutability": "nonpayable", 283 | "type": "function" 284 | }, 285 | { 286 | "constant": false, 287 | "inputs": [ 288 | { 289 | "name": "_kittyId", 290 | "type": "uint256" 291 | }, 292 | { 293 | "name": "_startingPrice", 294 | "type": "uint256" 295 | }, 296 | { 297 | "name": "_endingPrice", 298 | "type": "uint256" 299 | }, 300 | { 301 | "name": "_duration", 302 | "type": "uint256" 303 | } 304 | ], 305 | "name": "createSaleAuction", 306 | "outputs": [], 307 | "payable": false, 308 | "stateMutability": "nonpayable", 309 | "type": "function" 310 | }, 311 | { 312 | "constant": false, 313 | "inputs": [], 314 | "name": "unpause", 315 | "outputs": [], 316 | "payable": false, 317 | "stateMutability": "nonpayable", 318 | "type": "function" 319 | }, 320 | { 321 | "constant": true, 322 | "inputs": [ 323 | { 324 | "name": "", 325 | "type": "uint256" 326 | } 327 | ], 328 | "name": "sireAllowedToAddress", 329 | "outputs": [ 330 | { 331 | "name": "", 332 | "type": "address" 333 | } 334 | ], 335 | "payable": false, 336 | "stateMutability": "view", 337 | "type": "function" 338 | }, 339 | { 340 | "constant": true, 341 | "inputs": [ 342 | { 343 | "name": "_matronId", 344 | "type": "uint256" 345 | }, 346 | { 347 | "name": "_sireId", 348 | "type": "uint256" 349 | } 350 | ], 351 | "name": "canBreedWith", 352 | "outputs": [ 353 | { 354 | "name": "", 355 | "type": "bool" 356 | } 357 | ], 358 | "payable": false, 359 | "stateMutability": "view", 360 | "type": "function" 361 | }, 362 | { 363 | "constant": true, 364 | "inputs": [ 365 | { 366 | "name": "", 367 | "type": "uint256" 368 | } 369 | ], 370 | "name": "kittyIndexToApproved", 371 | "outputs": [ 372 | { 373 | "name": "", 374 | "type": "address" 375 | } 376 | ], 377 | "payable": false, 378 | "stateMutability": "view", 379 | "type": "function" 380 | }, 381 | { 382 | "constant": false, 383 | "inputs": [ 384 | { 385 | "name": "_kittyId", 386 | "type": "uint256" 387 | }, 388 | { 389 | "name": "_startingPrice", 390 | "type": "uint256" 391 | }, 392 | { 393 | "name": "_endingPrice", 394 | "type": "uint256" 395 | }, 396 | { 397 | "name": "_duration", 398 | "type": "uint256" 399 | } 400 | ], 401 | "name": "createSiringAuction", 402 | "outputs": [], 403 | "payable": false, 404 | "stateMutability": "nonpayable", 405 | "type": "function" 406 | }, 407 | { 408 | "constant": false, 409 | "inputs": [ 410 | { 411 | "name": "val", 412 | "type": "uint256" 413 | } 414 | ], 415 | "name": "setAutoBirthFee", 416 | "outputs": [], 417 | "payable": false, 418 | "stateMutability": "nonpayable", 419 | "type": "function" 420 | }, 421 | { 422 | "constant": false, 423 | "inputs": [ 424 | { 425 | "name": "_addr", 426 | "type": "address" 427 | }, 428 | { 429 | "name": "_sireId", 430 | "type": "uint256" 431 | } 432 | ], 433 | "name": "approveSiring", 434 | "outputs": [], 435 | "payable": false, 436 | "stateMutability": "nonpayable", 437 | "type": "function" 438 | }, 439 | { 440 | "constant": false, 441 | "inputs": [ 442 | { 443 | "name": "_newCFO", 444 | "type": "address" 445 | } 446 | ], 447 | "name": "setCFO", 448 | "outputs": [], 449 | "payable": false, 450 | "stateMutability": "nonpayable", 451 | "type": "function" 452 | }, 453 | { 454 | "constant": false, 455 | "inputs": [ 456 | { 457 | "name": "_genes", 458 | "type": "uint256" 459 | }, 460 | { 461 | "name": "_owner", 462 | "type": "address" 463 | } 464 | ], 465 | "name": "createPromoKitty", 466 | "outputs": [], 467 | "payable": false, 468 | "stateMutability": "nonpayable", 469 | "type": "function" 470 | }, 471 | { 472 | "constant": false, 473 | "inputs": [ 474 | { 475 | "name": "secs", 476 | "type": "uint256" 477 | } 478 | ], 479 | "name": "setSecondsPerBlock", 480 | "outputs": [], 481 | "payable": false, 482 | "stateMutability": "nonpayable", 483 | "type": "function" 484 | }, 485 | { 486 | "constant": true, 487 | "inputs": [], 488 | "name": "paused", 489 | "outputs": [ 490 | { 491 | "name": "", 492 | "type": "bool" 493 | } 494 | ], 495 | "payable": false, 496 | "stateMutability": "view", 497 | "type": "function" 498 | }, 499 | { 500 | "constant": false, 501 | "inputs": [], 502 | "name": "withdrawBalance", 503 | "outputs": [], 504 | "payable": false, 505 | "stateMutability": "nonpayable", 506 | "type": "function" 507 | }, 508 | { 509 | "constant": true, 510 | "inputs": [ 511 | { 512 | "name": "_tokenId", 513 | "type": "uint256" 514 | } 515 | ], 516 | "name": "ownerOf", 517 | "outputs": [ 518 | { 519 | "name": "owner", 520 | "type": "address" 521 | } 522 | ], 523 | "payable": false, 524 | "stateMutability": "view", 525 | "type": "function" 526 | }, 527 | { 528 | "constant": true, 529 | "inputs": [], 530 | "name": "GEN0_CREATION_LIMIT", 531 | "outputs": [ 532 | { 533 | "name": "", 534 | "type": "uint256" 535 | } 536 | ], 537 | "payable": false, 538 | "stateMutability": "view", 539 | "type": "function" 540 | }, 541 | { 542 | "constant": true, 543 | "inputs": [], 544 | "name": "newContractAddress", 545 | "outputs": [ 546 | { 547 | "name": "", 548 | "type": "address" 549 | } 550 | ], 551 | "payable": false, 552 | "stateMutability": "view", 553 | "type": "function" 554 | }, 555 | { 556 | "constant": false, 557 | "inputs": [ 558 | { 559 | "name": "_address", 560 | "type": "address" 561 | } 562 | ], 563 | "name": "setSaleAuctionAddress", 564 | "outputs": [], 565 | "payable": false, 566 | "stateMutability": "nonpayable", 567 | "type": "function" 568 | }, 569 | { 570 | "constant": true, 571 | "inputs": [ 572 | { 573 | "name": "_owner", 574 | "type": "address" 575 | } 576 | ], 577 | "name": "balanceOf", 578 | "outputs": [ 579 | { 580 | "name": "count", 581 | "type": "uint256" 582 | } 583 | ], 584 | "payable": false, 585 | "stateMutability": "view", 586 | "type": "function" 587 | }, 588 | { 589 | "constant": false, 590 | "inputs": [ 591 | { 592 | "name": "_v2Address", 593 | "type": "address" 594 | } 595 | ], 596 | "name": "setNewAddress", 597 | "outputs": [], 598 | "payable": false, 599 | "stateMutability": "nonpayable", 600 | "type": "function" 601 | }, 602 | { 603 | "constant": true, 604 | "inputs": [], 605 | "name": "secondsPerBlock", 606 | "outputs": [ 607 | { 608 | "name": "", 609 | "type": "uint256" 610 | } 611 | ], 612 | "payable": false, 613 | "stateMutability": "view", 614 | "type": "function" 615 | }, 616 | { 617 | "constant": false, 618 | "inputs": [], 619 | "name": "pause", 620 | "outputs": [], 621 | "payable": false, 622 | "stateMutability": "nonpayable", 623 | "type": "function" 624 | }, 625 | { 626 | "constant": true, 627 | "inputs": [ 628 | { 629 | "name": "_owner", 630 | "type": "address" 631 | } 632 | ], 633 | "name": "tokensOfOwner", 634 | "outputs": [ 635 | { 636 | "name": "ownerTokens", 637 | "type": "uint256[]" 638 | } 639 | ], 640 | "payable": false, 641 | "stateMutability": "view", 642 | "type": "function" 643 | }, 644 | { 645 | "constant": false, 646 | "inputs": [ 647 | { 648 | "name": "_matronId", 649 | "type": "uint256" 650 | } 651 | ], 652 | "name": "giveBirth", 653 | "outputs": [ 654 | { 655 | "name": "", 656 | "type": "uint256" 657 | } 658 | ], 659 | "payable": false, 660 | "stateMutability": "nonpayable", 661 | "type": "function" 662 | }, 663 | { 664 | "constant": false, 665 | "inputs": [], 666 | "name": "withdrawAuctionBalances", 667 | "outputs": [], 668 | "payable": false, 669 | "stateMutability": "nonpayable", 670 | "type": "function" 671 | }, 672 | { 673 | "constant": true, 674 | "inputs": [], 675 | "name": "symbol", 676 | "outputs": [ 677 | { 678 | "name": "", 679 | "type": "string" 680 | } 681 | ], 682 | "payable": false, 683 | "stateMutability": "view", 684 | "type": "function" 685 | }, 686 | { 687 | "constant": true, 688 | "inputs": [ 689 | { 690 | "name": "", 691 | "type": "uint256" 692 | } 693 | ], 694 | "name": "cooldowns", 695 | "outputs": [ 696 | { 697 | "name": "", 698 | "type": "uint32" 699 | } 700 | ], 701 | "payable": false, 702 | "stateMutability": "view", 703 | "type": "function" 704 | }, 705 | { 706 | "constant": true, 707 | "inputs": [ 708 | { 709 | "name": "", 710 | "type": "uint256" 711 | } 712 | ], 713 | "name": "kittyIndexToOwner", 714 | "outputs": [ 715 | { 716 | "name": "", 717 | "type": "address" 718 | } 719 | ], 720 | "payable": false, 721 | "stateMutability": "view", 722 | "type": "function" 723 | }, 724 | { 725 | "constant": false, 726 | "inputs": [ 727 | { 728 | "name": "_to", 729 | "type": "address" 730 | }, 731 | { 732 | "name": "_tokenId", 733 | "type": "uint256" 734 | } 735 | ], 736 | "name": "transfer", 737 | "outputs": [], 738 | "payable": false, 739 | "stateMutability": "nonpayable", 740 | "type": "function" 741 | }, 742 | { 743 | "constant": true, 744 | "inputs": [], 745 | "name": "cooAddress", 746 | "outputs": [ 747 | { 748 | "name": "", 749 | "type": "address" 750 | } 751 | ], 752 | "payable": false, 753 | "stateMutability": "view", 754 | "type": "function" 755 | }, 756 | { 757 | "constant": true, 758 | "inputs": [], 759 | "name": "autoBirthFee", 760 | "outputs": [ 761 | { 762 | "name": "", 763 | "type": "uint256" 764 | } 765 | ], 766 | "payable": false, 767 | "stateMutability": "view", 768 | "type": "function" 769 | }, 770 | { 771 | "constant": true, 772 | "inputs": [], 773 | "name": "erc721Metadata", 774 | "outputs": [ 775 | { 776 | "name": "", 777 | "type": "address" 778 | } 779 | ], 780 | "payable": false, 781 | "stateMutability": "view", 782 | "type": "function" 783 | }, 784 | { 785 | "constant": false, 786 | "inputs": [ 787 | { 788 | "name": "_genes", 789 | "type": "uint256" 790 | } 791 | ], 792 | "name": "createGen0Auction", 793 | "outputs": [], 794 | "payable": false, 795 | "stateMutability": "nonpayable", 796 | "type": "function" 797 | }, 798 | { 799 | "constant": true, 800 | "inputs": [ 801 | { 802 | "name": "_kittyId", 803 | "type": "uint256" 804 | } 805 | ], 806 | "name": "isReadyToBreed", 807 | "outputs": [ 808 | { 809 | "name": "", 810 | "type": "bool" 811 | } 812 | ], 813 | "payable": false, 814 | "stateMutability": "view", 815 | "type": "function" 816 | }, 817 | { 818 | "constant": true, 819 | "inputs": [], 820 | "name": "PROMO_CREATION_LIMIT", 821 | "outputs": [ 822 | { 823 | "name": "", 824 | "type": "uint256" 825 | } 826 | ], 827 | "payable": false, 828 | "stateMutability": "view", 829 | "type": "function" 830 | }, 831 | { 832 | "constant": false, 833 | "inputs": [ 834 | { 835 | "name": "_contractAddress", 836 | "type": "address" 837 | } 838 | ], 839 | "name": "setMetadataAddress", 840 | "outputs": [], 841 | "payable": false, 842 | "stateMutability": "nonpayable", 843 | "type": "function" 844 | }, 845 | { 846 | "constant": true, 847 | "inputs": [], 848 | "name": "saleAuction", 849 | "outputs": [ 850 | { 851 | "name": "", 852 | "type": "address" 853 | } 854 | ], 855 | "payable": false, 856 | "stateMutability": "view", 857 | "type": "function" 858 | }, 859 | { 860 | "constant": true, 861 | "inputs": [ 862 | { 863 | "name": "_id", 864 | "type": "uint256" 865 | } 866 | ], 867 | "name": "getKitty", 868 | "outputs": [ 869 | { 870 | "name": "isGestating", 871 | "type": "bool" 872 | }, 873 | { 874 | "name": "isReady", 875 | "type": "bool" 876 | }, 877 | { 878 | "name": "cooldownIndex", 879 | "type": "uint256" 880 | }, 881 | { 882 | "name": "nextActionAt", 883 | "type": "uint256" 884 | }, 885 | { 886 | "name": "siringWithId", 887 | "type": "uint256" 888 | }, 889 | { 890 | "name": "birthTime", 891 | "type": "uint256" 892 | }, 893 | { 894 | "name": "matronId", 895 | "type": "uint256" 896 | }, 897 | { 898 | "name": "sireId", 899 | "type": "uint256" 900 | }, 901 | { 902 | "name": "generation", 903 | "type": "uint256" 904 | }, 905 | { 906 | "name": "genes", 907 | "type": "uint256" 908 | } 909 | ], 910 | "payable": false, 911 | "stateMutability": "view", 912 | "type": "function" 913 | }, 914 | { 915 | "constant": false, 916 | "inputs": [ 917 | { 918 | "name": "_sireId", 919 | "type": "uint256" 920 | }, 921 | { 922 | "name": "_matronId", 923 | "type": "uint256" 924 | } 925 | ], 926 | "name": "bidOnSiringAuction", 927 | "outputs": [], 928 | "payable": true, 929 | "stateMutability": "payable", 930 | "type": "function" 931 | }, 932 | { 933 | "constant": true, 934 | "inputs": [], 935 | "name": "gen0CreatedCount", 936 | "outputs": [ 937 | { 938 | "name": "", 939 | "type": "uint256" 940 | } 941 | ], 942 | "payable": false, 943 | "stateMutability": "view", 944 | "type": "function" 945 | }, 946 | { 947 | "constant": true, 948 | "inputs": [], 949 | "name": "geneScience", 950 | "outputs": [ 951 | { 952 | "name": "", 953 | "type": "address" 954 | } 955 | ], 956 | "payable": false, 957 | "stateMutability": "view", 958 | "type": "function" 959 | }, 960 | { 961 | "constant": false, 962 | "inputs": [ 963 | { 964 | "name": "_matronId", 965 | "type": "uint256" 966 | }, 967 | { 968 | "name": "_sireId", 969 | "type": "uint256" 970 | } 971 | ], 972 | "name": "breedWithAuto", 973 | "outputs": [], 974 | "payable": true, 975 | "stateMutability": "payable", 976 | "type": "function" 977 | }, 978 | { 979 | "inputs": [], 980 | "payable": false, 981 | "stateMutability": "nonpayable", 982 | "type": "constructor" 983 | }, 984 | { 985 | "payable": true, 986 | "stateMutability": "payable", 987 | "type": "fallback" 988 | }, 989 | { 990 | "anonymous": false, 991 | "inputs": [ 992 | { 993 | "indexed": false, 994 | "name": "owner", 995 | "type": "address" 996 | }, 997 | { 998 | "indexed": false, 999 | "name": "matronId", 1000 | "type": "uint256" 1001 | }, 1002 | { 1003 | "indexed": false, 1004 | "name": "sireId", 1005 | "type": "uint256" 1006 | }, 1007 | { 1008 | "indexed": false, 1009 | "name": "cooldownEndBlock", 1010 | "type": "uint256" 1011 | } 1012 | ], 1013 | "name": "Pregnant", 1014 | "type": "event" 1015 | }, 1016 | { 1017 | "anonymous": false, 1018 | "inputs": [ 1019 | { 1020 | "indexed": false, 1021 | "name": "from", 1022 | "type": "address" 1023 | }, 1024 | { 1025 | "indexed": false, 1026 | "name": "to", 1027 | "type": "address" 1028 | }, 1029 | { 1030 | "indexed": false, 1031 | "name": "tokenId", 1032 | "type": "uint256" 1033 | } 1034 | ], 1035 | "name": "Transfer", 1036 | "type": "event" 1037 | }, 1038 | { 1039 | "anonymous": false, 1040 | "inputs": [ 1041 | { 1042 | "indexed": false, 1043 | "name": "owner", 1044 | "type": "address" 1045 | }, 1046 | { 1047 | "indexed": false, 1048 | "name": "approved", 1049 | "type": "address" 1050 | }, 1051 | { 1052 | "indexed": false, 1053 | "name": "tokenId", 1054 | "type": "uint256" 1055 | } 1056 | ], 1057 | "name": "Approval", 1058 | "type": "event" 1059 | }, 1060 | { 1061 | "anonymous": false, 1062 | "inputs": [ 1063 | { 1064 | "indexed": false, 1065 | "name": "owner", 1066 | "type": "address" 1067 | }, 1068 | { 1069 | "indexed": false, 1070 | "name": "kittyId", 1071 | "type": "uint256" 1072 | }, 1073 | { 1074 | "indexed": false, 1075 | "name": "matronId", 1076 | "type": "uint256" 1077 | }, 1078 | { 1079 | "indexed": false, 1080 | "name": "sireId", 1081 | "type": "uint256" 1082 | }, 1083 | { 1084 | "indexed": false, 1085 | "name": "genes", 1086 | "type": "uint256" 1087 | } 1088 | ], 1089 | "name": "Birth", 1090 | "type": "event" 1091 | }, 1092 | { 1093 | "anonymous": false, 1094 | "inputs": [ 1095 | { 1096 | "indexed": false, 1097 | "name": "newContract", 1098 | "type": "address" 1099 | } 1100 | ], 1101 | "name": "ContractUpgrade", 1102 | "type": "event" 1103 | } 1104 | ] 1105 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | --------------------------------------------------------------------------------