intelliot / xrp-api Goto Github PK
View Code? Open in Web Editor NEWMoved to https://github.com/xpring-eng/xrp-api
Moved to https://github.com/xpring-eng/xrp-api
GET http://localhost:3000/v1/accounts/1/info
Expected result:
400 Bad Request
{
"message": "...",
"errors": [...]
}
Actual result:
200 OK
{
"error": {
"name": "RippledError",
"data": {
"account": "rBayiNwjomzHtiJgCYVinWvkykrqmx8RQj",
"error": "actNotFound",
"error_code": 19,
"error_message": "Account not found.",
"id": 2,
"ledger_current_index": 687576,
"request": {
"account": "1",
"command": "account_info",
"id": 2,
"ledger_index": "current"
},
"status": "error",
"type": "response",
"validated": false
}
}
}
GET http://localhost:3000/v1/accounts/1/settings
Actual result:
200 OK
{
"errors": [
{
"name": "ValidationError",
"message": "instance.address does not conform to the 'address' format,instance.address does not match pattern '^r[1-9A-HJ-NP-Za-km-z]{25,34}$'"
}
]
}
message
field is missing (should be a sibling of errors
per the API spec)code
, not name
, per the API spec)Similar to XRPLF/rippled#2599, this API has a lot of slightly different formats for transactions. It's actually even worse here because the mix of formats derived from ripple-lib and rippled APIs. Here's a list of the ones I've seen in the schemas here:
Now, some of this is just a naming problem because there are different wrappers and whatnot that all need names (e.g. the immediate "engine result" from submitting a transaction vs. the result of looking up a transaction) but we may want to consider how many different things we want at all and when we want them.
At a minimum we should pick either the "RippleAPI-style" transaction JSON or the "rippled-style" transaction JSON and match that where possible. If we go with rippled-style transactions, I think it's fine to have some "extensions" like representing transaction Flags
as a map of booleans rather than an integer and parsing string encoding of memos and Domain
as text rather than hex.
(Fun fact: the field names from the rippled-style JSON are not strictly defined by the protocol, since the actual canonical format is the binary blob, so you could theoretically go straight from a different JSON format to a signed binary. But in all likelihood, the easiest way to do that is by converting to something pretty similar to the rippled format anyway.)
Responses from the API should use the HTTP code 404 Not Found if the thing in question was not found. (Unlike #5, this issue involves also adding the "404" responses to the API spec.)
Basically any API method with a path parameter should probably be able to return 404. Also anything that lets you use a ledger query parameter.
We should develop (possibly in this issue) a "style guide" for the API itself that can be used to make decisions about how the API should represent data. This guide can lay out the principles for how the API should operate and decisions about individual API details can reference this guide as a starting point.
A strictly RESTful interface is not a great fit for blockchain tech because the details of how you modify data in a decentralized consensus model add latency and other complications. However, it's not a bad idea to follow REST-like API design principles where they do work, as laid out in the following rules:
result
field, etc.rippled
server, or being misconfigured)Content-Type
header MUST use application/octet-stream
(or another, more specific type) in these cases.application/json
if a request omits the Content-Type header. The response MUST ALWAYS use the correct Content-Type header.-
(for negative numbers) but no leading +
.
for a decimal component.5E-1.25
which would be equivalent of the scientific notation 5.0 ร 10-1.25. The E
is uppercase.+
is not allowed, etc.)false
MAY be omitted. (In the rare cases where false
is not the flag's default value for some reason, the API should always explicitly specify the flag.)currency
and value
fields (and counterparty
for issued currencies, when we get there). Both drops
(integer) and XRP
(decimal) should be accepted currency
values on input, but drops
should be the default for responses from the API (or maybe that could be configurable?).While the API is still on major version 0, breaking changes will be made frequently without warning or documentation. When we think the API is stable enough we should declare the software version 1.
The remainder of the rules described in this section only apply after version 1 has been released.
v1
. If any incompatible changes to an API method are introduced, the new method will have a different version number such as v2
.Needs discussion. We could have fairly "RESTful" API methods that submits a data structure and the API translates that into the transaction(s) that should result in the specified data structure, but I think that's a bad idea.
Sequence
number increases with every transaction, there are no idempotent operations, and making changes to the ledger costs XRP as well. So seemingly-intuitive patterns like, "PUT {the settings I want}" are likely to shoot people in the foot, resulting in race conditions or latency traps.I think we should have a generic "Prepare Transaction" method that does a bunch of "best practice" pre-processing on something that mostly resembles the native rippled
transaction format, and produces a JSON + binary value that can be signed. It can have convenience features like translating a map of booleans into a Flags
integer, encoding memos, accepting counterparty
in places where the rippled
API wants issuer
, auto-filling Sequence
, Fee
, and any other fields we think are good like LastLedgerSequence
, etc. etc.. We may or may not want to combine this with the Sign operation.
This needs discussion. I'd like to see things follow the rippled
convention where capital letters indicate fields that are canonically written to some binary data structure and lower case letters indicate fields that are dynamically derived, but I'm not committed to that.
I also like snake_case
names more than camelCase names for legibility, but that seems unpopular in OpenAPI specs (maybe because OpenAPI itself uses a lot of camelCase field names?).
One of the most important features of the XRP Ledger for ILP compatibility is payment channels. To properly use payment channels, though, you need:
/channels/{channel_id}
or /accounts/{address}/channels/{destination}/{seq}
rippled
API, the channel_verify method does some of this, although it doesn't cover all the things you might want to do like checking when the channel expires and whether the channel currently holds enough XRP to fulfill the claim.The "Account Info" (which basically just returns an AccountRoot object) is the core definition of an account, so I think it makes sense in the hierarchy to put that operation at GET /accounts/{address}
instead of its current place at GET /accounts/{address}/info
.
I think @JoelKatz would argue that you usually want the "latest" data even if it's pending, but I think there's a good case to be made that you should query "validated" ledger data unless otherwise specified.
Basically, the way I see it is this. Validated data is stuff you can take action on. Pending stuff, it's nice to know about, but you don't necessarily want to do anything about it.
Both types of data are subject to change. With "validated" data, there may be new, forthcoming changes that you aren't seeing if you're looking at that ledger. With "pending" data, that's still possible but you also have to consider the possibility of rollbacks, because a tentative transaction may not have executed or may have executed differently by the time it becomes validated. So you can make much more concrete inferences about what's possible and what might happen from a "validated" ledger than you can from a "current" ledger.
I think it's good to be able to query either one (for example, I like that my bank shows "pending" transactions in the UI) but I think the "validated" ledger is a more reasonable default to work with.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.