transaction

package
v1.8.11 Latest Latest
Warning

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

Go to latest
Published: Dec 26, 2022 License: MIT Imports: 17 Imported by: 11

Documentation

Index

Constants

View Source
const (
	TxnSuccess         = 1 // Indicates the transaction is successful in updating the state or smart contract
	TxnChargeableError = 2 // Indicates the transaction is successful in updating the state or smart contract
	TxnFail            = 3 // Indicates a transaction has failed to update the state or smart contract
)
View Source
const (
	NEW_ALLOCATION_REQUEST    = "new_allocation_request"
	NEW_FREE_ALLOCATION       = "free_allocation_request"
	UPDATE_ALLOCATION_REQUEST = "update_allocation_request"
	FREE_UPDATE_ALLOCATION    = "free_update_allocation"
	LOCK_TOKEN                = "lock"
	UNLOCK_TOKEN              = "unlock"

	ADD_FREE_ALLOCATION_ASSIGNER = "add_free_storage_assigner"

	// Vesting SC
	VESTING_TRIGGER         = "trigger"
	VESTING_STOP            = "stop"
	VESTING_UNLOCK          = "unlock"
	VESTING_ADD             = "add"
	VESTING_DELETE          = "delete"
	VESTING_UPDATE_SETTINGS = "vestingsc-update-settings"

	// Storage SC
	STORAGESC_FINALIZE_ALLOCATION       = "finalize_allocation"
	STORAGESC_CANCEL_ALLOCATION         = "cancel_allocation"
	STORAGESC_CREATE_ALLOCATION         = "new_allocation_request"
	STORAGESC_CREATE_READ_POOL          = "new_read_pool"
	STORAGESC_READ_POOL_LOCK            = "read_pool_lock"
	STORAGESC_READ_POOL_UNLOCK          = "read_pool_unlock"
	STORAGESC_STAKE_POOL_LOCK           = "stake_pool_lock"
	STORAGESC_STAKE_POOL_UNLOCK         = "stake_pool_unlock"
	STORAGESC_UPDATE_BLOBBER_SETTINGS   = "update_blobber_settings"
	STORAGESC_UPDATE_VALIDATOR_SETTINGS = "update_validator_settings"
	STORAGESC_UPDATE_ALLOCATION         = "update_allocation_request"
	STORAGESC_WRITE_POOL_LOCK           = "write_pool_lock"
	STORAGESC_WRITE_POOL_UNLOCK         = "write_pool_unlock"
	STORAGESC_ADD_CURATOR               = "add_curator"
	STORAGESC_REMOVE_CURATOR            = "remove_curator"
	STORAGESC_CURATOR_TRANSFER          = "curator_transfer_allocation"
	STORAGESC_UPDATE_SETTINGS           = "update_settings"
	STORAGESC_COLLECT_REWARD            = "collect_reward"

	MINERSC_LOCK             = "addToDelegatePool"
	MINERSC_UNLOCK           = "deleteFromDelegatePool"
	MINERSC_MINER_SETTINGS   = "update_miner_settings"
	MINERSC_SHARDER_SETTINGS = "update_sharder_settings"
	MINERSC_UPDATE_SETTINGS  = "update_settings"
	MINERSC_UPDATE_GLOBALS   = "update_globals"
	MINERSC_MINER_DELETE     = "delete_miner"
	MINERSC_SHARDER_DELETE   = "delete_sharder"
	MINERSC_COLLECT_REWARD   = "collect_reward"

	// Faucet SC
	FAUCETSC_UPDATE_SETTINGS = "update-settings"

	ZCNSC_UPDATE_GLOBAL_CONFIG     = "update-global-config"
	ZCNSC_UPDATE_AUTHORIZER_CONFIG = "update-authorizer-config"
	ZCNSC_ADD_AUTHORIZER           = "add-authorizer"
	ZCNSC_DELETE_AUTHORIZER        = "delete-authorizer"
)
View Source
const (
	TxnTypeSend = 0 // A transaction to send tokens to another account, state is maintained by account

	TxnTypeLockIn = 2 // A transaction to lock tokens, state is maintained on the account and the parent lock in transaction

	// Any txn type that refers to a parent txn should have an odd value
	TxnTypeStorageWrite = 101 // A transaction to write data to the blobber
	TxnTypeStorageRead  = 103 // A transaction to read data from the blobber

	TxnTypeData = 10 // A transaction to just store a piece of data on the block chain

	TxnTypeSmartContract = 1000 // A smart contract transaction type
)
View Source
const GET_BALANCE = `/v1/client/get/balance?client_id=`
View Source
const TXN_SUBMIT_URL = "v1/transaction/put"
View Source
const TXN_VERIFY_URL = "v1/transaction/get/confirmation?hash="

Variables

View Source
var (
	// ErrInvalidRequest invalid request
	ErrInvalidRequest = errors.New("[txn] invalid request")

	// ErrNoAvailableSharder no any available sharder
	ErrNoAvailableSharder = errors.New("[txn] there is no any available sharder")

	// ErrNoTxnDetail No transaction detail was found on any of the sharders
	ErrNoTxnDetail = errors.New("[txn] no transaction detail was found on any of the sharders")

	// ErrTooLessConfirmation too less sharder to confirm transaction
	ErrTooLessConfirmation = errors.New("[txn] too less sharders to confirm it")
)

Functions

func InitCache added in v1.8.3

func InitCache(sharders []string)

func SendTransactionSync

func SendTransactionSync(txn *Transaction, miners []string)

Types

type NonceCache added in v1.8.3

type NonceCache struct {
	// contains filtered or unexported fields
}
var Cache *NonceCache

var defaultLogLevel = logger.DEBUG var Logger logger.Logger

func (*NonceCache) Evict added in v1.8.3

func (nc *NonceCache) Evict(clientId string)

func (*NonceCache) GetNextNonce added in v1.8.3

func (nc *NonceCache) GetNextNonce(clientId string) int64

func (*NonceCache) Set added in v1.8.3

func (nc *NonceCache) Set(clientId string, nonce int64)

type Ratio

type Ratio struct {
	ZCN  int64 `json:"zcn"`
	Size int64 `json:"size"`
}

type RoundBlockHeader

type RoundBlockHeader struct {
	Version               string `json:"version"`
	CreationData          int64  `json:"creation_date"`
	Hash                  string `json:"hash"`
	MinerID               string `json:"miner_id"`
	Round                 int64  `json:"round"`
	RoundRandomSeed       int64  `json:"round_random_seed"`
	MerkleTreeRoot        string `json:"merkle_tree_root"`
	StateHash             string `json:"state_hash"`
	ReceiptMerkleTreeRoot string `json:"receipt_merkle_tree_root"`
	NumberOfTxns          int64  `json:"num_txns"`
}

type SignFunc

type SignFunc = func(msg string) (string, error)

type SignWithWallet

type SignWithWallet = func(msg string, wallet interface{}) (string, error)

type SmartContractTxnData

type SmartContractTxnData struct {
	Name      string      `json:"name"`
	InputArgs interface{} `json:"input"`
}

type StorageAllocation

type StorageAllocation struct {
	ID             string `json:"id"`
	DataShards     int    `json:"data_shards"`
	ParityShards   int    `json:"parity_shards"`
	Size           int64  `json:"size"`
	Expiration     int64  `json:"expiration_date"`
	Owner          string `json:"owner_id"`
	OwnerPublicKey string `json:"owner_public_key"`
	ReadRatio      *Ratio `json:"read_ratio"`
	WriteRatio     *Ratio `json:"write_ratio"`
}

type Transaction

type Transaction struct {
	Hash              string `json:"hash,omitempty"`
	Version           string `json:"version,omitempty"`
	ClientID          string `json:"client_id,omitempty"`
	PublicKey         string `json:"public_key,omitempty"`
	ToClientID        string `json:"to_client_id,omitempty"`
	ChainID           string `json:"chain_id,omitempty"`
	TransactionData   string `json:"transaction_data"`
	Value             uint64 `json:"transaction_value"`
	Signature         string `json:"signature,omitempty"`
	CreationDate      int64  `json:"creation_date,omitempty"`
	TransactionType   int    `json:"transaction_type"`
	TransactionOutput string `json:"transaction_output,omitempty"`
	TransactionFee    uint64 `json:"transaction_fee"`
	TransactionNonce  int64  `json:"transaction_nonce"`
	OutputHash        string `json:"txn_output_hash"`
	Status            int    `json:"transaction_status"`
}

Transaction entity that encapsulates the transaction related data and meta data

func NewTransactionEntity

func NewTransactionEntity(clientID string, chainID string, publicKey string, nonce int64) *Transaction

func VerifyTransaction

func VerifyTransaction(txnHash string, sharders []string) (*Transaction, error)

VerifyTransaction query transaction status from sharders, and verify it by mininal confirmation

func (*Transaction) ComputeHashAndSign

func (t *Transaction) ComputeHashAndSign(signHandler SignFunc) error

func (*Transaction) ComputeHashAndSignWithWallet

func (t *Transaction) ComputeHashAndSignWithWallet(signHandler SignWithWallet, signingWallet interface{}) error

func (*Transaction) ComputeHashData

func (t *Transaction) ComputeHashData()

func (*Transaction) DebugJSON added in v1.3.0

func (t *Transaction) DebugJSON() []byte

func (*Transaction) VerifyTransaction

func (t *Transaction) VerifyTransaction(verifyHandler VerifyFunc) (bool, error)

type TxnReceipt

type TxnReceipt struct {
	Transaction *Transaction
}

TxnReceipt - a transaction receipt is a processed transaction that contains the output

func NewTransactionReceipt

func NewTransactionReceipt(t *Transaction) *TxnReceipt

NewTransactionReceipt - create a new transaction receipt

func (*TxnReceipt) GetHash

func (rh *TxnReceipt) GetHash() string

GetHash - implement interface

func (*TxnReceipt) GetHashBytes

func (rh *TxnReceipt) GetHashBytes() []byte

GetHashBytes - implement Hashable interface

type VerifyFunc

type VerifyFunc = func(signature, msgHash, publicKey string) (bool, error)

Jump to

Keyboard shortcuts

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