cregis_sdk_go

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2023 License: MIT Imports: 9 Imported by: 0

README

cregis-sdk-go

The sdk of cregis by golang is used to cregis server

Getting started

Prerequisites
  • Go: go version >=1.20
Getting SDK

With Go module support, simply add the following import

import "github.com/0xcregis/cregis-sdk-go"

to your code, and then go [build|run|test] will automatically fetch the necessary dependencies.

Otherwise, run the following Go command to install the sdk package:

$ go get -u github.com/0xcregis/cregis-sdk-go
Using SDK

First you need to import sdk package for using, one simplest example likes the follow example.go:

package main

import (
	"fmt"

	sdk "github.com/0xcregis/cregis-sdk-go"
)

func main() {
	c := sdk.NewClient("http://a0c1369e-12ec-467f-9989-7aba384a25e3.apple806.cc:81", "a4b0e563414a4e4dbeb407c89ce2f127", 1388205706190848)
	r, err := c.AddressLegal("195", "TXsmKpEuW7qWnXzJLGP9eDLvWPR2GRn1FS")
	if err != nil {
		fmt.Printf("err:%v", err.Error())
	} else {
		fmt.Printf("%+v", r)
	}
}

Learn more examples

Learn and practice more examples, please read the Test Case .

Documentation

See API documentation and descriptions for package.

Documentation

Index

Constants

View Source
const (
	URL_PREFIX     = "/api/v1"
	PAYOUT         = URL_PREFIX + "/payout"
	PAYOUT_QUERY   = URL_PREFIX + "/payout/query"
	ADDRESS_LEGAL  = URL_PREFIX + "/address/legal"
	ADDRESS_CREATE = URL_PREFIX + "/address/create"
	ADDRESS_INNER  = URL_PREFIX + "/address/inner"
	PROJECT_COINS  = URL_PREFIX + "/coins"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type API

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

func NewClient

func NewClient(url, apiKey string, pid int64) *API

NewClient user can create a client by the method *

url string host of cregis server
apiKey string special key to different users
pid int64 projectId

func (*API) AddressCreate

func (a *API) AddressCreate(chainId, callbackUrl, alias string) (*Result[ProjectAddress], error)

AddressCreate create an address to income *

chainId string code of blockchain
callbackUrl string set url to receive server event
alias  string nickname

func (*API) AddressInner

func (a *API) AddressInner(chainId, address string) (*Result[AddressInner], error)

AddressInner whether the address is an internal address *

chainId string code of blockchain
address string an address of blockchain

func (*API) AddressLegal

func (a *API) AddressLegal(chainId string, address string) (*Result[AddressLegal], error)

AddressLegal Check the legality of the address format *

chainId string code of blockchain
address string an address of blockchain

func (*API) ListCoins

func (a *API) ListCoins() (*Result[ProjectCoins], error)

ListCoins currencies supported by the project

func (*API) Payout

func (a *API) Payout(address, currency, amount, thirdPartyId, callbackUrl, remark string) (*Result[Payout], error)

Payout send tx of withdraw *

address string an address of tx toAddress
currency string coin flag,like this format 195@195
amount string value of tx
thirdPartyId string the business number of user,it is used to callbackUrl
callbackUrl string set url to receive server event
remark string to use other input data

func (*API) PayoutQuery

func (a *API) PayoutQuery(cid int64) (*Result[PayoutQuery], error)

PayoutQuery query order of withdrawal tx *

cid int64 orderId

type AddressInner

type AddressInner struct {
	/**
	 * 地址是否合法
	 */
	Result bool `json:"result"`
}

type AddressLegal

type AddressLegal struct {
	/**
	 * 地址是否合法
	 */
	Result bool `json:"result"`
}

type CregisClientInterface

type CregisClientInterface interface {
	//AddressLegal
	/**
	 * 检测地址合法性
	 *
	 * @param chainId 链编号
	 * @param address 地址
	 * @return 结果
	 */
	AddressLegal(chainId string, address string) (*Result[AddressLegal], error)

	//AddressInner
	/**
	 * 检测地址在项目中是否存在
	 *
	 * @param chainId 链编号
	 * @param address 地址
	 * @return 结果
	 */
	AddressInner(chainId, address string) (*Result[AddressInner], error)

	//ListCoins
	/**
	 * 获取支持的币种
	 * @return 币种列表
	 */
	ListCoins() (*Result[ProjectCoins], error)

	//Payout
	/**
	 * 发送提币申请
	 *
	 * @param address      提币地址
	 * @param currency 币种信息
	 *                 规则参考 <a href="https://app.apifox.com/link/project/2923699/apis/doc-2804947">https://app.apifox.com/link/project/2923699/apis/doc-2804947</a>
	 * @param amount       金额
	 * @param thirdPartyId 业务编号
	 * @param callbackUrl  回调地址
	 * @param remark 备注
	 * @return 提币结果
	 */
	Payout(address, currency, amount, thirdPartyId, callbackUrl, remark string) (*Result[Payout], error)

	//PayoutQuery
	/**
	 * 提币申请查看
	 * @param cid 业务编号
	 * @return 申请详细信息
	 */
	PayoutQuery(cid int64) (*Result[PayoutQuery], error)

	//AddressCreate
	/**
	 * 生成地址
	 * @param mainCoinType 主币编号
	 * @param callbackUrl 回调地址
	 * @param alias 地址别名
	 * @return 地址信息
	 */
	AddressCreate(chainId, callbackUrl, alias string) (*Result[ProjectAddress], error)
}

type Payout

type Payout struct {
	/**
	 * 转出订单编号
	 */
	Cid int64 `json:"cid"`
}

type PayoutQuery

type PayoutQuery struct {
	/**
	 * 项目编号
	 */
	Pid int64 `json:"pid"`
	/**
	 * 地址
	 */
	Address string `json:"address"`
	/**
	 * 链编号
	 */
	ChainId string `json:"chain_id"`
	/**
	 * 代币编号
	 */
	TokenId string `json:"token_id"`
	/**
	 * 币种标识
	 */
	Currency string `json:"currency"`
	/**
	 * 金额
	 */
	Amount string `json:"amount"`
	/**
	 * 调用方业务编号
	 */
	ThirdPartyId string `json:"third_party_id"`
	/**
	 * 备注
	 */
	Remark string `json:"remark"`
	/**
	 * 状态
	 */
	Status int `json:"status"`
	/**
	 * 交易哈希
	 */
	TxId string `json:"txid"`
	/**
	 * 区块高度
	 */
	BlockHeight string `json:"block_height"`
	/**
	 * 区块时间
	 */
	BlockTime string `json:"block_time"`
}

type ProjectAddress

type ProjectAddress struct {
	Address string `json:"address"`
}

type ProjectCoin

type ProjectCoin struct {
	CoinName string `json:"coin_name"`
	ChainId  string `json:"chain_id"`
	TokenId  string `json:"token_id"`
}

type ProjectCoins

type ProjectCoins struct {
	PayoutCoins  []*ProjectCoin `json:"payout_coins"`
	AddressCoins []*ProjectCoin `json:"address_coins"`
	OrderCoins   []*ProjectCoin `json:"order_coins"`
}

type Result

type Result[T any] struct {
	Code string `json:"code"`
	Msg  string `json:"msg"`
	Data T      `json:"data"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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