github.com/stellar/stellar-etl@v1.0.1-0.20240312145900-4874b6bf2b89/internal/transform/diagnostic_events.go (about) 1 package transform 2 3 import ( 4 "fmt" 5 6 "github.com/stellar/stellar-etl/internal/toid" 7 "github.com/stellar/stellar-etl/internal/utils" 8 9 "github.com/stellar/go/ingest" 10 "github.com/stellar/go/strkey" 11 "github.com/stellar/go/xdr" 12 ) 13 14 // TransformDiagnosticEvent converts a transaction's diagnostic events from the history archive ingestion system into a form suitable for BigQuery 15 func TransformDiagnosticEvent(transaction ingest.LedgerTransaction, lhe xdr.LedgerHeaderHistoryEntry) ([]DiagnosticEventOutput, error, bool) { 16 ledgerHeader := lhe.Header 17 outputTransactionHash := utils.HashToHexString(transaction.Result.TransactionHash) 18 outputLedgerSequence := uint32(ledgerHeader.LedgerSeq) 19 20 transactionIndex := uint32(transaction.Index) 21 22 outputTransactionID := toid.New(int32(outputLedgerSequence), int32(transactionIndex), 0).ToInt64() 23 24 outputCloseTime, err := utils.TimePointToUTCTimeStamp(ledgerHeader.ScpValue.CloseTime) 25 if err != nil { 26 return []DiagnosticEventOutput{}, fmt.Errorf("for ledger %d; transaction %d (transaction id=%d): %v", outputLedgerSequence, transactionIndex, outputTransactionID, err), false 27 } 28 29 diagnosticEvents, err := transaction.GetDiagnosticEvents() 30 if err != nil { 31 return []DiagnosticEventOutput{}, nil, false 32 } 33 34 var transformedDiagnosticEvents []DiagnosticEventOutput 35 36 for _, diagnoticEvent := range diagnosticEvents { 37 var outputContractId string 38 39 outputInSuccessfulContractCall := diagnoticEvent.InSuccessfulContractCall 40 event := diagnoticEvent.Event 41 outputExtV := event.Ext.V 42 outputType := event.Type.String() 43 outputBodyV := event.Body.V 44 body, _ := event.Body.GetV0() 45 46 outputBody, _ := xdr.MarshalBase64(body) 47 48 if event.ContractId != nil { 49 contractId := *event.ContractId 50 contractIdByte, _ := contractId.MarshalBinary() 51 outputContractId, _ = strkey.Encode(strkey.VersionByteContract, contractIdByte) 52 } 53 54 transformedDiagnosticEvent := DiagnosticEventOutput{ 55 TransactionHash: outputTransactionHash, 56 LedgerSequence: outputLedgerSequence, 57 TransactionID: outputTransactionID, 58 ClosedAt: outputCloseTime, 59 InSuccessfulContractCall: outputInSuccessfulContractCall, 60 ExtV: outputExtV, 61 ContractId: outputContractId, 62 Type: outputType, 63 BodyV: outputBodyV, 64 Body: outputBody, 65 } 66 67 transformedDiagnosticEvents = append(transformedDiagnosticEvents, transformedDiagnosticEvent) 68 } 69 70 return transformedDiagnosticEvents, nil, true 71 }