Godence
Get Started
install by go get.
go get github.com/lemonnekogh/godence
Convert Cadence value to Go value
If you have the following Cadence struct.
pub struct Person {
pub var age: UInt8
pub var Name: String
}
import "github.com/LemonNekoGH/godence"
type Person struct {
Age uint8 `godence:"age"` // you can specify field name in cadence by tag.
Name string
}
func main() {
dist := &Person{}
// Omit: You got a Cadence value from a script or transaction. And return value named 'ret'.
godence.ToGo(ret, dist)
}
Convert Go value to Cadence value
Convert to Cadecne Struct, Event, Resource is currently not support becase type name of Struct, Event, Resource is unpredictable.
Can i convert to AnyStruct and AnyResource?
Testing
Requirements
- Flow CLI: Use to emulate flow network.
Steps
- Start the flow emulator with command:
flow emulator - Deploy contract for testing to the emulator network:
flow deploy - Open another terminal and run
go clean -testcache && go test .
TODO-List: Go to Cadence
- Documents for Go to Cadence
Integers
- Go
intto CadenceInt - Go
int8to CadenceInt8 - Go
int16to CadenceInt16 - Go
int32to CadenceInt32 - Go
int64to CadenceInt64 - Go
*big.Intto CadenceInt128 - Go
*big.Intto CadenceInt256 - Go
uintto CadenceUInt - Go
uint8to CadenceUInt8 - Go
uint16to CadenceUInt16 - Go
uint32to CadenceUInt32 - Go
uint64to CadenceUInt64 - Go
*big.Intto CadenceUInt128 - Go
*big.Intto CadenceUInt256Fixed-Point Numbers
- Go
int64to CadenceFix64 - Go
uint64to CadenceUFix64Other
- Go
stringto CadenceString - Go
stringto CadencePath - Go
stringto CadenceAddress - Go
boolto CadenceBool - Go
sliceorarrayto CadenceArray Go?to CadenceStruct- Go
stringto CadenceCharacter Go?to CadenceResource- Go
?to CadenceDictionary Go?to CadenceEvent
TODO-List: Cadence to go
- Documents for Cadence base type to Go.
- Documents for Cadence complex type to Go.
Integers
- Cadence
Intto Go*big.Int - Cadence
Int8to Goint8 - Cadence
Int16to Goint16 - Cadence
Int32to Goint32 - Cadence
Int64to Goint64 - Cadence
Int128to Go*big.Int - Cadence
Int256to Go*big.Int - Cadence
UIntto Go*big.Int - Cadence
UInt8to Gouint8 - Cadence
UInt16to Gouint16 - Cadence
UInt32to Gouint32 - Cadence
UInt64to Gouint64 - Cadence
UInt128to Go*big.Int - Cadence
UInt256to Go*big.IntFixed-Point Numbers
- Cadence
Fix64to Goint64 - Cadence
UFix64to Gouint64Other
- Cadence
Stringto Gostring - Cadence
Pathto Gostring - Cadence
Addressto Gostringorcadence.Addressor[8]uint8 - Cadence
Boolto Gobool - Cadence
Arrayto Goslice - Cadence
Structto Gostruct - Cadence
Characterto Gostring - Cadence
Resourceto Gostruct - Cadence
Dictionaryto Gomap - Cadence
Eventto Gostruct