-
Notifications
You must be signed in to change notification settings - Fork 3.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[API] Add remaining endpoints to Poem API backend #2156
Conversation
e5b67be
to
ecffe6e
Compare
64c8c08
to
ef0a578
Compare
ecffe6e
to
60027e6
Compare
f3b8f20
to
b6576de
Compare
13c9275
to
6a48105
Compare
6a48105
to
65bb459
Compare
I had disabled the plugin-generated API docs and instead linked to the Stoplight version. To turn it back to using the new version, just change the links from |
65bb459
to
fb81b0c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So I don't see any big red flags, but my main concern is the number of TODOs and issues attached here. Are there any major blockers / behavior differences here from the original API?
poem = { git = "https://github.com/poem-web/poem" } | ||
poem-openapi = { git = "https://github.com/poem-web/poem" } | ||
serde = { version = "1.0.137", default-features = false } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we use the direct git rather than the releases?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mention this in the summary, I'm waiting for a recently landed change to make its way to crates.io.
@@ -0,0 +1,3 @@ | |||
# Aptos Node API v1 | |||
|
|||
todo |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
:(. Please put that this is in development / experimental or something like that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have another PR on top of this that adds all the docs.
@@ -20,6 +22,7 @@ pub fn parse_accept<E: BadRequestError>(accept: &Accept) -> Result<AcceptType, E | |||
"application/x-bcs" => return Ok(AcceptType::Bcs), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note we should use constants for these instead that we use elsewhere.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed. Beyond just constants, we should unify them: #2275.
@@ -43,7 +43,7 @@ impl Block { | |||
if ledger_version > latest_ledger_info.version() { | |||
return Err(Error::not_found( | |||
"ledger", | |||
TransactionId::Version(ledger_version), | |||
TransactionId::Version(U64::from(ledger_version)), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for fixing this, considering it wouldn't parse consistently.
api/types/src/wrappers.rs
Outdated
// Currently it is not possible to deserialize certain MoveTypes, such as | ||
// generic type params. In those cases, we give up on parsing them as |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why can't it be parsed with generic type params? I ended up doing this myself for the type, just deserializing the actual underlying struct might not work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For starters, the underlying function within the move create just doesn't handle generic type params at all. For this to work properly, I'd need to be able to inject additional parsing capabilities into the function so when it eventually parses down to the generic type param token, it knows what to do with it. Even this isn't enough because the enum they use doesn't have this as an option. So if we wanted to support it we'd have to add rewrite a lot of stuff ourselves (unless we got this support into move directly, but Victor says it doesn't really make sense there because it's only meant for concrete types).
@@ -31,7 +31,8 @@ use std::{ | |||
}; | |||
|
|||
// TODO: Add read_only / write_only (and their all variants) where appropriate. | |||
// TODO: Explore whether we should use discriminator_name, see https://github.com/poem-web/poem/issues/329. | |||
// TODO: Investigate the use of discriminator_name, see https://github.com/poem-web/poem/issues/329. | |||
// TODO: See https://github.com/poem-web/poem/issues/347 re mapping stuff. UPDATE: Wait for 2.0.7 to be released. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the timeline on that? And what does it block?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The mapping stuff should be out tomorrow. As for the discriminator stuff where we remove intermediates, unknown. It doesn't block anything, it just adds some extra intermediate types that bloat the spec a bit.
"sequence_number": "0", | ||
"gas_unit_price": "0", | ||
"max_gas_amount": "1000000", | ||
"gas_currency_code": "XUS", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we can get rid of XUS we should.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah we do actually, I don't think this test is enabled right now (for either v0 or v1). But in v1 there is no gas currency code field (not by my own choice, just by using the types properly).
@@ -38,7 +39,8 @@ async fn test_renders_move_acsii_string_into_utf8_string() { | |||
context | |||
.api_execute_script_function( | |||
&mut account, | |||
"Message::set_message", | |||
"Message", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this module should be snake case, interesting that it runs.
response | ||
.headers_mut() | ||
.insert(CONTENT_TYPE, HeaderValue::from_static(JSON)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Errors are always JSON?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I make sure of that.
api/src/poem_backend/page.rs
Outdated
@@ -22,7 +22,7 @@ impl Page { | |||
let start = self.start.unwrap_or(default); | |||
if start > max { | |||
return Err(E::bad_request_str(&format!( | |||
"Given start value ({}) is too large, it must be < {}", | |||
"Given start value ({}) is higher than the highest ledger version, it must be < {}", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
*current ledger version
There are certainly a lot of todos, but almost all of them are nice-to-haves. I'm currently working on those that aren't nice to haves. There are small functionality differences between the two APIs (generally the new API has more structure in its requests / responses). I've almost got a TS client working with the new API, beyond just the Rust tests passing. |
dd5b50b
to
5200f1d
Compare
5200f1d
to
7d902a0
Compare
7d902a0
to
ab72d73
Compare
✅ Forge test success on
|
* [API] Fix up tags for each endpoint * [API] Add POST /transactions * [API] Add /transactions/encode_submission * [API] Add get_transaction for single transaction * [API] Add /transactions/simulate to Poem backend * [API] Add /accounts/{address}/transactions to Poem backend * [API] Add /accounts/{address}/resource/{resource_type} to Poem backend * [API] Add /accounts/{address}/module/{resource_type} to Poem backend * [API] Add /table/{table_handle}/item to Poem backend * [API] Use U64 and U128 at all endpoints * [API] Fix up spec generation for some types * [API][v1] Enhance OpenAPI spec "newtypes"
Description
This PR does the following:
In the interest of moving fast I haven't split the commits up super nicely, but I can do so if this is too hard to review.
Once this PR lands, the new API will be pretty much ready to go, pending these issues: https://github.com/aptos-labs/aptos-core/issues?q=is%3Aissue+is%3Aopen+%5BAPI%5D%5Bv1%5D (many of which are nice-to-haves).
There are other things that would be nice to solve too, pending work with the framework:
pattern
andexample
fields in schema for newtypes poem-web/poem#320|
in the YAML spec poem-web/poem#333bad_request_handler
equivalent forMETHOD_NOT_ALLOWED
poem-web/poem#343Note: Currently the PR uses Poem from git directly, but that's just because I'm waiting for a committed change to make its way to crates.io (probably a day or two).
Note: I need to clean up some other tests I think, based on the output of
cargo nextest run --package smoke-test --test-threads 8
.Test Plan
Run a node:
Sample queries with curl:
Generating goldenfiles for the new API:
Confirming that the v0 API tests pass:
There are minor changes to the v0 API, e.g. returning epoch as a U64 instead of u64, or changes to how we represent type tags. I have tested that this doesn't break any of our clients / just add extra code so those changes don't manifest in the v0 API, but I still need to do more testing (particularly for TS).
This change is