Skip to content

Commit

Permalink
Hubble 526 protocol22 changes (#283)
Browse files Browse the repository at this point in the history
  • Loading branch information
chowbao authored Nov 5, 2024
1 parent 7706ea3 commit 204d343
Show file tree
Hide file tree
Showing 7 changed files with 580 additions and 282 deletions.
2 changes: 1 addition & 1 deletion docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ COPY . .
RUN go build -v -o /usr/local/bin ./...

# stage 2: runtime enviroment
FROM stellar/stellar-core:21.0.0-1872.c6f474133.focal
FROM stellar/unsafe-stellar-core:22.0.0-2126.rc3.92923c2db.focal

WORKDIR /etl

Expand Down
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:
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:
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.
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

0 comments on commit 204d343

Please sign in to comment.