client

package
v1.18.14 Latest Latest
Warning

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

Go to latest
Published: Dec 14, 2024 License: MIT Imports: 22 Imported by: 10

Documentation

Overview

Provides functions and data structures to interact with the system nodes in the context of the blockchain network.

Index

Constants

View Source
const GetBalanceUrl = "client/get/balance"

Variables

View Source
var (
	IsAppFlow = false
)
View Source
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 AuthUrl

func AuthUrl() string

func GetClient

func GetClient() *zcncrypto.Wallet

func GetClientSysKeys

func GetClientSysKeys(clients ...string) []sys.KeyPair

func GetNetwork

func GetNetwork(ctx context.Context) (*conf.Network, error)

GetNetwork gets current network details from 0chain network.

func GetWallet

func GetWallet() *zcncrypto.Wallet

func Id

func Id(clients ...string) string

func Init

func Init(ctx context.Context, cfg conf.Config) error

Init Initializes SDK.

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 MakeSCRestAPICallToSharder(scAddress string, relativePath string, params map[string]string, restApiUrls ...string) ([]byte, error)

func Mnemonic

func Mnemonic() string

func Nonce

func Nonce() int64

func PopulateClient

func PopulateClient(walletJSON, signatureScheme string) (zcncrypto.Wallet, error)

func PrivateKey

func PrivateKey() string

func PublicKey

func PublicKey(clients ...string) string

func SetAuthUrl

func SetAuthUrl(url string) error

SetAuthUrl will be called by app to set zauth URL to SDK

func SetIsAppFlow added in v1.18.14

func SetIsAppFlow(val bool)

func SetNonce

func SetNonce(n int64)

func SetSdkInitialized

func SetSdkInitialized(val bool)

func SetSignatureScheme

func SetSignatureScheme(signatureScheme string)

func SetSplitKeyWallet

func SetSplitKeyWallet(isSplitKeyWallet bool) error

splitKeyWallet parameter is valid only if SignatureScheme is "BLS0Chain"

func SetTxnFee

func SetTxnFee(f uint64)

func SetWallet

func SetWallet(w zcncrypto.Wallet)

SetWallet should be set before any transaction or client specific APIs

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 TxnFee

func TxnFee() uint64

func VerifySignature

func VerifySignature(signature string, msg string) (bool, error)

func VerifySignatureWith

func VerifySignatureWith(pubKey, signature, hash string) (bool, error)

func Wallet

func Wallet() *zcncrypto.Wallet

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 InitSdkOptions struct {
	WalletJSON              string
	BlockWorker             string
	ChainID                 string
	SignatureScheme         string
	Nonce                   int64
	IsSplitWallet           bool
	AddWallet               bool
	TxnFee                  *int
	MinConfirmation         *int
	MinSubmit               *int
	ConfirmationChainLength *int
	SharderConsensous       *int
	ZboxHost                string
	ZboxAppType             string
}

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

func GetNode() (*Node, error)

GetNode Returns Node instance. If this function is called before Init(), error is returned.

func (*Node) GetMinShardersVerify

func (n *Node) GetMinShardersVerify() int

GetMinShardersVerify Returns minimum sharders used for verification

func (*Node) GetStableMiners

func (n *Node) GetStableMiners() []string

GetStableMiners Returns stable miner urls. Length of stable miners is depedent on config's MinSubmit and number of miners in network.

func (*Node) Network

func (n *Node) Network() *conf.Network

Network Returns network configuration

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) Sharders

func (n *Node) Sharders() *NodeHolder

Sharders Returns NodeHolder instance

func (*Node) ShouldUpdateNetwork

func (n *Node) ShouldUpdateNetwork() (bool, *conf.Network, error)

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.

func (*Node) UpdateNetwork

func (n *Node) UpdateNetwork(network *conf.Network) error

UpdateNetwork 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

type SCRestAPIHandler func(response map[string][]byte, numSharders int, err error)

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

type SignFunc

type SignFunc func(hash string, clients ...string) (string, error)
var (
	Sign SignFunc
)

Jump to

Keyboard shortcuts

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