Documentation ¶
Overview ¶
Example (Register_deoss) ¶
package main import ( "context" "log" "os" "strings" "time" cess "github.com/CESSProject/cess-go-sdk" "github.com/CESSProject/cess-go-sdk/config" ) const DEFAULT_WAIT_TIME = time.Second * 15 const P2P_PORT = 4001 const TMP_DIR = "/tmp" func main() { cli, err := cess.New( context.Background(), config.CharacterName_Deoss, cess.ConnectRpcAddrs(strings.Split(os.Getenv("RPC_ADDRS"), " ")), cess.Mnemonic(os.Getenv("MY_MNEMONIC")), cess.TransactionTimeout(time.Duration(DEFAULT_WAIT_TIME)), cess.Bootnodes([]string{os.Getenv("BOOTSTRAP_NODES")}), cess.P2pPort(P2P_PORT), cess.Workspace(TMP_DIR), ) if err != nil { log.Fatalf("err: %v", err.Error()) } _, err = cli.RegisterOrUpdateDeoss(cli.GetPeerPublickey()) if err != nil { log.Fatalf("err: %v", err.Error()) } }
Output:
Example (Register_storage_node) ¶
package main import ( "context" "log" "os" "strings" "time" cess "github.com/CESSProject/cess-go-sdk" "github.com/CESSProject/cess-go-sdk/config" ) const DEFAULT_WAIT_TIME = time.Second * 15 const P2P_PORT = 4001 const TMP_DIR = "/tmp" func main() { cli, err := cess.New( context.Background(), config.CharacterName_Bucket, cess.ConnectRpcAddrs(strings.Split(os.Getenv("RPC_ADDRS"), " ")), cess.Mnemonic(os.Getenv("MY_MNEMONIC")), cess.TransactionTimeout(time.Duration(DEFAULT_WAIT_TIME)), cess.Bootnodes([]string{os.Getenv("BOOTSTRAP_NODES")}), cess.P2pPort(P2P_PORT), cess.Workspace(TMP_DIR), ) if err != nil { log.Fatalf("err: %v", err.Error()) } _, _, err = cli.RegisterOrUpdateSminer(cli.GetPeerPublickey(), os.Getenv("MY_ADDR"), 0) if err != nil { log.Fatalf("err: %v", err.Error()) } }
Output:
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
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
var DefaultTimeout = func(cfg *Config) error { return cfg.Apply(TransactionTimeout(pattern.BlockInterval)) }
DefaultTimeout configures the default transaction waiting timeout
Functions ¶
func New ¶
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 serviceName is used to specify the name of your service Warning:
cess-bucket (cess storage service) must be set to bucket DeOSS (cess decentralized object storage service) must be set to deoss cess-cli (cess client) must be set to client
func NewWithoutDefaults ¶
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 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 ¶
ConnectRpcAddrs configuration rpc address
func ProtocolPrefix ¶ added in v0.2.9
P2pPort configuration boot node list
func TransactionTimeout ¶
TransactionTimeout configures the waiting timeout for a transaction