Created
July 7, 2023 18:58
-
-
Save peterargue/da744c9e7c4bddbfee4d89240a3f4244 to your computer and use it in GitHub Desktop.
flow-go-sdk bug repro for tx ID mismatch
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package main | |
| import ( | |
| "context" | |
| "fmt" | |
| "log" | |
| "google.golang.org/grpc" | |
| "google.golang.org/grpc/credentials/insecure" | |
| sdk "github.com/onflow/flow-go-sdk" | |
| "github.com/onflow/flow-go-sdk/client" | |
| "github.com/onflow/flow-go/engine/common/rpc/convert" | |
| "github.com/onflow/flow-go/model/flow" | |
| "github.com/onflow/flow/protobuf/go/flow/access" | |
| ) | |
| const accessURL = "access-001.mainnet23.nodes.onflow.org:9000" | |
| func main() { | |
| ctx := context.Background() | |
| txID := sdk.HexToID("38559cfac11eba732f3de2420eac511393e223bc92b0c52f75b6604098e4181a") | |
| // Get transaction and result using the SDK | |
| sdkClient, err := client.New(accessURL, grpc.WithTransportCredentials(insecure.NewCredentials())) | |
| if err != nil { | |
| log.Fatalf("could not create client: %v", err) | |
| } | |
| tx, err := sdkClient.GetTransaction(ctx, txID) | |
| if err != nil { | |
| log.Fatalf("could not get transaction: %v", err) | |
| } | |
| result, err := sdkClient.GetTransactionResult(ctx, txID) | |
| if err != nil { | |
| log.Fatalf("could not get transaction result: %v", err) | |
| } | |
| // Get transaction using the gRPC directly | |
| conn, err := grpc.DialContext(ctx, accessURL, grpc.WithTransportCredentials(insecure.NewCredentials())) | |
| if err != nil { | |
| log.Fatalf("could not create connection: %v", err) | |
| } | |
| defer conn.Close() | |
| rpcClient := access.NewAccessAPIClient(conn) | |
| txMsg, err := rpcClient.GetTransaction(ctx, &access.GetTransactionRequest{ | |
| Id: txID[:], | |
| }) | |
| if err != nil { | |
| log.Fatalf("could not get transaction: %v", err) | |
| } | |
| tx2, err := convert.MessageToTransaction(txMsg.GetTransaction(), flow.Mainnet.Chain()) | |
| if err != nil { | |
| log.Fatalf("could not convert transaction: %v", err) | |
| } | |
| fmt.Printf("SDK TxID: %s\n", tx.ID()) | |
| fmt.Printf("SDK Result TxID: %s\n", result.TransactionID) | |
| fmt.Printf("gRPC TxID: %s\n", tx2.ID()) | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
output