Skip to content
This repository has been archived by the owner on Aug 2, 2022. It is now read-only.

Feature: generate chain api #150

Closed
jcalfee opened this issue Aug 9, 2017 · 15 comments
Closed

Feature: generate chain api #150

jcalfee opened this issue Aug 9, 2017 · 15 comments

Comments

@jcalfee
Copy link
Contributor

jcalfee commented Aug 9, 2017

Is it possible to get this data programmatically?

app().get_plugin<http_plugin>().add_api({
      CHAIN_RO_CALL(get_info),
      CHAIN_RO_CALL(get_block),
      CHAIN_RO_CALL(get_account),
      CHAIN_RO_CALL(get_table_rows_i64),
      CHAIN_RO_CALL(get_table_rows_i128i128_primary),
      CHAIN_RO_CALL(abi_json_to_bin),
      CHAIN_RO_CALL(abi_bin_to_json),
      CHAIN_RW_CALL(push_block),
      CHAIN_RW_CALL(push_transaction)
   });

A program that outputs JSON would probably be all we need. We can use this information to generate the help and API calls in other languages (javascript, python).

I also publish it in a small JSON only repository.

Here is an example:

  "get_table_rows_i64": {
    "brief": "Fetch smart contract data from an account.",
    "params": {
      "scope": "Name",
      "code": "Name",
      "table": "Name",
      "json": { "type": "Bool", "default": false},
      "lower_bound": {"type": "UInt64", "default": "0"},
      "upper_bound": {"type": "UInt64", "default": "-1"},
      "limit": {"type": "UInt32", "default": "10"}
    },
    "results": {
      "rows": {
        "type": "Vector",
        "doc": "one row per item, either encoded as hex String or JSON object"
      },
      "more": {
        "type": "Bool",
        "doc": "true if last element"
      }
    }
  }

source

This info in any format would be very helpful. It would help keep old calls consistent and make it easy to get the new methods. Any of these parameters could change and it would otherwise go unnoticed.

@bytemaster
Copy link
Contributor

This is a really good idea.

@bytemaster bytemaster added this to the EOS Beta milestone Aug 16, 2017
@jgiszczak jgiszczak self-assigned this Aug 17, 2017
@jgiszczak
Copy link
Contributor

jgiszczak commented Aug 25, 2017

Initial version produces:

  "get_table_rows_i64": {
     "brief": "Fetch smart contract data from an account.",
    "params": {
      "code": {
        "doc": "",
        "type": "Name"
      },
      "json": {
        "default": "false",
        "doc": "",
        "type": "Bool"
      },
      "limit": {
        "default": "10",
        "doc": "",
        "type": "UInt32"
      },
      "lower_bound": {
        "default": "0",
        "doc": "",
        "type": "UInt64"
      },
      "scope": {
        "doc": "",
        "type": "Name"
      },
      "table": {
        "doc": "",
        "type": "Name"
      },
      "upper_bound": {
        "default": "-1",
        "doc": "",
        "type": "UInt64"
      }
    },
    "results": {
      "more": {
        "doc": "true if last element in data is not the end and sizeof data() < limit",
        "type": "Bool"
      },
      "rows": {
        "doc": "one row per item, either encoded as hex String or JSON object",
        "type": "Vector"
      }
    }
  },
}

Argument and return types not handled: embedded members and typedefs.

@jcalfee
Copy link
Contributor Author

jcalfee commented Aug 29, 2017

Can you please be sure "params" are not sorted and maintain the original order from FC. The order is important, the API has an option to use unnamed parameters (ordered).

@jgiszczak
Copy link
Contributor

Revised to tolerate missing doc files. chainbase namespace doesn't seem to generate anything yet.

@jgiszczak
Copy link
Contributor

Revised to preserve order.

"get_table_rows": {
    "brief": "",
    "results": {
      "rows": {
        "type": "Vector",
        "doc": "one row per item, either encoded as hex String or JSON object"
      },
      "more": {
        "type": "Bool",
        "doc": "true if last element in data is not the end and sizeof data() < limit"
      }
    },
    "params": {
      "json": {
        "type": "Bool",
        "default": "false",
        "doc": ""
      },
      "scope": {
        "type": "Name",
        "doc": ""
      },
      "code": {
        "type": "Name",
        "doc": ""
      },
      "table": {
        "type": "Name",
        "doc": ""
      },
      "table_type": {
        "type": "String",
        "doc": ""
      },
      "table_key": {
        "type": "String",
        "doc": ""
      },
      "lower_bound": {
        "type": "String",
        "doc": ""
      },
      "upper_bound": {
        "type": "String",
        "doc": ""
      },
      "limit": {
        "type": "UInt32",
        "default": "10",
        "doc": ""
      }
    }
  },

@jgiszczak
Copy link
Contributor

Now handles embedded member structures/classes. Typedefs not yet supported without pulling in undesirables.

"push_block": {
    "brief": "",
    "results": {},
    "params": {
      "previous": {
        "type": "UInt32",
        "doc": ""
      },
      "timestamp": {
        "type": "Time",
        "doc": ""
      },
      "transaction_merkle_root": {
        "type": "checksum_type",
        "doc": ""
      },
      "producer": {
        "type": "UInt16",
        "doc": ""
      },
      "producer_changes": {
        "type": "RoundChanges",
        "doc": ""
      },
      "producer_signature": {
        "type": "Signature",
        "doc": ""
      },
      "cycles": {
        "type": "vector< cycle >",
        "doc": ""
      }
    }
  },

@jcalfee
Copy link
Contributor Author

jcalfee commented Sep 1, 2017

  • push_block is a very advanced call for an API. I don't think eosjs or the python API would need that.
  • For formatting and types, see types.eos ..
    • Types have the Upper then CamelCase format (operations start with a lower case)
    • Instead of vector< type> it would be Type[] (but this is removed if you remove push_block)
    • change checksum_type -> Checksum

Not all types have to be in types.eos (like Checksum for example). I can define extra base types (ex: base-types)

@jgiszczak
Copy link
Contributor

  • Instead of vector< type> it would be Type[] (but this is removed if you remove push_block)

A type conversion table is included, so any such foreign creatures can be translated from the C++ type to the eosjs type. There are a number of others that I'm not sure what they should be.

There's also a command line argument of methods to omit. It defaults to omitting just the read_only and read_write constructors, but it accepts any number of names.

The type conversion table is source controlled, so edits should be committed and pushed. Obviously the command line arguments are not, other than the defaults. The defaults can be updated in the source, or a "standard" shell script can be added. I expect there to be a discussion about exactly which methods should be exposed. I suspect push_block is not the only one that will make people hesitate.

@jcalfee
Copy link
Contributor Author

jcalfee commented Sep 2, 2017

Sounds good .. I like having the type conversion table close to the source of the data so that we get more consistent compatible implementations for anyone that wants to use it directly. I'll check out the code when it is ready.

@jcalfee
Copy link
Contributor Author

jcalfee commented Sep 19, 2017

Is this available?

@jgiszczak
Copy link
Contributor

Unfortunately no. I was taken off it in the run up to the 1.0 release before getting the last type working. I can probably pick it up again in the next few days, after I finish peer liveness checking.

@jcalfee
Copy link
Contributor Author

jcalfee commented Sep 19, 2017

I'll can update the API by hand easily if we need it. thanks for the update.

@heifner
Copy link
Contributor

heifner commented Jun 8, 2018

@jcalfee Where are we with eosjs and this? Does the get abi capability of nodeos provide all you need?

ljrprocc pushed a commit to bithacks-tech/myeosio that referenced this issue Jul 4, 2018
@brianjohnson5972
Copy link
Contributor

@wanderingbort or @heifner - @jgiszczak still has the python code to parse this, should we do this or should I close it?

@gleehokie
Copy link
Contributor

We could define the API using OpenAPI Spec (OAS), also known as Swagger, which would improve documentation and allow the use of OAS tools and libs with our API. Sandwich has a start on this already.

taokayan pushed a commit to taokayan/eos that referenced this issue May 15, 2019
NorseGaud pushed a commit that referenced this issue Jul 30, 2019
# This is the 1st commit message:

various improvements

# This is the commit message #2:

new hash

# This is the commit message #3:

fix for script path

# This is the commit message #4:

fixes

# This is the commit message #5:

fixes

# This is the commit message #6:

fixes

# This is the commit message #7:

fixes

# This is the commit message #8:

fixes

# This is the commit message #9:

fixes

# This is the commit message #10:

fixes

# This is the commit message #11:

fixes

# This is the commit message #12:

fixes

# This is the commit message #13:

fixes

# This is the commit message #14:

fixes

# This is the commit message #15:

fixes

# This is the commit message #16:

fixes

# This is the commit message #17:

fixes

# This is the commit message #18:

fixes

# This is the commit message #19:

fixes

# This is the commit message #20:

fixes

# This is the commit message #21:

fixes

# This is the commit message #22:

fixes

# This is the commit message #23:

fixes

# This is the commit message #24:

fixes

# This is the commit message #25:

fixes

# This is the commit message #26:

testing

# This is the commit message #27:

testing

# This is the commit message #28:

testing

# This is the commit message #29:

testing

# This is the commit message #30:

testing

# This is the commit message #31:

testing

# This is the commit message #32:

testing

# This is the commit message #33:

testing

# This is the commit message #34:

testing

# This is the commit message #35:

testing

# This is the commit message #36:

testing

# This is the commit message #37:

testing

# This is the commit message #38:

testing

# This is the commit message #39:

testing

# This is the commit message #40:

testing

# This is the commit message #41:

testing

# This is the commit message #42:

testing

# This is the commit message #43:

testing

# This is the commit message #44:

fixes

# This is the commit message #45:

fixes

# This is the commit message #46:

fixes

# This is the commit message #47:

fixes

# This is the commit message #48:

fixes

# This is the commit message #49:

fixes

# This is the commit message #50:

fixes

# This is the commit message #51:

fixes

# This is the commit message #52:

fixes

# This is the commit message #53:

fixes

# This is the commit message #54:

fixes

# This is the commit message #55:

fixes

# This is the commit message #56:

fixes

# This is the commit message #57:

fixes

# This is the commit message #58:

fixes

# This is the commit message #59:

fixes

# This is the commit message #60:

fixes

# This is the commit message #61:

fixes

# This is the commit message #62:

fixes

# This is the commit message #63:

fixes

# This is the commit message #64:

fixes

# This is the commit message #65:

fixes

# This is the commit message #66:

fixes

# This is the commit message #67:

fixes

# This is the commit message #68:

fixes

# This is the commit message #69:

fixes

# This is the commit message #70:

fixes

# This is the commit message #71:

fixes

# This is the commit message #72:

fixes

# This is the commit message #73:

fixes

# This is the commit message #74:

fixes

# This is the commit message #75:

fixes

# This is the commit message #76:

fixes

# This is the commit message #77:

fixes

# This is the commit message #78:

fixes

# This is the commit message #79:

more testing

# This is the commit message #80:

testing

# This is the commit message #81:

fixes

# This is the commit message #82:

fixes

# This is the commit message #83:

fixes

# This is the commit message #84:

fixes

# This is the commit message #85:

fixes

# This is the commit message #86:

fixes

# This is the commit message #87:

fixes

# This is the commit message #88:

fixes

# This is the commit message #89:

fixes

# This is the commit message #90:

fixes

# This is the commit message #91:

fixes

# This is the commit message #92:

fixes

# This is the commit message #93:

propagate-environment for buildkite-agent

# This is the commit message #94:

propagate-environment for buildkite-agent

# This is the commit message #95:

propagate-environment for buildkite-agent

# This is the commit message #96:

propagate-environment for buildkite-agent

# This is the commit message #97:

fixes

# This is the commit message #98:

fixes

# This is the commit message #99:

fixes

# This is the commit message #100:

fixes

# This is the commit message #101:

fixes

# This is the commit message #102:

fixes

# This is the commit message #103:

fixes

# This is the commit message #104:

fixes

# This is the commit message #105:

fixes

# This is the commit message #106:

fixes

# This is the commit message #107:

fixes

# This is the commit message #108:

fixes

# This is the commit message #109:

fixes

# This is the commit message #110:

fixes

# This is the commit message #111:

fixes

# This is the commit message #112:

fixes

# This is the commit message #113:

fixes

# This is the commit message #114:

fixes

# This is the commit message #115:

fixes

# This is the commit message #116:

fixes

# This is the commit message #117:

fixes

# This is the commit message #118:

fixes

# This is the commit message #119:

fixes

# This is the commit message #120:

fixes

# This is the commit message #121:

fixes

# This is the commit message #122:

fixes

# This is the commit message #123:

fixes

# This is the commit message #124:

fixes

# This is the commit message #125:

fixes

# This is the commit message #126:

fixes

# This is the commit message #127:

fixes

# This is the commit message #128:

fixes

# This is the commit message #129:

fixes

# This is the commit message #130:

fixes

# This is the commit message #131:

fixes

# This is the commit message #132:

fixes

# This is the commit message #133:

fixes

# This is the commit message #134:

fixes

# This is the commit message #135:

fixes

# This is the commit message #136:

fixes

# This is the commit message #137:

fixes

# This is the commit message #138:

fixes

# This is the commit message #139:

fixes

# This is the commit message #140:

fixes

# This is the commit message #141:

fixes

# This is the commit message #142:

fixes

# This is the commit message #143:

fixes

# This is the commit message #144:

fixes

# This is the commit message #145:

fixes

# This is the commit message #146:

fixes

# This is the commit message #147:

fixes

# This is the commit message #148:

fixes

# This is the commit message #149:

fixes

# This is the commit message #150:

fixes

# This is the commit message #151:

fixes

# This is the commit message #152:

fixes

# This is the commit message #153:

testing

# This is the commit message #154:

fixes

# This is the commit message #155:

fixes

# This is the commit message #156:

fixes

# This is the commit message #157:

fixes

# This is the commit message #158:

fixes

# This is the commit message #159:

fixes

# This is the commit message #160:

fixes

# This is the commit message #161:

fixes

# This is the commit message #162:

fixes

# This is the commit message #163:

fixes

# This is the commit message #164:

fixes

# This is the commit message #165:

fixes

# This is the commit message #166:

fixes

# This is the commit message #167:

fixes

# This is the commit message #168:

fixes

# This is the commit message #169:

fixes

# This is the commit message #170:

fixes

# This is the commit message #171:

fixes

# This is the commit message #172:

fixes

# This is the commit message #173:

fixes

# This is the commit message #174:

fixes

# This is the commit message #175:

fixes

# This is the commit message #176:

fixes

# This is the commit message #177:

fixes

# This is the commit message #178:

fixes

# This is the commit message #179:

fixes

# This is the commit message #180:

fixes

# This is the commit message #181:

fixes

# This is the commit message #182:

fixes

# This is the commit message #183:

fixes

# This is the commit message #184:

fixes

# This is the commit message #185:

fixes

# This is the commit message #186:

fixes
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

8 participants