Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/bjartek/underflow
Underflow is a library to help parse cadence datatypes into sane golang defaults
https://github.com/bjartek/underflow
Last synced: 3 days ago
JSON representation
Underflow is a library to help parse cadence datatypes into sane golang defaults
- Host: GitHub
- URL: https://github.com/bjartek/underflow
- Owner: bjartek
- Created: 2024-02-15T12:29:50.000Z (11 months ago)
- Default Branch: main
- Last Pushed: 2024-10-28T07:26:39.000Z (3 months ago)
- Last Synced: 2024-11-11T11:15:49.963Z (2 months ago)
- Language: Go
- Size: 101 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- Code of conduct: CODE_OF_CONDUCT.md
- Codeowners: CODEOWNERS
Awesome Lists containing this project
README
[![Coverage Status](https://coveralls.io/repos/github/bjartek/underflow/badge.svg?branch=main)](https://coveralls.io/github/bjartek/underflow?branch=main) [![ci](https://github.com/bjartek/underflow/actions/workflows/ci.yaml/badge.svg)](https://github.com/bjartek/underflow/actions/workflows/ci.yaml)
# UnderflowA library extracted out from https://github.com/bjartek/overflow that has less depdendencies and only parses to from go<>cadence
## How to convert a cadence.Value to terser json or a go interface{} value
if you want a `map[string]interface` use `underflow.CadenceValueToInterface`
```cadence
underflow.CadenceValueToJsonString()
```This will create a very terse representation
- it will skip any value that is empty/bottom type
- if a value is empty a key is skippedIf you do not like this you can configure it like this
```cadence
underflow.CadenceValueToJsonStringWithOption(, underflow.Options{
IncludeEmptyValues: true, //this will not skip empty values/keys
WrapWithComplexTypes: true, //this will wrap any complex types with another layer that includes the type
})
```## How to create a cadence value from a struct
```cadence
pub contract MyFancyContract {pub struct MyStruct{
pub let owner: Address
pub let name: String}
````Create the following go struct
```go
type MyFancyContract_MyStruct struct {
Owner string `cadence:"owner,cadenceAddress"`
Name string `cadence:"name"`
}myImpl := MyFancyContract_MyStruct{
Owner: "0x123",
Name: "bjartek is the best"
}//resolver is here a function that takes in the name of a go struct and returns the identifier of the cadence type on a given network
// resolver func(name string) (string, error)err, myCadenceValue :=underflow.InputToCadence(myImp, resolver)
```