Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hubble 526 protocol22 changes #283

Merged
merged 8 commits into from
Nov 5, 2024
Merged
Show file tree
Hide file tree
Changes from 6 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
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ require (
github.com/spf13/cobra v1.7.0
github.com/spf13/pflag v1.0.5
github.com/spf13/viper v1.17.0
github.com/stellar/go v0.0.0-20240906064426-eb4b2ab750b8
github.com/stellar/go v0.0.0-20240905180041-acfaa0686213
github.com/stretchr/testify v1.9.0
github.com/xitongsys/parquet-go v1.6.2
github.com/xitongsys/parquet-go-source v0.0.0-20240122235623-d6294584ab18
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -641,8 +641,8 @@ github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
github.com/spf13/viper v1.17.0 h1:I5txKw7MJasPL/BrfkbA0Jyo/oELqVmux4pR/UxOMfI=
github.com/spf13/viper v1.17.0/go.mod h1:BmMMMLQXSbcHK6KAOiFLz0l5JHrU89OdIRHvsk0+yVI=
github.com/stellar/go v0.0.0-20240906064426-eb4b2ab750b8 h1:jbG9brYkKwfxB5yX4fKMzRodS8ZloF1HjPQWfj4oo+4=
github.com/stellar/go v0.0.0-20240906064426-eb4b2ab750b8/go.mod h1:rrFK7a8i2h9xad9HTfnSN/dTNEqXVHKAbkFeR7UxAgs=
github.com/stellar/go v0.0.0-20240905180041-acfaa0686213 h1:224VUCwV1xmmeTru1zCmTHxvi2RECoHdfdWgd9ni518=
github.com/stellar/go v0.0.0-20240905180041-acfaa0686213/go.mod h1:rrFK7a8i2h9xad9HTfnSN/dTNEqXVHKAbkFeR7UxAgs=
github.com/stellar/go-xdr v0.0.0-20231122183749-b53fb00bcac2 h1:OzCVd0SV5qE3ZcDeSFCmOWLZfEWZ3Oe8KtmSOYKEVWE=
github.com/stellar/go-xdr v0.0.0-20231122183749-b53fb00bcac2/go.mod h1:yoxyU/M8nl9LKeWIoBrbDPQ7Cy+4jxRcWcOayZ4BMps=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
Expand Down
176 changes: 102 additions & 74 deletions internal/transform/operation.go
Original file line number Diff line number Diff line change
Expand Up @@ -1029,8 +1029,6 @@ func extractOperationDetails(operation xdr.Operation, transaction ingest.LedgerT
args = append(args, xdr.ScVal{Type: xdr.ScValTypeScvAddress, Address: &invokeArgs.ContractAddress})
args = append(args, xdr.ScVal{Type: xdr.ScValTypeScvSymbol, Sym: &invokeArgs.FunctionName})
args = append(args, invokeArgs.Args...)
params := make([]map[string]string, 0, len(args))
paramsDecoded := make([]map[string]string, 0, len(args))

details["type"] = "invoke_contract"

Expand All @@ -1044,28 +1042,7 @@ func extractOperationDetails(operation xdr.Operation, transaction ingest.LedgerT
details["contract_id"] = contractId
details["contract_code_hash"] = contractCodeHashFromTxEnvelope(transactionEnvelope)

for _, param := range args {
serializedParam := map[string]string{}
serializedParam["value"] = "n/a"
serializedParam["type"] = "n/a"

serializedParamDecoded := map[string]string{}
serializedParamDecoded["value"] = "n/a"
serializedParamDecoded["type"] = "n/a"

if scValTypeName, ok := param.ArmForSwitch(int32(param.Type)); ok {
serializedParam["type"] = scValTypeName
serializedParamDecoded["type"] = scValTypeName
if raw, err := param.MarshalBinary(); err == nil {
serializedParam["value"] = base64.StdEncoding.EncodeToString(raw)
serializedParamDecoded["value"] = param.String()
}
}
params = append(params, serializedParam)
paramsDecoded = append(paramsDecoded, serializedParamDecoded)
}
details["parameters"] = params
details["parameters_decoded"] = paramsDecoded
details["parameters"], details["parameters_decoded"] = serializeParameters(args)

if balanceChanges, err := parseAssetBalanceChangesFromContractEvents(transaction, network); err != nil {
return nil, err
Expand All @@ -1082,26 +1059,38 @@ func extractOperationDetails(operation xdr.Operation, transaction ingest.LedgerT
details["contract_id"] = contractIdFromTxEnvelope(transactionEnvelope)
details["contract_code_hash"] = contractCodeHashFromTxEnvelope(transactionEnvelope)

switch args.ContractIdPreimage.Type {
case xdr.ContractIdPreimageTypeContractIdPreimageFromAddress:
fromAddress := args.ContractIdPreimage.MustFromAddress()
address, err := fromAddress.Address.String()
if err != nil {
panic(fmt.Errorf("error obtaining address for: %s", args.ContractIdPreimage.Type))
preimageTypeMap := switchContractIdPreimageType(args.ContractIdPreimage)
for key, val := range preimageTypeMap {
if _, ok := preimageTypeMap[key]; ok {
details[key] = val
}
details["from"] = "address"
details["address"] = address
case xdr.ContractIdPreimageTypeContractIdPreimageFromAsset:
details["from"] = "asset"
details["asset"] = args.ContractIdPreimage.MustFromAsset().StringCanonical()
default:
panic(fmt.Errorf("unknown contract id type: %s", args.ContractIdPreimage.Type))
}
case xdr.HostFunctionTypeHostFunctionTypeUploadContractWasm:
details["type"] = "upload_wasm"
transactionEnvelope := getTransactionV1Envelope(transaction.Envelope)
details["ledger_key_hash"] = ledgerKeyHashFromTxEnvelope(transactionEnvelope)
details["contract_code_hash"] = contractCodeHashFromTxEnvelope(transactionEnvelope)
case xdr.HostFunctionTypeHostFunctionTypeCreateContractV2:
sydneynotthecity marked this conversation as resolved.
Show resolved Hide resolved
args := op.HostFunction.MustCreateContractV2()
details["type"] = "create_contract_v2"

transactionEnvelope := getTransactionV1Envelope(transaction.Envelope)
details["ledger_key_hash"] = ledgerKeyHashFromTxEnvelope(transactionEnvelope)
details["contract_id"] = contractIdFromTxEnvelope(transactionEnvelope)
details["contract_code_hash"] = contractCodeHashFromTxEnvelope(transactionEnvelope)

// ConstructorArgs is a list of ScVals
// This will initially be handled the same as InvokeContractParams until a different
// model is found necessary.
constructorArgs := args.ConstructorArgs
details["parameters"], details["parameters_decoded"] = serializeParameters(constructorArgs)

preimageTypeMap := switchContractIdPreimageType(args.ContractIdPreimage)
for key, val := range preimageTypeMap {
if _, ok := preimageTypeMap[key]; ok {
details[key] = val
}
}
default:
panic(fmt.Errorf("unknown host function type: %s", op.HostFunction.Type))
}
Expand Down Expand Up @@ -1637,8 +1626,6 @@ func (operation *transactionOperationWrapper) Details() (map[string]interface{},
args = append(args, xdr.ScVal{Type: xdr.ScValTypeScvAddress, Address: &invokeArgs.ContractAddress})
args = append(args, xdr.ScVal{Type: xdr.ScValTypeScvSymbol, Sym: &invokeArgs.FunctionName})
args = append(args, invokeArgs.Args...)
params := make([]map[string]string, 0, len(args))
paramsDecoded := make([]map[string]string, 0, len(args))

details["type"] = "invoke_contract"

Expand All @@ -1652,28 +1639,7 @@ func (operation *transactionOperationWrapper) Details() (map[string]interface{},
details["contract_id"] = contractId
details["contract_code_hash"] = contractCodeHashFromTxEnvelope(transactionEnvelope)

for _, param := range args {
serializedParam := map[string]string{}
serializedParam["value"] = "n/a"
serializedParam["type"] = "n/a"

serializedParamDecoded := map[string]string{}
serializedParamDecoded["value"] = "n/a"
serializedParamDecoded["type"] = "n/a"

if scValTypeName, ok := param.ArmForSwitch(int32(param.Type)); ok {
serializedParam["type"] = scValTypeName
serializedParamDecoded["type"] = scValTypeName
if raw, err := param.MarshalBinary(); err == nil {
serializedParam["value"] = base64.StdEncoding.EncodeToString(raw)
serializedParamDecoded["value"] = param.String()
}
}
params = append(params, serializedParam)
paramsDecoded = append(paramsDecoded, serializedParamDecoded)
}
details["parameters"] = params
details["parameters_decoded"] = paramsDecoded
details["parameters"], details["parameters_decoded"] = serializeParameters(args)

if balanceChanges, err := operation.parseAssetBalanceChangesFromContractEvents(); err != nil {
return nil, err
Expand All @@ -1690,26 +1656,38 @@ func (operation *transactionOperationWrapper) Details() (map[string]interface{},
details["contract_id"] = contractIdFromTxEnvelope(transactionEnvelope)
details["contract_code_hash"] = contractCodeHashFromTxEnvelope(transactionEnvelope)

switch args.ContractIdPreimage.Type {
case xdr.ContractIdPreimageTypeContractIdPreimageFromAddress:
fromAddress := args.ContractIdPreimage.MustFromAddress()
address, err := fromAddress.Address.String()
if err != nil {
panic(fmt.Errorf("error obtaining address for: %s", args.ContractIdPreimage.Type))
preimageTypeMap := switchContractIdPreimageType(args.ContractIdPreimage)
for key, val := range preimageTypeMap {
if _, ok := preimageTypeMap[key]; ok {
details[key] = val
}
details["from"] = "address"
details["address"] = address
case xdr.ContractIdPreimageTypeContractIdPreimageFromAsset:
details["from"] = "asset"
details["asset"] = args.ContractIdPreimage.MustFromAsset().StringCanonical()
default:
panic(fmt.Errorf("unknown contract id type: %s", args.ContractIdPreimage.Type))
}
case xdr.HostFunctionTypeHostFunctionTypeUploadContractWasm:
details["type"] = "upload_wasm"
transactionEnvelope := getTransactionV1Envelope(operation.transaction.Envelope)
details["ledger_key_hash"] = ledgerKeyHashFromTxEnvelope(transactionEnvelope)
details["contract_code_hash"] = contractCodeHashFromTxEnvelope(transactionEnvelope)
case xdr.HostFunctionTypeHostFunctionTypeCreateContractV2:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Operation cases are duplicated due to how the original stellar-etl was written

args := op.HostFunction.MustCreateContractV2()
details["type"] = "create_contract_v2"

transactionEnvelope := getTransactionV1Envelope(operation.transaction.Envelope)
details["ledger_key_hash"] = ledgerKeyHashFromTxEnvelope(transactionEnvelope)
details["contract_id"] = contractIdFromTxEnvelope(transactionEnvelope)
details["contract_code_hash"] = contractCodeHashFromTxEnvelope(transactionEnvelope)

// ConstructorArgs is a list of ScVals
// This will initially be handled the same as InvokeContractParams until a different
// model is found necessary.
Comment on lines +1680 to +1681
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when you say "until a different model is found necessary" do you mean if we need to update the schema/data model? Or is there a possibility core will change how they present this data?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah my assumption right now is that because these constructorArgs are also []ScVal that they can be handled the same way as the invoke params. But it is possible that core designed constructorArgs to be different but there were no existing examples at the time of writing 😅

So the comment is more like "hey these two things look similar and currently process similarly but that doesn't mean they will look and process similarly in the future until p23 is released and made permanent"

constructorArgs := args.ConstructorArgs
details["parameters"], details["parameters_decoded"] = serializeParameters(constructorArgs)

preimageTypeMap := switchContractIdPreimageType(args.ContractIdPreimage)
for key, val := range preimageTypeMap {
if _, ok := preimageTypeMap[key]; ok {
details[key] = val
}
}
default:
panic(fmt.Errorf("unknown host function type: %s", op.HostFunction.Type))
}
Expand Down Expand Up @@ -2175,3 +2153,53 @@ func dedupeParticipants(in []xdr.AccountId) (out []xdr.AccountId) {
}
return
}

func serializeParameters(args []xdr.ScVal) ([]map[string]string, []map[string]string) {
params := make([]map[string]string, 0, len(args))
paramsDecoded := make([]map[string]string, 0, len(args))

for _, param := range args {
serializedParam := map[string]string{}
serializedParam["value"] = "n/a"
serializedParam["type"] = "n/a"

serializedParamDecoded := map[string]string{}
serializedParamDecoded["value"] = "n/a"
serializedParamDecoded["type"] = "n/a"

if scValTypeName, ok := param.ArmForSwitch(int32(param.Type)); ok {
serializedParam["type"] = scValTypeName
serializedParamDecoded["type"] = scValTypeName
if raw, err := param.MarshalBinary(); err == nil {
serializedParam["value"] = base64.StdEncoding.EncodeToString(raw)
serializedParamDecoded["value"] = param.String()
}
}
params = append(params, serializedParam)
paramsDecoded = append(paramsDecoded, serializedParamDecoded)
}

return params, paramsDecoded
}

func switchContractIdPreimageType(contractIdPreimage xdr.ContractIdPreimage) map[string]interface{} {
details := map[string]interface{}{}

switch contractIdPreimage.Type {
case xdr.ContractIdPreimageTypeContractIdPreimageFromAddress:
fromAddress := contractIdPreimage.MustFromAddress()
address, err := fromAddress.Address.String()
if err != nil {
panic(fmt.Errorf("error obtaining address for: %s", contractIdPreimage.Type))
}
details["from"] = "address"
details["address"] = address
case xdr.ContractIdPreimageTypeContractIdPreimageFromAsset:
details["from"] = "asset"
details["asset"] = contractIdPreimage.MustFromAsset().StringCanonical()
default:
panic(fmt.Errorf("unknown contract id type: %s", contractIdPreimage.Type))
}

return details
}
Loading
Loading