sdkgo

package module
v0.0.65 Latest Latest
Warning

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

Go to latest
Published: Jun 13, 2023 License: Apache-2.0 Imports: 4 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, block transactions and other functions.

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"

Testing

To test,

  1. Run a CESS node locally.

  2. Run the command

    go test -v
    

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.Note that the p2p-go library needs to be used to complete the data transmission.

Create an sdk client instance

To create an sdk client, you need to provide some configuration information: your rpc address (if not, use the rpc address disclosed by CESS), your wallet private key, and transaction timeout. Please refer to the following examples:

cli, err := New(
    config.CharacterName_Client,
		ConnectRpcAddrs([]string{"wss://testnet-rpc0.cess.cloud/ws/", "wss://testnet-rpc1.cess.cloud/ws/"}),
		Mnemonic("xxx xxx ... xxx"),
		TransactionTimeout(time.Duration(time.Second*10)),
)
Register as a deoss role

Call the Register method to register. Note that the first parameter specifies that the role you register is deoss, If there is no error, you can view the transaction details through the returned transaction hash.

txhash, _, err := cli.Register(cli.GetCharacterName(), cli.GetSignatureAccPulickey(), "", 0)
Process data 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)
Create storage order

Before storing data, you also need to create a data storage order, and you need to fill in the roothash and segmentInfo obtained in the previous step, as well as the user account for uploading data, data name, and bucket name.

err := cli.GenerateStorageOrder(roothash, segmentInfo, owner, filename, bucketname)
Store data to storage nodes

After creating the storage order, wait for one block to find the storage node information allocated in the order. The next step is to store the data to the storage node through the WriteFileAction method in the p2p-go library.

After the storage node receives the data, it will automatically report this action. When all the storage nodes in the storage order have all reported, the data is considered to be stored successfully. As long as there is a storage node that does not report, it is regarded as a storage failure. After the timeout period in the order is exceeded, the storage nodes in the order will be reassigned randomly to start a new round of storage. You need to monitor this storage order, and re-give the data block to the newly allocated storage node until the data storage is successful. The count in the storage order indicates the number of times your data has been redistributed. An order can redistribute storage up to 5 times. If your data is still not successfully stored after 5 times, you need to re-upload your data.

Fetch your data

Call the ReadFileAction method in the p2p-go library to download all data blocks, and then restore the original data through the ReedSolomon_Restore method.

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 the default rpc address

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

DefaultTimeout configures the default transaction waiting timeout

Functions

func New

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

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

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

- If no transaction timeout is provided, the sdk client uses the default timeout: time.Duration(time.Second * 6)

- The characterName available in the sdk are: client, bucket, deoss

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 the sdk.

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 configuration rpc address

func Mnemonic

func Mnemonic(mnemonic string) Option

Mnemonic configures the mnemonic of the signature account

func TransactionTimeout added in v0.0.10

func TransactionTimeout(timeout time.Duration) Option

TransactionTimeout configures the waiting timeout for a transaction

Directories

Path Synopsis
core
sdk

Jump to

Keyboard shortcuts

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