utils

package
v0.0.0-...-cc4b867 Latest Latest
Warning

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

Go to latest
Published: Jul 27, 2022 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Overview

Copyright (C) THL A29 Limited, a Tencent company. All rights reserved.

SPDX-License-Identifier: Apache-2.0

Copyright (C) THL A29 Limited, a Tencent company. All rights reserved.

SPDX-License-Identifier: Apache-2.0

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"

	// 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"

	// 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"
)

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)

func BytesToU64

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

func CheckProposalRequestResp

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

func DecryptHibeTx

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

func Exists

func Exists(path string) bool

func GetCertificateId

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

func GetCertificateIdFromDER

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

func GetNanoByTimestampTxId

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

GetNanoByTimestampTxId validate and parse 160 ... 223 22

func GetRandTxId

func GetRandTxId() string

func GetTimestampTxId

func GetTimestampTxId() string

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

func GetTimestampTxIdByNano

func GetTimestampTxIdByNano(nano int64) string

GetTimestampTxIdByNano nanosecond

func I64ToBytes

func I64ToBytes(i int64) []byte

func InitConfig

func InitConfig(confPath string) error

func IsArchived

func IsArchived(txStatusCode common.TxStatusCode) bool

func IsArchivedString

func IsArchivedString(txStatusCode string) bool

func MakeEndorser

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

func MakeEndorserWithPath

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

func MakeEndorserWithPathAndP11Handle

func MakeEndorserWithPathAndP11Handle(keyFilePath, crtFilePath string, p11Handle *pkcs11.P11Handle,
	payload *common.Payload) (*common.EndorsementEntry, error)

func MakeEndorserWithPem deprecated

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

Deprecated: This function will be deleted when appropriate. Please use MakeEndorser

func MakePkEndorserWithPath

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

func MakePkEndorserWithPem deprecated

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

Deprecated: This function will be deleted when appropriate. Please use MakeEndorser

func NewEndorser deprecated

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

Deprecated: This function will be deleted when appropriate. Please use NewEndorserWithMemberType

func NewEndorserWithMemberType

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

func NewPayload

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

func NewPkEndorser

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

func ParseCert

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

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 deprecated

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

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

func SignPayloadBytes deprecated

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

Deprecated: This function will be deleted when appropriate. Please use SignPayloadBytesWithHashType

func SignPayloadBytesWithHashType

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

func SignPayloadWithHashType

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

func SignPayloadWithPath

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

func SignPayloadWithPkPath

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

func U64ToBytes

func U64ToBytes(i uint64) []byte

Types

type ChainClientConfigModel

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

Config global ChainClientConfigModel

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{})
}

type PayloadOption

type PayloadOption func(*commonPb.Payload)

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

Jump to

Keyboard shortcuts

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