utils

package module
v2.3.6 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2024 License: Apache-2.0 Imports: 45 Imported by: 75

Documentation

Index

Constants

View Source
const (
	// NativePrefix black list profix
	NativePrefix = "vm-native"
	// Violation black list message
	Violation = "该交易违规,内容已屏蔽。"
)
View Source
const (
	// Separator split the contract and method
	Separator = ":"
	// PrefixContractInfo prefix of contract info
	PrefixContractInfo = "Contract:"
	// PrefixContractByteCode prefix of contract bytecode
	PrefixContractByteCode = "ContractByteCode:"
	// PrefixContractMethodPayer prefix of contract method's payer address
	PrefixContractMethodPayer = "Payer:"
)
View Source
const (
	// DPosOrgId DPoS org id
	DPosOrgId = "dpos_org_id"
)
View Source
const DecBase = 10

DecBase 10

View Source
const (
	// KLV_LENGTH_SIZE 4
	KLV_LENGTH_SIZE = 4
)
View Source
const TopicTableColumnDdl = `` /* 494-byte string literal not displayed */

TopicTableColumnDdl describe topic table column

View Source
const TopicTableIndex = `` /* 281-byte string literal not displayed */

TopicTableIndex describe topic table index

View Source
const TopicTableUniqueKey = `UNIQUE KEY unique_index(chain_id,block_height,tx_id,event_index)`

TopicTableUniqueKey describe topic table unique key

Variables

View Source
var (
	// OidKeyBag oid key bag
	OidKeyBag = asn1.ObjectIdentifier{1, 2, 840, 113549, 1, 12, 10, 1, 1}
)

Functions

func AddPrefix added in v2.3.0

func AddPrefix(origin string, prefixs []string) string

AddPrefix add prefix to origin string, use delimiter :

func BinaryToUint32

func BinaryToUint32(in []byte) (uint32, error)

BinaryToUint32 binary to uint32

func CalcBlockHash

func CalcBlockHash(hashType string, b *commonPb.Block) ([]byte, error)

CalcBlockHash calculate block hash

func CalcDagHash

func CalcDagHash(hashType string, dag *commonPb.DAG) ([]byte, error)

CalcDagHash calculate DAG hash

func CalcPartialBlockHash

func CalcPartialBlockHash(hashType string, b *commonPb.Block) ([]byte, error)

CalcPartialBlockHash calculate partial block bytes hash contains Header without BlockHash, ConsensusArgs, Signature

func CalcRWSetHash

func CalcRWSetHash(hashType string, set *commonPb.TxRWSet) ([]byte, error)

CalcRWSetHash calculate read-write set hash return (nil, nil) if read-write set is nil

func CalcRWSetRoot

func CalcRWSetRoot(hashType string, txs []*commonPb.Transaction) ([]byte, error)

CalcRWSetRoot calculate txs' read-write set root hash, following the tx order in txs

func CalcResultBytes

func CalcResultBytes(result *commonPb.Result) ([]byte, error)

CalcResultBytes get bytearray of result

func CalcTxHash

func CalcTxHash(hashType string, t *commonPb.Transaction) ([]byte, error)

CalcTxHash calculate transaction hash, include tx.Payload, tx.signature, tx.Payload, tx.Result

func CalcTxHashWithVersion added in v2.3.0

func CalcTxHashWithVersion(hashType string, t *commonPb.Transaction, version int) ([]byte, error)

CalcTxHashWithVersion use version to judge if set tx gasUsed to zero when calc tx hash

func CalcTxRequestHash

func CalcTxRequestHash(hashType string, t *commonPb.Transaction) ([]byte, error)

CalcTxRequestHash calculate hash of transaction request

func CalcTxResultHash

func CalcTxResultHash(hashType string, result *commonPb.Result) ([]byte, error)

CalcTxResultHash calculate hash of transaction result

func CalcTxVerifyWorkers

func CalcTxVerifyWorkers(txCount int) int

CalcTxVerifyWorkers calculate work size of transaction verify

func CalcUnsignedTxBytes

func CalcUnsignedTxBytes(t *commonPb.Transaction) ([]byte, error)

CalcUnsignedTxBytes calculate unsigned transaction bytes [request payload bytes]

func CalcUnsignedTxRequestBytes

func CalcUnsignedTxRequestBytes(txReq *commonPb.TxRequest) ([]byte, error)

CalcUnsignedTxRequestBytes calculate unsigned transaction request bytes

func CanProposeEmptyBlock

func CanProposeEmptyBlock(consensusType consensusPb.ConsensusType) bool

CanProposeEmptyBlock can empty blocks be packed

func CertToAddrInt added in v2.3.0

func CertToAddrInt(cert *x509.Certificate, addrType config.AddrType) (*evmutils.Int, error)

CertToAddrInt create big.Int address by certificate

func CertToAddrStr added in v2.3.0

func CertToAddrStr(cert *x509.Certificate, addrType config.AddrType) (string, error)

CertToAddrStr create string address by certificate

func CheckChainIdFormat

func CheckChainIdFormat(chainId string) bool

CheckChainIdFormat check chain id format

func CheckContractNameFormat

func CheckContractNameFormat(name string) bool

CheckContractNameFormat check contract name format

func CheckEvmAddressFormat

func CheckEvmAddressFormat(addr string) bool

CheckEvmAddressFormat check evm address format

func CheckRootCertificate

func CheckRootCertificate(certPEM string) (bool, error)

CheckRootCertificate check the root certificate

func CheckTxIDFormat

func CheckTxIDFormat(txID string) bool

CheckTxIDFormat check tx id format

func CheckZxlAddrFormat added in v2.3.1

func CheckZxlAddrFormat(addr string) bool

CheckZxlAddrFormat check evm address format

func CreateGenesis

func CreateGenesis(cc *configPb.ChainConfig) (*commonPb.Block, []*commonPb.TxRWSet, error)

CreateGenesis create genesis block (with read-write set) based on chain config

func CurrentTimeMillisSeconds

func CurrentTimeMillisSeconds() int64

CurrentTimeMillisSeconds return current unix timestamp in milliseconds

func CurrentTimeSeconds

func CurrentTimeSeconds() int64

CurrentTimeSeconds return current unix timestamp in seconds

func DispatchTxVerifyTask

func DispatchTxVerifyTask(txs []*commonPb.Transaction) map[int][]*commonPb.Transaction

DispatchTxVerifyTask dispatch transaction verify task

func FilterBlacklistTxs added in v2.3.3

func FilterBlacklistTxs(txs []*commonPb.Transaction) []*commonPb.Transaction

FilterBlacklistTxs filter transactions with blacklist

func FilterBlockBlacklistEvents added in v2.3.3

func FilterBlockBlacklistEvents(events []*commonPb.ContractEvent, chainId string) []*commonPb.ContractEvent

FilterBlockBlacklistEvents filter events in blacklist tx id

func FilterBlockBlacklistTxRWSet added in v2.3.3

func FilterBlockBlacklistTxRWSet(txRWSet []*commonPb.TxRWSet, chainId string) (txRWSetNew []*commonPb.TxRWSet)

FilterBlockBlacklistTxRWSet filter txRWSet in blacklist tx id

func FilterBlockBlacklistTxs added in v2.3.3

func FilterBlockBlacklistTxs(block *commonPb.Block) *commonPb.Block

FilterBlockBlacklistTxs filter transactions with blacklist

func FilterBlockTxs

func FilterBlockTxs(reqSenderOrgId string, block *commonPb.Block) *commonPb.Block

FilterBlockTxs filter transactions with given sender org id

func FormatBlock

func FormatBlock(b *commonPb.Block) string

FormatBlock format block into string

func FormatRWSet

func FormatRWSet(set *commonPb.TxRWSet) string

FormatRWSet format rwset

func GZipCompressBytes

func GZipCompressBytes(data []byte) ([]byte, error)

GZipCompressBytes compress bytes with GZip(BestSpeed mode).

func GZipDeCompressBytes

func GZipDeCompressBytes(data []byte) ([]byte, error)

GZipDeCompressBytes decompress bytes with GZip.

func GenerateCreateTopicTableDdl

func GenerateCreateTopicTableDdl(t *commonPb.ContractEvent, chainId string) string

GenerateCreateTopicTableDdl generate create topic table

func GenerateInstallContractPayload

func GenerateInstallContractPayload(contractName, version string, runtimeType commonPb.RuntimeType, bytecode []byte,
	initParameters []*commonPb.KeyValuePair) (*commonPb.Payload, error)

GenerateInstallContractPayload generate install contract payload

func GenerateSaveBlockHeightWithTopicDdl

func GenerateSaveBlockHeightWithTopicDdl(t *commonPb.ContractEvent, chainId string, blockHeight uint64) string

GenerateSaveBlockHeightWithTopicDdl generate save block height with topic

func GenerateSaveContractEventDdl

func GenerateSaveContractEventDdl(t *commonPb.ContractEvent, chainId string, blockHeight uint64, eventIdx int) string

GenerateSaveContractEventDdl generate save contract event

func GenerateUpdateBlockHeightIndexDdl

func GenerateUpdateBlockHeightIndexDdl(blockHeight uint64) string

GenerateUpdateBlockHeightIndexDdl generate update block height index

func GetBlockVersion added in v2.3.2

func GetBlockVersion(cfgVersion string) uint32

GetBlockVersion 根据vX.Y.Z形势的字符串转换为int类型的BlockVersion @param cfgVersion @return uint32

func GetCertHash

func GetCertHash(_ string, userCrtPEM []byte, hashType string) ([]byte, error)

GetCertHash get certificate hash

func GetCertificateId

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

GetCertificateId get certificate id

func GetCertificateIdFromDER

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

GetCertificateIdFromDER get certificate id from DER

func GetCertificateIdHex

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

GetCertificateIdHex on input a certificate in PEM format, a hash algorithm(should be the one in chain configuration), output the identity of the certificate in the form of a string (under hexadecimal encoding)

func GetConsensusArgsFromBlock

func GetConsensusArgsFromBlock(block *commonPb.Block) (*consensusPb.BlockHeaderConsensusArgs, error)

GetConsensusArgsFromBlock get args from block

func GetContractByName

func GetContractByName(readObject func(contractName string, key []byte) ([]byte, error), name string) (
	*commonPb.Contract, error)

GetContractByName get contract by name

func GetContractByteCodeDbKey

func GetContractByteCodeDbKey(contractName string) []byte

GetContractByteCodeDbKey get contract byte code db key

func GetContractBytecode

func GetContractBytecode(readObject func(contractName string, key []byte) ([]byte, error), name string) (
	[]byte, error)

GetContractBytecode get contract bytecode

func GetContractDbKey

func GetContractDbKey(contractName string) []byte

GetContractDbKey get contract db key

func GetContractMethodPayerDbKey added in v2.3.4

func GetContractMethodPayerDbKey(contractName string, method string) []byte

GetContractMethodPayerDbKey return the key of contract + method => payer mapping

func GetContractMethodPayerPK added in v2.3.4

func GetContractMethodPayerPK(snapshot protocol.Snapshot, contractName string, method string) ([]byte, []byte, error)

GetContractMethodPayerPK return a payer public key of invoking contract

func GetContractMethodPayerPKFromAC added in v2.3.4

func GetContractMethodPayerPKFromAC(ac protocol.AccessControlProvider,
	contractName string, method string) (
	[]byte, []byte, error)

GetContractMethodPayerPKFromAC return a payer public key of invoking contract

func GetIntAddrFromMember added in v2.3.0

func GetIntAddrFromMember(member protocol.Member, addrType config.AddrType) (*evmutils.Int, error)

GetIntAddrFromMember calculate Int address from protocol member

func GetIntAddrFromPbMember added in v2.3.0

func GetIntAddrFromPbMember(pbMember *acPb.Member, addrType config.AddrType, hashType crypto.HashType) (*evmutils.Int,
	error)

GetIntAddrFromPbMember calculate Int address from pb member

func GetMemberPubKeySA

func GetMemberPubKeySA(member *acPb.Member, getter MemberGetter) ([]byte, uint32)

GetMemberPubKeySA get member public key

func GetNodeUidFromAddr

func GetNodeUidFromAddr(addr string) (string, error)

GetNodeUidFromAddr get protocol.NodeUId from node's address

func GetRandTxId

func GetRandTxId() string

GetRandTxId return hex string format random transaction id with length = 64

func GetRoleFromTx

func GetRoleFromTx(tx *commonPb.Transaction, ac protocol.AccessControlProvider) (protocol.Role, error)

GetRoleFromTx get role from tx

func GetSqlStatementCount

func GetSqlStatementCount(sql string) int

GetSqlStatementCount 判断一个sql字符串是由多少条独立的SQL语句组成

func GetSqlTableName

func GetSqlTableName(sql string) []string

GetSqlTableName 获得SQL中使用到的表名,如果带有dbName.tableName,那么返回完整的dbName.tableName

func GetStrAddrFromMember added in v2.3.0

func GetStrAddrFromMember(member protocol.Member, addrType config.AddrType) (string, error)

GetStrAddrFromMember calculate string address from protocol member

func GetStrAddrFromPbMember added in v2.3.0

func GetStrAddrFromPbMember(pbMember *acPb.Member, addrType config.AddrType, hashType crypto.HashType) (string, error)

GetStrAddrFromPbMember calculate string address from pb Member

func GetTimestampTxId added in v2.2.2

func GetTimestampTxId() string

GetTimestampTxId return hex string format random transaction id with length = 64 GetTimestampTxId by current time, see: GetTimestampTxIdByNano eg: 687dca1d9c4fdf1652fdfc072182654f53622c496aa94c05b47d34263cd99ec9

func GetTimestampTxIdByNano added in v2.2.2

func GetTimestampTxIdByNano(nano int64) string

GetTimestampTxIdByNano nanosecond TODO TxId is generated linearly according to Nano

func GetTxIdWithSeed

func GetTxIdWithSeed(seed int64) string

GetTxIdWithSeed return tx-id with seed

func GetTxIds

func GetTxIds(txs []*commonPb.Transaction) []string

GetTxIds get tx ids

func GetTxResourceName added in v2.3.4

func GetTxResourceName(tx *commonPb.Transaction) string

GetTxResourceName return the resource name this tx want to operate

func HasDPosTxWritesInHeader

func HasDPosTxWritesInHeader(block *commonPb.Block, chainConf protocol.ChainConf) bool

HasDPosTxWritesInHeader check if header has DPoS tx writes

func IsAllBlank

func IsAllBlank(args ...interface{}) bool

IsAllBlank args type only string/[]byte

func IsAnyBlank

func IsAnyBlank(args ...interface{}) bool

IsAnyBlank args type only string/[]byte

func IsCertManagementTx added in v2.3.0

func IsCertManagementTx(tx *commonPb.Transaction) bool

IsCertManagementTx the transaction is a cert management transaction or not

func IsConfBlock

func IsConfBlock(block *commonPb.Block) bool

IsConfBlock is it a configuration block

func IsConfigTx

func IsConfigTx(tx *commonPb.Transaction) bool

IsConfigTx the transaction is a config transaction or not separate blocks are required

func IsContractManagementTx added in v2.3.0

func IsContractManagementTx(tx *commonPb.Transaction) bool

IsContractManagementTx the transaction is a contract management transaction or not

func IsContractMgmtBlock

func IsContractMgmtBlock(b *commonPb.Block) bool

IsContractMgmtBlock check is contract management block

func IsContractMgmtTx

func IsContractMgmtTx(tx *commonPb.Transaction) bool

IsContractMgmtTx 是否是合约安装、升级的交易

func IsDagEqual added in v2.3.0

func IsDagEqual(dag1 *commonPb.DAG, dag2 *commonPb.DAG) (bool, error)

IsDagEqual compare two DAG by bytes

func IsEmptyBlock

func IsEmptyBlock(block *commonPb.Block) error

IsEmptyBlock is it a empty block

func IsManageContractAsConfigTx

func IsManageContractAsConfigTx(tx *commonPb.Transaction, enableSqlDB bool) bool

IsManageContractAsConfigTx Whether the Manager Contract is considered a configuration transaction

func IsManagementTx added in v2.2.0

func IsManagementTx(tx *commonPb.Transaction) bool

IsManagementTx the transaction is a management transaction or not separate blocks are required

func IsMultiSignManagementTx added in v2.3.0

func IsMultiSignManagementTx(tx *commonPb.Transaction) bool

IsMultiSignManagementTx the transaction is a multi sign management transaction or not

func IsNativeContract

func IsNativeContract(contractName string) bool

IsNativeContract return is native contract name

func IsNativeTx added in v2.2.0

func IsNativeTx(tx *commonPb.Transaction) (isNative bool, contractName string)

IsNativeTx check tx is a native contract invoke tx

func IsPubKeyManagementTx added in v2.3.0

func IsPubKeyManagementTx(tx *commonPb.Transaction) bool

IsPubKeyManagementTx the transaction is a pub key management transaction or not

func IsValidConfigTx

func IsValidConfigTx(tx *commonPb.Transaction) bool

IsValidConfigTx the transaction is a valid config transaction or not

func NameToAddrInt added in v2.3.0

func NameToAddrInt(name string, addrType config.AddrType, blockVersion uint32) (*evmutils.Int, error)

NameToAddrInt create big.Int address by name

func NameToAddrStr added in v2.3.0

func NameToAddrStr(name string, addrType config.AddrType, blockVersion uint32) (string, error)

NameToAddrStr create string address by name

func ParseCert

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

ParseCert convert bytearray to certificate

func ParsePkFromPbMember added in v2.3.0

func ParsePkFromPbMember(member *acPb.Member) (crypto.PublicKey, error)

ParsePkFromPbMember parse public key from member

func PkToAddrInt added in v2.3.0

func PkToAddrInt(pk crypto.PublicKey, addrType config.AddrType, hashType crypto.HashType) (*evmutils.Int, error)

PkToAddrInt create big.Int address by pk

func PkToAddrStr added in v2.3.0

func PkToAddrStr(pk crypto.PublicKey, addrType config.AddrType, hashType crypto.HashType) (string, error)

PkToAddrStr crete string address by pk

func RearrangeRWSet added in v2.3.0

func RearrangeRWSet(block *commonPb.Block, rwSetMap map[string]*commonPb.TxRWSet) []*commonPb.TxRWSet

RearrangeRWSet rearrange rwSetMap into slice by block.Txs order

func SignBlock

func SignBlock(hashType string, singer protocol.SigningMember, b *commonPb.Block) ([]byte, []byte, error)

SignBlock sign the block (in fact, here we sign block hash...) with signing member return hash bytes and signature bytes

func ToCamelCase

func ToCamelCase(field string) string

ToCamelCase as: abc_def -> AbcDef

func Uint32ToBinary

func Uint32ToBinary(in uint32) []byte

Uint32ToBinary uint32 to binary

func UnmarshalJsonStrKV2KVPairs

func UnmarshalJsonStrKV2KVPairs(jsonStr string) ([]*commonpb.KeyValuePair, error)

UnmarshalJsonStrKV2KVPairs 传入一个json字符串,该字符串key value都是string,转换为系统需要的KeyValuePair列表

func UpdateField

func UpdateField(params map[string][]byte, key string, config interface{}) (bool, error)

UpdateField set the key in data by params[key] to struct public field return if the field has been changed such as key->field: block_height -> BlockHeight

func VerifyBlockSig

func VerifyBlockSig(hashType string, b *commonPb.Block, ac protocol.AccessControlProvider) (bool, error)

VerifyBlockSig verify block proposer and signature

func VerifyCertIssue

func VerifyCertIssue(caCerts [][]byte, intermediateCerts [][]byte, cert []byte) error

VerifyCertIssue verify that the certificate is issued by the root/intermediate certificate caCerts caCert list, caCert means cert []byte(string)

func VerifyTxWithoutPayload

func VerifyTxWithoutPayload(tx *commonPb.Transaction, chainId string, ac protocol.AccessControlProvider,
	blockVersion uint32) error

VerifyTxWithoutPayload verify a transaction with access control provider. The payload of the transaction will not be verified.

Types

type BigInteger

type BigInteger struct {
	Value *big.Int
}

BigInteger wrapper for big.Int

func NewBigInteger

func NewBigInteger(value string) *BigInteger

NewBigInteger create a BigInteger

func NewZeroBigInteger

func NewZeroBigInteger() *BigInteger

NewZeroBigInteger create a BigInteger of zero

func Sub

func Sub(x, y *BigInteger) *BigInteger

Sub subtracts two big integer

func Sum

func Sum(x, y *BigInteger) *BigInteger

Sum adds two big integer

func (*BigInteger) Add

func (x *BigInteger) Add(y *BigInteger)

Add adds y to x

func (*BigInteger) Cmp

func (x *BigInteger) Cmp(y *BigInteger) int

Cmp compares x and y and returns:

-1 if x <  y
 0 if x == y
+1 if x >  y

func (*BigInteger) String

func (x *BigInteger) String() string

String gets string

func (*BigInteger) Sub

func (x *BigInteger) Sub(y *BigInteger)

Sub subs y from x

type BlockFingerPrint

type BlockFingerPrint string

BlockFingerPrint alias for string

func CalcBlockFingerPrint

func CalcBlockFingerPrint(block *commonPb.Block) BlockFingerPrint

CalcBlockFingerPrint since the block has not yet formed, snapshot uses fingerprint as the possible unique value of the block

func CalcBlockFingerPrintWithoutTx added in v2.2.0

func CalcBlockFingerPrintWithoutTx(block *commonPb.Block) BlockFingerPrint

CalcBlockFingerPrintWithoutTx 排除掉Tx的因素,计算Block的指纹,这样计算出来不管Block如何包含Tx,其指纹不变

func CalcFingerPrint

func CalcFingerPrint(chainId string, height uint64, timestamp int64,
	proposer, preHash, txRoot, dagHash, rwSetRoot []byte) BlockFingerPrint

CalcFingerPrint calculate finger print

type ERC20Config

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

ERC20Config for DPoS

type MemberGetter

type MemberGetter interface {
	// GetFullMemberInfo 根据CERT_HASH获得完整的Cert,根据DID获得DID Document
	GetFullMemberInfo(memberId []byte, mtype acPb.MemberType) ([]byte, error)
}

MemberGetter member getter interface

type StakeConfig

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

StakeConfig defines stake config

type TEEProof

type TEEProof struct {
	VerificationKey    bccrypto.PublicKey
	VerificationKeyPEM []byte
	EncryptionKey      bccrypto.EncryptKey
	EncryptionKeyPEM   []byte
	Certificate        *bcx509.Certificate
	CertificateDER     []byte
	Report             []byte
	Challenge          []byte
	Signature          []byte
}

TEEProof TEE proof

func AttestationVerify

func AttestationVerify(proof []byte, certOpts bcx509.VerifyOptions, reportFromChain []byte) (bool, *TEEProof, error)

AttestationVerify attestation verify

func AttestationVerifyComponents

func AttestationVerifyComponents(challenge, signature, report []byte,
	certificate *bcx509.Certificate, verificationKey bccrypto.PublicKey,
	encryptionKey bccrypto.EncryptKey, certOpts bcx509.VerifyOptions) (bool, *TEEProof, error)

AttestationVerifyComponents attestation verify components

func GrapheneAttestationVerify

func GrapheneAttestationVerify(proof *tee.RemoteAttestationResponse, certOpts bcx509.VerifyOptions,
	reportFromChain []byte) (bool, *TEEProof, error)

GrapheneAttestationVerify graphene attestation verify

Directories

Path Synopsis
gas

Jump to

Keyboard shortcuts

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