blockchain

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Jan 9, 2020 License: MIT Imports: 15 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// Big0 zero in big.Int
	Big0 = big.NewInt(0)

	// BigMax max big.Int
	BigMax = big.NewInt(10).Exp(big.NewInt(10), big.NewInt(33), nil)
)

Functions

func BuildCompactBulk added in v0.1.1

func BuildCompactBulk(newBuys, newSells map[ethereum.Address]byte, indices map[string]tbindex) ([][14]byte, [][14]byte, []*big.Int, error)

BuildCompactBulk build bulk compact rate

Types

type Blockchain

type Blockchain struct {
	*blockchain.BaseBlockchain
	// contains filtered or unexported fields
}

Blockchain object to interact with blockchain in reserve core

func NewBlockchain

func NewBlockchain(base *blockchain.BaseBlockchain, setting Setting) (*Blockchain, error)

NewBlockchain return new blockchain object

func (*Blockchain) CheckTokenIndices added in v0.1.1

func (b *Blockchain) CheckTokenIndices(tokenAddr ethereum.Address) error

CheckTokenIndices check token indices

func (*Blockchain) FetchBalanceData

func (b *Blockchain) FetchBalanceData(reserve ethereum.Address, atBlock uint64) (map[string]common.BalanceEntry, error)

FetchBalanceData return reserve balance at a block

func (*Blockchain) FetchRates

func (b *Blockchain) FetchRates(atBlock uint64, currentBlock uint64) (common.AllRateEntry, error)

FetchRates return all token rates

func (*Blockchain) GeneratedGetBalances added in v0.1.1

func (b *Blockchain) GeneratedGetBalances(opts blockchain.CallOpts, reserve ethereum.Address, tokens []ethereum.Address) ([]*big.Int, error)

func (*Blockchain) GeneratedGetListedTokens added in v0.1.2

func (b *Blockchain) GeneratedGetListedTokens(opts blockchain.CallOpts) ([]ethereum.Address, error)

GeneratedGetListedTokens call getListedToken function in pricing contract

func (*Blockchain) GeneratedGetRate added in v0.1.1

func (b *Blockchain) GeneratedGetRate(opts blockchain.CallOpts, token ethereum.Address, currentBlockNumber *big.Int, buy bool, qty *big.Int) (*big.Int, error)

GeneratedGetRate call get rate function from pricing contract

func (*Blockchain) GeneratedGetTokenIndicies added in v0.1.1

func (b *Blockchain) GeneratedGetTokenIndicies(opts blockchain.CallOpts, ratesContract ethereum.Address, tokenList []ethereum.Address) ([]*big.Int, []*big.Int, error)

func (*Blockchain) GeneratedGetTokenRates added in v0.1.1

func (b *Blockchain) GeneratedGetTokenRates(
	opts blockchain.CallOpts,
	ratesContract ethereum.Address,
	tokenList []ethereum.Address) ([]*big.Int, []*big.Int, []int8, []int8, []*big.Int, error)

func (*Blockchain) GeneratedSetBaseRate added in v0.1.1

func (b *Blockchain) GeneratedSetBaseRate(opts blockchain.TxOpts, tokens []ethereum.Address, baseBuy []*big.Int, baseSell []*big.Int, buy [][14]byte, sell [][14]byte, blockNumber *big.Int, indices []*big.Int) (*types.Transaction, error)

GeneratedSetBaseRate build tx for set base rate function

func (*Blockchain) GeneratedSetCompactData added in v0.1.1

func (b *Blockchain) GeneratedSetCompactData(opts blockchain.TxOpts, buy [][14]byte, sell [][14]byte, blockNumber *big.Int, indices []*big.Int) (*types.Transaction, error)

GeneratedSetCompactData build tx for set compact data function

func (*Blockchain) GeneratedWithdraw added in v0.1.1

func (b *Blockchain) GeneratedWithdraw(opts blockchain.TxOpts, token ethereum.Address, amount *big.Int, destination ethereum.Address) (*types.Transaction, error)

func (*Blockchain) GetDepositOPAddress added in v0.1.1

func (b *Blockchain) GetDepositOPAddress() ethereum.Address

GetDepositOPAddress return deposit operator address

func (*Blockchain) GetIntermediatorOPAddress added in v0.1.1

func (b *Blockchain) GetIntermediatorOPAddress() ethereum.Address

GetIntermediatorOPAddress return intermediator operator address

func (*Blockchain) GetPrice added in v0.1.1

func (b *Blockchain) GetPrice(token ethereum.Address, block *big.Int, priceType string, qty *big.Int, atBlock uint64) (*big.Int, error)

GetPrice return token rate

func (*Blockchain) GetPricingOPAddress added in v0.1.1

func (b *Blockchain) GetPricingOPAddress() ethereum.Address

GetPricingOPAddress return pricing operator address

func (*Blockchain) ListedTokens added in v0.1.2

func (b *Blockchain) ListedTokens() []ethereum.Address

ListedTokens return listed tokens

func (*Blockchain) LoadAndSetTokenIndices added in v0.1.1

func (b *Blockchain) LoadAndSetTokenIndices() error

LoadAndSetTokenIndices load and set token indices

func (*Blockchain) RegisterDepositOperator added in v0.1.1

func (b *Blockchain) RegisterDepositOperator(signer blockchain.Signer, nonceCorpus blockchain.NonceCorpus)

RegisterDepositOperator register operator

func (*Blockchain) RegisterPricingOperator added in v0.1.1

func (b *Blockchain) RegisterPricingOperator(signer blockchain.Signer, nonceCorpus blockchain.NonceCorpus)

RegisterPricingOperator register pricing operator

func (*Blockchain) Send

func (b *Blockchain) Send(
	token common.Token,
	amount *big.Int,
	dest ethereum.Address) (*types.Transaction, error)

Send request to blockchain

func (*Blockchain) SetRateMinedNonce added in v0.1.1

func (b *Blockchain) SetRateMinedNonce() (uint64, error)

SetRateMinedNonce returns nonce of the pricing operator in confirmed state (not pending state).

Getting mined nonce is not simple because there might be lag between node leading us to get outdated mined nonce from an unsynced node. To overcome this situation, we will keep a local nonce and require the nonce from node to be equal or greater than it. If the nonce from node is smaller than the local one, we will use the local one. However, if the local one stay with the same value for more than 15 mins, the local one is considered incorrect because the chain might be reorganized so we will invalidate it and assign it to the nonce from node.

func (*Blockchain) SetRates

func (b *Blockchain) SetRates(
	tokens []ethereum.Address,
	buys []*big.Int,
	sells []*big.Int,
	block *big.Int,
	nonce *big.Int,
	gasPrice *big.Int) (*types.Transaction, error)

SetRates set token rates we got a bug when compact is not set to old compact or when one of buy/sell got overflowed, it discards the other's compact TODO: Need better test coverage

func (*Blockchain) StandardGasPrice added in v0.1.1

func (b *Blockchain) StandardGasPrice() float64

StandardGasPrice return standard gas price

type CompactRate added in v0.1.1

type CompactRate struct {
	Base    *big.Int
	Compact byte
}

func BigIntToCompactRate added in v0.1.1

func BigIntToCompactRate(rate *big.Int, base *big.Int) (compactrate *CompactRate, overflow bool)

Convert rate to compact rate with preferred base if it is impossible to use preferred base because Compact doesnt fit 8bits, the base is changed to the rate, Compact is set to 0 and return overflow = true

type Setting added in v0.1.1

type Setting interface {
	GetInternalTokens() ([]common.Token, error)
	ETHToken() common.Token
	GetAddress(settings.AddressName) (ethereum.Address, error)
}

Setting interface for blockchain package

Jump to

Keyboard shortcuts

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