Skip to content

Commit

Permalink
Decode all params
Browse files Browse the repository at this point in the history
  • Loading branch information
chowbao committed Dec 14, 2023
1 parent 1eeca7a commit de782b6
Showing 1 changed file with 18 additions and 11 deletions.
29 changes: 18 additions & 11 deletions internal/transform/operation.go
Original file line number Diff line number Diff line change
Expand Up @@ -945,7 +945,7 @@ func extractOperationDetails(operation xdr.Operation, transaction ingest.LedgerT
args = append(args, xdr.ScVal{Type: xdr.ScValTypeScvSymbol, Sym: &invokeArgs.FunctionName})
args = append(args, invokeArgs.Args...)
params := make([]map[string]string, 0, len(args))
var decodedSymbolParamNames []string
paramsDecoded := make([]map[string]string, 0, len(args))

details["type"] = "invoke_contract"

Expand All @@ -958,19 +958,23 @@ func extractOperationDetails(operation xdr.Operation, transaction ingest.LedgerT
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)
}
if scValTypeName == "Sym" {
decodedSymbolParamNames = append(decodedSymbolParamNames, param.String())
serializedParamDecoded["value"] = param.String()
}
}
params = append(params, serializedParam)
paramsDecoded = append(paramsDecoded, serializedParamDecoded)
}
details["parameters"] = params
details["decoded_symbol_param_names"] = decodedSymbolParamNames
details["parameters_decoded"] = paramsDecoded

if balanceChanges, err := parseAssetBalanceChangesFromContractEvents(transaction, network); err != nil {
return nil, err
Expand Down Expand Up @@ -1539,7 +1543,7 @@ func (operation *transactionOperationWrapper) Details() (map[string]interface{},
args = append(args, xdr.ScVal{Type: xdr.ScValTypeScvSymbol, Sym: &invokeArgs.FunctionName})
args = append(args, invokeArgs.Args...)
params := make([]map[string]string, 0, len(args))
var decodedSymbolParamNames []string
paramsDecoded := make([]map[string]string, 0, len(args))

details["type"] = "invoke_contract"

Expand All @@ -1552,20 +1556,23 @@ func (operation *transactionOperationWrapper) Details() (map[string]interface{},
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()
}
if scValTypeName == "Sym" {
decodedSymbolParamNames = append(decodedSymbolParamNames, param.String())
}

}
params = append(params, serializedParam)
paramsDecoded = append(paramsDecoded, serializedParamDecoded)
}
details["parameters"] = params
details["decoded_symbol_param_names"] = decodedSymbolParamNames
details["parameters_decoded"] = paramsDecoded

if balanceChanges, err := operation.parseAssetBalanceChangesFromContractEvents(); err != nil {
return nil, err
Expand Down

0 comments on commit de782b6

Please sign in to comment.