utils

package
v2.3.3 Latest Latest
Warning

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

Go to latest
Published: Jul 18, 2023 License: Apache-2.0 Imports: 23 Imported by: 7

Documentation

Overview

Package utils common utils

Index

Constants

View Source
const (
	// SUCCESS ContractResult success code
	SUCCESS uint32 = 0
	// Separator chainmker hex ca
	Separator = byte(202)
)
View Source
const (
	HibeMsgKey           = "hibe_msg"
	HibeMsgIdKey         = "tx_id"
	HibeMsgCipherTextKey = "CT"
	HibeParamsKey        = "org_id"
	HibeParamsValueKey   = "params"
)

hibe msg's Keys

View Source
const (
	// System Block Contract keys
	KeyBlockContractWithRWSet        = "withRWSet"
	KeyBlockContractBlockHash        = "blockHash"
	KeyBlockContractBlockHeight      = "blockHeight"
	KeyBlockContractTxId             = "txId"
	KeyBlockContractTruncateValueLen = "truncateValueLen"
	KeyBlockContractTruncateModel    = "truncateModel"

	// System Chain Config Contract keys
	KeyChainConfigContractRoot              = "root"
	KeyChainConfigContractOrgId             = "org_id"
	KeyChainConfigAddrType                  = "addr_type"
	KeyChainConfigContractNodeId            = "node_id"
	KeyChainConfigContractNewNodeId         = "new_node_id"
	KeyChainConfigContractNodeIds           = "node_ids"
	KeyChainConfigContractBlockHeight       = "block_height"
	KeyChainConfigContractTrustMemberOrgId  = "org_id"
	KeyChainConfigContractTrustMemberInfo   = "member_info"
	KeyChainConfigContractTrustMemberNodeId = "node_id"
	KeyChainConfigContractTrustMemberRole   = "role"

	// CoreConfig keys
	KeyTxSchedulerTimeout         = "tx_scheduler_timeout"
	KeyTxSchedulerValidateTimeout = "tx_scheduler_validate_timeout"
	KeyEnableOptimizeChargeGas    = "enable_optimize_charge_gas"

	// BlockConfig keys
	KeyTxTimeOut       = "tx_timeout"
	KeyBlockTxCapacity = "block_tx_capacity"
	KeyBlockSize       = "block_size"
	KeyBlockInterval   = "block_interval"
	KeyTxParamterSize  = "tx_parameter_size"

	// CertManage keys
	KeyCertHashes = "cert_hashes"
	KeyCerts      = "certs"
	KeyCertCrl    = "cert_crl"

	// PrivateCompute keys
	KeyOrderId      = "order_id"
	KeyPrivateDir   = "private_dir"
	KeyContractName = "contract_name"
	KeyCodeHash     = "code_hash"
	KeyResult       = "result"
	KeyCodeHeader   = "code_header"
	KeyVersion      = "version"
	KeyIsDeploy     = "is_deploy"
	KeyRWSet        = "rw_set"
	KeyEvents       = "events"
	KeyReportHash   = "report_hash"
	KeySign         = "sign"
	KeyKey          = "key"
	KeyPayload      = "payload"
	KeyOrgIds       = "org_ids"
	KeySignPairs    = "sign_pairs"
	KeyCaCert       = "ca_cert"
	KeyEnclaveId    = "enclave_id"
	KeyReport       = "report"
	KeyProof        = "proof"
	KeyDeployReq    = "deploy_req"
	KeyPrivateReq   = "private_req"

	// PubkeyManage keys
	KeyPubkey      = "pubkey"
	KeyPubkeyRole  = "role"
	KeyPubkeyOrgId = "org_id"

	// Gas management
	KeyGasAddressKey       = "address_key"
	KeyGasPublicKey        = "public_key"
	KeyGasBatchRecharge    = "batch_recharge"
	KeyGasBalancePublicKey = "balance_public_key"
	KeyGasChargePublicKey  = "charge_public_key"
	KeyGasChargeGasAmount  = "charge_gas_amount"
	KeyGasFrozenPublicKey  = "frozen_public_key"
	KeySetInvokeBaseGas    = "set_invoke_base_gas"
	KeySetInvokeGasPrice   = "set_invoke_gas_price"
	KeySetInstallBaseGas   = "set_install_base_gas"
	KeySetInstallGasPrice  = "set_install_gas_price"

	// Vm multi sign
	KeyMultiSignEnableManualRun = "multi_sign_enable_manual_run"
)

nolint

View Source
const (
	// ArchiveConfig consts
	MysqlDBNamePrefix     = "cm_archived_chain"
	MysqlTableNamePrefix  = "t_block_info"
	RowsPerBlockInfoTable = 100000
)

nolint

Variables

This section is empty.

Functions

func BytesToI64

func BytesToI64(b []byte) (int64, error)

BytesToI64 bytes to int64 in little endian

func BytesToU64

func BytesToU64(b []byte) (uint64, error)

BytesToU64 bytes to uint64 in little endian

func CheckProposalRequestResp

func CheckProposalRequestResp(resp *common.TxResponse, needContractResult bool) error

CheckProposalRequestResp check tx response is ok or not

func DecryptHibeTx

func DecryptHibeTx(localId string, hibeParams []byte, hibePrvKey []byte, tx *common.Transaction,
	keyType crypto.KeyType) ([]byte, error)

DecryptHibeTx DecryptHibeTx

func Exists

func Exists(path string) bool

Exists returns a boolean indicating whether the error is known to report that a file or directory already exists.

func GetCertificateId

func GetCertificateId(certPEM []byte, hashType string) ([]byte, error)

GetCertificateId get cert id from cert pem

func GetCertificateIdFromDER

func GetCertificateIdFromDER(certDER []byte, hashType string) ([]byte, error)

GetCertificateIdFromDER get cert id from cert der

func GetNanoByTimestampTxId added in v2.2.1

func GetNanoByTimestampTxId(timestampTxId string) (nano int64, err error)

GetNanoByTimestampTxId validate and parse 160 ... 223 22

func GetRandTxId

func GetRandTxId() string

GetRandTxId get random tx id

func GetTimestampTxId added in v2.2.1

func GetTimestampTxId() string

GetTimestampTxId by current time, see: GetTimestampTxIdByNano eg: 687dca1d9c4fdf1652fdfc072182654f53622c496aa94c05b47d34263cd99ec9

func GetTimestampTxIdByNano added in v2.2.1

func GetTimestampTxIdByNano(nano int64) string

GetTimestampTxIdByNano nanosecond

func I64ToBytes

func I64ToBytes(i int64) []byte

I64ToBytes int64 to bytes in little endian

func IsArchived

func IsArchived(txStatusCode common.TxStatusCode) bool

IsArchived returns a boolean indicating whether is archived by txStatusCode in common.TxStatusCode

func IsArchivedString

func IsArchivedString(txStatusCode string) bool

IsArchivedString returns a boolean indicating whether is archived by txStatusCode in string

func MakeEndorser added in v2.1.0

func MakeEndorser(orgId string, hashType crypto.HashType, memberType accesscontrol.MemberType, keyPem,
	memberInfo []byte, payload *common.Payload) (*common.EndorsementEntry, error)

MakeEndorser returns *common.EndorsementEntry

func MakeEndorserWithPath added in v2.1.0

func MakeEndorserWithPath(keyFilePath, crtFilePath string, payload *common.Payload) (*common.EndorsementEntry, error)

MakeEndorserWithPath make endorser with key/cert file path

func MakeEndorserWithPathAndP11Handle added in v2.1.0

func MakeEndorserWithPathAndP11Handle(keyFilePath, crtFilePath string, p11Handle interface{},
	payload *common.Payload) (*common.EndorsementEntry, error)

MakeEndorserWithPathAndP11Handle make endorser with key/cert file path and P11Handle

func MakeEndorserWithPem added in v2.1.0

func MakeEndorserWithPem(keyPem, certPem []byte, payload *common.Payload) (*common.EndorsementEntry, error)

MakeEndorserWithPem make endorser with pem Deprecated: This function will be deleted when appropriate. Please use MakeEndorser

func MakePkEndorserWithPath added in v2.1.0

func MakePkEndorserWithPath(keyFilePath string, hashType crypto.HashType, orgId string,
	payload *common.Payload) (*common.EndorsementEntry, error)

MakePkEndorserWithPath make public mode endorser with key file path

func MakePkEndorserWithPem added in v2.1.0

func MakePkEndorserWithPem(keyPem []byte, hashType crypto.HashType, orgId string,
	payload *common.Payload) (*common.EndorsementEntry, error)

MakePkEndorserWithPem make public mode endorser with pem Deprecated: This function will be deleted when appropriate. Please use MakeEndorser

func NewEndorser added in v2.1.0

func NewEndorser(orgId string, certPem []byte, sig []byte) *common.EndorsementEntry

NewEndorser returns *common.EndorsementEntry Deprecated: This function will be deleted when appropriate. Please use NewEndorserWithMemberType

func NewEndorserWithMemberType added in v2.1.0

func NewEndorserWithMemberType(orgId string, memberInfo []byte, memberType accesscontrol.MemberType,
	sig []byte) *common.EndorsementEntry

NewEndorserWithMemberType new endorser with member type

func NewPayload

func NewPayload(opts ...PayloadOption) *commonPb.Payload

NewPayload new payload

func NewPkEndorser added in v2.1.0

func NewPkEndorser(orgId string, pk []byte, sig []byte) *common.EndorsementEntry

NewPkEndorser returns *common.EndorsementEntry

func ParseCert

func ParseCert(crtPEM []byte) (*bcx509.Certificate, error)

ParseCert parse cert pem to *bcx509.Certificate

func ReadHibeParamsWithFilePath

func ReadHibeParamsWithFilePath(hibeParamsFilePath string) ([]byte, error)

ReadHibeParamsWithFilePath Returns the serialized byte array of hibeParams

func ReadHibePrvKeysWithFilePath

func ReadHibePrvKeysWithFilePath(hibePrvKeyFilePath string) ([]byte, error)

ReadHibePrvKeysWithFilePath Returns the serialized byte array of hibePrvKey

func SignPayload

func SignPayload(privateKey crypto.PrivateKey, cert *bcx509.Certificate, payload *common.Payload) ([]byte, error)

SignPayload sign payload Deprecated: This function will be deleted when appropriate. Please use SignPayloadWithHashType

func SignPayloadBytes

func SignPayloadBytes(privateKey crypto.PrivateKey, cert *bcx509.Certificate, payloadBytes []byte) ([]byte, error)

SignPayloadBytes sign payload bytes Deprecated: This function will be deleted when appropriate. Please use SignPayloadBytesWithHashType

func SignPayloadBytesWithHashType added in v2.1.0

func SignPayloadBytesWithHashType(privateKey crypto.PrivateKey,
	hashType crypto.HashType, payloadBytes []byte) ([]byte, error)

SignPayloadBytesWithHashType sign payload bytes with specified hash type

func SignPayloadWithHashType added in v2.1.0

func SignPayloadWithHashType(privateKey crypto.PrivateKey,
	hashType crypto.HashType, payload *common.Payload) ([]byte, error)

SignPayloadWithHashType sign payload with specified hash type

func SignPayloadWithPath added in v2.1.0

func SignPayloadWithPath(keyFilePath, crtFilePath string, payload *common.Payload) ([]byte, error)

SignPayloadWithPath sign payload with specified key/cert file path

func SignPayloadWithPkPath added in v2.1.0

func SignPayloadWithPkPath(keyFilePath, hashType string, payload *common.Payload) ([]byte, error)

SignPayloadWithPkPath sign payload with specified key file path

func U64ToBytes

func U64ToBytes(i uint64) []byte

U64ToBytes uint64 to bytes in little endian

Types

type ChainClientConfigModel

type ChainClientConfigModel struct {
	ChainClientConfig chainClientConfigModel `mapstructure:"chain_client"`
}

ChainClientConfigModel define ChainClientConfigModel

func InitConfig

func InitConfig(confPath string) (*ChainClientConfigModel, error)

InitConfig init config from config file path

type Logger

type Logger interface {
	Debugf(format string, args ...interface{})
	Infof(format string, args ...interface{})
	Warnf(format string, args ...interface{})
	Errorf(format string, args ...interface{})

	Debug(args ...interface{})
	Info(args ...interface{})
	Warn(args ...interface{})
	Error(args ...interface{})
}

Logger define log interface

type PayloadOption

type PayloadOption func(*commonPb.Payload)

PayloadOption define payload option func

func AddParameter

func AddParameter(parameter *commonPb.KeyValuePair) PayloadOption

AddParameter add one Parameter of payload

func WithChainId

func WithChainId(chainId string) PayloadOption

WithChainId set chainId of payload

func WithContractName

func WithContractName(contractName string) PayloadOption

WithContractName set ContractName of payload

func WithExpirationTime

func WithExpirationTime(expirationTime int64) PayloadOption

WithExpirationTime set ExpirationTime of payload

func WithLimit

func WithLimit(limit *commonPb.Limit) PayloadOption

WithLimit set Limit of payload

func WithMethod

func WithMethod(method string) PayloadOption

WithMethod set Method of payload

func WithParameters

func WithParameters(parameters []*commonPb.KeyValuePair) PayloadOption

WithParameters set Parameters of payload

func WithSequence

func WithSequence(sequence uint64) PayloadOption

WithSequence set Sequence of payload

func WithTimestamp

func WithTimestamp(timestamp int64) PayloadOption

WithTimestamp set Timestamp of payload

func WithTxId

func WithTxId(txId string) PayloadOption

WithTxId set TxId of payload

func WithTxType

func WithTxType(txType commonPb.TxType) PayloadOption

WithTxType set TxType of payload

type TlsConfig added in v2.3.3

type TlsConfig struct {
	ServerName  string   `mapstructure:"server_name"`
	PrivKeyFile string   `mapstructure:"priv_key_file"`
	CertFile    string   `mapstructure:"cert_file"`
	TrustCaList []string `mapstructure:"trust_ca_list"`
}

TlsConfig 归档中心rpc使用的tls证书配置

Jump to

Keyboard shortcuts

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