Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on Jan 22, 2025. It is now read-only.

Conversation

CriesofCarrots
Copy link
Contributor

Problem

We need an easy way for users to view SPL Token transaction instructions, without having to resort to client-side language-specific decoding libraries.

Summary of Changes

  • Extend transaction-decoding support to include SPL token. Visible ingetConfirmedBlock and getConfirmedTransaction rpc responses. (A lot of this code could be simplified in the future by a verbose instruction-set enum produced by a procedural macro, such as Program macro to generate helper fns and documentation #10826 . That work is currently deprioritized, so in the meantime, this will unblock Token support in the Explorer and for other downstream users.)

Mostly closes #10476

@CriesofCarrots
Copy link
Contributor Author

CriesofCarrots commented Jul 30, 2020

Example:

$ curl -X POST -H "Content-Type: application/json" -d '{"jsonrpc": "2.0","id":1,"method":"getConfirmedTransaction","params":["4Gc8UodaLkreW3Rw4VvRiRVY9B9XZDdSNPQqK7c6x9MjgXgyhPdEZRCNDx433d7GyFrKkEye9YKwUkSaoYHjeexp","jsonParsed"]}' 127.0.0.1:8899

{
  "jsonrpc": "2.0",
  "result": {
    "meta": {
      "err": null,
      "fee": 30000,
      "postBalances": [99978098240, 0, 0, 0, 0, 0, 1726080, 1726080, 3361680, 381185280],
      "preBalances": [99978128240, 0, 0, 0, 0, 0, 1726080, 1726080, 3361680, 381185280],
      "status": {"Ok": null}
    },
    "slot": 84,
    "transaction": {
      "message": {
        "accountKeys": [
          { "4frSc8sFGfUsTMWeFmE2dg9NqgLXk63jTwwc1yGyR3dr": ["writable","signer"] },
          { "7rwPzjXQiiyDtKy4g8RuVwzGFiLbF6PZPgGzH981iiTs": ["writable","signer"] },
          { "2pivn1CTTYNTrWgYqK5coVLKqJA71zSnGzj4e7zRtbgm": ["writable","signer"] },
          { "4W1fvU92CeeMzrkwKq2vcsFMJFRKRCVbjvNRW7iz6y75": ["writable","signer"] },
          { "FuyAZqrhCUuz7ScPgwEgz8xxuWHnUkP45cyoB2uS5fhi": ["writable","signer"] },
          { "AKKtRwhPvqGhL6de3Bo3TNRCGMFU25tRvw3GSMPTFLRg": ["writable","signer"] },
          { "9DrMHtmBSE1JPAN78ZUt3XQ4dPaUsnAmnwwf4ABbne4o": ["writable"] },
          { "6G1hpMMGnGWAD5B7GaSMQEZZNuj1uma57ayVYxXWbkJJ": ["writable"] },
          { "Drz9WPMnJumHR3s1ecSBkLUybVwnpMHDbTWsUb4hSKQH": [] },
          { "TokenSVp5gheXUvJ6jGWGeCsgPKgnE3YgdGKRVCMY9o": [] }
        ],
        "instructions": [
          {
            "spl-token": {
              "amount": 1,
              "destination": "6G1hpMMGnGWAD5B7GaSMQEZZNuj1uma57ayVYxXWbkJJ",
              "multisigAuthority": "Drz9WPMnJumHR3s1ecSBkLUybVwnpMHDbTWsUb4hSKQH",
              "signers": [
                "7rwPzjXQiiyDtKy4g8RuVwzGFiLbF6PZPgGzH981iiTs",
                "2pivn1CTTYNTrWgYqK5coVLKqJA71zSnGzj4e7zRtbgm",
                "4W1fvU92CeeMzrkwKq2vcsFMJFRKRCVbjvNRW7iz6y75",
                "FuyAZqrhCUuz7ScPgwEgz8xxuWHnUkP45cyoB2uS5fhi",
                "AKKtRwhPvqGhL6de3Bo3TNRCGMFU25tRvw3GSMPTFLRg"
              ],
              "source": "9DrMHtmBSE1JPAN78ZUt3XQ4dPaUsnAmnwwf4ABbne4o",
              "type": "transfer"
            }
          }
        ],
        "recentBlockhash": "2oicQdXvE4G69RaXf9mRcRaXqMepPSuaxcCdqRJSuHi9"
      },
      "signatures": [
        "4Gc8UodaLkreW3Rw4VvRiRVY9B9XZDdSNPQqK7c6x9MjgXgyhPdEZRCNDx433d7GyFrKkEye9YKwUkSaoYHjeexp",
        "2JZcG6hcsSybY2MN2LtnZos2fQUkUdBhLrBMUyNWdbqLs3nEouwWJwjMt6Kb9z4UDEnfthsyWU9pZmHtBh7bAGxi",
        "65S9dEMp435BPHRr5yTixdwFz94PSRrxm8EZREkip5K7EYCBqEeorE89MtAxd7Zxq32Rd3W3R5DA6BxrLPT5zQBa",
        "3CALqCzUdNAv1Ue45ZPAQzozgnHco7qkc4mGrpMMQN6TXpdPw1XtsoVWpWQX5mL2UK3vtefFzVNm6PEXZ1YAUxYT",
        "2qqbraKD4tMzAJwaLHdt1UrejPG1BfjNivvDUxXRpicNjr6xjqZjbPSD8q6jwEEgB86QG9eSA5cZ6k6TadqD3w9F",
        "4FfuWE1E8NWR9fKHV2yp9D33SJGwEPKTrYashNqMpadMv2WahLA2rGVHFgrYempkx5KiYTEVsMMvfFvmUn5CXyt2"
      ]
    }
  },
  "id": 1
}

@CriesofCarrots
Copy link
Contributor Author

@jackcmay , could you please take a look at the account field names I've chosen, in particular? (The test in transaction-status/parse_token.rs is the easiest way to inspect.) The TokenInstruction docs and the instruction helper functions were not always consistent wrt account/variable naming, so I tried to pick field names that were understandable and consistent across the decoding.

@codecov
Copy link

codecov bot commented Jul 30, 2020

Codecov Report

Merging #11281 into master will increase coverage by 0.1%.
The diff coverage is 96.7%.

@@            Coverage Diff            @@
##           master   #11281     +/-   ##
=========================================
+ Coverage    82.5%    82.6%   +0.1%     
=========================================
  Files         316      317      +1     
  Lines       74543    75059    +516     
=========================================
+ Hits        61504    62019    +515     
- Misses      13039    13040      +1     

@mvines mvines added the v1.2 label Jul 30, 2020
Copy link
Contributor

@mvines mvines left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1. I'll let @jackcmay approve

@jackcmay
Copy link
Contributor

jackcmay commented Jul 30, 2020

@CriesofCarrots how about I update those variable names to make them consistent? Can you point me to an example?

})
);

// Test Approve, incl multisig
Copy link
Contributor

@jackcmay jackcmay Jul 30, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shall we re-release token now that this is fixed in: solana-labs/solana-program-library#164

Doesn't require a change to the program, just the helpers in instruction.rs

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good. I'll publish a new patch version tonight or tomorrow am.

@CriesofCarrots
Copy link
Contributor Author

@CriesofCarrots how about I update those variable names to make them consistent? Can you point me to an example?

In looking at this again, it's not inconsistency, per se. It's just that account_pubkey means different things in the context of different instructions. I think that's okay, actually. I was originally thinking I needed to be more explicit, but I've changed my mind on that. I'll update this code to call them all account.

Anyone have any opinions about the fact that I stripped out _pubkey for pubkey/address fields?

@CriesofCarrots CriesofCarrots force-pushed the decode-token-instructions branch from e8661e8 to 2c767aa Compare July 31, 2020 17:38
@CriesofCarrots CriesofCarrots force-pushed the decode-token-instructions branch from 2c767aa to 9de854e Compare July 31, 2020 17:40
@CriesofCarrots
Copy link
Contributor Author

@jackcmay updated. This look okay to you?

@CriesofCarrots CriesofCarrots added the automerge Merge this Pull Request automatically once CI passes label Jul 31, 2020
@CriesofCarrots CriesofCarrots merged commit 0f551d4 into solana-labs:master Jul 31, 2020
mergify bot pushed a commit that referenced this pull request Jul 31, 2020
* Token->SplToken

* Add spl_token instruction parsing

* Rebase on master

* Gracefully fail key len mismatches

(cherry picked from commit 0f551d4)

# Conflicts:
#	Cargo.lock
#	transaction-status/Cargo.toml
mergify bot added a commit that referenced this pull request Jul 31, 2020
* Decode token instructions (#11281)

* Token->SplToken

* Add spl_token instruction parsing

* Rebase on master

* Gracefully fail key len mismatches

(cherry picked from commit 0f551d4)

# Conflicts:
#	Cargo.lock
#	transaction-status/Cargo.toml

* Fix conflicts

Co-authored-by: Tyera Eulberg <[email protected]>
Co-authored-by: Tyera Eulberg <[email protected]>
@CriesofCarrots CriesofCarrots deleted the decode-token-instructions branch September 1, 2020 19:58
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
automerge Merge this Pull Request automatically once CI passes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Enhance RPC getConfirmedTransaction to support decoding transaction instruction info for SPL Token
3 participants