irys

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2023 License: MIT Imports: 10 Imported by: 1

README

irys-go Go Reference

Go Implementation SDK of Irys network, irys is the only provenance layer. It enables users to scale permanent data and precisely attribute its origin (arweave bundlr).

Install

go get -u  github.com/Ja7ad/irys

Examples

example of irys sdk in golang

Upload
package main

import (
	"fmt"
	"github.com/Ja7ad/irys"
	"github.com/Ja7ad/irys/token"
	"log"
	"os"
)

func main() {
	matic, err := token.NewMatic("foo")
	if err != nil {
		log.Fatal(err)
	}

	c, err := irys.New(irys.DefaultNode2, matic)
	if err != nil {
		log.Fatal(err)
	}

	file, err := os.Open("image.jpg")
	if err != nil {
		log.Fatal(err)
	}

	tx, err := c.Upload(file)
	if err != nil {
		log.Fatal(err)
	}

	fmt.Println(tx)
}
Download
package main

import (
	"fmt"
	"github.com/Ja7ad/irys"
	"github.com/Ja7ad/irys/token"
	"io"
	"log"
)

func main() {
	matic, err := token.NewMatic("foo")
	if err != nil {
		log.Fatal(err)
	}
	c, err := irys.New(irys.DefaultNode2, matic)
	if err != nil {
		log.Fatal(err)
	}

	file, err := c.Download("XjzDyneweD_Dmhuaipbi7HyXXvsY6IkMcIsumlB0G2M")
	if err != nil {
		log.Fatal(err)
	}
	defer file.Data.Close()

	b, err := io.ReadAll(file.Data)
	if err != nil {
		log.Fatal(err)
	}

	fmt.Println(string(b), file.Header, file.ContentLength, file.ContentType)
}
Calculate Price
package main

import (
	"fmt"
	"github.com/Ja7ad/irys"
	"github.com/Ja7ad/irys/token"
	"log"
)

func main() {
	matic, err := token.NewMatic("foo")
	if err != nil {
		log.Fatal(err)
	}
	c, err := irys.New(irys.DefaultNode1, matic)
	if err != nil {
		log.Fatal(err)
	}

	p, err := c.GetPrice(100000)
	if err != nil {
		log.Fatal(err)
	}

	fmt.Println(p.Int64())
}
Get Metadata
package main

import (
	"fmt"
	"github.com/Ja7ad/irys"
	"github.com/Ja7ad/irys/token"
	"log"
)

func main() {
	matic, err := token.NewMatic("foo")
	if err != nil {
		log.Fatal(err)
	}
	c, err := irys.New(irys.DefaultNode2, matic)
	if err != nil {
		log.Fatal(err)
	}

	tx, err := c.GetMetaData("XjzDyneweD_Dmhuaipbi7HyXXvsY6IkMcIsumlB0G2M")
	if err != nil {
		log.Fatal(err)
	}

	fmt.Println(tx)
}

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type File

type File struct {
	Data          io.ReadCloser
	Header        http.Header
	ContentLength int64
	ContentType   string
}

type Gateway

type Gateway interface {
	// GetPrice return fee base on fileSize in byte for selected token
	GetPrice(fileSize int) (*big.Int, error)
	// Upload upload file
	Upload(file io.Reader, tags ...Tag) (Transaction, error)
	// Download get file with header details
	Download(hash string) (*File, error)
	// GetMetaData get transaction details
	GetMetaData(hash string) (Transaction, error)
}

func New

func New(network Network, token token.Token, options ...Option) (Gateway, error)

New create Irys object

Example
matic, err := token.NewMatic("foo")
if err != nil {
	log.Fatal(err)
}
c, err := New(DefaultNode1, matic)
if err != nil {
	log.Fatal(err)
}

p, err := c.GetPrice(100000)
if err != nil {
	log.Fatal(err)
}

fmt.Println(p.Int64())

type Irys

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

func (*Irys) Download

func (i *Irys) Download(hash string) (*File, error)

func (*Irys) GetMetaData

func (i *Irys) GetMetaData(hash string) (Transaction, error)

func (*Irys) GetPrice

func (i *Irys) GetPrice(fileSize int) (*big.Int, error)

func (*Irys) Upload

func (i *Irys) Upload(file io.Reader, tags ...Tag) (Transaction, error)

type Network

type Network string
const (
	DefaultNode1  Network = "https://node1.irys.xyz"  // DefaultNode1 is node 1 irys
	DefaultNode2  Network = "https://node2.irys.xyz"  // DefaultNode2 is node 2 irys
	DefaultDevNet Network = "https://devnet.irys.xyz" // DefaultDevNet is a testnet for test irys
)

type Option

type Option func(irys *Irys)

func WithCustomClient

func WithCustomClient(c *http.Client) Option

WithCustomClient set custom http client for irys

type Tag

type Tag struct {
	Name  string `json:"name" avro:"name"`
	Value string `json:"value" avro:"value"`
}

type Transaction

type Transaction struct {
	ID        string `json:"id"`
	Currency  string `json:"currency"`
	Address   string `json:"address"`
	Owner     string `json:"owner"`
	Signature string `json:"signature"`
	Target    string `json:"target"`
	Tags      []Tag  `json:"tags"`
	Anchor    string `json:"anchor"`
	DataSize  string `json:"data_size"`
	RawSize   string `json:"raw_size"`
}

Directories

Path Synopsis
_example
download command
metadata command
price command
upload command

Jump to

Keyboard shortcuts

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