package executor

import "fmt"

/*
 * 用户合约存取kv数据时，key值前缀需要满足一定规范
 * 即key = keyPrefix + userKey
 * 需要字段前缀查询时，使用’-‘作为分割符号
 */

const (
	//KeyPrefixStateDB state db key必须前缀
	KeyPrefixStateDB = "mavl-broker-"
	//KeyPrefixLocalDB local db的key必须前缀
	KeyPrefixLocalDB = "LODB-broker-"

	innerMeta           = "inner-meta"
	outterMeta          = "outter-meta"
	callbackMeta        = "callback-meta"
	dstRollbackMeta     = "dst-rollback-meta"
	whiteList           = "white-list"
	//adminList           = "admin-list"
	passed              = "1"
	rejected            = "2"
	delimiter           = "&"
	bxhID               = "bxh-id"
	//appchainID          = "appchain-id"
	brokerAdmin          = "broker-admin"
)
//跨链协议版本信息
func BxhIDKey()[]byte{
	return []byte(KeyPrefixStateDB + bxhID)
}
//状态数据库中存储innermeta信息
func calInnerMetaKey() []byte {
	key := fmt.Sprintf("%s"+":%s", KeyPrefixStateDB, innerMeta)
	return []byte(key)
}
//状态数据库中存储outtermeta信息
func calOutterMetaKey() []byte {
	key := fmt.Sprintf("%s"+":%s", KeyPrefixStateDB, outterMeta)
	return []byte(key)
}

func calCallBackMetaKey() []byte {
	key := fmt.Sprintf("%s"+":%s", KeyPrefixStateDB, callbackMeta)
	return []byte(key)
}

func calDstRollBackMetaKey() []byte {
	key := fmt.Sprintf("%s"+":%s", KeyPrefixStateDB, dstRollbackMeta)
	return []byte(key)
}
//生成service key
func genServicePair(from, to string) string {
	return fmt.Sprintf("%s-%s",from, to)
}

func calServicePair(from,to string,index uint64)[]byte{
	 key :=fmt.Sprintf("%s%s-%s-%016d",KeyPrefixStateDB,from, to,index)
	return []byte(key)
}


func calEventKey(servicePair string,index uint64)[]byte{
	key :=fmt.Sprintf("%s%s-%016d",KeyPrefixStateDB,servicePair,index)
	return []byte(key)
}


func outMsgKey(to string, index uint64) []byte {
	return []byte(fmt.Sprintf("%sout-msg-%s-%016d",KeyPrefixStateDB, to, index))
}

func inMsgKey(from string, index uint64) []byte {
	return []byte(fmt.Sprintf("%sin-msg-%s-%016d",KeyPrefixStateDB,from, index))
}