base

package
v1.0.10 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	AssetApiCreate           = "/xasset/horae/v1/create"
	AssetApiAlter            = "/xasset/horae/v1/alter"
	AssetApiPublish          = "/xasset/horae/v1/publish"
	AssetApiQueryAsset       = "/xasset/horae/v1/query"
	AssetApiGrant            = "/xasset/horae/v1/grant"
	AssetApiFreeze           = "/xasset/horae/v1/freeze"
	AssetApiConsume          = "/xasset/horae/v1/consume"
	AssetApiTransfer         = "/xasset/damocles/v1/transfer"
	AssetApiQueryShard       = "/xasset/horae/v1/querysds"
	AssetApiListShardsByAddr = "/xasset/horae/v1/listsdsbyaddr"
	AssetApiListAssetByAddr  = "/xasset/horae/v1/listastbyaddr"
	AssetListShardsByAsset   = "/xasset/horae/v1/listsdsbyast"
	AssetApiGetEvidenceInfo  = "/xasset/horae/v1/getevidenceinfo"
	AssetApiListDiffByAddr   = "/xasset/horae/v1/listdiffbyaddr"
	FileApiGetStoken         = "/xasset/file/v1/getstoken"
	ListAssetHistory         = "/xasset/horae/v1/history"

	SceneListShardByAddr = "/xasset/scene/v1/listsdsbyaddr"
	SceneQueryShard      = "/xasset/scene/v1/qrysdsinfo"
	SceneListDiffByAddr  = "/xasset/scene/v1/listdiffbyaddr"
)
View Source
const (
	// 微信支付
	PayByWechat = 1
	// 阿里支付
	PayByAli = 2
	// 特殊支付
	PayBySpecial = 9
)

支付渠道类型

View Source
const (
	// 需要修改为正确的配置
	TestAppId    = 0
	TestAK       = "xxx"
	TestSK       = "xxx"
	TestEndpoint = "http://120.48.16.137:8360"
)
View Source
const (
	// 最大范围
	MaxLimit = 50
)

列表分页范围限制

View Source
const (
	XassetErrNoSucc = 0
)

服务端相应错误码

Variables

View Source
var (
	ComErrParamInvalid        = errors.New("param invalid")
	ComErrAccountSignFailed   = errors.New("account sign failed")
	ComErrJsonMarFailed       = errors.New("json marhsal failed")
	ComErrRequsetFailed       = errors.New("send request failed")
	ComErrRespCodeErr         = errors.New("request resp code error")
	ComErrUnmarshalBodyFailed = errors.New("json unmarhsal body failed")
	ComErrServRespErrnoErr    = errors.New("server resp errno error")
	ComErrGenRequestFailed    = errors.New("generate http request failed")
	ComErrXassetSignFailed    = errors.New("xasser access sign failed")
	ComErrConfigErr           = errors.New("client config error")
)

常用错误

View Source
var (
	ErrParamInvalid      = errors.New("param invalid")
	ErrAssetInvalid      = errors.New("asset invalid, must be a positive integer")
	ErrAddressInvalid    = errors.New("address invalid, empty string")
	ErrUserIdInvalid     = errors.New("user id invalid, must be a positive integer")
	ErrAmountInvalid     = errors.New("amount invalid, must be a positive integer or a zero value")
	ErrPriceInvalid      = errors.New("price invalid, must be a positive integer or a zero value")
	ErrNilPointer        = errors.New("target paramater valid, nil pointer")
	ErrDescInvalid       = errors.New("target paramater invalid, empty string")
	ErrAssetTypeInvalid  = errors.New("type invalid, must between 1 to 4")
	ErrAlterInfo         = errors.New("alter info invalid")
	ErrAlterAssetInvalid = errors.New("param for altering invalid, must contain amount or valid asset info")
	ErrShardInvalid      = errors.New("shard invalid, must be a positive integer")
	ErrImgInvalid        = errors.New("imgs invalid")
	ErrEvidenceInvalid   = errors.New("evidence type invalid, must between 0 to 1")
	ErrBytesInvalid      = errors.New("bytes invalid, nil pointer")
	ErrStatusInvalid     = errors.New("status invalid")
)

Functions

func AccountValid

func AccountValid(account *auth.Account) error

func AddrValid

func AddrValid(addr string) error

func AlterAssetInfoValid

func AlterAssetInfoValid(p *AlterAssetInfo) error

func AmountInvalid

func AmountInvalid(amount int) error

func AssetIdValid

func AssetIdValid(assetId int64) error

func AssetTypeValid

func AssetTypeValid(t AssetType) error

func ByteValid

func ByteValid(b []byte) error

func CreateAssetInfoValid

func CreateAssetInfoValid(p *CreateAssetInfo) error

func DescValid

func DescValid(desc string) error

func EvidenceValid

func EvidenceValid(evidence int) error

func FileValid

func FileValid(files []string) error

func HasAssetType

func HasAssetType(t AssetType) bool

func HasDesc

func HasDesc(desc string) bool

func HasId

func HasId(id int64) bool

func HasImg

func HasImg(imgs []string) bool

func IdValid

func IdValid(id int64) error

func ImgValid

func ImgValid(imgs []string) error

func PriceInvalid added in v1.0.3

func PriceInvalid(price int64) error

func ShardIdValid

func ShardIdValid(id int64) error

func StatusValid added in v1.0.3

func StatusValid(status int) error

func TestGetXassetConfig

func TestGetXassetConfig() *config.XassetCliConfig

Types

type AccessInfo

type AccessInfo struct {
	Bucket       string `json:"bucket"`
	EndPoint     string `json:"endpoint"`
	ObjectPath   string `json:"object_path"`
	AK           string `json:"access_key_id"`
	SK           string `json:"secret_access_key"`
	SessionToken string `json:"session_token"`
	CreateTime   string `json:"createTime"`
	Expiration   string `json:"expiration"`
}

type AlterAssetInfo

type AlterAssetInfo struct {
	AssetCate AssetType `json:"asset_cate,omitempty"`
	Title     string    `json:"title,omitempty"`
	Thumb     []string  `json:"thumb,omitempty"`
	ShortDesc string    `json:"short_desc,omitempty"`
	ImgDesc   []string  `json:"img_desc,omitempty"`
	AssetUrl  []string  `json:"asset_url,omitempty"`
	LongDesc  string    `json:"long_desc,omitempty"`
	AssetExt  string    `json:"asset_ext,omitempty"`
	GroupId   int64     `json:"group_id,omitempty"`
}

/////// Alter Asset //////////

type AlterAssetParam

type AlterAssetParam struct {
	AssetId   int64           `json:"asset_id"`
	Price     int64           `json:"price,omitempty"`
	Amount    int             `json:"amount,omitempty"`
	FileHash  string          `json:"file_hash"`
	AssetInfo *AlterAssetInfo `json:"asset_info"`
	Account   *auth.Account   `json:"account"`
}

func (*AlterAssetParam) Valid

func (t *AlterAssetParam) Valid() error

AlterAssetParam be valid where has the amount or thr asset info to be altered.

type AssetType

type AssetType int

资产类型

const (

	// 1.艺术品
	AssetCateArt AssetType
	// 2.收藏品
	AssetCateCollect
	// 3.门票
	AssetCateTicket
	// 4.酒店
	AssetCateHotel
)

type BaseResp

type BaseResp struct {
	RequestId string `json:"request_id"`
	Errno     int    `json:"errno"`
	Errmsg    string `json:"errmsg"`
}

type ConsumeShardParam added in v1.0.4

type ConsumeShardParam struct {
	AssetId  int64         `json:"asset_id"`
	ShardId  int64         `json:"shard_id"`
	Nonce    int64         `json:"nonce"`
	UAddr    string        `json:"user_addr"`
	USign    string        `json:"user_sign"`
	UPKey    string        `json:"user_pkey"`
	CAccount *auth.Account `json:"create_account"`
}

//////// Consume Shard ////////////

func (*ConsumeShardParam) Valid added in v1.0.4

func (t *ConsumeShardParam) Valid() error

type CreateAssetInfo

type CreateAssetInfo struct {
	AssetCate AssetType `json:"asset_cate"`
	Title     string    `json:"title"`
	Thumb     []string  `json:"thumb"`
	ShortDesc string    `json:"short_desc"`
	ImgDesc   []string  `json:"img_desc"`
	AssetUrl  []string  `json:"asset_url"`
	LongDesc  string    `json:"long_desc,omitempty"`
	AssetExt  string    `json:"asset_ext,omitempty"`
	GroupId   int64     `json:"group_id,omitempty"`
}

/////// Create Asset ///////////

type CreateAssetParam

type CreateAssetParam struct {
	Price     int64            `json:"price,omitempty"`
	Amount    int              `json:"amount"`
	AssetInfo *CreateAssetInfo `json:"asset_info"`
	Account   *auth.Account    `json:"account"`
	UserId    int64            `json:"user_id,omitempty"`
	FileHash  string           `json:"file_hash,omitempty"`
}

func (*CreateAssetParam) Valid

func (t *CreateAssetParam) Valid() error

type CreateAssetResp

type CreateAssetResp struct {
	BaseResp
	AssetId int64 `json:"asset_id"`
}

type FreezeAssetParam added in v1.0.4

type FreezeAssetParam struct {
	AssetId int64         `json:"asset_id"`
	Account *auth.Account `json:"account"`
}

//////// Freeze Asset ////////////

func (*FreezeAssetParam) Valid added in v1.0.4

func (t *FreezeAssetParam) Valid() error

type GetEvidenceInfoParam

type GetEvidenceInfoParam struct {
	AssetId int64 `json:"asset_id"`
}

/////////// Get Evidence Info /////////////

func (*GetEvidenceInfoParam) Valid

func (t *GetEvidenceInfoParam) Valid() error

type GetEvidenceInfoResp

type GetEvidenceInfoResp struct {
	BaseResp
	CreateAddr string            `json:"create_addr"`
	TxId       string            `json:"tx_id"`
	FileHash   string            `json:"file_hash"`
	GhCertId   string            `json:"gh_cert_id"`
	AssetInfo  *HoraeAssetObject `json:"asset_info"`
	Ctime      int64             `json:"ctime"`
}

type GetStokenParam

type GetStokenParam struct {
	Account *auth.Account `json:"account"`
}

///// Gen Token /////////

func (*GetStokenParam) Valid

func (t *GetStokenParam) Valid() error

type GetStokenResp

type GetStokenResp struct {
	BaseResp
	AccessInfo *AccessInfo `json:"accessInfo"`
}

type GrantAssetParam

type GrantAssetParam struct {
	AssetId  int64         `json:"asset_id"`
	ShardId  int64         `json:"shard_id"`
	Price    int64         `json:"price,omitempty"`
	Account  *auth.Account `json:"account"`
	Addr     string        `json:"addr"`
	ToAddr   string        `json:"to_addr"`
	ToUserId int64         `json:"to_userid,omitempty"`
}

//////// Grant Asset /////////////

func (*GrantAssetParam) Valid

func (p *GrantAssetParam) Valid() error

type GrantAssetResp

type GrantAssetResp struct {
	BaseResp
	AssetId int64 `json:"asset_id"`
	ShardId int64 `json:"shard_id"`
}

type HistoryMeta added in v1.0.5

type HistoryMeta struct {
	AssetId int64  `json:"asset_id"`
	Type    int    `json:"type"`
	ShardId int64  `json:"shard_id"`
	Price   int64  `json:"price"`
	TxId    string `json:"tx_id"`
	From    string `json:"from"`
	To      string `json:"to"`
	Ctime   int64  `json:"ctime"`
}

type HoraeAssetObject

type HoraeAssetObject struct {
	AssetId   int64      `json:"asset_id"`
	AssetCate int        `json:"asset_cate"`
	Title     string     `json:"title"`
	Thumb     []ThumbMap `json:"thumb"`
	ShortDesc string     `json:"short_desc"`
}

type ListAssetHisParam added in v1.0.4

type ListAssetHisParam struct {
	AssetId int64 `json:"asset_id"`
	ShardId int64 `json:"shard_id"`
	Page    int   `json:"page"`
	Limit   int   `json:"limit"`
}

//////// Get History ////////////

func (*ListAssetHisParam) Valid added in v1.0.4

func (t *ListAssetHisParam) Valid() error

type ListAssetHistoryResp added in v1.0.4

type ListAssetHistoryResp struct {
	BaseResp
	List     []*HistoryMeta `json:"list"`
	TotalCnt int            `json:"total_cnt"`
	Cursor   string         `json:"cursor"`
	HasMore  int            `json:"has_more"`
}

type ListAssetsByAddrParam added in v1.0.3

type ListAssetsByAddrParam struct {
	Addr   string `json:"addr"`
	Status int    `json:"status"`
	Page   int    `json:"page"`
	Limit  int    `json:"limit"`
}

/////// List Assets By Address //////////

func (*ListAssetsByAddrParam) Valid added in v1.0.3

func (t *ListAssetsByAddrParam) Valid() error

type ListAssetsByAddrResp added in v1.0.5

type ListAssetsByAddrResp struct {
	BaseResp
	List     []*QueryAssetMeta `json:"list"`
	TotalCnt int               `json:"total_cnt"`
}

type ListDiffByAddrNode added in v1.0.10

type ListDiffByAddrNode struct {
	AssetId int64      `json:"asset_id"`
	ShardId int64      `json:"shard_id"`
	Operate int        `json:"operate"`
	Title   string     `json:"title"`
	Thumb   []ThumbMap `json:"thumb"`
	Ctime   int64      `json:"ctime"`
}

type ListDiffByAddrParam added in v1.0.10

type ListDiffByAddrParam struct {
	Addr string `json:"addr"`
	// 可选参数
	Limit  int    `json:"limit"`
	Cursor string `json:"cursor"`
	OpTyps string `json:"op_types"`
}

////////// listdiffbyaddr /////////////////

func (*ListDiffByAddrParam) Valid added in v1.0.10

func (t *ListDiffByAddrParam) Valid() error

type ListDiffByAddrResp added in v1.0.10

type ListDiffByAddrResp struct {
	BaseResp
	List    []*ListDiffByAddrNode `json:"list"`
	Cursor  string                `json:"cursor"`
	HasMore int                   `json:"has_more"`
}

type ListShardsByAddrParam

type ListShardsByAddrParam struct {
	Addr  string `json:"addr"`
	Page  int    `json:"page"`
	Limit int    `json:"limit"`
	// 可选
	AssetId int64 `json:"asset_id"`
}

/////// List Shard By Address //////////

func (*ListShardsByAddrParam) Valid

func (t *ListShardsByAddrParam) Valid() error

type ListShardsByAddrResp added in v1.0.5

type ListShardsByAddrResp struct {
	BaseResp
	List     []*QueryShardMeta `json:"list"`
	TotalCnt int               `json:"total_cnt"`
}

type ListShardsByAssetParam added in v1.0.3

type ListShardsByAssetParam struct {
	AssetId int64  `json:"asset_id"`
	Cursor  string `json:"cursor"`
	Limit   int    `json:"limit"`
}

/////// List Shards By Asset //////////

func (*ListShardsByAssetParam) Valid added in v1.0.3

func (t *ListShardsByAssetParam) Valid() error

type ListShardsByAssetResp added in v1.0.5

type ListShardsByAssetResp struct {
	BaseResp
	List    []*QueryShardMeta `json:"list"`
	Cursor  string            `json:"cursor"`
	HasMore int               `json:"has_more"`
}

type PublishAssetParam

type PublishAssetParam struct {
	AssetId    int64         `json:"asset_id"`
	Account    *auth.Account `json:"account"`
	IsEvidence int           `json:"is_evidence,omitempty"`
}

//////// Publish Asset ////////////

func (*PublishAssetParam) Valid

func (t *PublishAssetParam) Valid() error

type QueryAssetMeta

type QueryAssetMeta struct {
	AssetId    int64      `json:"asset_id"`
	GroupId    int64      `json:"group_id"`
	AssetCate  int        `json:"asset_cate"`
	Title      string     `json:"title"`
	Thumb      []ThumbMap `json:"thumb"`
	ShortDesc  string     `json:"short_desc"`
	LongDesc   string     `json:"long_desc"`
	ImgDesc    []string   `json:"img_desc"`
	AssetUrl   []string   `json:"asset_url"`
	AssetExt   string     `json:"asset_ext"`
	Price      int64      `json:"price"`
	Amount     int        `json:"amount"`
	Status     int        `json:"status"`
	CreateAddr string     `json:"create_addr"`
	Ctime      int64      `json:"ctime"`
	Mtime      int64      `json:"mtime"`
	TxId       string     `json:"tx_id"`
}

type QueryAssetParam

type QueryAssetParam struct {
	AssetId int64 `json:"asset_id"`
}

//////// Query Asset //////////

func (*QueryAssetParam) Valid

func (t *QueryAssetParam) Valid() error

type QueryAssetResp

type QueryAssetResp struct {
	BaseResp
	Meta *QueryAssetMeta `json:"meta"`
}

type QueryShardMeta

type QueryShardMeta struct {
	AssetId   int64           `json:"asset_id"`
	ShardId   int64           `json:"shard_id"`
	Price     int64           `json:"price"`
	OwnerAddr string          `json:"owner_addr"`
	Status    int             `json:"status"`
	TxId      string          `json:"tx_id"`
	AssetInfo *ShardAssetInfo `json:"asset_info"`
	Ctime     int64           `json:"ctime"`
}

type QueryShardParam

type QueryShardParam struct {
	AssetId int64 `json:"asset_id"`
	ShardId int64 `json:"shard_id"`
}

//////// Query Shard ////////////

func (*QueryShardParam) Valid

func (t *QueryShardParam) Valid() error

type QueryShardResp

type QueryShardResp struct {
	BaseResp
	Meta *QueryShardMeta `json:"meta"`
}

type RequestRes

type RequestRes struct {
	HttpCode int         `json:"http_code"`
	ReqUrl   string      `json:"req_url"`
	Header   http.Header `json:"header"`
	Body     string      `json:"body"`
}

///// General Client ///////

type SceneListDiffByAddrParam added in v1.0.10

type SceneListDiffByAddrParam struct {
	Addr  string `json:"addr"`
	Token string `json:"token"`
	// 可选参数
	Limit  int    `json:"limit"`
	Cursor string `json:"cursor"`
	OpTyps string `json:"op_types"`
}

////////// Scene listdiffbyaddr /////////////////

func (*SceneListDiffByAddrParam) Valid added in v1.0.10

func (t *SceneListDiffByAddrParam) Valid() error

type SceneListMeta added in v1.0.9

type SceneListMeta struct {
	AssetId int64      `json:"asset_id"`
	ShardId int64      `json:"shard_id"`
	Title   string     `json:"title"`
	Thumb   []ThumbMap `json:"thumb"`
}

type SceneListShardByAddrParam added in v1.0.9

type SceneListShardByAddrParam struct {
	Addr   string `json:"addr"`
	Token  string `json:"token"`
	Cursor string `json:"cursor"`
	Limit  int    `json:"limit"`
}

//////// Scene ListShardByAddr ////////////

func (*SceneListShardByAddrParam) Valid added in v1.0.9

func (t *SceneListShardByAddrParam) Valid() error

type SceneListShardByAddrResp added in v1.0.9

type SceneListShardByAddrResp struct {
	BaseResp
	List    []*SceneListMeta `json:"list"`
	Cursor  string           `json:"cursor"`
	HasMore int              `json:"has_more"`
}

type SceneQueryMeta added in v1.0.9

type SceneQueryMeta struct {
	AssetId    int64      `json:"asset_id"`
	ShardId    int64      `json:"shard_id"`
	OwnerAddr  string     `json:"owner_addr"`
	Status     int        `json:"status"`
	TxId       string     `json:"tx_id"`
	Ctime      int64      `json:"ctime"`
	JumpLink   string     `json:"jump_link"`
	Price      int64      `json:"price"`
	Title      string     `json:"title"`
	Thumb      []ThumbMap `json:"thumb"`
	AssetUrl   []string   `json:"asset_url"`
	ImgDesc    []string   `json:"img_desc"`
	ShortDesc  string     `json:"short_desc"`
	CreateAddr string     `json:"create_addr"`
}

type SceneQueryShardParam added in v1.0.9

type SceneQueryShardParam struct {
	Addr    string `json:"addr"`
	Token   string `json:"token"`
	AssetId int64  `json:"asset_id"`
	ShardId int64  `json:"shard_id"`
}

//////// Scene QueryShard ////////////

func (*SceneQueryShardParam) Valid added in v1.0.9

func (t *SceneQueryShardParam) Valid() error

type SceneQueryShardResp added in v1.0.9

type SceneQueryShardResp struct {
	BaseResp
	Meta *SceneQueryMeta `json:"meta"`
}

type ShardAssetInfo

type ShardAssetInfo struct {
	Title      string     `json:"title"`
	AssetCate  int        `json:"asset_cate"`
	Thumb      []ThumbMap `json:"thumb"`
	ShortDesc  string     `json:"short_desc"`
	CreateAddr string     `json:"create_addr"`
	GroupId    int64      `json:"group_id"`
}

type TestLogger

type TestLogger struct {
}

mock logger

func (*TestLogger) Debug

func (t *TestLogger) Debug(msg string, ctx ...interface{})

func (*TestLogger) Error

func (t *TestLogger) Error(msg string, ctx ...interface{})

func (*TestLogger) Info

func (t *TestLogger) Info(msg string, ctx ...interface{})

func (*TestLogger) Trace

func (t *TestLogger) Trace(msg string, ctx ...interface{})

func (*TestLogger) Warn

func (t *TestLogger) Warn(msg string, ctx ...interface{})

type ThumbMap

type ThumbMap struct {
	Urls   map[string]string `json:"urls"`
	Width  string            `json:"width"`
	Height string            `json:"height"`
}

type TransferAssetParam

type TransferAssetParam struct {
	AssetId  int64         `json:"asset_id"`
	ShardId  int64         `json:"shard_id"`
	Price    int64         `json:"price,omitempty"`
	Account  *auth.Account `json:"account"`
	Addr     string        `json:"addr"`
	ToAddr   string        `json:"to_addr"`
	ToUserId int64         `json:"to_userid,omitempty"`
}

//////// Transfer Asset //////////

func (*TransferAssetParam) Valid

func (p *TransferAssetParam) Valid() error

type UploadFileParam

type UploadFileParam struct {
	Account  *auth.Account `json:"account"`
	FileName string        `json:"file_name"`
	FilePath string        `json:"file_path"`
	DataByte []byte        `json:"data_byte"`
	Property string        `json:"property"`
}

////// Upload File ///////////// Account 创建资产区块链账户 FileName 文件名称 FilePath 文件绝对路径 DataByte 文件二进制串 Property 文件属性。例如图片类型文件,则为图片宽高,格式为 width_height 注意:文件路径和二进制串为二选一

func (*UploadFileParam) Valid

func (t *UploadFileParam) Valid() error

type UploadFileResp

type UploadFileResp struct {
	Link       string      `json:"link"`
	AccessInfo *AccessInfo `json:"accessInfo"`
}

type XassetBaseClient

type XassetBaseClient struct {
	Cfg    *config.XassetCliConfig
	Logger *logs.Logger
}

XassetBaseClient

func (*XassetBaseClient) GetConfig

func (t *XassetBaseClient) GetConfig() *config.XassetCliConfig

func (*XassetBaseClient) GetTarceId

func (t *XassetBaseClient) GetTarceId(header http.Header) string

func (*XassetBaseClient) InitClient

func (t *XassetBaseClient) InitClient(cfg *config.XassetCliConfig, logger logs.LogDriver) error

func (*XassetBaseClient) Post

func (t *XassetBaseClient) Post(uri, data string) (*RequestRes, error)

Jump to

Keyboard shortcuts

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