generated from TBD54566975/tbd-project-template
-
Notifications
You must be signed in to change notification settings - Fork 16
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
Support did_dht_resolution in C #390
Merged
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
build/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
compile: | ||
mkdir -p build | ||
gcc -o build/web5_c_example web5_c.c -L../../target/release -lweb5_c -I../../bindings/web5_c | ||
|
||
clean: | ||
rm -rf build | ||
|
||
run: compile | ||
./build/web5_c_example |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
## Example Description | ||
|
||
This C example demonstrates basic usage of the Web5 SDK functions through the C bindings. Specifically, it showcases: | ||
|
||
1. Resolving a `did:dht` identifier | ||
2. Printing the resolved DID document or an error message | ||
|
||
This example demonstrates how to resolve a DHT-based DID using the Web5 SDK in C. It uses the `did_dht_resolve` function with a hardcoded DID URI and the default gateway. The program then prints either the resolved DID document or an error message to the console. | ||
|
||
|
||
## Running the Example | ||
|
||
To run this C example: | ||
|
||
1. Ensure you have a C compiler installed (e.g. GCC) and [Just](https://github.com/casey/just) command runner. | ||
andresuribe87 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
2. Navigate to the root directory of the project where the main Justfile is located. | ||
|
||
3. Generate the C dynamic library by running: | ||
|
||
``` | ||
just bindc | ||
``` | ||
|
||
This command will build the necessary C bindings for the Web5 SDK. | ||
|
||
4. Navigate to the `examples/CExample` directory where the example-specific Justfile is located. | ||
KendallWeihe marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
5. Compile the example using the Justfile recipe: | ||
|
||
``` | ||
just compile | ||
``` | ||
|
||
This command will create a `build` directory and compile the C example using GCC with the appropriate flags and library paths. | ||
|
||
6. Run the compiled example: | ||
|
||
``` | ||
just run | ||
``` | ||
|
||
This will compile (if not already done) and execute the example program, demonstrating the usage of Web5 SDK functions in C. | ||
|
||
7. To clean up the build artifacts: | ||
|
||
``` | ||
just clean | ||
``` | ||
|
||
This will remove the `build` directory. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include "web5_c.h" | ||
|
||
int main() { | ||
const char* did_uri = "did:dht:qgmmpyjw5hwnqfgzn7wmrm33ady8gb8z9ideib6m9gj4ys6wny8y"; | ||
const char* gateway_url = NULL; // Using the default gateway | ||
|
||
char* result = did_dht_resolve(did_uri, gateway_url); | ||
|
||
if (result != NULL) { | ||
printf("%s", result); | ||
free_string(result); | ||
} else { | ||
printf("Failed to resolve DID\n"); | ||
} | ||
|
||
return 0; | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
at some point we should introduce better error handling over the C FFI, but it's not necessary at this moment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Created #392 to track.