rnsgo

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2023 License: MIT Imports: 3 Imported by: 0

README

RNS.GO - A simple Go implementation of RNS to resolve Names and Addresses

Introduction

RNS.GO is a simple Go implementation of RNS to resolve Names and Addresses.

Installation

go get github.com/wehmoen/rnsgo

Usage

package main

import (
	"fmt"
	"github.com/wehmoen/rnsgo"
)

func main() {
	client := rnsgo.NewClient()

	// Resolve a name to an address
	address, err := client.GetAddress("jihoz.ron")
	if err != nil {
		fmt.Println(err)
		return
	}
	
	fmt.Printf("RNS Name %s resolve to address: %s\n", "jihoz.ron", address)
	
	// Resolve an address to a name
	name, err := client.GetName("0xa09a9b6f90ab23fcdcd6c3d087c1dfb65dddfb05")
	
	if err != nil {
        fmt.Println(err)
        return
    }
	
	fmt.Printf("Address %s resolve to name: %s\n", "0xa09a9b6f90ab23fcdcd6c3d087c1dfb65dddfb05", name)
	
	// Batch resolve names to addressess
	getAddressBatchInput := []rnsgo.Name{"jihoz.ron", "dwi.ron", "wehmoen.ron"}
	
	getAddressBatchResult, err := client.GetAddressBatch(getAddressBatchInput)
	
	if err != nil {
        fmt.Println(err)
        return
    }
	
	for name, address := range getAddressBatchResult {
		fmt.Printf("RNS Name %s resolve to address: %s\n", name, address)
	}
	
	// Batch resolve addresses to names
	getNameBatchInput := []rnsgo.Address{"0xa09a9b6f90ab23fcdcd6c3d087c1dfb65dddfb05", "0x445ba6f9f553872fa9cdc14f5c0639365b39c140", "0x3759468f9fd589665c8affbe52414ef77f863f72"}
	
	getNameBatchResult, err := client.GetNameBatch(getNameBatchInput)
	
	if err != nil {
        fmt.Println(err)
        return
    }
	
	for address, name := range getNameBatchResult {
		fmt.Printf("Address %s resolve to RNS name: %s\n", address, name)
	}
}

License

MIT License

Support

For support, please contact wehmoen on the Axie Infinity Discord server: https://discord.gg/axie

Documentation

Index

Constants

View Source
const (
	// RNSRestApiUrl is the base url for the RNS REST API
	RNSRestApiUrl = "https://rns.rest"
	// RNSRestApiHeaderName is the header name for the RNS REST API
	RNSRestApiHeaderName = "X-LIB"
	// RNSRestApiHeaderNameValue is the header value for the RNS REST API
	RNSRestApiHeaderNameValue = "rns.go lib"
	// RNSLabelSuffix is the suffix for RNS labels
	RNSLabelSuffix = ".ron"
	// RoninAddressPrefix is the prefix for Ronin addresses
	RoninAddressPrefix = "ronin:"
	// EthAddressPrefix is the prefix for Ethereum addresses
	EthAddressPrefix = "0x"

	// ErrInvalidName Error Invalid Name
	ErrInvalidName = "invalid_name"
	// ErrInvalidAddress Error Invalid Address
	ErrInvalidAddress = "invalid_address"
	// ErrInvalidBatchRequest Error Invalid Batch Request
	ErrInvalidBatchRequest = "invalid_batch_request"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Address

type Address string

func (Address) Normalize

func (a Address) Normalize() Address

func (Address) String

func (a Address) String() string

func (Address) Valid

func (a Address) Valid() bool

type BatchAddressRequest

type BatchAddressRequest struct {
	Addresses []Address `json:"addresses"`
}

func (*BatchAddressRequest) Route

func (b *BatchAddressRequest) Route() string

type BatchAddressResponse

type BatchAddressResponse map[Name]*Address

type BatchNameRequest

type BatchNameRequest struct {
	Names []Name `json:"names"`
}

func (*BatchNameRequest) Route

func (b *BatchNameRequest) Route() string

type BatchNameResponse

type BatchNameResponse map[Address]*Name

type BatchRequest

type BatchRequest interface {
	Route() string
}

type Name

type Name string

func (Name) String

func (n Name) String() string

func (Name) Valid

func (n Name) Valid() bool

type RNS

type RNS struct {
	// contains filtered or unexported fields
}

func NewClient

func NewClient(options ...string) RNS

func (*RNS) GetAddress

func (r *RNS) GetAddress(name Name) (Address, error)

func (*RNS) GetAddressBatch

func (r *RNS) GetAddressBatch(names []Name) (BatchAddressResponse, error)

func (*RNS) GetName

func (r *RNS) GetName(address Address) (Name, error)

func (*RNS) GetNameBatch

func (r *RNS) GetNameBatch(addresses []Address) (BatchNameResponse, error)

Jump to

Keyboard shortcuts

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