stellarshell

package module
v0.0.0-...-d9075f5 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2019 License: Apache-2.0 Imports: 11 Imported by: 1

README

go-stellar-ipfs

Version License Document

Dependencies

Install

go get -u github.com/aanupam23/go-stellar-ipfs

Getting Started

go-stellar-ipfs is a library that acts as a bridge between Stellar and IPFS. It combines the low fee and fast speed stellar with ipfs. Using this library you can build Stellar and IPFS application very quickly.

go-stellar-ipfs implements StellarShell that helps you use premade functions for sending any sort of data to IPFS using stellar transaction, memo, manage data and also allows reading of that data.

This library is divided in modular functions, which you can utilize in your application.

Refer the below examples for sample usage.

Example

A complete example which implements addition of IPFS data in stellar compatible format using memo hash field.

package main

import (
        "fmt"
        "github.com/stellar/go/txnbuild"
        si "github.com/aanupam23/go-stellar-ipfs"
)

func main() {
        kp, _ := keypair.Parse(SECRETKEY)
        client := horizonclient.DefaultTestNetClient
        ar := horizonclient.AccountRequest{AccountID: kp.Address()}
        sourceAccount, err := client.AccountDetail(ar)
        check(err)

        ss := si.NewStellarShell("localhost:5001", "public")

        // Adding file to IPFS
        thash, err := ss.AddIpfsString("Meow")
        if err != nil {
                error := ss.IsListening()
                panic(error) // ends where
        }
        
        op := Payment{
            Destination: DESITINATION,
            Amount:      "10",
            Asset:       NativeAsset{},
        }

        tx := Transaction{
            SourceAccount: &sourceAccount,
            Operations:    []Operation{&op},
            Timebounds:    NewInfiniteTimeout(),
            Memo:          MemoHash(thash),
            Network:       network.TestNetworkPassphrase,
        }

        txe, err := tx.BuildSignEncode(kp.(*keypair.Full))
        if err != nil {
                panic(error)
        }
        fmt.Println(txe)
}

Replace SECRETKEY and DESITINATION with your inputs.

Another example, that reads the IPFS hash data after converting hash to multiaddr IPFS hash.

package main

import (
        "fmt"
        si "github.com/aanupam23/go-stellar-ipfs"
)

func main() {
        ss := si.NewStellarShell("localhost:5001", "public")

        thash, err: ss.ReadMemoHash(txnid)

        output, err := ss.IpfsDataString(thash)
        if err != nil {
                error := ss.IsListening()
                panic(error) // ends where
        }

        fmt.Println(output)
}

If you wish to get data in an io.Reader, than replace IpfsDataString with IpfsData function

        output, err := ss.IpfsData(thash)
        if err != nil {
                error := ss.IsListening()
                panic(error)
        }

Check the godoc for complete list of functions.

Running your code

Start IPFS daemon

ipfs daemon

Once IPFS Daemon is initialized, run your code. If IPFS is not installed on your system, refer this guide for installing IPFS.

Mentions

Upcoming/Missing Features

This library acts as a bridge between go-ipfs-api and stellar to make features easier to use.

Features Status
1 Private Stellar
2 IPFS hash validation x
3 IPFS bootstrap x
4 SEP-0022 Support x
5 IPFS Add options x
6 Suggest any feature -

Contribute

go-stellar-ipfs is open source and all contributions are welcome.

Please refer CONTRIBUTING.md for information.

Licence

License

Stellar is trademark of Stellar Development Foundation.

IPFS is trademark of Protocol Labs.

Documentation

Overview

go-stellar-ipfs is a library that acts as a bridge between Stellar and IPFS. It combines the low fee and fast speed stellar with ipfs

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Decodebase64

func Decodebase64(s string) ([]byte, error)

Decodebase64 decodes base64 to byte

func Ipfs2Sipfs

func Ipfs2Sipfs(ipfshash string) ([32]byte, error)

Ipfs2Sipfs converts IPFS multiaddr to stellar compatible memo hash type

func Ipfs2SipfsD

func Ipfs2SipfsD(ipfshash string) ([]byte, error)

Ipfs2SipfsD converts IPFS multiaddr to stellar compatible manage data byte

func Sipfs2Ipfs

func Sipfs2Ipfs(memo []byte) string

Sipfs2Ipfs Decodes Stellar memo hash to IPFS multiaddr hash

Types

type StellarShell

type StellarShell struct {
	SShell  *shi.Shell
	DClient *horizon.Client
}

StellarShell adds new capabilities to package shell that implements a remote API interface for running a stellar compatible ipfs daemon

func NewStellarShell

func NewStellarShell(hostname string, sclient string) *StellarShell

NewStellarShell create a new Stellar shell for library methods hostname should be the host for IPFS(Use localhost:5001 for local client) sclient is passing Horizon client, use sclient="testnet" for https://horizon-testnet.stellar.org, use sclient="public" for https://horizon.stellar.org If you wish to use custom client, than pass your custom horizon client URL as string

func (*StellarShell) AddIpfs

func (s *StellarShell) AddIpfs(r io.Reader) (string, error)

AddIpfs implements method for adding data from io Reader and returns the ipfs hash

func (*StellarShell) AddIpfsString

func (s *StellarShell) AddIpfsString(dstring string) (string, error)

AddIpfsString implements method for adding data from a string and returns the ipfs hash

func (*StellarShell) DataHash

func (s *StellarShell) DataHash(r io.Reader) ([]byte, error)

DataHash implements method for reading data from io Reader and returns stellar manage data compatible hash in byte

func (*StellarShell) IpfsData

func (s *StellarShell) IpfsData(thash string) (io.ReadCloser, error)

IpfsData implements method for reading data from valid IPFS hash and returns data as io Reader

func (*StellarShell) IpfsDataString

func (s *StellarShell) IpfsDataString(thash string) (string, error)

IpfsDataString implements method for reading data from valid IPFS hash and returns data in string

func (*StellarShell) IsListening

func (s *StellarShell) IsListening() error

IsListening implements basic method for checking if ipfs daemon is running

func (*StellarShell) IsReady

func (s *StellarShell) IsReady(thash string)

IsReady implements method for checking if ipfs daemon is ready

func (*StellarShell) IsValid

func (s *StellarShell) IsValid(thash string)

TODO: Check if it is actually a valid IPFS hash IsValid checks the IPFS hash is a valid multiaddr hash

func (*StellarShell) MemoHash

func (s *StellarShell) MemoHash(r io.Reader) ([32]byte, error)

MemoHash implements method for reading data from io Reader and returns stellar memo compatible hash in byte

func (*StellarShell) ReadDataHash

func (s *StellarShell) ReadDataHash(publickey string, DataKeyid string) (string, error)

ReadDataHash returns valid IPFS hash from a Datakey id of managedata

func (*StellarShell) ReadMemoHash

func (s *StellarShell) ReadMemoHash(txnid string) (string, error)

ReadMemoHash returns valid IPFS hash from a transaction id

Jump to

Keyboard shortcuts

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