Skip to content

Instantly share code, notes, and snippets.

@peterargue
Created July 7, 2023 18:58
Show Gist options
  • Select an option

  • Save peterargue/da744c9e7c4bddbfee4d89240a3f4244 to your computer and use it in GitHub Desktop.

Select an option

Save peterargue/da744c9e7c4bddbfee4d89240a3f4244 to your computer and use it in GitHub Desktop.
flow-go-sdk bug repro for tx ID mismatch
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())
}
@peterargue
Copy link
Author

output

$ go run compare_tx_ids.go
SDK TxID:        06e254293add97d9a9519eac42a30c8450ff7f51556392901462f5476ca06a18
SDK Result TxID: 38559cfac11eba732f3de2420eac511393e223bc92b0c52f75b6604098e4181a
gRPC TxID:       38559cfac11eba732f3de2420eac511393e223bc92b0c52f75b6604098e4181a

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment