Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 12 additions & 40 deletions internal/transform/operation.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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 {
Expand All @@ -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()
Expand All @@ -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)
Expand All @@ -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())
}
Expand Down Expand Up @@ -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)
Expand All @@ -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 {
Expand All @@ -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()
Expand All @@ -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)
Expand All @@ -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()))
}
Expand Down Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down
28 changes: 14 additions & 14 deletions internal/transform/operation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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,
},
},
Expand All @@ -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,
Expand All @@ -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,
},
},
Expand All @@ -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,
Expand All @@ -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,
},
},
Expand Down
Loading