Skip to content
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

DOC: Examples with stellar_sdk #12

Open
martin-thoma opened this issue Jul 22, 2021 · 3 comments
Open

DOC: Examples with stellar_sdk #12

martin-thoma opened this issue Jul 22, 2021 · 3 comments
Assignees
Labels
documentation Improvements or additions to documentation

Comments

@martin-thoma
Copy link
Contributor

martin-thoma commented Jul 22, 2021

It would be really nice to see more examples in combination with stellar_sdk, e.g. how would you parse this?

from stellar_sdk.server import Server

HORIZON_URL = "https://horizon.stellar.org"

with Server(HORIZON_URL) as server:
    operation = server.operations().operation("121692259040116737").call()
    transaction = server.transactions().transaction(operation["transaction_hash"]).call()

Adding examples like https://github.com/StellarCN/py-stellar-base/tree/master/examples would also be nice

@overcat
Copy link
Member

overcat commented Jul 22, 2021

Hello, the following is an example. In my opinion, it may be a good idea to integrate it into stellar-sdk, but currently I don't want to force users to use this library. I will add appropriate examples to this repository, thank you for your suggestions.

from stellar_sdk.server import Server
from stellar_model import TransactionResponse
HORIZON_URL = "https://horizon.stellar.org"

with Server(HORIZON_URL) as server:
    operation = server.operations().operation("121692259040116737").call()
    transaction = server.transactions().transaction(operation["transaction_hash"]).call()
    # parse it
    parsed_transaction = TransactionResponse.parse_obj(transaction)
    print(parsed_transaction.fee_account)

@overcat overcat self-assigned this Jul 22, 2021
@overcat overcat added the documentation Improvements or additions to documentation label Jul 22, 2021
@martin-thoma
Copy link
Contributor Author

How would you parse the operation?

@overcat
Copy link
Member

overcat commented Jul 22, 2021

from stellar_sdk.server import Server
from stellar_model import TransactionResponse, OperationResponse
HORIZON_URL = "https://horizon.stellar.org"

with Server(HORIZON_URL) as server:
    operation = server.operations().operation("121692259040116737").call()
    transaction = server.transactions().transaction(operation["transaction_hash"]).call()
    # parse it
    parsed_transaction = TransactionResponse.parse_obj(transaction)
    print(parsed_transaction.fee_account)
    parsed_operation = OperationResponse.parse_obj(operation)
    print(parsed_operation.record.type)
    print(parsed_operation.record.buying_asset_code)

Please check all supported endpoints through here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

2 participants