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

services/horizon/internal/ingest/processors: Ingest new invoke host operation type #5488

Merged
merged 5 commits into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
61 changes: 45 additions & 16 deletions services/horizon/internal/ingest/processors/operations_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -676,22 +676,7 @@ 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))

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

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

if balanceChanges, err := operation.parseAssetBalanceChangesFromContractEvents(); err != nil {
return nil, err
Expand All @@ -717,6 +702,32 @@ func (operation *transactionOperationWrapper) Details() (map[string]interface{},
default:
panic(fmt.Errorf("unknown contract id type: %s", args.ContractIdPreimage.Type))
}
case xdr.HostFunctionTypeHostFunctionTypeCreateContractV2:
args := op.HostFunction.MustCreateContractV2()
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))
}
tamirms marked this conversation as resolved.
Show resolved Hide resolved
details["from"] = "address"
details["address"] = address
details["salt"] = fromAddress.Salt.String()
case xdr.ContractIdPreimageTypeContractIdPreimageFromAsset:
details["from"] = "asset"
details["asset"] = args.ContractIdPreimage.MustFromAsset().StringCanonical()
default:
panic(fmt.Errorf("unknown contract id type: %s", args.ContractIdPreimage.Type))
}

details["parameters"] = extractFunctionArgs(args.ConstructorArgs)

if balanceChanges, err := operation.parseAssetBalanceChangesFromContractEvents(); err != nil {
return nil, err
} else {
details["asset_balance_changes"] = balanceChanges
}
case xdr.HostFunctionTypeHostFunctionTypeUploadContractWasm:
default:
panic(fmt.Errorf("unknown host function type: %s", op.HostFunction.Type))
Expand All @@ -740,6 +751,24 @@ func (operation *transactionOperationWrapper) Details() (map[string]interface{},
return details, nil
}

func extractFunctionArgs(args []xdr.ScVal) []map[string]string {
params := make([]map[string]string, 0, len(args))
for _, param := range args {
serializedParam := map[string]string{}
serializedParam["value"] = "n/a"
serializedParam["type"] = "n/a"

if scValTypeName, ok := param.ArmForSwitch(int32(param.Type)); ok {
Shaptic marked this conversation as resolved.
Show resolved Hide resolved
serializedParam["type"] = scValTypeName
if raw, err := param.MarshalBinary(); err == nil {
serializedParam["value"] = base64.StdEncoding.EncodeToString(raw)
}
}
params = append(params, serializedParam)
}
return params
}

// Searches an operation for SAC events that are of a type which represent
// asset balances having changed.
//
Expand Down
Loading
Loading