Skip to content

LemonNekoGH/godence

Folders and files

NameName
Last commit message
Last commit date

Latest commit

6e79675 Β· May 4, 2024

History

38 Commits
Nov 1, 2022
Aug 6, 2022
Apr 1, 2023
Jul 31, 2022
Jul 31, 2022
May 4, 2024
Jul 31, 2022
Jul 30, 2022
May 4, 2024
May 4, 2024
May 4, 2024
May 4, 2024
Apr 7, 2023
May 4, 2024
Aug 7, 2022

Repository files navigation

Godence

codecov Unit Test Go Reference GitHub top language

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

  1. Start the flow emulator with command: flow emulator
  2. Deploy contract for testing to the emulator network: flow deploy
  3. Open another terminal and run go clean -testcache && go test .

TODO-List: Go to Cadence

  • Documents for Go to Cadence

Integers

  • Go int to Cadence Int
  • Go int8 to Cadence Int8
  • Go int16 to Cadence Int16
  • Go int32 to Cadence Int32
  • Go int64 to Cadence Int64
  • Go *big.Int to Cadence Int128
  • Go *big.Int to Cadence Int256
  • Go uint to Cadence UInt
  • Go uint8 to Cadence UInt8
  • Go uint16 to Cadence UInt16
  • Go uint32 to Cadence UInt32
  • Go uint64 to Cadence UInt64
  • Go *big.Int to Cadence UInt128
  • Go *big.Int to Cadence UInt256

Fixed-Point Numbers

  • Go int64 to Cadence Fix64
  • Go uint64 to Cadence UFix64

Other

  • Go string to Cadence String
  • Go string to Cadence Path
  • Go string to Cadence Address
  • Go bool to Cadence Bool
  • Go slice or array to Cadence Array
  • Go ? to Cadence Struct
  • Go string to Cadence Character
  • Go ? to Cadence Resource
  • Go ? to Cadence Dictionary
  • Go ? to Cadence Event

TODO-List: Cadence to go

  • Documents for Cadence base type to Go.
  • Documents for Cadence complex type to Go.

Integers

  • Cadence Int to Go *big.Int
  • Cadence Int8 to Go int8
  • Cadence Int16 to Go int16
  • Cadence Int32 to Go int32
  • Cadence Int64 to Go int64
  • Cadence Int128 to Go *big.Int
  • Cadence Int256 to Go *big.Int
  • Cadence UInt to Go *big.Int
  • Cadence UInt8 to Go uint8
  • Cadence UInt16 to Go uint16
  • Cadence UInt32 to Go uint32
  • Cadence UInt64 to Go uint64
  • Cadence UInt128 to Go *big.Int
  • Cadence UInt256 to Go *big.Int

Fixed-Point Numbers

  • Cadence Fix64 to Go int64
  • Cadence UFix64 to Go uint64

Other

  • Cadence String to Go string
  • Cadence Path to Go string
  • Cadence Address to Go string or cadence.Address or [8]uint8
  • Cadence Bool to Go bool
  • Cadence Array to Go slice
  • Cadence Struct to Go struct
  • Cadence Character to Go string
  • Cadence Resource to Go struct
  • Cadence Dictionary to Go map
  • Cadence Event to Go struct