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

Better `tx` RPC API #1299

Open
frol opened this issue Sep 11, 2019 · 8 comments

Comments

@frol
Copy link
Member

commented Sep 11, 2019

nearprotocol/NEPs#1

RPC API of the transaction (tx) should be restructured according to the conversation nearprotocol/docs#55 (comment)

NOTE: It is a breaking change. Do we have consumers of this API (except Explorer)? It seems that the only consumer is Explorer and I can fix it.

The issues to address in the RPC API:

  • Expose more information on the tx RPC (there should not be less information than in the block RPC response)
  • Align the structure of the block (the transactions section) and tx responses
  • Transaction should have:
    • block hash
    • shard id (?)
    • fees (Total fees denominated in NEAR, Gas used (units of gas), Gas price (price per unit in NEAR))
  • CreateAccount action should expose the account id
  • Cover the public API with extensive tests, so it gets apparent when something gets changed when it should not.
@frol

This comment has been minimized.

Copy link
Member Author

commented Sep 11, 2019

block RPC currently returns transactions list with a structure that is completely different from the tx RPC:

$ http post http://rpc.nearprotocol.com/ jsonrpc=2.0 id=dontcare method=block 'params:=[173592]'

{
    "id": "dontcare",
    "jsonrpc": "2.0",
    "result": {
        "header": {
            "approval_mask": [
                false,
                true
            ],
            "approval_sigs": [
                "ed25519:5tn8MtX8yQ2qzdRs8W6Homz4KWS2kQcoEnLXBXEa9qRUczAfYqUD3R3QxRAoWA9AwM1niauyt6VaQFn8sijEqkhS"
            ],
            "epoch_hash": "Di12sDSYsUH6ocaMf9NPKcBrUikEiCRPNkydKgZgEi8u",
            "hash": "BZnGxodahyU3Ssuh5dVNbAeBt3wqXTu8f8mLeo5cb4cH",
            "height": 173592,
            "prev_hash": "HhH72gqstfm5KGW6wf8nFa1tVjfeGjhsmv1NSxLutAdQ",
            "prev_state_root": "ABh7ZArZtVvEghH8SNXrDaTAMCFYzEayFFkg61j1qzc9",
            "signature": "ed25519:3CA8HwcmPDSdUuCdjBeFWP8AvK36yQ1PhDRz4PgF8RLT3fgQm4GoH242j5QNJvXrdws8ASygWJtaAqrUkHjug52X",
            "timestamp": 1568047128577482804,
            "total_weight": 208940,
            "tx_root": "11111111111111111111111111111111",
            "validator_proposals": []
        },
        "transactions": [
            {
                "actions": [
                    "CreateAccount",
                    {
                        "Transfer": {
                            "deposit": "10000000000000000000"
                        }
                    },
                    {
                        "AddKey": {
                            "access_key": {
                                "nonce": 0,
                                "permission": "FullAccess"
                            },
                            "public_key": "ed25519:J2Jrr74mgHxL5AmHeRSesWPgCA8jqcGqcEGKC2EEu59t"
                        }
                    }
                ],
                "hash": "2ZBygTrowP7MTeRQ8rXp8v84benMTaYbHhwFw5w85CTS",
                "nonce": 110,
                "public_key": "ed25519:oNCFEmRotRHTySKqmAwifNZ8VRpYS973p8cL61y7eiE",
                "receiver_id": "studio-n5ubb8npy",
                "signature": "ed25519:54uxKxJz5N4nzjYbeAuMKZVqUUwj2i9wXgjEeVNYx79mYXQr9bmfysDE5hGo2Smc1NNsTZ8Q6W62uymxq94TEy8J",
                "signer_id": "test"
            }
        ]
    }
}
$ http post http://rpc.nearprotocol.com/ jsonrpc=2.0 id=dontcare method=tx 'params:=["2ZBygTrowP7MTeRQ8rXp8v84benMTaYbHhwFw5w85CTS"]'

{
    "id": "dontcare",
    "jsonrpc": "2.0",
    "result": {
        "status": "Completed",
        "transactions": [
            {
                "hash": "2ZBygTrowP7MTeRQ8rXp8v84benMTaYbHhwFw5w85CTS",
                "result": {
                    "logs": [],
                    "receipts": [
                        "CdbagwttuZnTcjGT3R8Qs9fsv8GFuFeUtJVnVZeAjoop"
                    ],
                    "result": null,
                    "status": "Completed"
                }
            },
            {
                "hash": "CdbagwttuZnTcjGT3R8Qs9fsv8GFuFeUtJVnVZeAjoop",
                "result": {
                    "logs": [],
                    "receipts": [],
                    "result": "",
                    "status": "Completed"
                }
            }
        ]
    }
}

Notice that there is no information about the actions.

@frol

This comment has been minimized.

Copy link
Member Author

commented Sep 12, 2019

@evgenykuzyakov

This comment has been minimized.

Copy link
Collaborator

commented Sep 12, 2019

Suggestion to fix result to be able to get the actual returned values: #1307

@frol

This comment has been minimized.

Copy link
Member Author

commented Sep 12, 2019

@evgenykuzyakov I must admit that I don't understand #1307 (I lack the knowledge around that area), and how it is related to this issue.

@evgenykuzyakov

This comment has been minimized.

Copy link
Collaborator

commented Sep 13, 2019

For CreateAccount action should expose the account id, transaction has the receiver which exposes the newly created account_id

@frol

This comment has been minimized.

Copy link
Member Author

commented Sep 13, 2019

@evgenykuzyakov Yeap, Illia has already pointed that out to me, so crossing it out from the list.

@evgenykuzyakov

This comment has been minimized.

Copy link
Collaborator

commented Sep 13, 2019

Why not just build standard API that is copies the inner structure using View conversion. E.g. expose Receipt with ActionReceipt structure, and also associated TransactionResult.

@evgenykuzyakov

This comment has been minimized.

Copy link
Collaborator

commented Sep 13, 2019

So we have a ReceiptView struct that we can serialize towards JSON. It has all the information about what actions are there, who is the predecessor and the signer.
For every executed receipt, we have a TransactionResult, which contain genereated receipt_ids that can be used to retrieve ReceiptViews.

To get the first ReceiptId from the signed transaction we can use TransactionResult of the SignedTransaction hash.

@kcole16 kcole16 referenced this issue Oct 18, 2019
18 of 22 tasks complete
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.