Merged
Conversation
|
This seems incredibly powerful. I've got an open PR to support the |
Contributor
|
I'm going to approve this because the code is clean and it solves the problem for now; but in general I think we need to avoid this form of metaprogramming, as it makes the code opaque to all but the most experienced readers. I'm on a warpath to rip it out of steem-js, for instance. |
goldibex
approved these changes
Oct 30, 2017
Contributor
|
and @biophil this will indeed moot your PR. thanks for bearing with us. |
Dont-Copy-That-Floppy
pushed a commit
to Dont-Copy-That-Floppy/steem-python
that referenced
this pull request
Feb 23, 2025
Implement generic API access
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A call for something like
steem.get_accounts(["ned"])currently calls a getattr trampoline which causes the method to be delegated to a method on theSteemdclass which is really just a wrapper around theexecmethod of the HTTP client class, ultimately generating a JSONRPC HTTP request that looks like this:In general these wrappers may extend
steemd, do some processing of arguments / return value, or even implement entirely new functions not present insteemditself (for exampleget_account("ned")is pure Python code which essentially callsget_accounts(["ned"])). But many wrappers, likeget_accounts(), are bareexec()calls.Since Python is a dynamic language, we can implement these wrappers automatically, so for example
list_accounts()(a method for which no wrapper exists inSteemd) can be called as:All the relevant information is present to create the JSON HTTP request in a convenient syntax.
Note that no wrapper or other specific information about
list_accountsappears in anysteem-pythonsource file! How does this black magic work? It's simple, you can call anything you please, even nonsense keyboard mashing will work so long as they follow the syntax:Of course given such a garbage call, the server will return an error which will be raised as an exception in Python. But it shows how the Python code now supports calling literally any method -- it just forwards the call to the server without any checking whatsoever. This is the power of a dynamic language!
But that's not all. The
appbase/developversion ofsteemdsupports named fields for all API queries. So it is also now possible to write this call as:Keyword arguments is an important API upgrade. Now server-side functionality of API calls can be upgraded to accept additional parameters, without breaking backward compatibility with old client code.
This PR implements all of the above functionality.
Support for this keyword argument style of API call is not backwards compatible with legacy (pre-
appbase) nodes, but someday soon (HF20?) we will hopefully retire such nodes. User code which needs to speak to legacy nodes can still use the positional argument style or the wrappers in theSteemdclass. So this PR shouldn't break any user applications.