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

Using GetParsedTransaction to obtain event data is incorrect #223

Open
langubtc opened this issue Jun 21, 2024 · 0 comments
Open

Using GetParsedTransaction to obtain event data is incorrect #223

langubtc opened this issue Jun 21, 2024 · 0 comments

Comments

@langubtc
Copy link

langubtc commented Jun 21, 2024

Hello developer, I use GetParsedTransaction to get event data, but the data obtained and the data from Solscan are incorrect. Can I ask for your help?
tx:LofiBXmyHkjVRiK6Ae76DBBDSLUHFrMpdpZzYYYRz4tmWtj2jXP9bARRpMBwGiGDeDhu5Sz8wTvorxYSdD72Nj2

   func GetTransaction(ctx context.Context, signature string) {
	txSig := solana.MustSignatureFromBase58(signature)
	version := uint64(0)
	out, err := client.GetParsedTransaction(
		context.TODO(),
		txSig,
		&rpc.GetParsedTransactionOpts{
			MaxSupportedTransactionVersion: &version,
			Commitment:                     rpc.CommitmentConfirmed,
		},
	)

	if err != nil {
		panic(err)
	}

	for _, instructions := range out.Meta.InnerInstructions {
		for _, uniner := range instructions.Instructions {
			if uniner.Program == "" && uniner.ProgramId.String() == "6EF8rrecthR5Dkzon8Nwu78hRvfCKubJ14M5uBEwF6P" {
				binary, err := base58.Decode(uniner.Data.String())
				if err != nil {
					continue
				}

				acEvent := models.TransactionData{}

				decoder := bin.NewBorshDecoder(binary)

				err = decoder.Decode(&acEvent)
				if err != nil {
					continue
				}

				fmt.Println(acEvent)
			}

		}
	}
}

out:

{GN5YtALYZdstsseG99VcK3dhpt4aUGVuZb3XkdNk4DUP 5006513049810348600 14928840578314757302 true J37sAcQU91S2zhFLb3PrfJ1z1FJEVicjUuHyLC5AV2xv 345558380229795933 2623109577306031043 1718900353}
type TransactionData struct {
	Mint                 solana.PublicKey `json:"mint"`
	SolAmount            uint64           `json:"solAmount"`
	TokenAmount          uint64           `json:"tokenAmount"`
	IsBuy                bool             `json:"isBuy"`
	User                 solana.PublicKey `json:"user"` 
	Timestamp            int64            `json:"timestamp"`
	VirtualSolReserves   uint64           `json:"virtualSolReserves"`
	VirtualTokenReserves uint64           `json:"virtualTokenReserves"`
}

Looks like the data type is incorrect,I want to get data like this。

{
  "mint": {
    "type": "publicKey",
    "data": "AsjBCMaWLYcemXGxWcqmdB28dhA1nat5Q1h4hR2fpump"
  },
  "solAmount": {
    "type": "u64",
    "data": "2585918907"
  },
  "tokenAmount": {
    "type": "u64",
    "data": "41544892677520"
  },
  "isBuy": {
    "type": "bool",
    "data": false
  },
  "user": {
    "type": "publicKey",
    "data": "DfMxre4cKmvogbLrPigxmibVTTQDuzjdXojWzjCXXhzj"
  },
  "timestamp": {
    "type": "i64",
    "data": "1718900353"
  },
  "virtualSolReserves": {
    "type": "u64",
    "data": "43487672804"
  },
  "virtualTokenReserves": {
    "type": "u64",
    "data": "740209763511468"
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant