transaction

package
v1.18.0-RC10 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2024 License: MIT Imports: 23 Imported by: 11

Documentation

Overview

Provides low-level functions and types to work with the native smart contract transactions.

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"
	LOCK_TOKEN                = "lock"
	UNLOCK_TOKEN              = "unlock"

	ADD_FREE_ALLOCATION_ASSIGNER = "add_free_storage_assigner"

	// 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_UPDATE_SETTINGS           = "update_settings"
	ADD_HARDFORK                        = "add_hardfork"
	STORAGESC_COLLECT_REWARD            = "collect_reward"
	STORAGESC_KILL_BLOBBER              = "kill_blobber"
	STORAGESC_KILL_VALIDATOR            = "kill_validator"
	STORAGESC_SHUTDOWN_BLOBBER          = "shutdown_blobber"
	STORAGESC_SHUTDOWN_VALIDATOR        = "shutdown_validator"
	STORAGESC_RESET_BLOBBER_STATS       = "reset_blobber_stats"
	STORAGESC_RESET_ALLOCATION_STATS    = "reset_allocation_stats"
	STORAGESC_RESET_BLOBBER_VERSION     = "update_blobber_version"
	STORAGESC_INSERT_KILLED_PROVIDER_ID = "insert_killed_provider_id"

	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"
	MINERSC_KILL_MINER       = "kill_miner"
	MINERSC_KILL_SHARDER     = "kill_sharder"

	// 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_AUTHORIZER_HEALTH_CHECK  = "authorizer-health-check"
	ZCNSC_DELETE_AUTHORIZER        = "delete-authorizer"
	ZCNSC_COLLECT_REWARD           = "collect-rewards"
	ZCNSC_LOCK                     = "add-to-delegate-pool"
	ZCNSC_UNLOCK                   = "delete-from-delegate-pool"

	ESTIMATE_TRANSACTION_COST = `/v1/estimate_txn_fee`
	FEES_TABLE                = `/v1/fees_table`
)
View Source
const (
	StorageSmartContractAddress = `6dba10422e368813802877a85039d3985d96760ed844092319743fb3a76712d7`
	FaucetSmartContractAddress  = `6dba10422e368813802877a85039d3985d96760ed844092319743fb3a76712d3`
	MinerSmartContractAddress   = `6dba10422e368813802877a85039d3985d96760ed844092319743fb3a76712d9`
	ZCNSCSmartContractAddress   = `6dba10422e368813802877a85039d3985d96760ed844092319743fb3a76712e0`
)
View Source
const (
	GET_MINERSC_CONFIGS     = "/configs"
	GET_MINERSC_GLOBALS     = "/globalSettings"
	STORAGESC_GET_SC_CONFIG = "/storage-config"
)
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 BLOCK_BY_ROUND_URL = "v1/screst/6dba10422e368813802877a85039d3985d96760ed844092319743fb3a76712d7/block?round="
View Source
const MINERSC_SCADDRESS = "6dba10422e368813802877a85039d3985d96760ed844092319743fb3a76712d9"
View Source
const STORAGE_SCADDRESS = "6dba10422e368813802877a85039d3985d96760ed844092319743fb3a76712d7"
View Source
const TXN_SUBMIT_URL = "v1/transaction/put"
View Source
const TXN_VERIFY_URL = "v1/transaction/get/confirmation?hash="
View Source
const ZCNSC_SCADDRESS = "6dba10422e368813802877a85039d3985d96760ed844092319743fb3a76712e0"

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 EstimateFee added in v1.8.16

func EstimateFee(txn *Transaction, miners []string, reqPercent ...float32) (uint64, error)

EstimateFee estimates transaction fee

func GetFeesTable added in v1.8.17

func GetFeesTable(miners []string, reqPercent ...float32) (map[string]map[string]int64, error)

GetFeesTable get fee tables

func SendTransactionSync

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

Types

type Block added in v1.8.12

type Block struct {
	Hash                  string `json:"hash" gorm:"uniqueIndex:idx_bhash"`
	Version               string `json:"version"`
	CreationDate          int64  `json:"creation_date" gorm:"index:idx_bcreation_date"`
	Round                 int64  `json:"round" gorm:"index:idx_bround"`
	MinerID               string `json:"miner_id"`
	RoundRandomSeed       int64  `json:"round_random_seed"`
	MerkleTreeRoot        string `json:"merkle_tree_root"`
	StateHash             string `json:"state_hash"`
	ReceiptMerkleTreeRoot string `json:"receipt_merkle_tree_root"`
	NumTxns               int    `json:"num_txns"`
	MagicBlockHash        string `json:"magic_block_hash"`
	PrevHash              string `json:"prev_hash"`
	Signature             string `json:"signature"`
	ChainId               string `json:"chain_id"`
	StateChangesCount     int    `json:"state_changes_count"`
	RunningTxnCount       string `json:"running_txn_count"`
	RoundTimeoutCount     int    `json:"round_timeout_count"`
}

type InputMap added in v1.17.13

type InputMap struct {
	Fields map[string]string `json:"fields"`
}

func GetConfig added in v1.17.13

func GetConfig(configType string) (conf *InputMap, err error)

GetStorageSCConfig retrieves storage SC configurations.

type OptimisticVerifier added in v1.8.12

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

func NewOptimisticVerifier added in v1.8.12

func NewOptimisticVerifier(sharders []string) *OptimisticVerifier

func (*OptimisticVerifier) VerifyTransactionOptimistic added in v1.8.12

func (v *OptimisticVerifier) VerifyTransactionOptimistic(txnHash string) (*Transaction, error)

type Ratio

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

type RoundBlockHeader

type RoundBlockHeader struct {
	Version               string `json:"version"`
	CreationDate          int64  `json:"creation_date"`
	Hash                  string `json:"block_hash"`
	PreviousBlockHash     string `json:"previous_block_hash"`
	MinerID               string `json:"miner_id"`
	Round                 int64  `json:"round"`
	RoundRandomSeed       int64  `json:"round_random_seed"`
	MerkleTreeRoot        string `json:"merkle_tree_root"`
	StateChangesCount     int    `json:"state_changes_count"`
	StateHash             string `json:"state_hash"`
	ReceiptMerkleTreeRoot string `json:"receipt_merkle_tree_root"`
	NumberOfTxns          int64  `json:"num_txns"`
}

type SignFunc

type SignFunc = func(msg string, clientId ...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"`
}

SmartContractTxnData data structure to hold the smart contract transaction data

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"`
	MinLockDemand  float64 `json:"min_lock_demand"`
}

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 SmartContractTxn added in v1.17.13

func SmartContractTxn(scAddress string, sn SmartContractTxnData, verifyTxn bool, clients ...string) (
	hash, out string, nonce int64, txn *Transaction, err error)

func SmartContractTxnValue added in v1.17.13

func SmartContractTxnValue(scAddress string, sn SmartContractTxnData, value uint64, verifyTxn bool, clients ...string) (
	hash, out string, nonce int64, txn *Transaction, err error)

func SmartContractTxnValueFee added in v1.17.13

func SmartContractTxnValueFee(scAddress string, sn SmartContractTxnData,
	value, fee uint64, verifyTxn bool, clients ...string) (hash, out string, nonce int64, t *Transaction, err error)

func SmartContractTxnValueFeeWithRetry added in v1.17.13

func SmartContractTxnValueFeeWithRetry(scAddress string, sn SmartContractTxnData,
	value, fee uint64, verifyTxn bool, clients ...string) (hash, out string, nonce int64, t *Transaction, err error)

func VerifyTransaction

func VerifyTransaction(txnHash string) (*Transaction, error)

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

func VerifyTransactionTrusted added in v1.8.12

func VerifyTransactionTrusted(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) VerifySigWith added in v1.17.0

func (t *Transaction) VerifySigWith(pubkey string, verifyHandler VerifyFunc) (bool, error)

VerifySigWith verify the signature with the given public key and handler

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(publicKey, signature, msgHash string) (bool, error)

Jump to

Keyboard shortcuts

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