caip

package module
v0.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 16, 2021 License: MIT Imports: 7 Imported by: 0

README

go-caip

CAIP standard utils

Installation

go get github.com/ChainAgnostic/go-caip

ChainID (CAIP-2)

// From namespace + reference
c, err := new(ChainID).Format("eip155", "1")
if err != nil {
    panic(err)
}
c.String() // "eip155:1"

// Parse CAIP-2 ChainID
c, err := new(ChainID).Parse("eip155:1")
if err != nil {
    panic(err)
}

b, err := json.Marshal(c) // {"namespace": "eip155", "reference": "1"}

c := new(ChainID)
err := json.Unmarshal(b, c)

AccountID (CAIP-10)

// From namespace + reference
c, err := new(AccountID).Format(new(ChainID).Format("eip155", "1"), "0xab16a96d359ec26a11e2c2b3d8f8b8942d5bfcdb")
if err != nil {
    panic(err)
}
c.String() // "eip155:1"

// Parse CAIP-2 AccountID
c, err := new(AccountID).Parse("eip155:1:0xab16a96d359ec26a11e2c2b3d8f8b8942d5bfcdb")
if err != nil {
    panic(err)
}

b, err := json.Marshal(c) // { "chain_id": {"namespace": "eip155", "reference": "1"}, "account_address": 0xab16a96d359ec26a11e2c2b3d8f8b8942d5bfcdb" }

c := new(AccountID)
err := json.Unmarshal(b, c)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AccountID

type AccountID struct {
	ChainID *ChainID `json:"chain_id"`
	Address string   `json:"account_address"`
}

func (*AccountID) Format

func (c *AccountID) Format(chainID *ChainID, address string) (*AccountID, error)

func (*AccountID) MarshalJSON

func (c *AccountID) MarshalJSON() ([]byte, error)

func (*AccountID) Parse

func (c *AccountID) Parse(s string) (*AccountID, error)

func (*AccountID) Scan

func (c *AccountID) Scan(src interface{}) error

func (*AccountID) String

func (c *AccountID) String() string

func (*AccountID) UnmarshalJSON

func (c *AccountID) UnmarshalJSON(data []byte) error

func (*AccountID) Value

func (c *AccountID) Value() (driver.Value, error)

type ChainID

type ChainID struct {
	Namespace string `json:"namespace"`
	Reference string `json:"reference"`
}

func (*ChainID) Format

func (c *ChainID) Format(namespace, reference string) (*ChainID, error)

func (*ChainID) MarshalJSON

func (c *ChainID) MarshalJSON() ([]byte, error)

func (*ChainID) Parse

func (c *ChainID) Parse(s string) (*ChainID, error)

func (*ChainID) Scan

func (c *ChainID) Scan(src interface{}) error

func (*ChainID) String

func (c *ChainID) String() string

func (*ChainID) UnmarshalJSON

func (c *ChainID) UnmarshalJSON(data []byte) error

func (*ChainID) Value

func (c *ChainID) Value() (driver.Value, error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL