Documentation ¶
Overview ¶
Provides functions and data structures to interact with the system nodes in the context of the blockchain network.
Index ¶
- Constants
- Variables
- func AuthUrl() string
- func GetClient() *zcncrypto.Wallet
- func GetClientSysKeys(clients ...string) []sys.KeyPair
- func GetNetwork(ctx context.Context) (*conf.Network, error)
- func GetWallet() *zcncrypto.Wallet
- func Id(clients ...string) string
- func Init(ctx context.Context, cfg conf.Config) error
- func InitCache(sharders *NodeHolder)
- func InitSDK(walletJSON string, blockWorker, chainID, signatureScheme string, nonce int64, ...) error
- func InitSDKWithWebApp(params InitSdkOptions) error
- func IsSDKInitialized() bool
- func IsWalletSet() bool
- func MakeSCRestAPICallToSharder(scAddress string, relativePath string, params map[string]string, ...) ([]byte, error)
- func Mnemonic() string
- func Nonce() int64
- func PopulateClient(walletJSON, signatureScheme string) (zcncrypto.Wallet, error)
- func PrivateKey() string
- func PublicKey(clients ...string) string
- func SetAuthUrl(url string) error
- func SetIsAppFlow(val bool)
- func SetNonce(n int64)
- func SetSdkInitialized(val bool)
- func SetSignatureScheme(signatureScheme string)
- func SetSplitKeyWallet(isSplitKeyWallet bool) error
- func SetTxnFee(f uint64)
- func SetWallet(w zcncrypto.Wallet)
- func SetWalletMode(mode bool)
- func SignatureScheme() string
- func SplitKeyWallet() bool
- func TxnFee() uint64
- func VerifySignature(signature string, msg string) (bool, error)
- func VerifySignatureWith(pubKey, signature, hash string) (bool, error)
- func Wallet() *zcncrypto.Wallet
- type Client
- type GetBalanceResponse
- type InitSdkOptions
- type Node
- func (n *Node) GetMinShardersVerify() int
- func (n *Node) GetStableMiners() []string
- func (n *Node) Network() *conf.Network
- func (n *Node) ResetStableMiners()
- func (n *Node) Sharders() *NodeHolder
- func (n *Node) ShouldUpdateNetwork() (bool, *conf.Network, error)
- func (n *Node) UpdateNetwork(network *conf.Network) error
- type NodeHolder
- type NodeStruct
- type NonceCache
- type SCRestAPIHandler
- type SignFunc
Constants ¶
const GetBalanceUrl = "client/get/balance"
Variables ¶
var (
IsAppFlow = false
)
var SignFn = func(hash string) (string, error) { ss := zcncrypto.NewSignatureScheme(client.signatureScheme) err := ss.SetPrivateKey(client.wallet.Keys[0].PrivateKey) if err != nil { return "", err } return ss.Sign(hash) }
Functions ¶
func GetClientSysKeys ¶
func GetNetwork ¶
GetNetwork gets current network details from 0chain network.
func InitCache ¶
func InitCache(sharders *NodeHolder)
func InitSDK ¶
func InitSDK(walletJSON string, blockWorker, chainID, signatureScheme string, nonce int64, addWallet bool, options ...int) error
InitSDK Initialize the storage SDK
- walletJSON: Client's wallet JSON
- blockWorker: Block worker URL (block worker refers to 0DNS)
- chainID: ID of the blokcchain network
- signatureScheme: Signature scheme that will be used for signing transactions
- preferredBlobbers: List of preferred blobbers to use when creating an allocation. This is usually configured by the client in the configuration files
- nonce: Initial nonce value for the transactions
- fee: Preferred value for the transaction fee, just the first value is taken
func InitSDKWithWebApp ¶ added in v1.18.14
func InitSDKWithWebApp(params InitSdkOptions) error
func IsSDKInitialized ¶
func IsSDKInitialized() bool
func IsWalletSet ¶
func IsWalletSet() bool
func MakeSCRestAPICallToSharder ¶ added in v1.18.14
func PopulateClient ¶
func PrivateKey ¶
func PrivateKey() string
func SetAuthUrl ¶
SetAuthUrl will be called by app to set zauth URL to SDK
func SetIsAppFlow ¶ added in v1.18.14
func SetIsAppFlow(val bool)
func SetSdkInitialized ¶
func SetSdkInitialized(val bool)
func SetSignatureScheme ¶
func SetSignatureScheme(signatureScheme string)
func SetSplitKeyWallet ¶
splitKeyWallet parameter is valid only if SignatureScheme is "BLS0Chain"
func SetWalletMode ¶ added in v1.18.0
func SetWalletMode(mode bool)
SetWalletMode sets current wallet split key mode.
func SignatureScheme ¶
func SignatureScheme() string
func SplitKeyWallet ¶
func SplitKeyWallet() bool
func VerifySignatureWith ¶
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
maintains client's information
type GetBalanceResponse ¶
type GetBalanceResponse struct { Txn string `json:"txn"` Round int64 `json:"round"` Balance int64 `json:"balance"` Nonce int64 `json:"nonce"` }
func GetBalance ¶
func GetBalance(clientIDs ...string) (*GetBalanceResponse, error)
func (GetBalanceResponse) ToToken ¶
func (b GetBalanceResponse) ToToken() (float64, error)
ToToken converts Balance to ZCN tokens.
type InitSdkOptions ¶ added in v1.18.14
type Node ¶
type Node struct {
// contains filtered or unexported fields
}
Node Maintains central states of SDK (client's context, network). Initialized through Init function. Use client.GetNode() to get its instance after Init is called.
func GetNode ¶
GetNode Returns Node instance. If this function is called before Init(), error is returned.
func (*Node) GetMinShardersVerify ¶
GetMinShardersVerify Returns minimum sharders used for verification
func (*Node) GetStableMiners ¶
GetStableMiners Returns stable miner urls. Length of stable miners is depedent on config's MinSubmit and number of miners in network.
func (*Node) ResetStableMiners ¶
func (n *Node) ResetStableMiners()
ResetStableMiners resets stable miners as a random permutation of network miners. Length of stable miners is depedent on config's MinSubmit and number of miners in network.
func (*Node) ShouldUpdateNetwork ¶
ShouldUpdateNetwork Gets network details and return it as second value. First value is true iff current network details doesn't match existing network details. Use node.UpdateNetwork() method to set the new network.
type NodeHolder ¶
type NodeHolder struct {
// contains filtered or unexported fields
}
func NewHolder ¶
func NewHolder(nodes []string, consensus int) *NodeHolder
func (*NodeHolder) All ¶
func (h *NodeHolder) All() (res []string)
func (*NodeHolder) Fail ¶
func (h *NodeHolder) Fail(id string)
func (*NodeHolder) Healthy ¶
func (h *NodeHolder) Healthy() (res []string)
func (*NodeHolder) Success ¶
func (h *NodeHolder) Success(id string)
type NodeStruct ¶
type NodeStruct struct {
// contains filtered or unexported fields
}
func NewNode ¶
func NewNode(id string) *NodeStruct
type NonceCache ¶
type NonceCache struct {
// contains filtered or unexported fields
}
var Cache *NonceCache
func (*NonceCache) Evict ¶
func (nc *NonceCache) Evict(clientId string)
func (*NonceCache) GetNextNonce ¶
func (nc *NonceCache) GetNextNonce(clientId string) int64
func (*NonceCache) Set ¶
func (nc *NonceCache) Set(clientId string, nonce int64)
type SCRestAPIHandler ¶
SCRestAPIHandler is a function type to handle the response from the SC Rest API
`response` - the response from the SC Rest API `numSharders` - the number of sharders that responded `err` - the error if any