Documentation ¶
Overview ¶
Package utils common utils
Index ¶
- Constants
- func BytesToI64(b []byte) (int64, error)
- func BytesToU64(b []byte) (uint64, error)
- func CheckProposalRequestResp(resp *common.TxResponse, needContractResult bool) error
- func DecryptHibeTx(localId string, hibeParams []byte, hibePrvKey []byte, tx *common.Transaction, ...) ([]byte, error)
- func Exists(path string) bool
- func GetCertificateId(certPEM []byte, hashType string) ([]byte, error)
- func GetCertificateIdFromDER(certDER []byte, hashType string) ([]byte, error)
- func GetNanoByTimestampTxId(timestampTxId string) (nano int64, err error)
- func GetRandTxId() string
- func GetTimestampTxId() string
- func GetTimestampTxIdByNano(nano int64) string
- func I64ToBytes(i int64) []byte
- func IsArchived(txStatusCode common.TxStatusCode) bool
- func IsArchivedString(txStatusCode string) bool
- func MakeEndorser(orgId string, hashType crypto.HashType, memberType accesscontrol.MemberType, ...) (*common.EndorsementEntry, error)
- func MakeEndorserWithPath(keyFilePath, crtFilePath string, payload *common.Payload) (*common.EndorsementEntry, error)
- func MakeEndorserWithPathAndP11Handle(keyFilePath, crtFilePath string, p11Handle interface{}, ...) (*common.EndorsementEntry, error)
- func MakeEndorserWithPem(keyPem, certPem []byte, payload *common.Payload) (*common.EndorsementEntry, error)
- func MakePkEndorserWithPath(keyFilePath string, hashType crypto.HashType, orgId string, ...) (*common.EndorsementEntry, error)
- func MakePkEndorserWithPem(keyPem []byte, hashType crypto.HashType, orgId string, payload *common.Payload) (*common.EndorsementEntry, error)
- func NewEndorser(orgId string, certPem []byte, sig []byte) *common.EndorsementEntry
- func NewEndorserWithMemberType(orgId string, memberInfo []byte, memberType accesscontrol.MemberType, ...) *common.EndorsementEntry
- func NewPayload(opts ...PayloadOption) *commonPb.Payload
- func NewPkEndorser(orgId string, pk []byte, sig []byte) *common.EndorsementEntry
- func ParseCert(crtPEM []byte) (*bcx509.Certificate, error)
- func ReadHibeParamsWithFilePath(hibeParamsFilePath string) ([]byte, error)
- func ReadHibePrvKeysWithFilePath(hibePrvKeyFilePath string) ([]byte, error)
- func SignPayload(privateKey crypto.PrivateKey, cert *bcx509.Certificate, ...) ([]byte, error)
- func SignPayloadBytes(privateKey crypto.PrivateKey, cert *bcx509.Certificate, payloadBytes []byte) ([]byte, error)
- func SignPayloadBytesWithHashType(privateKey crypto.PrivateKey, hashType crypto.HashType, payloadBytes []byte) ([]byte, error)
- func SignPayloadWithHashType(privateKey crypto.PrivateKey, hashType crypto.HashType, ...) ([]byte, error)
- func SignPayloadWithPath(keyFilePath, crtFilePath string, payload *common.Payload) ([]byte, error)
- func SignPayloadWithPkPath(keyFilePath, hashType string, payload *common.Payload) ([]byte, error)
- func U64ToBytes(i uint64) []byte
- type ChainClientConfigModel
- type Logger
- type PayloadOption
- func AddParameter(parameter *commonPb.KeyValuePair) PayloadOption
- func WithChainId(chainId string) PayloadOption
- func WithContractName(contractName string) PayloadOption
- func WithExpirationTime(expirationTime int64) PayloadOption
- func WithLimit(limit *commonPb.Limit) PayloadOption
- func WithMethod(method string) PayloadOption
- func WithParameters(parameters []*commonPb.KeyValuePair) PayloadOption
- func WithSequence(sequence uint64) PayloadOption
- func WithTimestamp(timestamp int64) PayloadOption
- func WithTxId(txId string) PayloadOption
- func WithTxType(txType commonPb.TxType) PayloadOption
- type TlsConfig
Constants ¶
const ( // SUCCESS ContractResult success code SUCCESS uint32 = 0 // Separator chainmker hex ca Separator = byte(202) )
const ( HibeMsgKey = "hibe_msg" HibeMsgIdKey = "tx_id" HibeMsgCipherTextKey = "CT" HibeParamsKey = "org_id" HibeParamsValueKey = "params" )
hibe msg's Keys
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
const ( // ArchiveConfig consts MysqlDBNamePrefix = "cm_archived_chain" MysqlTableNamePrefix = "t_block_info" RowsPerBlockInfoTable = 100000 )
nolint
Variables ¶
This section is empty.
Functions ¶
func BytesToI64 ¶
BytesToI64 bytes to int64 in little endian
func BytesToU64 ¶
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 ¶
Exists returns a boolean indicating whether the error is known to report that a file or directory already exists.
func GetCertificateId ¶
GetCertificateId get cert id from cert pem
func GetCertificateIdFromDER ¶
GetCertificateIdFromDER get cert id from cert der
func GetNanoByTimestampTxId ¶ added in v2.2.1
GetNanoByTimestampTxId validate and parse 160 ... 223 22
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
GetTimestampTxIdByNano nanosecond
func IsArchived ¶
func IsArchived(txStatusCode common.TxStatusCode) bool
IsArchived returns a boolean indicating whether is archived by txStatusCode in common.TxStatusCode
func IsArchivedString ¶
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 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 ¶
ReadHibeParamsWithFilePath Returns the serialized byte array of hibeParams
func ReadHibePrvKeysWithFilePath ¶
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
SignPayloadWithPath sign payload with specified key/cert file path
func SignPayloadWithPkPath ¶ added in v2.1.0
SignPayloadWithPkPath sign payload with specified key file path
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 ¶
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 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 WithTxType ¶
func WithTxType(txType commonPb.TxType) PayloadOption
WithTxType set TxType of payload