sdk

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Dec 23, 2020 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	UnknownTransactionHashErr     = errors.New("unknown transaction hash")
	UnconfirmedTransactionErr     = errors.New("transaction does not have enough block confirmation")
	InsufficientBalanceErr        = errors.New("account does not have enough balance")
	InsufficientGasErr            = errors.New("insufficient gas for transaction")
	InsufficientTransactionFeeErr = errors.New("transaction fee is not enough to cover gas * gas price")
	InvalidDepositErr             = errors.New("transaction fee deposit is invalid")
)
View Source
var (
	UnimplementedError     = errors.New("unimplemented")
	NoPrivateKeyError      = errors.New("no private key is provided")
	InvalidPrivateKeyError = errors.New("invalid private key")
	InvalidAddressError    = errors.New("invalid Ethereum address")
)
View Source
var ConfirmationRequirement = 0
View Source
var PredefinedAccounts = make([]*Account, len(PredefinedPrivateKeys))
View Source
var PredefinedPrivateKeys = []string{
	"0x4f3edf983ac636a65a842ce7c78d9aa706d3b113bce9c46f30d7d21715b23b1d",
	"0x6cbed15c793ce57650b9877cf6fa156fbef513c4e6134f022a85b1ffdd59b2a1",
	"0x6370fd033278c143179d81c5526140625662b8daa446c22ee2d73db3707e620c",
	"0x646f1ce2fdad0e6deeeb5c7e8e5543bdde65e86029e2fd9fc169899c440a7913",
	"0xadd53f9a7e588d003326d1cbf9e4a43c061aadd9bc938c843a79e7b4fd2ad743",
	"0x395df67f0c2d2d9fe1ad08d1bc8b6627011959b79c53d7dd6a3536a33ab8a4fd",
	"0xe485d098507f54e7733a205420dfddbe58db035fa577fc294ebd14db90767a52",
	"0xa453611d9419d0e56f499079478fd72c37b251a94bfde4d19872c44cf65386e3",
	"0x829e924fdf021ba3dbbc4225edfece9aca04b929d6e75613329ca6f1d31c0bb4",
	"0xb0057716d5917badaf911b193b12b910811c1497b5bada8d7711f758981c3773",
}

Functions

func GenerateEthAccount

func GenerateEthAccount() (address string, privateKey string, err error)

* Generate a ethereum Account. If any error happens inside, the third return value, err, will be non-nil. Otherwise err will be nil, with the first and second return value being Address and privateKey of the generated Account.

func NewProvider added in v0.0.3

func NewProvider(backend Backend) *provider

func Version added in v0.0.8

func Version() struct {
	VersionStr string
	VersionNum int
}

func VersionNum added in v0.0.8

func VersionNum() int

func VersionStr added in v0.0.8

func VersionStr() string

Types

type Account added in v0.0.3

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

func (*Account) Address added in v0.0.3

func (acc *Account) Address() Address

func (*Account) PrivateKey added in v0.0.3

func (acc *Account) PrivateKey() string

type Address added in v0.0.3

type Address string

func (Address) IsValid added in v0.0.3

func (addr Address) IsValid() bool

type Backend added in v0.0.3

type Backend interface {
	bind.ContractBackend
	ethereum.ChainReader
	ethereum.ChainStateReader
	ethereum.TransactionReader
	NetworkID(ctx context.Context) (*big.Int, error)
}

type Hash added in v0.0.3

type Hash string

type Manager added in v0.0.3

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

func NewManager added in v0.0.3

func NewManager(backend Backend, managerAddress Address) (manager *Manager, err error)

* Create a new TFC instance by providing the sdk object and the Address of TFC ERC20 contract

func (*Manager) ClaimTFC added in v0.0.3

func (manager *Manager) ClaimTFC(ctx context.Context, amount *big.Int, nonce *big.Int, signature string, claimer *Account) (doneCh chan interface{}, errCh chan error)

func (*Manager) ClaimTFCSync added in v0.0.3

func (manager *Manager) ClaimTFCSync(ctx context.Context, amount *big.Int, nonce *big.Int, signature string, claimer *Account) (err error)

func (*Manager) GetUnusedNonce added in v0.0.3

func (manager *Manager) GetUnusedNonce() (nonce *big.Int, err error)

func (*Manager) IsNonceUsed added in v0.0.3

func (manager *Manager) IsNonceUsed(nonce *big.Int) (used bool, err error)

func (*Manager) SignTFCClaim added in v0.0.3

func (manager *Manager) SignTFCClaim(recipient Address, amount *big.Int, nonce *big.Int, signer *Account) (signature string, err error)

func (*Manager) Signer added in v0.0.3

func (manager *Manager) Signer() (signerAddress Address, err error)

func (*Manager) TFCAddress added in v0.0.3

func (manager *Manager) TFCAddress() (tfcAddress Address, err error)

* Returns the name of the token, i.e. TFCToken

func (*Manager) UntilClaimTFCComplete added in v0.0.5

func (manager *Manager) UntilClaimTFCComplete(ctx context.Context, recipient Address, amount *big.Int, nonce *big.Int, confirmationRequirement int) (doneCh chan interface{}, errCh chan error)

type MockBackend added in v0.0.3

type MockBackend struct {
	*backends.SimulatedBackend
	// contains filtered or unexported fields
}

func NewMockBackend added in v0.0.3

func NewMockBackend() *MockBackend

func (*MockBackend) NetworkID added in v0.1.0

func (b *MockBackend) NetworkID(ctx context.Context) (*big.Int, error)

func (*MockBackend) SendTransaction added in v0.0.3

func (b *MockBackend) SendTransaction(ctx context.Context, tx *types.Transaction) error

func (*MockBackend) SubscribeNewTransaction added in v0.0.3

func (b *MockBackend) SubscribeNewTransaction(ch chan *types.Transaction) event.Subscription

type MockEthereum added in v0.0.3

type MockEthereum struct {
	Backend *MockBackend
	// contains filtered or unexported fields
}

func NewMockEthereum added in v0.0.3

func NewMockEthereum() *MockEthereum

func (*MockEthereum) Start added in v0.0.3

func (eth *MockEthereum) Start()

func (*MockEthereum) Stop added in v0.0.3

func (eth *MockEthereum) Stop()

type SDK

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

func NewSDK

func NewSDK(blockchainEndpoint string) (sdk *SDK, error error)

NewSDK creates a new SDK instance with connection to Backend endpoint

func NewSDKWithBackend added in v0.0.3

func NewSDKWithBackend(backend Backend) (sdk *SDK)

func (SDK) AsyncTransaction added in v0.0.3

func (p SDK) AsyncTransaction(ctx context.Context, txHash common.Hash, confirmationNumber int) (receiptCh chan *types.Receipt, errCh chan error)

func (*SDK) CreateAccount added in v0.0.3

func (sdk *SDK) CreateAccount() (account *Account)

func (*SDK) DefaultAccount added in v0.0.2

func (sdk *SDK) DefaultAccount() *Account

* DefaultAccount returns the current default Account in sdk (can be set via SetDefaultAccount())

func (*SDK) DeployManager added in v0.0.3

func (sdk *SDK) DeployManager(ctx context.Context, deployer *Account) (managerAddressCh chan Address, errCh chan error)

func (*SDK) DeployManagerSync added in v0.0.3

func (sdk *SDK) DeployManagerSync(ctx context.Context, deployer *Account) (managerAddress Address, err error)

func (*SDK) DeployTFC added in v0.0.3

func (sdk *SDK) DeployTFC(ctx context.Context, deployer *Account) (tfcAddressCh chan Address, errCh chan error)

func (*SDK) DeployTFCSync added in v0.0.3

func (sdk *SDK) DeployTFCSync(ctx context.Context, deployer *Account) (tfcAddress Address, err error)

func (*SDK) Manager added in v0.0.3

func (sdk *SDK) Manager(managerAddress Address) (manager *Manager, err error)

func (*SDK) RetrieveAccount added in v0.0.3

func (sdk *SDK) RetrieveAccount(privateKey string) (account *Account, err error)

func (*SDK) SetDefaultAccount added in v0.0.2

func (sdk *SDK) SetDefaultAccount(privateKey string) (err error)

setDefaultAccount sets the default Account to sign ethereum transactions by providing its privateKey

func (*SDK) TFC added in v0.0.3

func (sdk *SDK) TFC(tfcAddress Address) (tfc *TFC, err error)

* Creates a new TFC instance based on current sdk. This function is a wrapper of NewTFC()

func (*SDK) Version added in v0.0.8

func (sdk *SDK) Version() struct {
	VersionStr string
	VersionNum int
}

type TFC

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

func NewTFC

func NewTFC(backend Backend, tfcAddress Address) (tfc *TFC, err error)

* Create a new TFC instance by providing the sdk object and the Address of TFC ERC20 contract

func (*TFC) Allowance

func (tfc *TFC) Allowance(owner Address, spender Address) (amount *big.Int, err error)

* Returns the amount which spender is still allowed to withdraw from owner.

func (*TFC) Approve

func (tfc *TFC) Approve(ctx context.Context, spender Address, amount *big.Int, sender *Account) (doneCh chan interface{}, errCh chan error)

* Allows spender to withdraw from the current Account (specified in SDK) multiple times, up to the given amount.

This function requires privateKey has been set in SDK.

func (TFC) AsyncTransaction added in v0.0.3

func (p TFC) AsyncTransaction(ctx context.Context, txHash common.Hash, confirmationNumber int) (receiptCh chan *types.Receipt, errCh chan error)

func (*TFC) BalanceOf

func (tfc *TFC) BalanceOf(address Address) (balance *big.Int, err error)

* Returns the Account balance with the provided Address.

func (*TFC) BridgeTFCExchange added in v0.1.0

func (tfc *TFC) BridgeTFCExchange(ctx context.Context, depositTransactionHash string, amount *big.Int, minter *Account, depositTransactionConfirmationRequirement int) (recipient Address, transactionHashErr error, doneCh chan interface{}, errCh chan error)

func (*TFC) BridgeTFCExchangeAsync added in v0.1.2

func (tfc *TFC) BridgeTFCExchangeAsync(ctx context.Context, depositTransactionHash string, amount *big.Int, minter *Account, depositTransactionConfirmationRequirement int) (recipient Address, mintTransactionHash string, err error)

func (*TFC) CheckTransactionFeeDeposit added in v0.2.0

func (tfc *TFC) CheckTransactionFeeDeposit(ctx context.Context, depositTransactionHash string, bridgeAccountAddress Address, depositTransactionConfirmationRequirement int) (recipient Address, depositAmount *big.Int, err error)

func (*TFC) Decimals

func (tfc *TFC) Decimals() (decimals uint8, err error)

* Returns the number of decimals the token uses - e.g. 8, means to divide the token amount by 100000000 to get its user representation.

func (*TFC) EstimateTFCExchangeFee added in v0.2.0

func (tfc *TFC) EstimateTFCExchangeFee(ctx context.Context, recipient Address, amount *big.Int, bridgeAccount *Account, minGas uint64, transactionFeeRate float64) (requiredTransferAmount *big.Int, estimatedGas uint64, gasPrice *big.Int, err error)

func (*TFC) Mint

func (tfc *TFC) Mint(ctx context.Context, to Address, amount *big.Int, sender *Account) (doneCh chan interface{}, errCh chan error)

* Generate the amount of tokens and put them in the balance of the given "to" Account. This function can only be called by Account (specified in SDK) which has MINTER_ROLE of smart contract.

This function requires privateKey has been set in SDK.

func (*TFC) MintSync added in v0.0.4

func (tfc *TFC) MintSync(ctx context.Context, to Address, amount *big.Int, sender *Account) (err error)

func (*TFC) Name

func (tfc *TFC) Name() (name string, err error)

* Returns the name of the token, i.e. TFCToken

func (*TFC) SendMintTransaction added in v0.2.0

func (tfc *TFC) SendMintTransaction(ctx context.Context, recipient Address, amount *big.Int, minter *Account, depositAmount *big.Int, estimatedGas uint64, gasPrice *big.Int, transactionFeeRate float64) (mintTransactionHash string, err error)

func (*TFC) Symbol

func (tfc *TFC) Symbol() (symbol string, err error)

* Returns the symbol of the token, i.e. TFC

func (*TFC) TotalSupply

func (tfc *TFC) TotalSupply() (totalSupply *big.Int, err error)

* Returns the total token supply.

func (*TFC) Transfer

func (tfc *TFC) Transfer(ctx context.Context, to Address, amount *big.Int, sender *Account) (doneCh chan interface{}, errCh chan error)

* Transfer the amount of balance from current Account (specified in SDK) to the given "to" Account.

This function requires privateKey has been set in SDK.

func (*TFC) TransferFrom

func (tfc *TFC) TransferFrom(ctx context.Context, from Address, to string, amount *big.Int, sender *Account) (doneCh chan interface{}, errCh chan error)

* Transfer the amount of balance from the given "from" Account to the given "to" Account.

This function requires privateKey has been set in SDK, which will be used to sign the ethereum transaction.

func (*TFC) TransferSync added in v0.0.3

func (tfc *TFC) TransferSync(ctx context.Context, to Address, amount *big.Int, sender *Account) (err error)

func (*TFC) UntilBridgeTFCExchangeComplete added in v0.1.2

func (tfc *TFC) UntilBridgeTFCExchangeComplete(ctx context.Context, mintTransactionHash string, confirmationRequirement int) (doneCh chan interface{}, errCh chan error)

Jump to

Keyboard shortcuts

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