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

Do you know how hard I tried to get the TransactionDetails? #150

Open
yangyile1990 opened this issue Jul 11, 2023 · 1 comment
Open

Do you know how hard I tried to get the TransactionDetails? #150

yangyile1990 opened this issue Jul 11, 2023 · 1 comment

Comments

@yangyile1990
Copy link

func (s *Solana) GetLog(blockNum int64, mapToken map[string]*anychain.Token) ([]*anychain.ContractTokenTran, *cerror.CError) {
latestBlockNum, erc := s.GetBlockNum()
if erc != nil {
return nil, erc
}

if false {
	block, err := s.client2.GetBlockWithConfig(context.TODO(), uint64(blockNum), client.GetBlockConfig{
		Commitment:         rpc2.CommitmentFinalized,
		TransactionDetails: rpc2.GetBlockConfigTransactionDetailsFull,
		Rewards:            nil,
	})
	if err != nil {
		return nil, cerror.NewError(cerror.CODE_THIRD_REQ_ERROR, err.Error())
	}
	fmt.Println(utjson.NeatString(block))
} else {
	out, err := s.client.GetBlockWithOpts(context.TODO(), uint64(blockNum), &rpc.GetBlockOpts{
		Encoding:   solana.EncodingBase64,
		Commitment: rpc.CommitmentFinalized,
		// Get only signatures:
		TransactionDetails: rpc.TransactionDetailsFull,
		// Exclude rewards:
		//Rewards: &includeRewards,
	})
	if err != nil {
		return nil, cerror.NewError(cerror.CODE_THIRD_REQ_ERROR, err.Error())
	}
	//fmt.Println(utjson.NeatString(out))

	var res = make([]*anychain.ContractTokenTran, 0, len(out.Transactions))
	for i, x := range out.Transactions {
		transaction, err := x.GetTransaction()
		if err != nil {
			panic(err)
		}
		fmt.Println(utjson.NeatString(transaction))
		if i > 3 {
			break
		}
		res = append(res, &anychain.ContractTokenTran{
			Chain:             SOLANA,
			TxId:              transaction.Signatures[0].String(),
			TransferTimestamp: out.BlockTime.Time().UnixMilli(),
			BlockNum:          int64(*out.BlockHeight),
			Confirmations:     latestBlockNum - int64(*out.BlockHeight),
			Result:            true,
			Remark:            "SUCCESS",
			FeeSymbol:         SOL,
			FeeSymbolPrice:    "0.1",
			FeeAmountCoin:     "0.1",
			FeeAmountUsdt:     "0.1",
			Transfers:         []*anychain.CallbackTransfer{},
		})
		list, err := transaction.AccountMetaList()
		if err != nil {
			return nil, cerror.NewError(cerror.CODE_THIRD_REQ_ERROR, err.Error())
		}
		fmt.Println(utjson.NeatString(list))

		//instruction, err := vote.DecodeInstruction(list, transaction.Message.Instructions[0].Data)
		//if err != nil {
		//	return nil, cerror.NewError(cerror.CODE_THIRD_REQ_ERROR, err.Error())
		//}
		//fmt.Println(utjson.NeatString(instruction))

		//dataBts, err := base58.Decode(transaction.Message.Instructions[0].Data)
		//if err != nil {
		//	t.Fatal(err)
		//}
	}
	out.Transactions = nil
	fmt.Println(utjson.NeatString(out))

	return res, nil
}
return nil, nil

}

How to parse the (transaction.Message.Instructions[0].Data)?

@gagliardetto
Copy link
Owner

gagliardetto commented Jul 11, 2023 via email

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

2 participants