zcncore

package
v1.0.9 Latest Latest
Warning

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

Go to latest
Published: Jul 19, 2019 License: MIT Imports: 13 Imported by: 11

Documentation

Index

Constants

View Source
const (
	StatusSuccess      int = 0
	StatusNetworkError int = 1
	// TODO: Change to specific error
	StatusError   int = 2
	StatusUnknown int = -1
)
View Source
const (
	OpGetTokenLockConfig int = 0
	OpGetLockedTokens    int = 1
)
View Source
const FaucetSmartContractAddress = `6dba10422e368813802877a85039d3985d96760ed844092319743fb3a76712d3`
View Source
const InterestPoolSmartContractAddress = `6dba10422e368813802877a85039d3985d96760ed844092319743fb3a76712d9`
View Source
const MultiSigRegisterFuncName = "register"
View Source
const MultiSigSmartContractAddress = `27b5ef7120252b79f9dd9c05505dd28f328c80f6863ee446daede08a84d651a7`
View Source
const MultiSigVoteFuncName = "vote"
View Source
const StorageSmartContractAddress = `6dba10422e368813802877a85039d3985d96760ed844092319743fb3a76712d7`
View Source
const TOKEN_UNIT = int64(10000000000)

Variables

View Source
var GET_BALANCE = `/v1/client/get/balance?client_id=`
View Source
var GET_LOCKED_TOKENS = `/v1/screst/` + InterestPoolSmartContractAddress + `/getPoolsStats?client_id=`
View Source
var GET_LOCK_CONFIG = `/v1/scstate/get?sc_address=`
View Source
var LATEST_FINALIZED_BLOCK = `/v1/block/get/latest_finalized`
View Source
var PUT_TRANSACTION = `/v1/transaction/put`
View Source
var REGISTER_CLIENT = `/v1/client/put`
View Source
var TXN_VERIFY_URL = `/v1/transaction/get/confirmation?hash=`

Functions

func CloseLog

func CloseLog()

CloseLog closes log file

func ConvertToToken

func ConvertToToken(value int64) float64

ConvertToToken converts the value to ZCN tokens

func ConvertToValue

func ConvertToValue(token float64) int64

ConvertToValue converts ZCN tokens to value

func CreateMSVote

func CreateMSVote(proposal, grpClientID, signerWalletstr, toClientID string, token int64) (string, error)

CreateMSVote create a vote for multisig

func CreateMSWallet

func CreateMSWallet(t, n int) (string, string, []string, error)

CreateMSWallet returns multisig wallet information

func CreateWallet

func CreateWallet(numKeys int, statusCb WalletCallback) error

CreateWallet creates the a wallet for the configure signature scheme. It also registers the wallet again to block chain.

func GetBalance

func GetBalance(cb GetBalanceCallback) error

GetBalance retreives wallet balance from sharders

func GetBalanceWallet

func GetBalanceWallet(walletStr string, cb GetBalanceCallback) error

GetBalance retreives wallet balance from sharders

func GetClientID

func GetClientID(pkey string) string

GetClientID -- computes Client ID from publickey

func GetLockConfig

func GetLockConfig(cb GetInfoCallback) error

GetLockConfig returns the lock token configuration information such as interest rate from blockchain

func GetLockedTokens

func GetLockedTokens(cb GetInfoCallback) error

GetLockedTokens returns the ealier locked token pool stats

func GetMultisigPayload

func GetMultisigPayload(mswstr string) (interface{}, error)

GetMultisigPayload given a multisig wallet as a string, makes a multisig wallet payload to register

func GetMultisigVotePayload

func GetMultisigVotePayload(msvstr string) (interface{}, error)

GetMultisigVotePayload given a multisig vote as a string, makes a multisig vote payload to register

func GetWallet

func GetWallet(walletStr string) (*zcncrypto.Wallet, error)

GetWallet get a wallet object from a wallet string

func GetWalletClientID

func GetWalletClientID(walletStr string) (string, error)

GetWalletClientID -- given a walletstr return ClientID

func Init

func Init(c string) error

Init inializes the SDK with miner, sharder and signature scheme provided in configuration provided in JSON format

func InitZCNSDK

func InitZCNSDK(miners []string, sharders []string, signscheme string) error

InitZCNSDK initializes the SDK with miner, sharder and signature scheme provided.

func IsMnemonicValid

func IsMnemonicValid(mnemonic string) bool

IsMnemonicValid is an utility function to check the mnemonic valid

func RecoverWallet

func RecoverWallet(mnemonic string, numKeys int, statusCb WalletCallback) error

RecoverWallet recovers the previously generated wallet using the mnemonic. It also registers the wallet again to block chain.

func RegisterToMiners

func RegisterToMiners(wallet *zcncrypto.Wallet, statusCb WalletCallback) error

RegisterToMiners can be used to register the wallet.

func RegisterWallet

func RegisterWallet(walletString string, cb WalletCallback)

RegisterWallet registers multisig related wallets

func SetLogFile

func SetLogFile(logFile string, verbose bool)

SetLogFile - sets file path to write log verbose - true - console output; false - no console output

func SetLogLevel

func SetLogLevel(lvl int)

SetLogLevel set the log level. lvl - 0 disabled; higher number (upto 4) more verbosity

func SetWalletInfo

func SetWalletInfo(w string) error

SetWalletInfo should be set before any transaction or GetBalance APIs

Types

type ChainConfig

type ChainConfig struct {
	ChainID         string   `json:"chain_id,omitempty"`
	Miners          []string `json:"miners"`
	Sharders        []string `json:"sharders"`
	SignatureScheme string   `json:"signaturescheme"`
}

type GetBalanceCallback

type GetBalanceCallback interface {
	OnBalanceAvailable(status int, value int64)
}

GetBalanceCallback needs to be implemented by the caller of GetBalance() to get the status

type GetInfoCallback

type GetInfoCallback interface {
	// OnInfoAvailable will be called when GetLockTokenConfig is complete
	// if status == StatusSuccess then info is valid
	// is status != StatusSuccess then err will give the reason
	OnInfoAvailable(op int, status int, info string, err string)
}

GetInfoCallback needs to be implemented by the caller of GetLockTokenConfig() and GetLockedTokens()

type MSTransfer

type MSTransfer struct {
	ClientID   string `json:"from"`
	ToClientID string `json:"to"`
	Amount     int64  `json:"amount"`
}

MSTransfer - a data structure to hold state transfer from one client to another

type MSVote

type MSVote struct {
	ProposalID string `json:"proposal_id"`

	// Client ID in transfer is that of the multi-sig wallet, not the signer.
	Transfer MSTransfer `json:"transfer"`

	Signature string `json:"signature"`
}

MSVote -- this should mimic the type Vote defined in MultiSig SC

type MSVoteCallback

type MSVoteCallback interface {
	OnVoteComplete(status int, proposal string, err string)
}

MSVoteCallback callback definition multisig Vote function

type MSWallet

type MSWallet struct {
	Id              int                                  `json:"id"`
	SignatureScheme string                               `json:"signature_scheme"`
	GroupClientID   string                               `json:"group_client_id"`
	GroupKey        *zcncrypto.BLS0ChainScheme           `json:"group_key"`
	SignerClientIDs []string                             `json:"sig_client_ids"`
	SignerKeys      []zcncrypto.BLS0ChainThresholdScheme `json:"signer_keys"`
	T               int                                  `json:"threshold"`
	N               int                                  `json:"num_subkeys"`
}

MSWallet Client data necessary for a multi-sig wallet.

func (*MSWallet) Marshal

func (msw *MSWallet) Marshal() (string, error)

Marshal returns json string

type MultisigSCWallet

type MultisigSCWallet struct {
	ClientID        string `json:"client_id"`
	SignatureScheme string `json:"signature_scheme"`
	PublicKey       string `json:"public_key"`

	SignerThresholdIDs []string `json:"signer_threshold_ids"`
	SignerPublicKeys   []string `json:"signer_public_keys"`

	NumRequired int `json:"num_required"`
}

MultisigSCWallet --this should mimic MultisigWallet definition in MultiSig SC

type Transaction

type Transaction struct {
	// contains filtered or unexported fields
}

func NewMSTransaction

func NewMSTransaction(walletstr string, cb TransactionCallback) (*Transaction, error)

NewMSTransaction new transaction object for multisig operation

func NewTransaction

func NewTransaction(cb TransactionCallback) (*Transaction, error)

NewTransaction allocation new generic transaction object for any operation

func (*Transaction) ExecuteFaucetSC added in v1.0.3

func (t *Transaction) ExecuteFaucetSC(methodName string, input []byte) error

func (*Transaction) ExecuteFaucetSCWallet

func (t *Transaction) ExecuteFaucetSCWallet(walletStr string, methodName string, input []byte) error

ExecuteFaucetSCWallet impements the Faucet Smart contract for a given wallet

func (*Transaction) GetTransactionError

func (t *Transaction) GetTransactionError() string

func (*Transaction) GetTransactionHash

func (t *Transaction) GetTransactionHash() string

func (*Transaction) GetVerifyError

func (t *Transaction) GetVerifyError() string

func (*Transaction) GetVerifyOutput

func (t *Transaction) GetVerifyOutput() string

func (*Transaction) LockTokens

func (t *Transaction) LockTokens(val int64, durationHr int64, durationMin int) error

func (*Transaction) RegisterMultiSig

func (t *Transaction) RegisterMultiSig(walletstr string, mswallet string) error

RegisterMultiSig register a multisig wallet with the SC.

func (*Transaction) RegisterVote

func (t *Transaction) RegisterVote(signerwalletstr string, msvstr string) error

RegisterVote register a multisig wallet with the SC.

func (*Transaction) Send

func (t *Transaction) Send(toClientID string, val int64, desc string) error

func (*Transaction) SendWithSignature added in v1.0.3

func (t *Transaction) SendWithSignature(toClientID string, val int64, desc string, sig string) error

func (*Transaction) SetTransactionCallback

func (t *Transaction) SetTransactionCallback(cb TransactionCallback) error

func (*Transaction) SetTransactionHash

func (t *Transaction) SetTransactionHash(hash string) error

func (*Transaction) StoreData

func (t *Transaction) StoreData(data string) error

func (*Transaction) UnlockTokens

func (t *Transaction) UnlockTokens(poolID string) error

func (*Transaction) Verify

func (t *Transaction) Verify() error

type TransactionCallback

type TransactionCallback interface {
	OnTransactionComplete(t *Transaction, status int)
	OnVerifyComplete(t *Transaction, status int)
}

TransactionCallback needs to be implemented by the caller for transaction related APIs

type TransactionScheme

type TransactionScheme interface {
	// SetTransactionCallback implements storing the callback
	// used to call after the transaction or verification is completed
	SetTransactionCallback(cb TransactionCallback) error
	// Send implements sending token to a given clientid
	Send(toClientID string, val int64, desc string) error
	// SendWithSignature implements sending token.
	// signature will be passed by application where multi signature is involved.
	SendWithSignature(toClientID string, val int64, desc string, sig string) error
	// StoreData implements store the data to blockchain
	StoreData(data string) error
	// ExecuteFaucetSC impements the Faucet Smart contract
	ExecuteFaucetSC(methodName string, input []byte) error
	// ExecuteFaucetSCWallet impements the Faucet Smart contract for a given wallet
	ExecuteFaucetSCWallet(walletStr string, methodName string, input []byte) error
	// GetTransactionHash implements retrieval of hash of the submitted transaction
	GetTransactionHash() string
	// LockTokens implements the lock token.
	LockTokens(val int64, durationHr int64, durationMin int) error
	// UnlockTokens implements unlocking of earlier locked tokens.
	UnlockTokens(poolID string) error
	//RegisterMultiSig registers a group wallet and subwallets with MultisigSC
	RegisterMultiSig(walletstr, mswallet string) error
	// SetTransactionHash implements verify a previous transation status
	SetTransactionHash(hash string) error
	// Verify implements verify the transaction
	Verify() error
	// GetVerifyOutput implements the verifcation output from sharders
	GetVerifyOutput() string
	// GetTransactionError implements error string incase of transaction failure
	GetTransactionError() string
	// GetVerifyError implements error string incase of verify failure error
	GetVerifyError() string
}

TransactionScheme implements few methods for block chain

type WalletCallback

type WalletCallback interface {
	OnWalletCreateComplete(status int, wallet string, err string)
}

WalletCallback needs to be implmented for wallet creation.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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