common

package
v0.0.0-...-f9b7526 Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2021 License: MIT Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CfxURLMainNet      = "http://mainnet-jsonrpc.conflux-chain.org:12537"
	MatchflowURLTest   = "https://dev.matchflow.io"
	ShuttleflowURLTest = "https://dev.shuttleflow.io"

	ZeroAddress = "0x0000000000000000000000000000000000000000"

	EventHashTransfer = "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef"
	EventHashDeposit  = "0x5548c837ab068cf56a2c2479df0882a4922fd203edb7517321831d95078c5f62"
	EventHashWithdraw = "0x9b1bfa7fa9ee420a16e124f794c35ac9f90472acc99140eb2f6447c714cad8eb"
	EventHashWrite    = "0x3802ba8117dc6bf5de2a857e440679e83bb0f9b68094ede7167234a5f97319ed"
)

Public constants in Conflux or DEX.

View Source
const (
	// FcABI FC ABI
	FcABI = "./common/build/FC.abi"
	// CrclABI CRC-L ABI
	CrclABI = "./common/build/CRCL.abi"
	// Erc777ABI ERC777 ABI
	Erc777ABI = "./common/build/ERC777.abi"
	// BoomflowABI Boomflow ABI
	BoomflowABI = "./common/build/Boomflow.abi"
	// CustodianABI Custodian Core ABI
	CustodianABI = "./common/build/CustodianCore.abi"
	// Create2ABI Create2Factory ABI
	Create2ABI = "./common/build/Create2Factory.abi"
	// Erc20ABI ERC20 ABI
	Erc20ABI = "./common/build/ERC20.abi"
	// EthFactoryABI EthFactory ABI
	EthFactoryABI = "./common/build/EthFactory.abi"
)

Variables

View Source
var (
	Big0 = big.NewInt(0)
	Big1 = big.NewInt(1)
)

Common values often used

View Source
var AesSecret = "123456789abcfake"

AesSecret the password of aes encrypt

View Source
var CustodianAddress = ""

CustodianAddress is the machine address where custodian node running on

View Source
var DexAdmin = "0x0000000000000000000000000000000000000000"

DexAdmin is the conflux address of admin of dex

View Source
var DexAdminPrivKey = ""

DexAdminPrivKey the private key of dex admin

View Source
var DingDingAccessToken string

DingDingAccessToken is the access token to send message to Dingding.

View Source
var MatchflowURL = ""

MatchflowURL is the url of matchflow rest api

View Source
var NumEpochsConfirmed *big.Int = big.NewInt(10)

NumEpochsConfirmed is the number of epochs before latest state that treated as confirmed.

Functions

func AesDecrypt

func AesDecrypt(cryted string, key string) string

AesDecrypt aes decrypt

func AesEncrypt

func AesEncrypt(orig string, key string) string

AesEncrypt aes encrypt

func Alert

func Alert(module, message string)

Alert sends a message of specific module to Dingding.

func AlertMatchflow

func AlertMatchflow()

AlertMatchflow signal a fatal error to DEX.

func AlertShuttleflow

func AlertShuttleflow()

AlertShuttleflow signal a fatal error to DEX.

func Alertf

func Alertf(module, format string, a ...interface{})

Alertf sends a message of specific module to Dingding.

func GetNetworkId

func GetNetworkId() uint32

func InPauseTimeRange

func InPauseTimeRange() bool

InPauseTimeRange check whether current Shanghai time is between 7 a.m. and 11 p.m.

func Mul

func Mul(x, y decimal.Decimal) decimal.Decimal

Mul multiply two decimal and truncate the result to scale 18

func MustNewCfx

func MustNewCfx(cfxURL string) *sdk.Client

MustNewCfx must creates an instance of CFX client.

func NewLogger

func NewLogger(module string, optionalFields ...map[string]interface{}) logrus.FieldLogger

NewLogger creates a new logger with module and optional fields.

func Notify

func Notify(message string)

Notify sends a message to Dingding.

func Notifyf

func Notifyf(format string, a ...interface{})

Notifyf sends a message to Dingding.

func PKCS7Padding

func PKCS7Padding(ciphertext []byte, blocksize int) []byte

PKCS7Padding padding

func PKCS7UnPadding

func PKCS7UnPadding(origData []byte) []byte

PKCS7UnPadding unpadding

Types

type AccountBalances

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

AccountBalances represents a collection of accounts with their balances. Note, the account address is case-insensitive to avoid BIP-155 address.

func NewAccountBalances

func NewAccountBalances() *AccountBalances

NewAccountBalances creates an instance of AccountBalances.

func (*AccountBalances) Add

func (ab *AccountBalances) Add(account string, amount *big.Int)

Add adds a new account with amount as balance if not exists. Otherwise, add amount to the existing balance.

func (*AccountBalances) Get

func (ab *AccountBalances) Get(account string) *big.Int

Get returns the balance of specified account if exists. Otherwise, return zero.

func (AccountBalances) GoString

func (ab AccountBalances) GoString() string

GoString implements the fmt.GoStringer interface.

func (*AccountBalances) Map

func (ab *AccountBalances) Map() map[string]*big.Int

Map returns the underlying account balances data structure. Generally, it is used for iteration purpose, and should never change the data outside of AccountBalances.

func (AccountBalances) String

func (ab AccountBalances) String() string

GoString implements the fmt.Stringer interface.

func (*AccountBalances) Sum

func (ab *AccountBalances) Sum() *big.Int

Sum calculates the sum of balances for all accounts.

type Asset

type Asset struct {
	ID                    int     `json:"id"`
	Name                  string  `json:"name"`
	ContractAddress       string  `json:"contractAddress"`
	TokenAddress          string  `json:"tokenAddress"`
	DecimalDigits         int     `json:"decimalDigits"`
	CrossChain            bool    `json:"crossChain"`
	MinimumWithdrawAmount float64 `json:"minimumWithdrawAmount"`
}

Asset conflux dex currency Auto-generated by https://mholt.github.io/json-to-go/

func GetAssets

func GetAssets(matchflowURL string) []Asset

GetAssets queries and returns the asset list via Matchflow REST API.

type AssetResponse

type AssetResponse struct {
	Success bool   `json:"success"`
	Message string `json:"message"`
	Data    struct {
		Total int     `json:"total"`
		Items []Asset `json:"items"`
	} `json:"data"`
}

AssetResponse conflux DEX currencies

type Balance

type Balance struct {
	ID        int     `json:"id"`
	UserID    int     `json:"userId"`
	Currency  string  `json:"currency"`
	Hold      float64 `json:"hold"`
	Available float64 `json:"available"`
	Status    string  `json:"status"`
	Balance   string  `json:"balanceString"`
}

Balance conflux DEX balance

type BalanceResponse

type BalanceResponse struct {
	Success bool   `json:"success"`
	Message string `json:"message"`
	Data    struct {
		Total int       `json:"total"`
		Items []Balance `json:"items"`
	} `json:"data"`
}

BalanceResponse conflux DEX balances of a user

type Client

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

Client resty client wrapper

func NewClient

func NewClient(url string) *Client

NewClient init

func (*Client) GetAssets

func (c *Client) GetAssets() []Asset

GetAssets gets the all available assets.

func (*Client) GetBalance

func (c *Client) GetBalance(account string) ([]Balance, error)

GetBalance get the balance of the specified account.

type Contract

type Contract struct {
	Contract *sdk.Contract
}

Contract represents an smart contract of Conflux DEX.

func GetContract

func GetContract(client *sdk.Client, abiPath string, address string) *Contract

GetContract creates an instance of contract.

func (*Contract) Address

func (c *Contract) Address() string

Address returns the contract address.

func (*Contract) BalanceOf

func (c *Contract) BalanceOf(account string, epoch ...*types.Epoch) (*big.Int, error)

BalanceOf returns the balance of specified account.

func (*Contract) ListAccounts

func (c *Contract) ListAccounts(offset *big.Int, epoch ...*types.Epoch) ([]string, error)

ListAccounts lists account since specified offset in CRCL.

func (*Contract) ListAllAccounts

func (c *Contract) ListAllAccounts(epoch *types.Epoch) []string

ListAllAccounts lists all accounts in CRCL.

func (*Contract) MintedTx

func (c *Contract) MintedTx(txHash string, epoch ...*types.Epoch) (bool, error)

MintedTx checks if the transaction has been executed with error.

func (*Contract) MintedTxList

func (c *Contract) MintedTxList(index int64, epoch ...*types.Epoch) string

MintedTxList returns the list of all minted transactions.

func (*Contract) MustGetBalanceOf

func (c *Contract) MustGetBalanceOf(account string, epoch ...*types.Epoch) *big.Int

MustGetBalanceOf returns the balance of specified account.

func (*Contract) MustGetMintedTx

func (c *Contract) MustGetMintedTx(txHash string, epoch ...*types.Epoch) bool

MustGetMintedTx checks if the transaction has been executed.

func (*Contract) MustGetTotalSupply

func (c *Contract) MustGetTotalSupply(epoch ...*types.Epoch) *big.Int

MustGetTotalSupply returns the specified total supply of this contract.

func (*Contract) TotalAccount

func (c *Contract) TotalAccount(epoch ...*types.Epoch) (*big.Int, error)

TotalAccount returns total number of accounts in CRCL.

func (*Contract) TotalSupply

func (c *Contract) TotalSupply(epoch ...*types.Epoch) (*big.Int, error)

TotalSupply returns the total supply of this CRCL contract.

type MatchflowConfig

type MatchflowConfig struct {
	FullEpoch    string
	PartialEpoch string
	InitialAudit bool
	DbAddress    string
	DbPass       string
	Pausable     bool
	DexStartTime string
	DbUser       string
}

MatchflowConfig configuration for matchflow auditor

Jump to

Keyboard shortcuts

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