Skip to content

Commit

Permalink
Add optionalU64ToPtr
Browse files Browse the repository at this point in the history
  • Loading branch information
chipshort committed Jun 4, 2024
1 parent 26ff52f commit c1a7fed
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
7 changes: 2 additions & 5 deletions internal/api/lib.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,15 +161,12 @@ func AnalyzeCode(cache Cache, checksum []byte) (*types.AnalysisReport, error) {
}
requiredCapabilities := string(copyAndDestroyUnmanagedVector(report.required_capabilities))
entrypoints := string(copyAndDestroyUnmanagedVector(report.entrypoints))
var contract_migrate_version *uint64
if report.contract_migrate_version.is_some {
contract_migrate_version = (*uint64)(&report.contract_migrate_version.value)
}

res := types.AnalysisReport{
HasIBCEntryPoints: bool(report.has_ibc_entry_points),
RequiredCapabilities: requiredCapabilities,
Entrypoints: strings.Split(entrypoints, ","),
ContractMigrateVersion: contract_migrate_version,
ContractMigrateVersion: optionalU64ToPtr(report.contract_migrate_version),
}
return &res, nil
}
Expand Down
7 changes: 7 additions & 0 deletions internal/api/memory.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,13 @@ func copyAndDestroyUnmanagedVector(v C.UnmanagedVector) []byte {
return out
}

func optionalU64ToPtr(val C.OptionalU64) *uint64 {
if val.is_some {
return (*uint64)(&val.value)
}
return nil
}

// copyU8Slice copies the contents of an Option<&[u8]> that was allocated on the Rust side.
// Returns nil if and only if the source is None.
func copyU8Slice(view C.U8SliceView) []byte {
Expand Down

0 comments on commit c1a7fed

Please sign in to comment.