base

package
v0.2.6 Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2022 License: MIT Imports: 4 Imported by: 13

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrUnsupportedFunction = errors.New("This chain does not support this feature.")
)

Functions

func CatchPanicAndMapToBasicError

func CatchPanicAndMapToBasicError(errOfResult *error)

[zh] 该方法会捕捉 panic 抛出的值,并转成一个 error 对象通过参数指针返回 * 注意: 如果想要返回它抓住的 error, 必须使用命名返回值!! * [en] This method will catch the value thrown by panic, and turn it into an error object and return it through the parameter pointer * Note: If you want to return the error it caught, you must use a named return value! ! * ``` * func actionWillThrowError(parameters...) (namedErr error, other...) { * defer CatchPanicAndMapToBasicError(&namedErr) * // action code ... * return namedErr, other... * } * ```

func MapAnyToBasicError

func MapAnyToBasicError(e any) error

func MapListConcurrent

func MapListConcurrent(list []interface{}, limit int, maper func(interface{}) (interface{}, error)) ([]interface{}, error)

This method will traverse the array concurrently and map each object in the array. @param list: [TYPE1], a list that all item is TYPE1 @param limit: maximum number of tasks to execute, 0 means no limit @param maper: func(TYPE1) (TYPE2, error), a function that input TYPE1, return TYPE2

you can throw an error to finish task.

@return : [TYPE2], a list that all item is TYPE2 @example : ```

nums := []interface{}{1, 2, 3, 4, 5, 6}
res, _ := MapListConcurrent(nums, func(i interface{}) (interface{}, error) {
    return strconv.Itoa(i.(int) * 100), nil
})
println(res) // ["100" "200" "300" "400" "500" "600"]

```

func MapListConcurrentStringToString

func MapListConcurrentStringToString(strList []string, maper func(string) (string, error)) ([]string, error)

The encapsulation of MapListConcurrent.

func MaxBigInt

func MaxBigInt(x, y *big.Int) *big.Int

Return the more biger of the two numbers

Types

type Account

type Account interface {
	// @return privateKey data
	PrivateKey() ([]byte, error)
	// @return privateKey string that will start with 0x.
	PrivateKeyHex() (string, error)

	// @return publicKey data
	PublicKey() []byte
	// @return publicKey string that will start with 0x.
	PublicKeyHex() string

	// @return address string
	Address() string

	Sign(message []byte, password string) ([]byte, error)
	SignHex(messageHex string, password string) (*OptionalString, error)
}

type AddressUtil

type AddressUtil interface {
	// @param publicKey can start with 0x or not.
	EncodePublicKeyToAddress(publicKey string) (string, error)
	// @return publicKey that will start with 0x.
	DecodeAddressToPublicKey(address string) (string, error)

	IsValidAddress(address string) bool
}

type Balance

type Balance struct {
	Total  string
	Usable string
}

func EmptyBalance

func EmptyBalance() *Balance

type Chain

type Chain interface {
	MainToken() Token

	BalanceOfAddress(address string) (*Balance, error)
	BalanceOfPublicKey(publicKey string) (*Balance, error)
	BalanceOfAccount(account Account) (*Balance, error)

	// Send the raw transaction on-chain
	// @return the hex hash string
	SendRawTransaction(signedTx string) (string, error)

	// Fetch transaction details through transaction hash
	FetchTransactionDetail(hash string) (*TransactionDetail, error)

	// Fetch transaction status through transaction hash
	FetchTransactionStatus(hash string) TransactionStatus

	// Batch fetch the transaction status, the hash list and the return value,
	// which can only be passed as strings separated by ","
	// @param hashListString The hash of the transactions to be queried in batches, a string concatenated with ",": "hash1,hash2,hash3"
	// @return Batch transaction status, its order is consistent with hashListString: "status1,status2,status3"
	BatchFetchTransactionStatus(hashListString string) string
}

type OptionalBool added in v0.2.3

type OptionalBool struct {
	Value bool
}

Optional bool for easy of writing iOS code

type OptionalString added in v0.2.3

type OptionalString struct {
	Value string
}

Optional string for easy of writing iOS code

type SDKEnumInt

type SDKEnumInt = int

type SDKEnumString

type SDKEnumString = string

type Token

type Token interface {
	Chain() Chain

	TokenInfo() (*TokenInfo, error)

	BalanceOfAddress(address string) (*Balance, error)
	BalanceOfPublicKey(publicKey string) (*Balance, error)
	BalanceOfAccount(account Account) (*Balance, error)
}

type TokenInfo

type TokenInfo struct {
	Name    string
	Symbol  string
	Decimal int16
}

type Transaction

type Transaction struct {
}

type TransactionDetail

type TransactionDetail struct {
	// hash string on chain
	HashString string

	// transaction amount
	Amount string

	EstimateFees string

	// sender's address
	FromAddress string
	// receiver's address
	ToAddress string

	Status TransactionStatus
	// transaction completion timestamp (s), 0 if Status is in Pending
	FinishTimestamp int64
	// failure message
	FailureMessage string
}

Transaction details that can be fetched from the chain

type TransactionStatus

type TransactionStatus = SDKEnumInt
const (
	TransactionStatusNone    TransactionStatus = 0
	TransactionStatusPending TransactionStatus = 1
	TransactionStatusSuccess TransactionStatus = 2
	TransactionStatusFailure TransactionStatus = 3
)

Jump to

Keyboard shortcuts

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