Skip to content

Commit

Permalink
add GetTokenSymbol, update default (#65)
Browse files Browse the repository at this point in the history
  • Loading branch information
AstaFrode authored Jun 6, 2023
1 parent 311df94 commit d5ad90b
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 19 deletions.
2 changes: 1 addition & 1 deletion chain/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ func (c *ChainSDK) GetTokenSymbol() string {
return c.tokenSymbol
}

func (c *ChainSDK) GetCharacterName() string {
func (c *ChainSDK) GetRoleName() string {
return c.name
}

Expand Down
10 changes: 5 additions & 5 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ const (
// NewSDK constructs a new client from the Config.
//
// This function consumes the config. Do not reuse it (really!).
func (cfg *Config) NewSDK(characterName string) (sdk.SDK, error) {
if characterName != CharacterName_Bucket &&
characterName != CharacterName_Deoss &&
characterName != CharacterName_Client {
func (cfg *Config) NewSDK(roleName string) (sdk.SDK, error) {
if roleName != CharacterName_Bucket &&
roleName != CharacterName_Deoss &&
roleName != CharacterName_Client {
return nil, fmt.Errorf("invalid character name")
}
return chain.NewChainSDK(characterName, cfg.Rpc, cfg.Mnemonic, cfg.Timeout)
return chain.NewChainSDK(roleName, cfg.Rpc, cfg.Mnemonic, cfg.Timeout)
}

// Apply applies the given options to the config, returning the first error
Expand Down
7 changes: 5 additions & 2 deletions core/sdk/sdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,11 @@ type SDK interface {
// SetChainState sets the state of the chain node.
SetChainState(state bool)

// GetCharacterName returns the character name.
GetCharacterName() string
// GetRoleName returns the role name.
GetRoleName() string

// GetTokenSymbol returns the token symbol
GetTokenSymbol() string

// Reconnect for reconnecting chains.
Reconnect() error
Expand Down
7 changes: 2 additions & 5 deletions defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ package sdkgo

import "github.com/CESSProject/sdk-go/core/pattern"

// DefaultRpcAddrs configures client to use default RPC address.
// DefaultRpcAddrs configures the default rpc address
var DefaultRpcAddrs = func(cfg *Config) error {
rpcAddrs := []string{
"wss://testnet-rpc0.cess.cloud/ws/",
Expand All @@ -18,15 +18,12 @@ var DefaultRpcAddrs = func(cfg *Config) error {
return cfg.Apply(ConnectRpcAddrs(rpcAddrs))
}

// DefaultListenPort configures client to use default listen port.
// DefaultTimeout configures the default transaction waiting timeout
var DefaultTimeout = func(cfg *Config) error {
return cfg.Apply(TransactionTimeout(pattern.BlockInterval))
}

// Complete list of default options and when to fallback on them.
//
// Please *DON'T* specify default options any other way. Putting this all here
// makes tracking defaults *much* easier.
var defaults = []struct {
fallback func(cfg *Config) bool
opt Option
Expand Down
4 changes: 2 additions & 2 deletions examples.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func Example_RegisterDeoss() {
if err != nil {
panic(err)
}
txhash, _, err := cli.Register(cli.GetCharacterName(), cli.GetSignatureAccPulickey(), "", 0)
txhash, _, err := cli.Register(cli.GetRoleName(), cli.GetSignatureAccPulickey(), "", 0)
if err != nil {
panic(err)
}
Expand All @@ -53,7 +53,7 @@ func Example_RegisterStorageNode() {
if err != nil {
panic(err)
}
txhash, _, err := cli.Register(cli.GetCharacterName(), cli.GetSignatureAccPulickey(), "cXxxx...xxx", 100000)
txhash, _, err := cli.Register(cli.GetRoleName(), cli.GetSignatureAccPulickey(), "cXxxx...xxx", 100000)
if err != nil {
panic(err)
}
Expand Down
7 changes: 3 additions & 4 deletions options.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,23 @@ import (
"github.com/CESSProject/sdk-go/core/pattern"
)

// ConnectRpcAddrs configures client to connect to the given RPC
// addresses.
// ConnectRpcAddrs configuration rpc address
func ConnectRpcAddrs(s []string) Option {
return func(cfg *Config) error {
cfg.Rpc = s
return nil
}
}

// Workspace configures client to use the given workspace.
// Mnemonic configures the mnemonic of the signature account
func Mnemonic(mnemonic string) Option {
return func(cfg *Config) error {
cfg.Mnemonic = mnemonic
return nil
}
}

// TransactionTimeout configures the transaction timeout period.
// TransactionTimeout configures the waiting timeout for a transaction
func TransactionTimeout(timeout time.Duration) Option {
return func(cfg *Config) error {
if timeout < pattern.BlockInterval {
Expand Down

0 comments on commit d5ad90b

Please sign in to comment.