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

Update README docs #44

Merged
merged 1 commit into from
Nov 22, 2023
Merged
Changes from all 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
66 changes: 64 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,68 @@
# c-polygonid

C wrapper for polygonid libraries.
This is a wrapper library for several PolygonID Go libraries, designed for use
with C/C++ languages. It can also be used in mobile development or other
infrastructures facing challenges with Go integration.

An overview of the major functions looks like this:
```
GoUint8 PLGNAtomicQuerySigV2Inputs(char** jsonResponse, char* jsonRequest, char* cfg, PLGNStatus** status);
```

`GoUint8` is a type alias for `signed char`, which essentially represents a Go
bool. It can be `0` or `1`. Generally, the function returns `1` in the event of
a successful operation and `0` in the event of failure.

If the `status` pointer is not NULL, a new PLGNStatus object will be allocated,
containing details about errors. This object should be freed with the
`PLGNStatusFree` function to avoid a memory leak.

`jsonRequest` and `jsonResponse` are plain JSON objects. Their contents depend
on the specific function and should be documented in the
[polygonid.go](cmd/polygonid/polygonid.go) file. The examples of requests to
different functions can be found in [testdata](testdata) directory.

## Configuration

The configuration object is a JSON document with the following structure:
```json5
{
"ipfsNodeUrl": "http://localhost:5001", // IPFS Node URL
"chainConfigs": {
"1": { // Chain ID as decimal
"rpcUrl": "http://localhost:8545", // RPC URL
"stateContractAddr": "0xEA9aF2088B4a9770fC32A12fD42E61BDD317E655" // State contract address
},
"0x10": { // Chain ID in hexadecimal format
"rpcUrl": "http://localhost:8545",
"stateContractAddr": "0xEA9aF2088B4a9770fC32A12fD42E61BDD317E655"
}
}
}
```

This object should be passed on each call to the library.
It is not memorized or cached.

## Errors

In case of an error, the function returns `0`, and if the pointer to the
`PLGNStatus` struct is not NULL, a struct object will be allocated and filled
with the following structure:

```C
typedef struct _PLGNStatus
{
PLGNStatusCode status;
char *error_msg;
} PLGNStatus;
```

Here, `PLGNStatusCode` is the status enum that can be seen in the .h file
included in the distribution of this library, and `error_msg` is a string
containing a detailed, human-readable error.

This object should be freed with `PLGNStatusFree` function.

## Build on macos M1

Expand Down Expand Up @@ -32,4 +94,4 @@ clang -L../ios -lpolygonid-darwin-arm64 \
-framework CoreServices \
`pkg-config --libs --cflags libcjson` \
json_functions_tests.c && ./a.out
```
```