Skip to content
Merged

Su #246

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 36 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,52 +1,71 @@
<div align="center">
English | [简体中文](README_CN.md)

<p align="center">
<a href="https://cess.network/"><img src="https://github.com/CESSProject/doc-v2/blob/main/assets/introduction/banner.jpg"></a>
</p>

# Go sdk for CESS network
<h1 align="center">CESS Network SDK for Go</h1>

<div align="center">

[![GitHub license](https://img.shields.io/badge/license-Apache2-blue)](#LICENSE)
<a href=""><img src="https://img.shields.io/badge/golang-%3E%3D1.20-blue.svg" /></a>
<a href=""><img src="https://img.shields.io/badge/golang-%3E%3D1.22-blue.svg" /></a>
[![Go Reference](https://pkg.go.dev/badge/github.com/CESSProject/cess-go-sdk.svg)](https://pkg.go.dev/github.com/CESSProject/cess-go-sdk)
[![build](https://github.com/CESSProject/cess-go-sdk/actions/workflows/build&test.yml/badge.svg)](https://github.com/CESSProject/cess-go-sdk/actions/workflows/build&test.yml)
[![Go Report Card](https://goreportcard.com/badge/github.com/CESSProject/cess-go-sdk)](https://goreportcard.com/report/github.com/CESSProject/cess-go-sdk)

</div>

The go sdk implementation of the CESS network, which provides RPC calls, status queries, block transactions and other functions.
CESS Network SDK for Go allows you to access the CESS blockchain network, such as querying block data, transactions, and calling RPC methods. You don't need to deal with API related tasks such as signing and building requests to access the CESS blockchain network. It also allows you to access the storage network, such as uploading or downloading data directly from storage nodes, as well as implementations of file chunking, encryption, and redundancy.

## 📝 Reporting Vulnerability

If you find any system errors or you have better suggestions, please submit an issue or PR, or join the [CESS discord](https://discord.gg/mYHTMfBwNS) to communicate with us.

## 📢 Announcement
**CESS test network rpc endpoints**
## Bulletin
- Test Network RPC Endpoint
```
wss://testnet-rpc.cess.network/ws/
```

## 🚰 CESS test network faucet
- Test Network Faucet
```
https://www.cess.network/faucet.html
```

## 🏗 Usage
## Requirements
Install a Go environment newer than 1.22.x.

## Installation

To get the package use the standard:
Use `go get` to install SDK:

```sh
go get "github.com/CESSProject/cess-go-sdk"
go get -u "github.com/CESSProject/cess-go-sdk"
```

## Quick Use
Quickly create your SDK client:
```golang
cli, err := sdkgo.New(
context.Background(),
sdkgo.ConnectRpcAddrs("wss://testnet-rpc.cess.network/ws/"),
)
```

## ✅ Testing

## Testing

To run test:

```sh
make check
```

## 📖 Document

- [Reference](https://pkg.go.dev/github.com/CESSProject/cess-go-sdk)
## Documentation
- [Guidebook](https://doc.cess.network/developer/cess-sdk/sdk-golang)
- [Reference](https://pkg.go.dev/github.com/CESSProject/cess-go-sdk)

## Issues

If you find any system errors or you have better suggestions, please submit an [issue](https://github.com/CESSProject/cess-go-sdk/issues/new) or PR, or join the [CESS discord](https://discord.gg/mYHTMfBwNS) to communicate with us.

## License

Expand Down
79 changes: 79 additions & 0 deletions README_CN.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
<p align="center">
<a href="https://cess.network/"><img src="https://github.com/CESSProject/doc-v2/blob/main/assets/introduction/banner.jpg"></a>
</p>

<h1 align="center">CESS Network SDK for Go</h1>

<div align="center">

[![GitHub license](https://img.shields.io/badge/license-Apache2-blue)](#LICENSE)
<a href=""><img src="https://img.shields.io/badge/golang-%3E%3D1.22-blue.svg" /></a>
[![Go Reference](https://pkg.go.dev/badge/github.com/CESSProject/cess-go-sdk.svg)](https://pkg.go.dev/github.com/CESSProject/cess-go-sdk)
[![build](https://github.com/CESSProject/cess-go-sdk/actions/workflows/build&test.yml/badge.svg)](https://github.com/CESSProject/cess-go-sdk/actions/workflows/build&test.yml)
[![Go Report Card](https://goreportcard.com/badge/github.com/CESSProject/cess-go-sdk)](https://goreportcard.com/report/github.com/CESSProject/cess-go-sdk)

</div>

CESS Network SDK for Go 允许您访问CESS区块链网络,如查询区块数据、交易、调用RPC方法。您无需处理 API 相关任务(如签名和构建请求)即可访问CESS区块链网络。还允许您访问存储网络,如直接从存储节点上传或下载数据,以及文件分块,加密,冗余的实现。

## 公告
- 测试网RPC端点
```
wss://testnet-rpc.cess.network/ws/
```

- 测试网水龙头地址
```
https://www.cess.network/faucet.html
```

## 环境要求

安装比 1.22.x 更新的Go环境。

## 安装

使用 `go get` 安装SDK:

```sh
go get -u "github.com/CESSProject/cess-go-sdk"
```

## 快速使用

快速创建您的 SDK 客户端:
```golang
cli, err := sdkgo.New(
context.Background(),
sdkgo.ConnectRpcAddrs("wss://testnet-rpc.cess.network/ws/"),
)
```

## 测试

运行测试:

```sh
make check
```

## 文档

- [Guidebook](https://doc.cess.network/developer/cess-sdk/sdk-golang)
- [Reference](https://pkg.go.dev/github.com/CESSProject/cess-go-sdk)

## 问题

如果你发现任何系统错误或者有更好的建议,请提交[issue](https://github.com/CESSProject/cess-go-sdk/issues/new)或者PR,或者加入[CESS discord](https://discord.gg/mYHTMfBwNS)与我们交流。

## License

许可依据 [Apache 2.0](https://github.com/CESSProject/cess-go-sdk/blob/main/LICENSE)








7 changes: 1 addition & 6 deletions cfg.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"time"

"github.com/CESSProject/cess-go-sdk/chain"
"github.com/CESSProject/cess-go-sdk/config"
)

// Config describes a set of settings for a client
Expand All @@ -26,16 +25,12 @@ type Config struct {
// Option is a client config option that can be given to the client constructor
type Option func(cfg *Config) error

// // Option is a client config option that can be given to the client constructor
// type Option func(cfg *Config) error
const DefaultName = "cess-sdk-go"

// NewSDK constructs a new client from the Config.
//
// This function consumes the config. Do not reuse it (really!).
func (cfg *Config) NewSDK(ctx context.Context) (chain.Chainer, error) {
if cfg.Name == "" {
cfg.Name = config.CharacterName_Default
}
return chain.NewChainClient(ctx, cfg.Name, cfg.Rpc, cfg.Mnemonic, cfg.Timeout)
}

Expand Down
13 changes: 0 additions & 13 deletions config/config.go

This file was deleted.

16 changes: 12 additions & 4 deletions defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,12 @@ var DefaultRpcAddrs = func(cfg *Config) error {

// DefaultTimeout configures the default transaction waiting timeout
var DefaultTimeout = func(cfg *Config) error {
return cfg.Apply(TransactionTimeout(time.Second * 30))
return cfg.Apply(TransactionTimeout(time.Second * 18))
}

// DefaultTimeout configures the default transaction waiting timeout
var DefaultSDKName = func(cfg *Config) error {
return cfg.Apply(Name(DefaultName))
}

// Complete list of default options and when to fallback on them.
Expand All @@ -37,11 +42,14 @@ var defaults = []struct {
fallback: func(cfg *Config) bool { return cfg.Timeout == 0 },
opt: DefaultTimeout,
},
{
fallback: func(cfg *Config) bool { return cfg.Name == "" },
opt: DefaultSDKName,
},
}

// 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.
// FallbackDefaults Default options are used if and only
// if no other relevant options apply.
var FallbackDefaults Option = func(cfg *Config) error {
for _, def := range defaults {
if !def.fallback(cfg) {
Expand Down
20 changes: 8 additions & 12 deletions sdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,22 @@ import (
"github.com/CESSProject/cess-go-sdk/chain"
)

// New constructs a new sdk client with the given options, falling back on
// reasonable defaults. The defaults are:
// NewDefault constructs a new SDK client using the given options and default options.
//
// - If no rpc address is provided, the sdk client uses the default address
// "wss://testnet-rpc.cess.network/ws/"
// If no rpc endpoint are provided, use the default: “wss://testnet-rpc.cess.network/ws/”
//
// - If no transaction timeout is provided, the sdk client uses the default
// timeout: time.Duration(time.Second * 6)
// If no transaction timeout are provided, use the default timeout: 18s
//
// - The serviceName is used to specify the name of your service
// If no name are provided, use the default name: cess-sdk-go
func New(ctx context.Context, opts ...Option) (chain.Chainer, error) {
return NewWithoutDefaults(ctx, append(opts, FallbackDefaults)...)
}

// NewWithoutDefaults constructs a new client with the given options but
// *without* falling back on reasonable defaults.
// New constructs a new sdk client with the given options.
//
// 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.
// If no rpc endpoint are provided, the CESS blockchain network cannot be accessed.
//
// If no account mnemonic are provided, block transactions cannot be conducted.
func NewWithoutDefaults(ctx context.Context, opts ...Option) (chain.Chainer, error) {
var cfg Config
if err := cfg.Apply(opts...); err != nil {
Expand Down
Loading