core

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Dec 17, 2018 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ETHToken = Token{
	ID:       "ETH",
	Name:     "Ethereum",
	Address:  "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee",
	Decimals: 18,
}

ETHToken is the configuration of Ethereum, will never be changed.

Functions

func NewCliFlags

func NewCliFlags() []cli.Flag

NewCliFlags returns cli flags to configure a core client.

Types

type CachedClient

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

CachedClient is the wrapper of Core Client with caching ability.

func NewCachedClient

func NewCachedClient(client *Client) *CachedClient

NewCachedClient creates a new core client instance.

func (*CachedClient) FromWei

func (cc *CachedClient) FromWei(address common.Address, amount *big.Int) (float64, error)

FromWei formats the given amount in wei to human friendly number with preconfigured token decimals.

func (*CachedClient) ToWei

func (cc *CachedClient) ToWei(address common.Address, amount float64) (*big.Int, error)

ToWei return the given human friendly number to wei unit.

func (*CachedClient) Tokens

func (cc *CachedClient) Tokens() ([]Token, error)

Tokens purges the current cached tokens and fetching from Core server.

type Client

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

Client is the the real implementation of core client interface.

func NewClient

func NewClient(sugar *zap.SugaredLogger, url, signingKey string) (*Client, error)

NewClient creates a new core client instance.

func NewClientFromContext

func NewClientFromContext(sugar *zap.SugaredLogger, c *cli.Context) (*Client, error)

NewClientFromContext returns new core client from cli flags.

func (*Client) FromWei

func (c *Client) FromWei(address common.Address, amount *big.Int) (float64, error)

FromWei formats the given amount in wei to human friendly number with preconfigured token decimals.

func (*Client) GetActiveTokens

func (c *Client) GetActiveTokens() ([]Token, error)

GetActiveTokens return list of active token from external reserve

func (*Client) GetInternalTokens

func (c *Client) GetInternalTokens() ([]Token, error)

GetInternalTokens return list of internal token from Kyber reserve

func (*Client) ToWei

func (c *Client) ToWei(address common.Address, amount float64) (*big.Int, error)

ToWei return the given human friendly number to wei unit.

func (*Client) Tokens

func (c *Client) Tokens() ([]Token, error)

Tokens returns all configured tokens. Example response JSON:

{
 "data": {
   "tokens": {
     "tokens": [
       {
         "id": "ABT",
         "name": "ArcBlock",
         "address": "0xb98d4c97425d9908e66e53a6fdf673acca0be986",
         "decimals": 18,
         "active": true,
         "internal": true,
         "last_activation_change": 1535021910190
       },
       {
         "id": "ADX",
         "name": "AdEx",
         "address": "0x4470BB87d77b963A013DB939BE332f927f2b992e",
         "decimals": 4,
         "active": true,
         "internal": false,
         "last_activation_change": 1535021910195
       }
     ]
   }
 }
}

type Interface

type Interface interface {
	Tokens() ([]Token, error)
	FromWei(common.Address, *big.Int) (float64, error)
	ToWei(common.Address, float64) (*big.Int, error)
}

Interface represents a client o interact with KyberNetwork core APIs.

type MockClient

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

MockClient is a simple mock client sending mock token from Core

func NewMockClient

func NewMockClient() *MockClient

NewMockClient creates a new instance of MockClient, that implements core.Interface, intended to use in tests.

func (*MockClient) FromWei

func (mc *MockClient) FromWei(_ common.Address, _ *big.Int) (float64, error)

FromWei formats the given amount in wei to human friendly number with preconfigured token decimals.

func (*MockClient) GetActiveTokens

func (mc *MockClient) GetActiveTokens() ([]Token, error)

GetActiveTokens return list of Active Tokens from core

func (*MockClient) GetInternalTokens

func (mc *MockClient) GetInternalTokens() ([]Token, error)

GetInternalTokens returns list of Internal Token from core

func (*MockClient) ToWei

func (mc *MockClient) ToWei(_ common.Address, _ float64) (*big.Int, error)

ToWei return the given human friendly number to wei unit.

func (*MockClient) Tokens

func (mc *MockClient) Tokens() ([]Token, error)

Tokens returns all tokens of MockClient.

type Token

type Token struct {
	ID       string `json:"id"`
	Name     string `json:"name"`
	Address  string `json:"address"`
	Decimals int64  `json:"decimals"`
}

Token is a ERC20 token allowed to trade in core. Note: all fields below are valid, uncomment when needed.

func LookupToken

func LookupToken(client Interface, ID string) (Token, error)

LookupToken returns the token with given id from results of Tokens of given core client.

func (*Token) FromWei

func (t *Token) FromWei(amount *big.Int) float64

FromWei converts the given amount in Wei with following formatting rule.

  • Decimals: 3 FromWei(1100) = 1.1
  • Decimals: 2 FromWei(1100) = 11
  • Decimals: 5 FromWei(1100) = 0.11

func (*Token) ToWei

func (t *Token) ToWei(amount float64) *big.Int

ToWei return the given human friendly number to wei unit.

Jump to

Keyboard shortcuts

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