sdkgo

package module
v0.0.60 Latest Latest
Warning

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

Go to latest
Published: May 31, 2023 License: Apache-2.0 Imports: 5 Imported by: 0

README

Go sdk for CESS network

GitHub license Go Reference build Go Report Card

The go sdk implementation of the CESS network, which provides RPC calls, status queries, and access to the p2p storage network of the CESS chain.

Reporting a Vulnerability

If you find out any vulnerability, Please send an email to frode@cess.one, we are happy to communicate with you.

Installation

To get the package use the standard:

go get -u "github.com/CESSProject/sdk-go"

Using Go modules is recommended.

Documentation & Examples

Please refer to https://pkg.go.dev/github.com/CESSProject/sdk-go

Usage

Usually, you only care about how to access your data in the CESS network, you need to build such a web service yourself, this sdk will help you quickly realize data access.

Create an sdk client instance

The following is an example of creating an sdk client:

cli, err := New(
    config.DefaultName,
    ConnectRpcAddrs([]string{""}),
    ListenPort(15000),
    Workspace("/"),
    Mnemonic("xxx xxx ... xxx"),
    TransactionTimeout(time.Duration(time.Second*10)),
)

Creating a client requires you to configure some information, you can refer to the following configuration files:

# The rpc endpoint of the chain node
Rpc:
  - "ws://127.0.0.1:9948/"
  - "wss://testnet-rpc0.cess.cloud/ws/"
  - "wss://testnet-rpc1.cess.cloud/ws/"
# Account mnemonic
Mnemonic: "xxx xxx xxx"
# Service workspace
Workspace: /
# Service running address
Address: "127.0.0.1"
# P2P communication port
P2P_Port: 8088
# Service listening port
HTTP_Port: 15000
Register as an oss role

Call the Register method to register. Note that the first parameter specifies that the role you register is oss, and its value can be any one of "oss","OSS","Deoss","DEOSS".

txhash, err := cli.Register("oss", "", 0)
Process your documents according to the specifications of CESS

Call the ProcessingData method to process your file. You need to specify the file path. The method returns a segment list and the unique identifier hash of the file in the CESS network.

segmentInfo, roothash, err := cli.ProcessingData(filepath)
Store your files

Call the PutFile method to store your files. You need to specify a bucket to store the files. CESS will automatically create the bucket for you, provided that the name of the bucket is legal. You can call the CheckBucketName method in advance to check whether the name of the bucket meets the requirements. After the storage is successful, it will return count. The count indicates the number of times your file is stored. A file can only be stored up to 5 times. If your file is not stored successfully after 5 times, you need to upload your file again.

count, err := cli.PutFile(publickey, segmentInfo, roothash, filename, buckname)
Download file

Call the GetFile method to download the file you want, and this method will save the file you downloaded under the roothash name in the directory you specify.

filepath, err := n.Cli.GetFile(roothash, dir)

License

Licensed under Apache 2.0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultRpcAddrs = func(cfg *Config) error {
	rpcAddrs := []string{
		"wss://testnet-rpc0.cess.cloud/ws/",
		"wss://testnet-rpc1.cess.cloud/ws/",
	}
	return cfg.Apply(ConnectRpcAddrs(rpcAddrs))
}

DefaultRpcAddrs configures client to use default RPC address.

View Source
var DefaultTimeout = func(cfg *Config) error {
	return cfg.Apply(TransactionTimeout(pattern.BlockInterval))
}

DefaultListenPort configures client to use default listen port.

Functions

func Example_newClient added in v0.0.25

func Example_newClient()

func Example_registerMiner added in v0.0.25

func Example_registerMiner()

func Example_registerOss added in v0.0.25

func Example_registerOss()

func New

func New(name string, opts ...Option) (sdk.SDK, error)

New constructs a new client with the given options, falling back on reasonable defaults. The defaults are:

- If no transport and listen addresses are provided, the node listens to the default addresses "/ip4/0.0.0.0/tcp/15000";

- If no Rpc address is provided, the client uses the default address "wss://testnet-rpc0.cess.cloud/ws/"" or "wss://testnet-rpc1.cess.cloud/ws/";

- If no working directory is provided, the client uses the current directory as the working directory;

func NewWithoutDefaults

func NewWithoutDefaults(name string, opts ...Option) (sdk.SDK, error)

NewWithoutDefaults constructs a new client with the given options but *without* falling back on reasonable defaults.

Warning: This function should not be considered a stable interface. We may choose to add required services at any time and, by using this function, you opt-out of any defaults we may provide.

Types

type Config

type Config = config.Config

Config describes a set of settings for a client.

type Option

type Option = config.Option

Option is a client config option that can be given to the client constructor

var FallbackDefaults Option = func(cfg *Config) error {
	for _, def := range defaults {
		if !def.fallback(cfg) {
			continue
		}
		if err := cfg.Apply(def.opt); err != nil {
			return err
		}
	}
	return nil
}

FallbackDefaults applies default options to the libp2p node if and only if no other relevant options have been applied. will be appended to the options passed into New.

func ConnectRpcAddrs

func ConnectRpcAddrs(s []string) Option

ConnectRpcAddrs configures client to connect to the given RPC addresses.

func Mnemonic

func Mnemonic(mnemonic string) Option

Workspace configures client to use the given workspace.

func TransactionTimeout added in v0.0.10

func TransactionTimeout(timeout time.Duration) Option

TransactionTimeout configures the transaction timeout period.

Directories

Path Synopsis
core
sdk

Jump to

Keyboard shortcuts

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