diff --git a/internal/transform/operation.go b/internal/transform/operation.go index 30a06e70..15fb699a 100644 --- a/internal/transform/operation.go +++ b/internal/transform/operation.go @@ -1082,7 +1082,7 @@ func extractOperationDetails(operation xdr.Operation, transaction ingest.LedgerT transactionEnvelope := getTransactionV1Envelope(transaction.Envelope) details["ledger_key_hash"] = ledgerKeyHashFromTxEnvelope(transactionEnvelope) details["contract_id"] = contractId - details["contract_code_hash"] = contractCodeHashFromTxEnvelope(transactionEnvelope) + details["contract_code_hash"] = nil details["parameters"], details["parameters_decoded"] = serializeParameters(args) details["parameters_json"], details["parameters_json_decoded"], err = serializeScValArray(args) @@ -1103,7 +1103,7 @@ func extractOperationDetails(operation xdr.Operation, transaction ingest.LedgerT transactionEnvelope := getTransactionV1Envelope(transaction.Envelope) details["ledger_key_hash"] = ledgerKeyHashFromTxEnvelope(transactionEnvelope) details["contract_id"] = contractIdFromTxEnvelope(transactionEnvelope) - details["contract_code_hash"] = contractCodeHashFromTxEnvelope(transactionEnvelope) + details["contract_code_hash"] = nil preimageTypeMap := switchContractIdPreimageType(args.ContractIdPreimage) for key, val := range preimageTypeMap { @@ -1115,7 +1115,7 @@ func extractOperationDetails(operation xdr.Operation, transaction ingest.LedgerT details["type"] = "upload_wasm" transactionEnvelope := getTransactionV1Envelope(transaction.Envelope) details["ledger_key_hash"] = ledgerKeyHashFromTxEnvelope(transactionEnvelope) - details["contract_code_hash"] = contractCodeHashFromTxEnvelope(transactionEnvelope) + details["contract_code_hash"] = nil case xdr.HostFunctionTypeHostFunctionTypeCreateContractV2: var err error args := op.HostFunction.MustCreateContractV2() @@ -1124,7 +1124,7 @@ func extractOperationDetails(operation xdr.Operation, transaction ingest.LedgerT transactionEnvelope := getTransactionV1Envelope(transaction.Envelope) details["ledger_key_hash"] = ledgerKeyHashFromTxEnvelope(transactionEnvelope) details["contract_id"] = contractIdFromTxEnvelope(transactionEnvelope) - details["contract_code_hash"] = contractCodeHashFromTxEnvelope(transactionEnvelope) + details["contract_code_hash"] = nil details["parameters"], details["parameters_decoded"] = serializeParameters(args.ConstructorArgs) details["parameters_json"], details["parameters_json_decoded"], err = serializeScValArray(args.ConstructorArgs) @@ -1149,14 +1149,14 @@ func extractOperationDetails(operation xdr.Operation, transaction ingest.LedgerT transactionEnvelope := getTransactionV1Envelope(transaction.Envelope) details["ledger_key_hash"] = ledgerKeyHashFromTxEnvelope(transactionEnvelope) details["contract_id"] = contractIdFromTxEnvelope(transactionEnvelope) - details["contract_code_hash"] = contractCodeHashFromTxEnvelope(transactionEnvelope) + details["contract_code_hash"] = nil case xdr.OperationTypeRestoreFootprint: details["type"] = "restore_footprint" transactionEnvelope := getTransactionV1Envelope(transaction.Envelope) details["ledger_key_hash"] = ledgerKeyHashFromTxEnvelope(transactionEnvelope) details["contract_id"] = contractIdFromTxEnvelope(transactionEnvelope) - details["contract_code_hash"] = contractCodeHashFromTxEnvelope(transactionEnvelope) + details["contract_code_hash"] = nil default: return details, fmt.Errorf("unknown operation type: %s", operation.Body.Type.String()) } @@ -1704,7 +1704,7 @@ func (operation *transactionOperationWrapper) Details() (map[string]interface{}, transactionEnvelope := getTransactionV1Envelope(operation.transaction.Envelope) details["ledger_key_hash"] = ledgerKeyHashFromTxEnvelope(transactionEnvelope) details["contract_id"] = contractId - details["contract_code_hash"] = contractCodeHashFromTxEnvelope(transactionEnvelope) + details["contract_code_hash"] = nil details["parameters"], details["parameters_decoded"] = serializeParameters(args) details["parameters_json"], details["parameters_json_decoded"], err = serializeScValArray(args) @@ -1725,7 +1725,7 @@ func (operation *transactionOperationWrapper) Details() (map[string]interface{}, transactionEnvelope := getTransactionV1Envelope(operation.transaction.Envelope) details["ledger_key_hash"] = ledgerKeyHashFromTxEnvelope(transactionEnvelope) details["contract_id"] = contractIdFromTxEnvelope(transactionEnvelope) - details["contract_code_hash"] = contractCodeHashFromTxEnvelope(transactionEnvelope) + details["contract_code_hash"] = nil preimageTypeMap := switchContractIdPreimageType(args.ContractIdPreimage) for key, val := range preimageTypeMap { @@ -1737,7 +1737,7 @@ func (operation *transactionOperationWrapper) Details() (map[string]interface{}, details["type"] = "upload_wasm" transactionEnvelope := getTransactionV1Envelope(operation.transaction.Envelope) details["ledger_key_hash"] = ledgerKeyHashFromTxEnvelope(transactionEnvelope) - details["contract_code_hash"] = contractCodeHashFromTxEnvelope(transactionEnvelope) + details["contract_code_hash"] = nil case xdr.HostFunctionTypeHostFunctionTypeCreateContractV2: var err error args := op.HostFunction.MustCreateContractV2() @@ -1746,7 +1746,7 @@ func (operation *transactionOperationWrapper) Details() (map[string]interface{}, transactionEnvelope := getTransactionV1Envelope(operation.transaction.Envelope) details["ledger_key_hash"] = ledgerKeyHashFromTxEnvelope(transactionEnvelope) details["contract_id"] = contractIdFromTxEnvelope(transactionEnvelope) - details["contract_code_hash"] = contractCodeHashFromTxEnvelope(transactionEnvelope) + details["contract_code_hash"] = nil details["parameters"], details["parameters_decoded"] = serializeParameters(args.ConstructorArgs) details["parameters_json"], details["parameters_json_decoded"], err = serializeScValArray(args.ConstructorArgs) @@ -1771,14 +1771,14 @@ func (operation *transactionOperationWrapper) Details() (map[string]interface{}, transactionEnvelope := getTransactionV1Envelope(operation.transaction.Envelope) details["ledger_key_hash"] = ledgerKeyHashFromTxEnvelope(transactionEnvelope) details["contract_id"] = contractIdFromTxEnvelope(transactionEnvelope) - details["contract_code_hash"] = contractCodeHashFromTxEnvelope(transactionEnvelope) + details["contract_code_hash"] = nil case xdr.OperationTypeRestoreFootprint: details["type"] = "restore_footprint" transactionEnvelope := getTransactionV1Envelope(operation.transaction.Envelope) details["ledger_key_hash"] = ledgerKeyHashFromTxEnvelope(transactionEnvelope) details["contract_id"] = contractIdFromTxEnvelope(transactionEnvelope) - details["contract_code_hash"] = contractCodeHashFromTxEnvelope(transactionEnvelope) + details["contract_code_hash"] = nil default: panic(fmt.Errorf("unknown operation type: %s", operation.OperationType())) } @@ -1838,24 +1838,6 @@ func contractIdFromContractData(ledgerKey xdr.LedgerKey) string { return contractId } -func contractCodeHashFromTxEnvelope(transactionEnvelope xdr.TransactionV1Envelope) string { - for _, ledgerKey := range transactionEnvelope.Tx.Ext.SorobanData.Resources.Footprint.ReadOnly { - contractCode := contractCodeFromContractData(ledgerKey) - if contractCode != "" { - return contractCode - } - } - - for _, ledgerKey := range transactionEnvelope.Tx.Ext.SorobanData.Resources.Footprint.ReadWrite { - contractCode := contractCodeFromContractData(ledgerKey) - if contractCode != "" { - return contractCode - } - } - - return "" -} - func ledgerKeyHashFromTxEnvelope(transactionEnvelope xdr.TransactionV1Envelope) []string { var ledgerKeyHash []string for _, ledgerKey := range transactionEnvelope.Tx.Ext.SorobanData.Resources.Footprint.ReadOnly { @@ -1873,16 +1855,6 @@ func ledgerKeyHashFromTxEnvelope(transactionEnvelope xdr.TransactionV1Envelope) return ledgerKeyHash } -func contractCodeFromContractData(ledgerKey xdr.LedgerKey) string { - contractCode, ok := ledgerKey.GetContractCode() - if !ok { - return "" - } - - contractCodeHash := contractCode.Hash.HexString() - return contractCodeHash -} - func filterEvents(diagnosticEvents []xdr.DiagnosticEvent) []xdr.ContractEvent { var filtered []xdr.ContractEvent for _, diagnosticEvent := range diagnosticEvents { diff --git a/internal/transform/operation_test.go b/internal/transform/operation_test.go index ea9b9023..f3a685ad 100644 --- a/internal/transform/operation_test.go +++ b/internal/transform/operation_test.go @@ -1854,7 +1854,7 @@ func makeOperationTestOutputs() (transformedOperations []OperationOutput) { "function": "HostFunctionTypeHostFunctionTypeInvokeContract", "type": "invoke_contract", "contract_id": "CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABSC4", - "contract_code_hash": "", + "contract_code_hash": nil, "asset_balance_changes": []map[string]interface{}{}, "ledger_key_hash": nilStringArray, "parameters": []map[string]string{ @@ -1897,7 +1897,7 @@ func makeOperationTestOutputs() (transformedOperations []OperationOutput) { "function": "HostFunctionTypeHostFunctionTypeInvokeContract", "type": "invoke_contract", "contract_id": "CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABSC4", - "contract_code_hash": "", + "contract_code_hash": nil, "asset_balance_changes": []map[string]interface{}{}, "ledger_key_hash": nilStringArray, "parameters": []map[string]string{ @@ -1944,7 +1944,7 @@ func makeOperationTestOutputs() (transformedOperations []OperationOutput) { "function": "HostFunctionTypeHostFunctionTypeCreateContract", "type": "create_contract", "contract_id": "", - "contract_code_hash": "", + "contract_code_hash": nil, "from": "address", "address": "CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABSC4", "ledger_key_hash": nilStringArray, @@ -1956,7 +1956,7 @@ func makeOperationTestOutputs() (transformedOperations []OperationOutput) { "function": "HostFunctionTypeHostFunctionTypeCreateContract", "type": "create_contract", "contract_id": "", - "contract_code_hash": "", + "contract_code_hash": nil, "from": "address", "address": "CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABSC4", "ledger_key_hash": nilStringArray, @@ -1972,7 +1972,7 @@ func makeOperationTestOutputs() (transformedOperations []OperationOutput) { "function": "HostFunctionTypeHostFunctionTypeCreateContract", "type": "create_contract", "contract_id": "", - "contract_code_hash": "", + "contract_code_hash": nil, "from": "asset", "asset": ":GAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAWHF", "ledger_key_hash": nilStringArray, @@ -1984,7 +1984,7 @@ func makeOperationTestOutputs() (transformedOperations []OperationOutput) { "function": "HostFunctionTypeHostFunctionTypeCreateContract", "type": "create_contract", "contract_id": "", - "contract_code_hash": "", + "contract_code_hash": nil, "from": "asset", "asset": ":GAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAWHF", "ledger_key_hash": nilStringArray, @@ -2000,7 +2000,7 @@ func makeOperationTestOutputs() (transformedOperations []OperationOutput) { "function": "HostFunctionTypeHostFunctionTypeCreateContractV2", "type": "create_contract_v2", "contract_id": "", - "contract_code_hash": "", + "contract_code_hash": nil, "from": "asset", "asset": ":GAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAWHF", "ledger_key_hash": nilStringArray, @@ -2028,7 +2028,7 @@ func makeOperationTestOutputs() (transformedOperations []OperationOutput) { "function": "HostFunctionTypeHostFunctionTypeCreateContractV2", "type": "create_contract_v2", "contract_id": "", - "contract_code_hash": "", + "contract_code_hash": nil, "from": "asset", "asset": ":GAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAWHF", "ledger_key_hash": nilStringArray, @@ -2059,7 +2059,7 @@ func makeOperationTestOutputs() (transformedOperations []OperationOutput) { OperationDetails: map[string]interface{}{ "function": "HostFunctionTypeHostFunctionTypeUploadContractWasm", "type": "upload_wasm", - "contract_code_hash": "", + "contract_code_hash": nil, "ledger_key_hash": nilStringArray, }, ClosedAt: hardCodedLedgerClose, @@ -2068,7 +2068,7 @@ func makeOperationTestOutputs() (transformedOperations []OperationOutput) { OperationDetailsJSON: map[string]interface{}{ "function": "HostFunctionTypeHostFunctionTypeUploadContractWasm", "type": "upload_wasm", - "contract_code_hash": "", + "contract_code_hash": nil, "ledger_key_hash": nilStringArray, }, }, @@ -2082,7 +2082,7 @@ func makeOperationTestOutputs() (transformedOperations []OperationOutput) { "type": "extend_footprint_ttl", "extend_to": xdr.Uint32(1234), "contract_id": "", - "contract_code_hash": "", + "contract_code_hash": nil, "ledger_key_hash": nilStringArray, }, ClosedAt: hardCodedLedgerClose, @@ -2092,7 +2092,7 @@ func makeOperationTestOutputs() (transformedOperations []OperationOutput) { "type": "extend_footprint_ttl", "extend_to": xdr.Uint32(1234), "contract_id": "", - "contract_code_hash": "", + "contract_code_hash": nil, "ledger_key_hash": nilStringArray, }, }, @@ -2105,7 +2105,7 @@ func makeOperationTestOutputs() (transformedOperations []OperationOutput) { OperationDetails: map[string]interface{}{ "type": "restore_footprint", "contract_id": "", - "contract_code_hash": "", + "contract_code_hash": nil, "ledger_key_hash": nilStringArray, }, ClosedAt: hardCodedLedgerClose, @@ -2114,7 +2114,7 @@ func makeOperationTestOutputs() (transformedOperations []OperationOutput) { OperationDetailsJSON: map[string]interface{}{ "type": "restore_footprint", "contract_id": "", - "contract_code_hash": "", + "contract_code_hash": nil, "ledger_key_hash": nilStringArray, }, },